Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: make SAMPGDK_CPP_WRAPPERS declare and define a sampgdk class. #178

Open
grasmanek94 opened this issue May 1, 2017 · 1 comment

Comments

@grasmanek94
Copy link
Contributor

grasmanek94 commented May 1, 2017

This popped up into my head a long time ago and didn't come around to implementing this myself, so I will just leave it here as a suggestion for whomever would like to work on this.

The problem:
Sometimes you want to override the behavior of sa-mp (or other SampGDK provided) functions. This can be cumbersome and result in functions with different prototypes, prefixes, suffixes, defines and sometimes a combination of the mentioned things. Most commonly this is with SendClientMessage* functions.

The suggestion:
Encapsulate all SampGDK functions in a class and mark them all as virtual when SAMPGDK_CPP_WRAPPERS is defined. Users can then create their own class which inherits from the base SampGDK class and customize the behavior of all functions to their likeness, all in a standard manner. Optionally SampGDK should provide a global variable that can be used directly, and provide a function like sampgdk_class_init(BaseClass* ptr) which would set the global variable to an user instantiated class (probably a derived class).

Example:

class SampGDK
{
public:
	virtual int SendClientMessage(int playerid, int color, const char* message);
};

SampGDK* sampgdk_global; // maybe someone can come up with a more creative name

class MyGamemodeSDK : public SampGDK
{
	int SendClientMessage(int playerid, int color, const char* message) override;
};

int MyGamemodeSDK::SendClientMessage(int playerid, int color, const char* message)
{
	return SampGDK::SendClientMessage(playerid, color, TranslateMessage(message));
}

//somewhere in the code
sampgdk_class_init(new MyGamemodeSDK());

Plugins that extend PAWN functionality wouldn't need this, in either case, each plugin should have its own instance of the 'global function pointer', to guarantee consistency.

@NegativeIQ
Copy link

Yeah that would be awesome. And its not just client messages... Get/Set pos, instead of passing floats we could use custom Vector class...Many useful stuff is possible....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@grasmanek94 @NegativeIQ and others