Raised This Month: $ Target: $400
 0% 

How to reorganize code in a huge plugin?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nergal
Veteran Member
Join Date: Apr 2012
Old 03-01-2015 , 16:09   How to reorganize code in a huge plugin?
Reply With Quote #1

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?
__________________
nergal is offline
ClassicGuzzi
Veteran Member
Join Date: Oct 2013
Location: Argentina
Old 03-01-2015 , 16:35   Re: How to reorganize code in a huge plugin?
Reply With Quote #2

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.
__________________

Last edited by ClassicGuzzi; 03-01-2015 at 16:36.
ClassicGuzzi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-01-2015 , 17:13   Re: How to reorganize code in a huge plugin?
Reply With Quote #3

You can split a plugin into separate files without turning it into separate plugins.

For example in NativeVotes:
  • nativevotes.sp has the core functionality of the plugin plus its natives
  • nativevotes/data-keyvalues.sp has all the things for manipulating a vote handle "owned" by NativeVotes (its named data-keyvalues because the backing store may change later)
  • nativevotes/game.sp has functions for individual games that NativeVotes supports as well as Game_ abstract functions that determines which function to call for which game.

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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-01-2015 at 17:14.
Powerlord is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-01-2015 , 17:38   Re: How to reorganize code in a huge plugin?
Reply With Quote #4

Quote:
Originally Posted by ClassicGuzzi View Post
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.
Well I DON'T want to use natives, that's why I'm asking how I can reorganize a huge plugin into multiple files to later all compile into 1 file.

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?
__________________

Last edited by nergal; 03-01-2015 at 17:42.
nergal is offline
ClassicGuzzi
Veteran Member
Join Date: Oct 2013
Location: Argentina
Old 03-01-2015 , 18:07   Re: How to reorganize code in a huge plugin?
Reply With Quote #5

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.
__________________

Last edited by ClassicGuzzi; 03-01-2015 at 18:22.
ClassicGuzzi is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-02-2015 , 01:04   Re: How to reorganize code in a huge plugin?
Reply With Quote #6

Quote:
Originally Posted by ClassicGuzzi View Post
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.
One C++ tutorial on Organization actually helped me out.

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.
__________________

Last edited by nergal; 03-02-2015 at 01:08.
nergal is offline
ClassicGuzzi
Veteran Member
Join Date: Oct 2013
Location: Argentina
Old 03-02-2015 , 01:10   Re: How to reorganize code in a huge plugin?
Reply With Quote #7

Quote:
Originally Posted by nergal View Post
One C++ tutorial on Organization actually helped me out.

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 should do that with my dodgeball plugin now that you mentioned it.

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
__________________
ClassicGuzzi is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 03-02-2015 , 08:40   Re: How to reorganize code in a huge plugin?
Reply With Quote #8

Quote:
Originally Posted by ClassicGuzzi View Post
I should do that with my dodgeball plugin now that you mentioned it.

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
I've used the 1.7 syntax when it was still development phase
__________________
nergal is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 03-02-2015 , 09:29   Re: How to reorganize code in a huge plugin?
Reply With Quote #9

#include "file.sp"
__________________
Chdata is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode