I will work on a "master/core" plugin with some Cvars(8+).
I need to pass the values of these Cvars to other "slave plugins/modules".
The values are planned to read only once by the "slaves/modules" during OnConfigsExecuted().
There will be 10+ "slaves/modules" that need these values.
What is the "best", less expensive &/or smartest way?
FindConVar or
native or even a
forward?
and why?
Or is there a better/other way I'm missing?
"FindConVar"-Way
Quote:
Core plugin
PHP Code:
public void OnPluginStart()
{
gc_sName = CreateConVar("plugin_name", "Name", "");
gc_iTime = CreateConVar("plugin_time", "10.0", "");
}
Less code on core.
Least code at all.
ok to make it foolproof I should hook convar change too.
this way many plugins call the same convars from convar-cache(?)
Module plugin
PHP Code:
public void OnConfigsExecuted()
{
ConVar cBuffer = FindConVar("plugin_name");
cBuffer.GetString(g_sName, sizeof(g_sName));
cBuffer = FindConVar("plugin_time");
g_fTime = cBuffer.FloatValue;
}
|
"Native"-Way
Quote:
Core plugin
PHP Code:
public void OnPluginStart()
{
gc_sName = CreateConVar("myplugin_name", "Name", "");
gc_fTime = CreateConVar("myplugin_time", "10.0", "");
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("MyPlugin_Name", Native_Name);
CreateNative("MyPlugin_Time", Native_Time);
RegPluginLibrary("myplugin");
}
public int Native_Name(Handle plugin, int args)
{
char sName[32];
gc_sName.GetString(sName, sizeof(sName));
SetNativeString(1, sName, sizeof(sName));
}
public int Native_Time(Handle plugin, int args)
{
return gc_fTime.FloatValue;
}
more code on core - less work on modules
This way many api calls to the core module(?)
Module plugin
PHP Code:
#include myplugin
public void OnConfigsExecuted()
{
MyPlugin_Name(g_sName);
g_fTime = MyPlugin_Time();
}
|
"Forward"-Way
Quote:
Core plugin
PHP Code:
public void OnPluginStart()
{
gc_sName = CreateConVar("plugin_name", "Name", "");
gc_iTime = CreateConVar("plugin_time", "10.0", "");
}
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_hSendConfig = CreateGlobalForward("MyPlugin_Config", ET_Ignore, Param_String, Param_Cell);
RegPluginLibrary("myplugin");
}
public int OnConfigsExecuted()
{
char sName[32];
gc_sName.GetString(sName, sizeof(sName));
Call_StartForward(g_hSendConfig);
Call_PushString(sName);
Call_PushFloat(gc_fTime.FloatValue);
Call_Finish();
}
more code on core - less work on modules
This way the forward will only called once and all plugins will recieve the values.
I assume this is the less expensive way.
Module plugin
PHP Code:
#include myplugin
public void MyPlugin_Config(char[] name, float time)
{
Format(g_sName, sizeof(g_sName), name);
g_fTime = time;
}
|
I know there are maybe some missing lines, missing var declartions or rather HookConVarChanges.
These example codes are just for better visualization of the question.
From the point of writing new modules I would prefer natives or forwards.
My gut tells me to use forwards.
What do you think? Thanks for reading!
__________________