probably a bit cheaper calculationwise
This commit is contained in:
parent
8be8ced61a
commit
4b89862452
@ -15,15 +15,32 @@ static const char entityList[][] = { "env_entity_igniter", "env_explosion", "env
|
|||||||
"info_player_counterterrorist", "info_player_terrorist", "infodecal", \
|
"info_player_counterterrorist", "info_player_terrorist", "infodecal", \
|
||||||
"item_assaultsuit", "item_defuser", "item_kevlar", \
|
"item_assaultsuit", "item_defuser", "item_kevlar", \
|
||||||
"light", "light_environment", "light_spot", "move_rope", "path_track", "planted_c4", \
|
"light", "light_environment", "light_spot", "move_rope", "path_track", "planted_c4", \
|
||||||
"point_viewcontrol", "shadow_control", "vgui_screen", "worldspawn"};
|
"point_viewcontrol", "shadow_control", "vgui_screen", "func_tracktrain", "worldspawn", \
|
||||||
|
"func_tanktrain"};
|
||||||
|
|
||||||
bool bEnabled[MAXPLAYERS + 1],
|
bool bEnabled[MAXPLAYERS + 1];
|
||||||
bBind[MAXPLAYERS + 1],
|
|
||||||
bHolding[MAXPLAYERS + 1],
|
|
||||||
bDontRenderFire[MAXPLAYERS + 1];
|
|
||||||
|
|
||||||
int iDistance[MAXPLAYERS + 1],
|
int iDistance[MAXPLAYERS + 1];
|
||||||
iFlameEntity = -1;
|
|
||||||
|
float g_fClientOrigin[MAXPLAYERS + 1][3];
|
||||||
|
|
||||||
|
public void OnPluginStart()
|
||||||
|
{
|
||||||
|
// Run the cache timer every 0.5 seconds globally
|
||||||
|
CreateTimer(0.5, Timer_CacheOrigins, _, TIMER_REPEAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action Timer_CacheOrigins(Handle timer)
|
||||||
|
{
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
{
|
||||||
|
if (IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient(i))
|
||||||
|
{
|
||||||
|
GetClientAbsOrigin(i, g_fClientOrigin[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Plugin_Continue;
|
||||||
|
}
|
||||||
|
|
||||||
public Plugin myinfo =
|
public Plugin myinfo =
|
||||||
{
|
{
|
||||||
@ -37,9 +54,6 @@ public Plugin myinfo =
|
|||||||
public void OnClientAuthorized(int client, const char[] auth)
|
public void OnClientAuthorized(int client, const char[] auth)
|
||||||
{
|
{
|
||||||
bEnabled[client] = false;
|
bEnabled[client] = false;
|
||||||
bBind[client] = false;
|
|
||||||
bHolding[client] = false;
|
|
||||||
bDontRenderFire[client] = false;
|
|
||||||
iDistance[client] = 800;
|
iDistance[client] = 800;
|
||||||
|
|
||||||
char sIP[32];
|
char sIP[32];
|
||||||
@ -59,12 +73,7 @@ public void OnEntityCreated(int entity, const char[] classname)
|
|||||||
{
|
{
|
||||||
bool hook = false;
|
bool hook = false;
|
||||||
|
|
||||||
if (!strcmp(classname, "entityflame"))
|
if (!strncmp(classname, "prop_", 5))
|
||||||
{
|
|
||||||
iFlameEntity = EntIndexToEntRef(entity);
|
|
||||||
hook = true;
|
|
||||||
}
|
|
||||||
else if (!strncmp(classname, "prop_", 5))
|
|
||||||
{
|
{
|
||||||
hook = true;
|
hook = true;
|
||||||
}
|
}
|
||||||
@ -86,37 +95,35 @@ public void OnEntityCreated(int entity, const char[] classname)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bFoundEntity[MAXPLAYERS + 1];
|
|
||||||
int iSearchEntity[MAXPLAYERS + 1];
|
|
||||||
|
|
||||||
public bool EnumerateSphere(int entity, any client)
|
|
||||||
{
|
|
||||||
if (entity == iSearchEntity[client])
|
|
||||||
{
|
|
||||||
bFoundEntity[client] = true;
|
|
||||||
return false; // Stop enumerating early
|
|
||||||
}
|
|
||||||
return true; // Keep enumerating
|
|
||||||
}
|
|
||||||
|
|
||||||
public Action DoTransmit(int entity, int client)
|
public Action DoTransmit(int entity, int client)
|
||||||
{
|
{
|
||||||
if (bDontRenderFire[client] && entity == EntRefToEntIndex(iFlameEntity))
|
if (IsFakeClient(client) || !bEnabled[client])
|
||||||
return Plugin_Handled;
|
|
||||||
|
|
||||||
if (IsFakeClient(client) || !bEnabled[client] || (bBind[client] && !bHolding[client]))
|
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
|
|
||||||
if (GetEdictFlags(entity) & FL_EDICT_ALWAYS)
|
if (GetEdictFlags(entity) & FL_EDICT_ALWAYS)
|
||||||
SetEdictFlags(entity, GetEdictFlags(entity) ^ FL_EDICT_ALWAYS);
|
SetEdictFlags(entity, GetEdictFlags(entity) ^ FL_EDICT_ALWAYS);
|
||||||
|
|
||||||
static float vec[3];
|
// Get Entity Origin
|
||||||
GetClientAbsOrigin(client, vec);
|
static float entVec[3];
|
||||||
|
if (HasEntProp(entity, Prop_Send, "m_vecOrigin"))
|
||||||
|
{
|
||||||
|
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", entVec);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Plugin_Continue; // If it doesnt have an origin, let it render safely
|
||||||
|
}
|
||||||
|
|
||||||
iSearchEntity[client] = entity;
|
// Use GetVectorDistance with UseSquared=true (avoids an expensive Square Root calculation)
|
||||||
bFoundEntity[client] = false;
|
float maxDist = float(iDistance[client]);
|
||||||
|
float distanceSq = ((g_fClientOrigin[client][0] - entVec[0]) * (g_fClientOrigin[client][0] - entVec[0])) +
|
||||||
|
((g_fClientOrigin[client][1] - entVec[1]) * (g_fClientOrigin[client][1] - entVec[1])) +
|
||||||
|
((g_fClientOrigin[client][2] - entVec[2]) * (g_fClientOrigin[client][2] - entVec[2]));
|
||||||
|
|
||||||
TR_EnumerateEntitiesSphere(vec, float(iDistance[client]), PARTITION_SOLID_EDICTS | PARTITION_TRIGGER_EDICTS | PARTITION_NON_STATIC_EDICTS, EnumerateSphere, client);
|
if (distanceSq > (maxDist * maxDist))
|
||||||
|
{
|
||||||
|
return Plugin_Handled; // Out of range, hide it from the software renderer!
|
||||||
|
}
|
||||||
|
|
||||||
return bFoundEntity[client] ? Plugin_Continue : Plugin_Handled;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user