vphysics: fix saverestore

This commit is contained in:
nillerusr
2022-06-14 13:09:10 +03:00
parent b84ad64171
commit 94916a20ce
10 changed files with 300 additions and 122 deletions
+24 -5
View File
@@ -1,4 +1,4 @@
//========= Copyright Valve Corporation, All rights reserved. ============//
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
@@ -65,6 +65,8 @@ public:
// -----------------------------------------------------------------------------
void SetFreeOnDestruct( bool value ) { m_freeOnDestruct = value; }
// Debugging only!!!!
void GetLRUHandleList( CUtlVector< memhandle_t >& list );
void GetLockHandleList( CUtlVector< memhandle_t >& list );
@@ -77,6 +79,7 @@ protected:
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; }
@@ -123,7 +126,8 @@ protected:
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;
};
@@ -139,7 +143,10 @@ public:
~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
@@ -154,6 +161,17 @@ public:
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 )
{
@@ -181,8 +199,9 @@ public:
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() );
}
@@ -251,7 +270,7 @@ private:
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--;