How to reorganize code in a huge plugin?
I often find myself making big plugins and I want to reorganize the code into multiple files but I find it difficult how to reorganize them...
How can I reorganize a single huge plugin into multiple files? |
Re: How to reorganize code in a huge plugin?
It depends of what the plugin does. If the plugin has stock functions like IsValidClient for example but A LOT of them you could move them to an include file (unless they use global variables form the plugin).
If you really want to separate in multiple files you have to keep in mind that, either those other plugins won't have functions directly related to the main plugin, or you are going to use a "core" plugin with natives to communicate with other plugins, with you only should do it if you want a flexible and modular plugin. |
Re: How to reorganize code in a huge plugin?
You can split a plugin into separate files without turning it into separate plugins.
For example in NativeVotes:
That's just an example and your plugin may be done differently. basevotes is another plugin to take a look at as it consists of basevotes.sp and a separate sp file for each vote type is supports. |
Re: How to reorganize code in a huge plugin?
Quote:
I've been reading tutorials on C++ that talk about how to organize a project into multiple files. But it feels clunky and difficult trying that with Sourcepawn (Yes I know they're 2 different languages xD) Which is why I'm asking if there's a way to organize a huge plugin so that it'll work just fine when compiled from multiple files. I'm pretty sure the issue with this is from having global variables but is there a way? |
Re: How to reorganize code in a huge plugin?
As powerlord said, you could separate them into multiples .sp and include them at the beginning of your main file, like #include "nativevotes/data-keyvalues.sp"
Every global declared on that file will be accessible on your main file. |
Re: How to reorganize code in a huge plugin?
Quote:
it said to split up code based on "responsibility/function" of each code class and struct definitions, typedefs, global variables, constants, #defined macros, #pragma directives, and stocks all go into the .inc file while code in the .sp is split down for each action every part of the code does. Through that rule, I was able to break up my plugin into 3 .inc files for defs, globals, and stocks and 7 .sp files not counting the core to compile them all against. I think I'll post a tutorial in the tutorial section. |
Re: How to reorganize code in a huge plugin?
Quote:
By the way, I don't know on which plugin are you going to do this, but you could also start changing things to the new 1.7 syntax while you are in it :bee: |
Re: How to reorganize code in a huge plugin?
Quote:
|
Re: How to reorganize code in a huge plugin?
#include "file.sp"
|
All times are GMT -4. The time now is 00:35. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.