Backed out changeset: 8048e61b5382.

This commit is contained in:
Nicholas Hastings 2012-12-27 16:39:04 -05:00
parent df76b7285c
commit bb9d5e11f1

View File

@ -33,35 +33,33 @@
#include "conditions.h" #include "conditions.h"
#include "util.h" #include "util.h"
#include "bitvec.h"
#include <iplayerinfo.h> #include <iplayerinfo.h>
typedef CBitVec<96> condbits_t; typedef uint64_t condflags_t;
condbits_t g_PlayerConds[MAXPLAYERS+1]; condflags_t g_PlayerConds[MAXPLAYERS+1];
IForward *g_addCondForward = NULL; IForward *g_addCondForward = NULL;
IForward *g_removeCondForward = NULL; IForward *g_removeCondForward = NULL;
int playerCondOffset = -1; int playerCondOffset = -1;
int playerCondExOffset = -1; int playerCondExOffset = -1;
int playerCondEx2Offset = -1;
int conditionBitsOffset = -1; int conditionBitsOffset = -1;
bool g_bIgnoreRemove; bool g_bIgnoreRemove;
inline void GetPlayerConds(CBaseEntity *pPlayer, condbits_t *pOut) #define MAX_CONDS (sizeof(uint64_t) * 8)
inline condflags_t GetPlayerConds(CBaseEntity *pPlayer)
{ {
uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset); uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset);
uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset); uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset);
uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset); uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset);
uint32_t playerCondEx2 = *(uint32_t *)((intptr_t)pPlayer + playerCondEx2Offset);
pOut->SetDWord(0, playerCond); uint64_t playerCondExAdj = playerCondEx;
pOut->Set(0u, condBits); playerCondExAdj <<= 32;
pOut->SetDWord(1, playerCondEx);
pOut->SetDWord(2, playerCondEx2); return playerCond|condBits|playerCondExAdj;
} }
void Conditions_OnGameFrame(bool simulating) void Conditions_OnGameFrame(bool simulating)
@ -69,16 +67,14 @@ void Conditions_OnGameFrame(bool simulating)
if (!simulating) if (!simulating)
return; return;
condbits_t *oldconds; condflags_t oldconds;
condbits_t newconds; condflags_t newconds;
condbits_t *addedconds; condflags_t addedconds;
condbits_t *removedconds; condflags_t removedconds;
int i, j;
int maxClients = gpGlobals->maxClients; int maxClients = gpGlobals->maxClients;
for (i = 1; i <= maxClients; i++) for (int i = 1; i <= maxClients; i++)
{ {
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
if (!pPlayer || !pPlayer->IsInGame()) if (!pPlayer || !pPlayer->IsInGame())
@ -89,39 +85,39 @@ void Conditions_OnGameFrame(bool simulating)
continue; continue;
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i); CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i);
oldconds = &g_PlayerConds[i]; oldconds = g_PlayerConds[i];
GetPlayerConds(pEntity, &newconds); newconds = GetPlayerConds(pEntity);
if (*oldconds == newconds) if (oldconds == newconds)
continue; continue;
addedconds = &newconds; addedconds = newconds &~ oldconds;
for (j = 0; j < addedconds->GetNumDWords(); ++j) removedconds = oldconds &~ newconds;
{
addedconds->Clear(j * sizeof(int), oldconds->GetDWord(j));
}
removedconds = oldconds; uint64_t j;
for (j = 0; j < removedconds->GetNumDWords(); ++j) condflags_t bit;
{
removedconds->Clear(j * sizeof(int), newconds.GetDWord(j));
}
for (j = 0; (j = addedconds->FindNextSetBit( j )) != -1; ++j) for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= addedconds; j++)
{
if ((addedconds & bit) == bit)
{ {
g_addCondForward->PushCell(i); g_addCondForward->PushCell(i);
g_addCondForward->PushCell(j); g_addCondForward->PushCell(j & 0xFFFFFFFF);
g_addCondForward->Execute(NULL, NULL); g_addCondForward->Execute(NULL, NULL);
} }
for (j = 0; (j = addedconds->FindNextSetBit( j )) != -1; ++j)
{
g_removeCondForward->PushCell(i);
g_removeCondForward->PushCell(j);
g_removeCondForward->Execute(NULL, NULL);
} }
g_PlayerConds[i].Copy( newconds ); for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= removedconds; j++)
{
if ((removedconds & bit) == bit)
{
g_removeCondForward->PushCell(i);
g_removeCondForward->PushCell(j & 0xFFFFFFFF);
g_removeCondForward->Execute(NULL, NULL);
}
}
g_PlayerConds[i] = newconds;
} }
} }
@ -152,21 +148,8 @@ bool InitialiseConditionChecks()
playerCondExOffset = prop.actual_offset; playerCondExOffset = prop.actual_offset;
if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx2", &prop)) if (playerCondOffset == -1 || playerCondExOffset == -1 || conditionBitsOffset == -1)
{
g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx2 prop offset");
return false; return false;
}
playerCondEx2Offset = prop.actual_offset;
if (playerCondOffset == -1
|| playerCondExOffset == -1
|| playerCondEx2Offset == -1
|| conditionBitsOffset == -1)
{
return false;
}
int maxClients = gpGlobals->maxClients; int maxClients = gpGlobals->maxClients;
for (int i = 1; i <= maxClients; i++) for (int i = 1; i <= maxClients; i++)
@ -175,7 +158,7 @@ bool InitialiseConditionChecks()
if (!pPlayer || !pPlayer->IsInGame()) if (!pPlayer || !pPlayer->IsInGame())
continue; continue;
GetPlayerConds(gamehelpers->ReferenceToEntity(i), &g_PlayerConds[i]); g_PlayerConds[i] = GetPlayerConds(gamehelpers->ReferenceToEntity(i));
} }
g_pSM->AddGameFrameHook(Conditions_OnGameFrame); g_pSM->AddGameFrameHook(Conditions_OnGameFrame);
@ -185,7 +168,7 @@ bool InitialiseConditionChecks()
void Conditions_OnClientPutInServer(int client) void Conditions_OnClientPutInServer(int client)
{ {
g_PlayerConds[client].Init(); g_PlayerConds[client] = 0;
} }
void RemoveConditionChecks() void RemoveConditionChecks()