Skip to content

Commit

Permalink
Implement CEntityHandle & CEntitySystem (alliedmodders#134)
Browse files Browse the repository at this point in the history
Add CConcreteEntityList, CEntityComponent, CScriptComponent, CGameEntitySystem, rewrite IHandleEntity to use CEntityHandle instead of CBaseHandle, update NUM_SERIAL_NUM_BITS, comment out old CBaseEntity, obsolete basehandle.h
  • Loading branch information
zer0k-z authored Sep 30, 2023
1 parent 0ac0302 commit 7931af0
Show file tree
Hide file tree
Showing 23 changed files with 543 additions and 267 deletions.
40 changes: 40 additions & 0 deletions entity2/entitysystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "const.h"
#include "entity2/entitysystem.h"

CBaseEntity* CEntitySystem::GetBaseEntity(CEntityIndex entnum)
{
if (entnum.Get() <= -1 || entnum.Get() >= (MAX_TOTAL_ENTITIES - 1))
return nullptr;

CEntityIdentity* pChunkToUse = m_EntityList.m_pIdentityChunks[entnum.Get() / MAX_ENTITIES_IN_LIST];
if (!pChunkToUse)
return nullptr;

CEntityIdentity* pIdentity = &pChunkToUse[entnum.Get() % MAX_ENTITIES_IN_LIST];
if (!pIdentity)
return nullptr;

if (pIdentity->m_EHandle.GetEntryIndex() != entnum.Get())
return nullptr;

return dynamic_cast<CBaseEntity*>(pIdentity->m_pInstance);
}

CBaseEntity* CEntitySystem::GetBaseEntity(const CEntityHandle& hEnt)
{
if (!hEnt.IsValid())
return nullptr;

CEntityIdentity* pChunkToUse = m_EntityList.m_pIdentityChunks[hEnt.GetEntryIndex() / MAX_ENTITIES_IN_LIST];
if (!pChunkToUse)
return nullptr;

CEntityIdentity* pIdentity = &pChunkToUse[hEnt.GetEntryIndex() % MAX_ENTITIES_IN_LIST];
if (!pIdentity)
return nullptr;

if (pIdentity->m_EHandle != hEnt)
return nullptr;

return dynamic_cast<CBaseEntity*>(pIdentity->m_pInstance);
}
4 changes: 2 additions & 2 deletions game/client/in_forcefeedback.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//====== Copyright © 1996-2004, Valve Corporation, All rights reserved. =======
//====== Copyright 1996-2004, Valve Corporation, All rights reserved. =======
//
// Purpose: Force feeback OS level handlers
//
//=============================================================================
#include <windows.h>
#include "basehandle.h"
#include "entityhandle.h"
#include "UtlVector.h"
#include "usercmd.h"
#include "cdll_client_int.h"
Expand Down
2 changes: 1 addition & 1 deletion game/client/in_joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// $NoKeywords: $
//===========================================================================//
#include "cbase.h"
#include "basehandle.h"
#include "entityhandle.h"
#include "utlvector.h"
#include "cdll_client_int.h"
#include "cdll_util.h"
Expand Down
2 changes: 1 addition & 1 deletion game/client/in_mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "hud.h"
#include "cdll_int.h"
#include "kbutton.h"
#include "basehandle.h"
#include "entityhandle.h"
#include "usercmd.h"
#include "input.h"
#include "iviewrender.h"
Expand Down
4 changes: 2 additions & 2 deletions game/client/in_trackir.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: TrackIR handling function
//
Expand All @@ -21,7 +21,7 @@
#include "vphysics_interface.h"
#include <icvar.h>
#include <baseentity_shared.h>
#include "basehandle.h"
#include "entityhandle.h"
#include "ehandle.h"
#include "utlvector.h"
#include "cdll_client_int.h"
Expand Down
8 changes: 8 additions & 0 deletions game/server/baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#pragma once
#endif

#include "entityidentity.h"
class CBaseEntity : public CEntityInstance
{
};

#if 0
#define TEAMNUM_NUM_BITS 6

#include <ctype.h>
Expand Down Expand Up @@ -2906,4 +2912,6 @@ FORCEINLINE bool EntityNamesMatch( const char *pszQuery, string_t nameToMatch )
return false;
}

#endif

#endif // BASEENTITY_H
26 changes: 7 additions & 19 deletions game/shared/ehandle.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
Expand All @@ -11,36 +11,24 @@
#pragma once
#endif

#if defined( _DEBUG ) && defined( GAME_DLL )
#include "tier0/dbg.h"
#include "cbase.h"
#endif


#include "const.h"
#include "basehandle.h"
#include "entitylist_base.h"


class IHandleEntity;

#include "entityhandle.h"
#include "entity2/entitysystem.h"

// -------------------------------------------------------------------------------------------------- //
// Game-code CBaseHandle implementation.
// -------------------------------------------------------------------------------------------------- //

inline IHandleEntity* CBaseHandle::Get() const
inline IHandleEntity* CEntityHandle::Get() const
{
extern CBaseEntityList *g_pEntityList;
return g_pEntityList->LookupEntity( *this );
extern CEntitySystem *g_pEntitySystem;
return g_pEntitySystem->GetBaseEntity( *this );
}


// -------------------------------------------------------------------------------------------------- //
// CHandle.
// -------------------------------------------------------------------------------------------------- //
template< class T >
class CHandle : public CBaseHandle
class CHandle : public CEntityHandle
{
public:

Expand Down
4 changes: 2 additions & 2 deletions game/shared/entitylist_base.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
Expand All @@ -12,7 +12,7 @@


#include "const.h"
#include "basehandle.h"
#include "entityhandle.h"
#include "tier1/utllinkedlist.h"
#include "ihandleentity.h"

Expand Down
4 changes: 2 additions & 2 deletions game/shared/sharedvar.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
Expand All @@ -13,7 +13,7 @@

#include "convar.h"
#include "ispsharedmemory.h"
#include "basehandle.h"
#include "entityhandle.h"
#include "isaverestore.h"


Expand Down
206 changes: 0 additions & 206 deletions public/basehandle.h

This file was deleted.

Loading

0 comments on commit 7931af0

Please sign in to comment.