don't store entity pointer - might ruin performance
This commit is contained in:
parent
30b1efb4e3
commit
7d8854d516
@ -12,7 +12,9 @@
|
||||
#include "profiler.h"
|
||||
|
||||
CachedEntity::CachedEntity() {
|
||||
#if PROXY_ENTITY != true
|
||||
m_pEntity = nullptr;
|
||||
#endif
|
||||
m_Bones = 0;
|
||||
m_Bones = new matrix3x4_t[MAXSTUDIOBONES];
|
||||
m_pHitboxCache = new EntityHitboxCache(this);
|
||||
@ -26,7 +28,7 @@ CachedEntity::~CachedEntity() {
|
||||
}
|
||||
|
||||
IClientEntity* CachedEntity::InternalEntity() {
|
||||
return m_pEntity;
|
||||
return g_IEntityList->GetClientEntity(m_IDX);
|
||||
}
|
||||
|
||||
void EntityCache::Invalidate() {
|
||||
@ -38,13 +40,16 @@ void CachedEntity::Update(int idx) {
|
||||
SEGV_BEGIN
|
||||
|
||||
m_IDX = idx;
|
||||
if (!RAW_ENT(this)) return;
|
||||
#if PROXY_ENTITY != true
|
||||
m_pEntity = g_IEntityList->GetClientEntity(idx);
|
||||
if (!m_pEntity) {
|
||||
return;
|
||||
}
|
||||
m_iClassID = m_pEntity->GetClientClass()->m_ClassID;
|
||||
#endif
|
||||
m_iClassID = RAW_ENT(this)->GetClientClass()->m_ClassID;
|
||||
|
||||
Vector origin = m_pEntity->GetAbsOrigin();
|
||||
Vector origin = RAW_ENT(this)->GetAbsOrigin();
|
||||
//if (TF2 && EstimateAbsVelocity) EstimateAbsVelocity(m_pEntity, m_vecVelocity);
|
||||
/*if ((gvars->realtime - m_fLastUpdate) >= 0.05f) {
|
||||
//if (gvars->tickcount - m_nLastTick > 1) {
|
||||
@ -74,7 +79,6 @@ void CachedEntity::Update(int idx) {
|
||||
if (m_pHitboxCache) {
|
||||
SAFE_CALL(m_pHitboxCache->Update());
|
||||
}
|
||||
|
||||
if (m_iClassID == g_pClassID->C_Player) {
|
||||
m_Type = EntityType::ENTITY_PLAYER;
|
||||
} else if (m_iClassID == g_pClassID->CTFGrenadePipebombProjectile ||
|
||||
@ -105,7 +109,6 @@ void CachedEntity::Update(int idx) {
|
||||
m_flDistance = (g_pLocalPlayer->v_Origin.DistTo(m_vecOrigin));
|
||||
}
|
||||
m_bAlivePlayer = false;
|
||||
|
||||
// TODO temporary!
|
||||
/*m_bCritProjectile = false;
|
||||
m_bIsVisible = false;
|
||||
@ -127,7 +130,7 @@ void CachedEntity::Update(int idx) {
|
||||
}
|
||||
|
||||
if (m_Type == EntityType::ENTITY_PLAYER) {
|
||||
m_bAlivePlayer = !(NET_BYTE(m_pEntity, netvar.iLifeState));
|
||||
m_bAlivePlayer = !(NET_BYTE(RAW_ENT(this), netvar.iLifeState));
|
||||
if (m_pPlayerInfo) {
|
||||
delete m_pPlayerInfo;
|
||||
m_pPlayerInfo = 0;
|
||||
@ -145,7 +148,7 @@ void CachedEntity::Update(int idx) {
|
||||
m_iHealth = CE_INT(this, netvar.iBuildingHealth);
|
||||
m_iMaxHealth = CE_INT(this, netvar.iBuildingMaxHealth);
|
||||
}
|
||||
SEGV_END_INFO("Updating entity")
|
||||
SEGV_END_INFO("Updating entity");
|
||||
}
|
||||
|
||||
static CatVar fast_vischeck(CV_SWITCH, "fast_vischeck", "0", "Fast VisCheck", "VisCheck only certain player hitboxes");
|
||||
@ -194,7 +197,7 @@ bool CachedEntity::IsVisible() {
|
||||
|
||||
matrix3x4_t* CachedEntity::GetBones() {
|
||||
if (!m_bBonesSetup) {
|
||||
m_bBonesSetup = m_pEntity->SetupBones(m_Bones, MAXSTUDIOBONES, 0x100, 0); // gvars->curtime
|
||||
m_bBonesSetup = RAW_ENT(this)->SetupBones(m_Bones, MAXSTUDIOBONES, 0x100, 0); // gvars->curtime
|
||||
}
|
||||
return m_Bones;
|
||||
}
|
||||
@ -210,9 +213,7 @@ EntityCache::~EntityCache() {
|
||||
void EntityCache::Update() {
|
||||
m_nMax = g_IEntityList->GetHighestEntityIndex();
|
||||
for (int i = 0; i < m_nMax && i < MAX_ENTITIES; i++) {
|
||||
//logging::Info("Updating %i", i);
|
||||
m_pArray[i].Update(i);
|
||||
//logging::Info("Back!");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,44 +24,28 @@ struct mstudiobbox_t;
|
||||
#define MAX_STRINGS 16
|
||||
#define MAX_ENTITIES 2048
|
||||
|
||||
#define PROXY_ENTITY true
|
||||
|
||||
#if PROXY_ENTITY == true
|
||||
#define RAW_ENT(ce) ((ce) ? (ce)->InternalEntity() : nullptr)
|
||||
#else
|
||||
#define RAW_ENT(ce) ce->m_pEntity
|
||||
#endif
|
||||
|
||||
#define CE_VAR(entity, offset, type) \
|
||||
NET_VAR(entity->m_pEntity, offset, type)
|
||||
NET_VAR(RAW_ENT(entity), offset, type)
|
||||
|
||||
#define CE_INT(entity, offset) CE_VAR(entity, offset, int)
|
||||
#define CE_FLOAT(entity, offset) CE_VAR(entity, offset, float)
|
||||
#define CE_BYTE(entity, offset) CE_VAR(entity, offset, unsigned char)
|
||||
#define CE_VECTOR(entity, offset) CE_VAR(entity, offset, Vector)
|
||||
|
||||
#define CE_GOOD_NO_DORMANT_CHECK(entity) (!g_Settings.bInvalid && dynamic_cast<CachedEntity*>(entity) && dynamic_cast<IClientEntity*>(entity->m_pEntity))
|
||||
#define CE_GOOD(entity) (!g_Settings.bInvalid && dynamic_cast<CachedEntity*>(entity) && dynamic_cast<IClientEntity*>(entity->m_pEntity) && (g_IEntityList->GetClientEntity(entity->m_IDX) == entity->m_pEntity) && entity->m_pEntity->GetIClientEntity() && !entity->m_pEntity->GetIClientEntity()->IsDormant())
|
||||
#define CE_GOOD(entity) (!g_Settings.bInvalid && dynamic_cast<CachedEntity*>(entity) && RAW_ENT(entity) && !RAW_ENT(entity)->IsDormant())
|
||||
#define CE_BAD(entity) (!CE_GOOD(entity))
|
||||
|
||||
#define IDX_GOOD(idx) (idx >= 0 && idx < HIGHEST_ENTITY && idx < MAX_ENTITIES)
|
||||
#define IDX_BAD(idx) !IDX_GOOD(idx)
|
||||
|
||||
#define PROXY_ENTITY false
|
||||
|
||||
#if PROXY_ENTITY == true
|
||||
#define RAW_ENT(ce) ce->InternalEntity()
|
||||
#else
|
||||
#define RAW_ENT(ce) ce->m_pEntity
|
||||
#endif
|
||||
|
||||
|
||||
// This will be used later. maybe.
|
||||
#define ENTITY_ITERATE_INT(iterator, entity, max) \
|
||||
for (int iterator = 0; iterator < max; iterator++) { \
|
||||
CachedEntity* entity = gEntityCache.GetEntity(iterator); \
|
||||
if (CE_BAD(entity)) continue;
|
||||
|
||||
#define ENTITY_ITERATE_EVERYTHING(iterator, entity) \
|
||||
ENTITY_ITERATE_INT(iterator, entity, gEntityCache.m_nMax)
|
||||
|
||||
#define ENTITY_ITERATE_PLAYERS(iterator, entity) \
|
||||
ENTITY_ITERATE_INT(iterator, entity, MIN(gEntityCache.m_nMax, 64))
|
||||
|
||||
#define END_ENTITY_ITERATING }
|
||||
|
||||
#define HIGHEST_ENTITY gEntityCache.m_nMax
|
||||
#define ENTITY(idx) gEntityCache.GetEntity(idx)
|
||||
|
||||
@ -146,11 +130,13 @@ public:
|
||||
EntityHitboxCache* m_pHitboxCache;
|
||||
int m_IDX;
|
||||
IClientEntity* InternalEntity();
|
||||
IClientEntity* m_pEntity;
|
||||
Vector m_vecVOrigin;
|
||||
Vector m_vecVelocity;
|
||||
Vector m_vecAcceleration;
|
||||
float m_fLastUpdate;
|
||||
#if PROXY_ENTITY != true || 1 // FIXME??
|
||||
IClientEntity* m_pEntity;
|
||||
#endif
|
||||
};
|
||||
|
||||
class EntityCache {
|
||||
|
@ -214,7 +214,7 @@ void ProcessEntity(CachedEntity* ent) {
|
||||
if (ent->m_iClassID == g_pClassID->CTFTankBoss && tank) {
|
||||
AddEntityString(ent, "Tank");
|
||||
} else if (ent->m_iClassID == g_pClassID->CTFDroppedWeapon && item_esp && item_dropped_weapons) {
|
||||
AddEntityString(ent, format("WEAPON ", ent->m_pEntity->GetClientClass()->GetName()));
|
||||
AddEntityString(ent, format("WEAPON ", RAW_ENT(ent)->GetClientClass()->GetName()));
|
||||
} else if (ent->m_iClassID == g_pClassID->CCurrencyPack && item_money) {
|
||||
if (CE_BYTE(ent, netvar.bDistributed)) {
|
||||
if (item_money_red) {
|
||||
@ -312,7 +312,7 @@ void ProcessEntity(CachedEntity* ent) {
|
||||
CachedEntity* weapon = ENTITY(CE_INT(ent, netvar.hActiveWeapon) & 0xFFF);
|
||||
if (CE_GOOD(weapon)) {
|
||||
if (show_weapon) {
|
||||
AddEntityString(ent, std::string(vfunc<const char*(*)(IClientEntity*)>(weapon->m_pEntity, 398, 0)(weapon->m_pEntity)));
|
||||
AddEntityString(ent, std::string(vfunc<const char*(*)(IClientEntity*)>(RAW_ENT(weapon), 398, 0)(RAW_ENT(weapon))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,9 +256,9 @@ void DoWalking() {
|
||||
IClientEntity* owner_weapon = g_IEntityList->GetClientEntity(owner_weapon_eid);
|
||||
if (owner_weapon && CE_GOOD(g_pLocalPlayer->weapon())) {
|
||||
// IsBaseCombatWeapon()
|
||||
if (vfunc<bool(*)(IClientEntity*)>(g_pLocalPlayer->weapon()->m_pEntity, 190, 0)(g_pLocalPlayer->weapon()->m_pEntity) &&
|
||||
if (vfunc<bool(*)(IClientEntity*)>(RAW_ENT(g_pLocalPlayer->weapon()), 190, 0)(RAW_ENT(g_pLocalPlayer->weapon())) &&
|
||||
vfunc<bool(*)(IClientEntity*)>(owner_weapon, 190, 0)(owner_weapon)) {
|
||||
int my_slot = vfunc<int(*)(IClientEntity*)>(g_pLocalPlayer->weapon()->m_pEntity, 395, 0)(g_pLocalPlayer->weapon()->m_pEntity);
|
||||
int my_slot = vfunc<int(*)(IClientEntity*)>(RAW_ENT(g_pLocalPlayer->weapon()), 395, 0)(RAW_ENT(g_pLocalPlayer->weapon()));
|
||||
int owner_slot = vfunc<int(*)(IClientEntity*)>(owner_weapon, 395, 0)(owner_weapon);
|
||||
if (g_pLocalPlayer->clazz == tf_medic && always_medigun) {
|
||||
if (my_slot != 1) {
|
||||
|
@ -77,7 +77,7 @@ void Draw() {
|
||||
|
||||
if (!debug_info) return;
|
||||
if (CE_GOOD(g_pLocalPlayer->weapon())) {
|
||||
AddSideString(format("Slot: ", vfunc<int(*)(IClientEntity*)>(g_pLocalPlayer->weapon()->m_pEntity, 395, 0)(g_pLocalPlayer->weapon()->m_pEntity)));
|
||||
AddSideString(format("Slot: ", vfunc<int(*)(IClientEntity*)>(RAW_ENT(g_pLocalPlayer->weapon()), 395, 0)(RAW_ENT(g_pLocalPlayer->weapon()))));
|
||||
/*AddSideString(colors::white, "Weapon: %s [%i]", RAW_ENT(g_pLocalPlayer->weapon())->GetClientClass()->GetName(), g_pLocalPlayer->weapon()->m_iClassID);
|
||||
//AddSideString(colors::white, "flNextPrimaryAttack: %f", CE_FLOAT(g_pLocalPlayer->weapon(), netvar.flNextPrimaryAttack));
|
||||
//AddSideString(colors::white, "nTickBase: %f", (float)(CE_INT(g_pLocalPlayer->entity, netvar.nTickBase)) * gvars->interval_per_tick);
|
||||
|
@ -143,7 +143,6 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (CE_GOOD(g_pLocalPlayer->entity)) {
|
||||
g_pLocalPlayer->v_OrigViewangles = cmd->viewangles;
|
||||
// PROF_BEGIN();
|
||||
@ -226,7 +225,6 @@ bool CreateMove_hook(void* thisptr, float inputSample, CUserCmd* cmd) {
|
||||
g_Settings.last_angles = cmd->viewangles;
|
||||
}
|
||||
|
||||
|
||||
// PROF_END("CreateMove");
|
||||
g_pLocalPlayer->bAttackLastTick = (cmd->buttons & IN_ATTACK);
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user