Skip to content

Commit

Permalink
vphysics: fix saverestore
Browse files Browse the repository at this point in the history
  • Loading branch information
nillerusr committed Jun 14, 2022
1 parent b84ad64 commit 94916a2
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 122 deletions.
2 changes: 1 addition & 1 deletion public/datamap.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ DECLARE_FIELD_SIZE( FIELD_MODELNAME, sizeof(void*))
DECLARE_FIELD_SIZE( FIELD_SOUNDNAME, sizeof(void*))
DECLARE_FIELD_SIZE( FIELD_EHANDLE, sizeof(void*))
DECLARE_FIELD_SIZE( FIELD_CLASSPTR, sizeof(void*))
DECLARE_FIELD_SIZE( FIELD_EDICT, sizeof(int))
DECLARE_FIELD_SIZE( FIELD_EDICT, sizeof(void*))
DECLARE_FIELD_SIZE( FIELD_POSITION_VECTOR, 3 * sizeof(float))
DECLARE_FIELD_SIZE( FIELD_TIME, sizeof(float))
DECLARE_FIELD_SIZE( FIELD_TICK, sizeof(int))
Expand Down
10 changes: 10 additions & 0 deletions public/tier0/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,16 @@ typedef void * HINSTANCE;
#error
#endif

// !!! NOTE: if you get a compile error here, you are using VALIGNOF on an abstract type :NOTE !!!
#define VALIGNOF_PORTABLE( type ) ( sizeof( AlignOf_t<type> ) - sizeof( type ) )

#if defined( COMPILER_GCC ) || defined( COMPILER_MSVC )
#define VALIGNOF( type ) __alignof( type )
#define VALIGNOF_TEMPLATE_SAFE( type ) VALIGNOF_PORTABLE( type )
#else
#error "PORT: Code only tested with MSVC! Must validate with new compiler, and use built-in keyword if available."
#endif

// Pull in the /analyze code annotations.
#include "annotations.h"

Expand Down
29 changes: 24 additions & 5 deletions public/tier1/datamanager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
Expand Down Expand Up @@ -65,6 +65,8 @@ class CDataManagerBase

// -----------------------------------------------------------------------------

void SetFreeOnDestruct( bool value ) { m_freeOnDestruct = value; }

// Debugging only!!!!
void GetLRUHandleList( CUtlVector< memhandle_t >& list );
void GetLockHandleList( CUtlVector< memhandle_t >& list );
Expand All @@ -77,6 +79,7 @@ class CDataManagerBase
void *GetResource_NoLock( memhandle_t handle );
void *GetResource_NoLockNoLRUTouch( memhandle_t handle );
void *LockResource( memhandle_t handle );
void *LockResourceReturnCount( int *pCount, memhandle_t handle );

// NOTE: you must call this from the destructor of the derived class! (will assert otherwise)
void FreeAllLists() { FlushAll(); m_listsAreFreed = true; }
Expand Down Expand Up @@ -123,7 +126,8 @@ class CDataManagerBase
unsigned short m_lockList;
unsigned short m_freeList;
unsigned short m_listsAreFreed : 1;
unsigned short m_unused : 15;
unsigned short m_freeOnDestruct : 1;
unsigned short m_unused : 14;

};

Expand All @@ -139,7 +143,10 @@ class CDataManager : public CDataManagerBase
~CDataManager<STORAGE_TYPE, CREATE_PARAMS, LOCK_TYPE, MUTEX_TYPE>()
{
// NOTE: This must be called in all implementations of CDataManager
FreeAllLists();
if ( m_freeOnDestruct )
{
FreeAllLists();
}
}

// Use GetData() to translate pointer to LOCK_TYPE
Expand All @@ -154,6 +161,17 @@ class CDataManager : public CDataManagerBase
return NULL;
}

LOCK_TYPE LockResourceReturnCount( int *pCount, memhandle_t hMem )
{
void *pLock = BaseClass::LockResourceReturnCount( pCount, hMem );
if ( pLock )
{
return StoragePointer(pLock)->GetData();
}

return NULL;
}

// Use GetData() to translate pointer to LOCK_TYPE
LOCK_TYPE GetResource_NoLock( memhandle_t hMem )
{
Expand Down Expand Up @@ -181,8 +199,9 @@ class CDataManager : public CDataManagerBase
memhandle_t CreateResource( const CREATE_PARAMS &createParams, bool bCreateLocked = false )
{
BaseClass::EnsureCapacity(STORAGE_TYPE::EstimatedSize(createParams));
unsigned short memoryIndex = BaseClass::CreateHandle( bCreateLocked );
STORAGE_TYPE *pStore = STORAGE_TYPE::CreateResource( createParams );
AUTO_LOCK_( CDataManagerBase, *this );
unsigned short memoryIndex = BaseClass::CreateHandle( bCreateLocked );
return BaseClass::StoreResourceInHandle( memoryIndex, pStore, pStore->Size() );
}

Expand Down Expand Up @@ -251,7 +270,7 @@ class CDataManager : public CDataManagerBase

inline unsigned short CDataManagerBase::FromHandle( memhandle_t handle )
{
uintp fullWord = (uintp)handle;
unsigned int fullWord = (unsigned int)reinterpret_cast<uintp>( handle );
unsigned short serial = fullWord>>16;
unsigned short index = fullWord & 0xFFFF;
index--;
Expand Down
Loading

0 comments on commit 94916a2

Please sign in to comment.