diff --git a/src/engine/sys_dll.cpp b/src/engine/sys_dll.cpp index e65fa81d..1b63ecef 100644 --- a/src/engine/sys_dll.cpp +++ b/src/engine/sys_dll.cpp @@ -104,7 +104,7 @@ bool CModAppSystemGroup::StaticCreate(CModAppSystemGroup* pModAppSystemGroup) #endif // !CLIENT_DLL #ifndef DEDICATED - g_pClientEntityList = (CClientEntityList*)g_FactorySystem.GetFactory(VCLIENTENTITYLIST_INTERFACE_VERSION); + g_pClientEntityList = (IClientEntityList*)g_FactorySystem.GetFactory(VCLIENTENTITYLIST_INTERFACE_VERSION); g_pEngineTraceClient = (CEngineTraceClient*)g_FactorySystem.GetFactory(INTERFACEVERSION_ENGINETRACE_CLIENT); g_ImGuiConfig.Load(); // Load ImGui configs. diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt index 684aacec..e4c7f6dc 100644 --- a/src/game/CMakeLists.txt +++ b/src/game/CMakeLists.txt @@ -207,7 +207,10 @@ add_sources( SOURCE_GROUP "Entity" "client/c_baseanimating.h" "client/c_baseanimatingoverlay.h" "client/c_basecombatcharacter.h" + "client/cliententitylist.cpp" "client/cliententitylist.h" + "client/entitylist_clientbase.h" + "client/icliententityinternal.h" ) add_sources( SOURCE_GROUP "Player" diff --git a/src/game/client/cliententitylist.cpp b/src/game/client/cliententitylist.cpp new file mode 100644 index 00000000..cd9160ad --- /dev/null +++ b/src/game/client/cliententitylist.cpp @@ -0,0 +1,7 @@ +#include "cliententitylist.h" + +//----------------------------------------------------------------------------- +// Purpose: a global list of all the entities in the game. All iteration through +// entities is done through this object. +//----------------------------------------------------------------------------- +CClientEntityList* g_clientEntityList = nullptr; // todo(amos): obtain game object. diff --git a/src/game/client/cliententitylist.h b/src/game/client/cliententitylist.h index a72170a6..92662b01 100644 --- a/src/game/client/cliententitylist.h +++ b/src/game/client/cliententitylist.h @@ -11,8 +11,14 @@ #ifdef _WIN32 #pragma once #endif -#include "public/icliententitylist.h" #include "tier1/utlvector.h" +#include "tier1/utllinkedlist.h" + +#include "public/icliententitylist.h" + +#include "entitylist_clientbase.h" +#include "icliententityinternal.h" +#include "entitylist_clientbase.h" #include "c_baseplayer.h" // Implement this class and register with entlist to receive entity create/delete notification @@ -23,17 +29,21 @@ public: virtual void OnEntityDeleted(C_BaseEntity* pEntity) {}; }; -class CClientEntityList : public IClientEntityList +class CClientEntityList : public C_BaseEntityList, public IClientEntityList { - class CPVSNotifyInfo // !TODO: confirm this!! +protected: + // Cached info for networked entities. + struct EntityCacheInfo_t { - public: - //IPVSNotify* m_pNotify; - IClientRenderable* m_pRenderable; - unsigned char m_InPVSStatus; // Combination of the INPVS_ flags. - unsigned short m_PVSNotifiersLink; // Into m_PVSNotifyInfos. + // Cached off because GetClientNetworkable is called a *lot* + IClientNetworkable* m_pNetworkable; + unsigned short m_BaseEntitiesIndex; // Index into m_BaseEntities (or m_BaseEntities.InvalidIndex() if none). + unsigned short m_bDormant; // cached dormant state - this is only a bit }; + virtual EntityCacheInfo_t *GetClientNetworkableArray() = 0; + +private: CUtlVector m_entityListeners; int m_iNumServerEnts; // Current count @@ -41,15 +51,15 @@ class CClientEntityList : public IClientEntityList int m_iNumClientNonNetworkable; // Non networkable count int m_iMaxUsedServerIndex; // Current last used slot - // !TODO: - /* // This holds fast lookups for special edicts. EntityCacheInfo_t m_EntityCacheInfo[NUM_ENT_ENTRIES]; // For fast iteration. - CUtlLinkedList m_BaseEntities;*/ + CUtlLinkedList m_BaseEntities; }; -inline CClientEntityList* g_pClientEntityList = nullptr; +COMPILE_TIME_ASSERT(sizeof(CClientEntityList) == 0x3800C0); + +inline IClientEntityList* g_pClientEntityList = nullptr; #endif // CLIENTENTITYLIST_H diff --git a/src/game/client/entitylist_clientbase.h b/src/game/client/entitylist_clientbase.h new file mode 100644 index 00000000..b619800c --- /dev/null +++ b/src/game/client/entitylist_clientbase.h @@ -0,0 +1,34 @@ +#ifndef ENTITYLIST_CLIENTBASE_H +#define ENTITYLIST_CLIENTBASE_H + +#include +#include +#include + +class C_BaseEntityList +{ +public: + + // Overridables. +protected: + + // These are notifications to the derived class. It can cache info here if it wants. + virtual void OnAddEntity(IHandleEntity* pEnt, const CBaseHandle& handle) = 0; // NOTE: implemented in engine! + + // It is safe to delete the entity here. We won't be accessing the pointer after + // calling OnRemoveEntity. + virtual void OnRemoveEntity(IHandleEntity* pEnt, const CBaseHandle& handle) = 0; // NOTE: implemented in engine! + +private: + // The first MAX_EDICTS entities are networkable. The rest are client-only or server-only. + CEntInfo m_EntPtrArray[NUM_ENT_ENTRIES]; + CEntInfoList m_activeList; + CEntInfoList m_freeNonNetworkableList; + + // Client Sound (Miles) entities. + CThreadMutex m_clientSoundEntsMutex; + IHandleEntity* m_pClientSoundEnts[NUM_ENT_ENTRIES]; + ssize_t m_clientSoundEntCount; +}; + +#endif // ENTITYLIST_CLIENTBASE_H diff --git a/src/game/client/icliententityinternal.h b/src/game/client/icliententityinternal.h new file mode 100644 index 00000000..66897b1e --- /dev/null +++ b/src/game/client/icliententityinternal.h @@ -0,0 +1,32 @@ +//====== Copyright © 1996-2005, Valve Corporation, All rights reserved. =======// +// +// Purpose: +// +// $NoKeywords: $ +//=============================================================================// +#ifndef ICLIENTENTITYINTERNAL_H +#define ICLIENTENTITYINTERNAL_H +#ifdef _WIN32 +#pragma once +#endif + +#include "icliententity.h" +//#include "clientleafsystem.h" + +//----------------------------------------------------------------------------- +// Forward declarations +//----------------------------------------------------------------------------- + +class ClientClass; + + +//----------------------------------------------------------------------------- +// represents a handle used only by the client DLL +//----------------------------------------------------------------------------- + +typedef CBaseHandle ClientEntityHandle_t; +typedef unsigned short SpatialPartitionHandle_t; + + + +#endif // ICLIENTENTITYINTERNAL_H \ No newline at end of file diff --git a/src/game/shared/entitylist_base.h b/src/game/shared/entitylist_base.h index 268c4908..acbaae37 100644 --- a/src/game/shared/entitylist_base.h +++ b/src/game/shared/entitylist_base.h @@ -26,5 +26,26 @@ public: void ClearLinks(); }; +class CEntInfoList +{ +public: + CEntInfoList(); -#endif // ENTITYLIST_BASE_H \ No newline at end of file + const CEntInfo *Head() const { return m_pHead; } + const CEntInfo *Tail() const { return m_pTail; } + CEntInfo *Head() { return m_pHead; } + CEntInfo *Tail() { return m_pTail; } + //void AddToHead( CEntInfo *pElement ) { LinkAfter( NULL, pElement ); } + //void AddToTail( CEntInfo *pElement ) { LinkBefore( NULL, pElement ); } + + //void LinkBefore( CEntInfo *pBefore, CEntInfo *pElement ); + //void LinkAfter( CEntInfo *pBefore, CEntInfo *pElement ); + //void Unlink( CEntInfo *pElement ); + //bool IsInList( CEntInfo *pElement ); + +private: + CEntInfo *m_pHead; + CEntInfo *m_pTail; +}; + +#endif // ENTITYLIST_BASE_H