Hey all!
So, I am trying to learn how to use bitwise operation as a replacement for booleans (ex. bool g_bEnabled[MAXPLAYERS+1]) (performance optimization).
Here is something I have coded:
PHP Code:
#include <sourcemod>
int g_iClients;
public void OnPluginStart()
{
RegAdminCmd("sm_testbit", Command_Callback, ADMFLAG_ROOT);
if (GetClientCount(true))
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i) && !IsFakeClient(i))
{
OnClientPostAdminCheck(i);
}
}
}
}
public void OnClientPostAdminCheck(int client)
{
g_iClients |= client;
}
public void OnClientDisconnect(int client)
{
g_iClients &= ~client;
}
public Action Command_Callback(int client, int args)
{
ReplyToCommand(client, "[SM] g_iClients: %s.", g_iClients & client ? "Found" : "Not found");
return Plugin_Handled;
}
I have 2 questions:
1.) Did I add and remove the client indexes correctly with the g_iClients variable?
2.) Would I use:
Code:
g_iClients & client
Or:
Code:
g_iClients & (1 << client)
To check if the client exists in the variable?
Thanks,
Grant