Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot General Programming split pawn codes

 
  • 0 Vote(s) - 0 Average
split pawn codes
redex
Offline

Burgershot Member
Posts: 10
Threads: 5
Joined: May 2021
Reputation: 0
Location: Germany
#1
2021-07-28, 03:46 PM
hi.
i am working on a sa-mp gamemode project, its going to take about +50k code line, i was wondering is there any way to split the code, for exp put the JOBS related codes to another file and include it , so if i need to edit something about jobs i dont need to check hell a lot code lines to fix a problem!

how can i do that? is it good?
can it cause bad effects like lags or some other bad effects to server?
if u know anything please let me know, thanks!
Kwarde
Offline

Burgershot Member
Posts: 99
Threads: 2
Joined: Sep 2020
Reputation: 8
Location: The Netherlands
#2
2021-07-28, 06:57 PM (This post was last modified: 2021-07-28, 07:05 PM by Kwarde.)
Well off course! And you absolutely should do that! You're also already doing it in fact when including includes.. Thus use #include to include different files.
#include <someInclude> would attempt to include "PATH_TO_INCLUDES_DIRECTORY/someInclude.inc"
#include "someInclude.inc" or #include "someInclude" would attempt to include "PATH_RELATIVE_FILE/someInclude.inc" (you could use different extensions. Eg. gamemode sf-cnr uses .pwn for all includes -- don't, though. ".inc" is the correct file extension)

For example:

./gamemodes/gamemode.pwn

Code:
#include <a_samp>

#include "src/assembly.inc"

public OnGameModeInit()
{
    print("Final OnGameModeInit() call!");
    return 1;
}

./gamemodes/src/assembly.inc
Code:
#include "src/init.inc"
#include "src/server/mysql.inc"

./gamemodes/src/init.inc
Code:
#include <YSI_Coding\y_hooks>

hook OnGameModeInit()
{
    print("First OnGameModeInit() call! Start loading gamemode");
   return 1;
}

./gamemodes/src/server/mysql.inc
Code:
#include <YSI_Coding\y_hooks>

hook OnGameModeInit()
{
    print("Second OnGameModeInit() call! Setting up MySQL connection");
    return 1;
}
Etc..

There are probably 'rules' around as how to name files (eg. using 'header.inc' and 'impl.inc' files) but I'm too noob for that :-)
Here are a few gamemodes that do use multiple files in case you need examples. 
https://github.com/PatrickGTR/gta-open
https://github.com/MaxAndolini/NG-RP
https://github.com/zeelorenc/sf-cnr

Ultimately this will all be combined into one file (by the pre-processor) - including the plugins. It has no effect on the performance of the server.
If you're curious and want to see that for yourself, compile with option "-l" (either put #pragma option -l in your script (do use the latest compiler) or append it to pawncc args).
This will show the output of the stage after the pre-processor's output and before compiling it to assembler code/binary file (amx) in a .asm file. This for example (note that this doesn't make much sense):

./script.pwn
Code:
#include "myInclude.inc"

#pragma option -l

#define MY_CONSTANT 5

main()
{
    print("MY_CONSTANT IS "#MY_CONSTANT);
}

./myInclude.inc
Code:
native print(const string[]);
Would output something like this: (without "#file" and "#line" outputs: when using -l it adds that to the script to show what's where)
Code:
native print(const string[]);

main()
{
    print("MY_CONSTANT IS "#5);
}
Pinch
Offline

Burgershot Member
Posts: 391
Threads: 19
Joined: Apr 2019
Reputation: 22
Location: Belgrade, Serbia
#3
2021-07-28, 07:48 PM
https://github.com/Southclaws/sampctl/wiki/Modern-Pawn
https://github.com/TradeWars/gamemode/blob/master/docs/Style-Guide.md
Using Pawn.CMD?
If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
redex
Offline

Burgershot Member
Posts: 10
Threads: 5
Joined: May 2021
Reputation: 0
Location: Germany
#4
2021-07-29, 10:21 AM
thank u guys it was really helpful +rep
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode