Skip to content

Commit

Permalink
Fix comment and reduce branching in TF2_IsPlayerInCondition.
Browse files Browse the repository at this point in the history
  • Loading branch information
psychonic committed May 21, 2016
1 parent e127a55 commit 9b3b2eb
Showing 1 changed file with 34 additions and 28 deletions.
62 changes: 34 additions & 28 deletions plugins/include/tf2_stocks.inc
Expand Up @@ -529,43 +529,49 @@ stock int TF2_GetPlayerConditionFlags(int client)
*/
stock bool TF2_IsPlayerInCondition(int client, TFCond cond)
{
// Conditions are stored across two netprops now, one for each 32-bit segment.
if (view_as<int>(cond) < 32)
// Conditions are stored across multiple netprops now, one for each 32-bit segment.
int iCond = view_as<int>(cond);
switch (iCond / 32)
{
int bit = 1 << view_as<int>(cond);
if ((GetEntProp(client, Prop_Send, "m_nPlayerCond") & bit) == bit)
case 0:
{
return true;
int bit = 1 << iCond;
if ((GetEntProp(client, Prop_Send, "m_nPlayerCond") & bit) == bit)
{
return true;
}

if ((GetEntProp(client, Prop_Send, "_condition_bits") & bit) == bit)
{
return true;
}
}

if ((GetEntProp(client, Prop_Send, "_condition_bits") & bit) == bit)
case 1:
{
return true;
int bit = (1 << (iCond - 32));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx") & bit) == bit)
{
return true;
}
}
}
else if (view_as<int>(cond) < 64)
{
int bit = (1 << (view_as<int>(cond) - 32));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx") & bit) == bit)
case 2:
{
return true;
int bit = (1 << (iCond - 64));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx2") & bit) == bit)
{
return true;
}
}
}
else if (view_as<int>(cond) < 96)
{
int bit = (1 << (view_as<int>(cond) - 64));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx2") & bit) == bit)
{
return true;
}
}
else
{
int bit = (1 << (view_as<int>(cond) - 96));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx3") & bit) == bit)
case 3:
{
return true;
int bit = (1 << (iCond - 96));
if ((GetEntProp(client, Prop_Send, "m_nPlayerCondEx3") & bit) == bit)
{
return true;
}
}
default:
ThrowError("Invalid TFCond value %d", iCond);
}

return false;
Expand Down

0 comments on commit 9b3b2eb

Please sign in to comment.