Custom MMS Interfaces
I've used the normal HL2SDK Interfaces for years, but never contemplated making my own before. Since I am constantly reusing the same code in each MMS plugin I do, I figured creating some Interfaces for handling/managing Menus/UserMessages/GameEvents/etc. wouldn't be a bad idea.
I am however a little confused on what the exact setup of Interfaces is. Just from looking around, it looks like you can use g_SMAPI->MetaFactory(INTERFACE_NAME, NULL, NULL); to get the interface pointer on the iface you create in another plugin, but I am not sure what else I need (such as the version defines, version names, and anything else such as how to expose it to other MMS plugins once its loaded and running). I didn't see anything on the Wiki regarding this (could have sworn I did a while back) so I would like any information on doing this. |
Re: Custom MMS Interfaces
I am pretty sure that the interface system requires implementation of QueryInterface(). Creating a pointer to the interface is created within your plugin, then your QueryInterface() should return the pointer you create. I believe it is a simple string comparison. Let me know if you need more help, I know my explanation was kind of quick.
|
Re: Custom MMS Interfaces
Are you looking to use one binary between all of your MMS plugins so you don't have to have that code in each one? Or are you looking for your own library that you can link into each plugin so you don't have to have rehash the same code over and over again?
|
Re: Custom MMS Interfaces
I am looking to create a binary file, and expose specific customs functions via interfaces that I create. I actually never thought about doing this until I saw Voogru's hat extension/MMS plugin that does this, and I realized how nice that would be.
|
Re: Custom MMS Interfaces
An interface isn't anything fancy. Check this out, this is the file you would distribute:
IMyInterface.h Code:
#define MYINTERFACE_VERSION "MYINTERFACE001" // Increment the version number any time you a) add a function or b) remove a function. If you neglect to do this, the virtual table will not match.MyInterface.h Code:
class CMyInterface : public IMyInterfaceCode:
CMyInteface g_MyInterface;Code:
void *MyPlugin::QueryInterface(const char *version_string)Something like this for any plugin that tries to use MyInterface... Code:
#include "IMyInterface.h" |
Re: Custom MMS Interfaces
I was just looking for a recommendation as far as another MMS plugin that used a custom iface, but that is perfect, thank you.
|
Re: Custom MMS Interfaces
Hi,
one thing I don't understand is why you use different interface versions? If you, for example, have BLA_VER002, do you instantiate CBla001 and CBla002 and then pass that one that fits the version string? Or do I misunderstand something? Thanks! |
Re: Custom MMS Interfaces
The version number ensures proper virtual function index mapping. For example, if I released a new version of my interface with new functions, lets say FunctionD and FunctionE:
Code:
#define MYINTERFACE_VERSION "MYINTERFACE002"Code:
if(StrEqual("INTERFACE_001", "INTERFACE_002")) { |
Re: Custom MMS Interfaces
FWIW, SourceMod exposes its extension system through MM:S, so you can use MM:S plugins as if they were also extensions.
|
Re: Custom MMS Interfaces
Thanks! And when exactly I need to add a pure virtual destructor? If I'm informed correctly, it is not possible to instantiate abstract classes, so it shouldn't matter if it has a constructor/destructor?!
|
| All times are GMT -4. The time now is 05:28. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.