Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datacache/mdlcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,7 @@ studiohdr_t *CMDLCache::UnserializeMDL( MDLHandle_t handle, void *pData, int nDa

// critical! store a back link to our data
// this is fetched when re-establishing dependent cached data (vtx/vvd)
pStudioHdrIn->virtualModel = (int)(uintp)handle;
pStudioHdrIn->SetVirtualModel( MDLHandleToVirtual( handle ) );

MdlCacheMsg( "MDLCache: Alloc studiohdr %s\n", GetModelName( handle ) );

Expand Down Expand Up @@ -1953,7 +1953,7 @@ bool CMDLCache::ReadMDLFile( MDLHandle_t handle, const char *pMDLFileName, CUtlB

// critical! store a back link to our data
// this is fetched when re-establishing dependent cached data (vtx/vvd)
pStudioHdr->virtualModel = (int)(uintp)handle;
pStudioHdr->SetVirtualModel( MDLHandleToVirtual( handle ) );

// Make sure all dependent files are valid
if ( !VerifyHeaders( pStudioHdr ) )
Expand Down
6 changes: 3 additions & 3 deletions game/client/c_baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ void C_BaseAnimating::LockStudioHdr()

if ( pNewWrapper->GetVirtualModel() )
{
MDLHandle_t hVirtualModel = (MDLHandle_t)(intp)(pStudioHdr->virtualModel)&0xffff;
MDLHandle_t hVirtualModel = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() );
mdlcache->LockStudioHdr( hVirtualModel );
}

Expand All @@ -982,7 +982,7 @@ void C_BaseAnimating::UnlockStudioHdr()
// Parallel rendering: don't unlock model data until end of rendering
if ( pStudioHdr->GetVirtualModel() )
{
MDLHandle_t hVirtualModel = (MDLHandle_t)(intp)pStudioHdr->virtualModel&0xffff;
MDLHandle_t hVirtualModel = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() );
pCallQueue->QueueCall( mdlcache, &IMDLCache::UnlockStudioHdr, hVirtualModel );
}
pCallQueue->QueueCall( mdlcache, &IMDLCache::UnlockStudioHdr, m_hStudioHdr );
Expand All @@ -993,7 +993,7 @@ void C_BaseAnimating::UnlockStudioHdr()
// Immediate-mode rendering, can unlock immediately
if ( pStudioHdr->GetVirtualModel() )
{
MDLHandle_t hVirtualModel = (MDLHandle_t)(intp)pStudioHdr->virtualModel&0xffff;
MDLHandle_t hVirtualModel = VoidPtrToMDLHandle( pStudioHdr->VirtualModel() );
mdlcache->UnlockStudioHdr( hVirtualModel );
}
mdlcache->UnlockStudioHdr( m_hStudioHdr );
Expand Down
4 changes: 2 additions & 2 deletions game/server/baseanimating.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2580,7 +2580,7 @@ void CBaseAnimating::LockStudioHdr()

if ( pStudioHdrContainer && pStudioHdrContainer->GetVirtualModel() )
{
MDLHandle_t hVirtualModel = (MDLHandle_t)(intp)(pStudioHdrContainer->GetRenderHdr()->virtualModel)&0xffff;
MDLHandle_t hVirtualModel = VoidPtrToMDLHandle(pStudioHdrContainer->GetRenderHdr()->VirtualModel());
mdlcache->LockStudioHdr( hVirtualModel );
}
m_pStudioHdr = pStudioHdrContainer; // must be last to ensure virtual model correctly set up
Expand All @@ -2598,7 +2598,7 @@ void CBaseAnimating::UnlockStudioHdr()
mdlcache->UnlockStudioHdr( modelinfo->GetCacheHandle( mdl ) );
if ( m_pStudioHdr->GetVirtualModel() )
{
MDLHandle_t hVirtualModel = (MDLHandle_t)(intp)(m_pStudioHdr->GetRenderHdr()->virtualModel)&0xffff;
MDLHandle_t hVirtualModel = VoidPtrToMDLHandle(m_pStudioHdr->GetRenderHdr()->VirtualModel());
mdlcache->UnlockStudioHdr( hVirtualModel );
}
}
Expand Down
10 changes: 10 additions & 0 deletions public/datacache/imdlcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ namespace OptimizedModel
//-----------------------------------------------------------------------------
using MDLHandle_t = unsigned short;

inline MDLHandle_t VoidPtrToMDLHandle( void *ptr )
{
return ( MDLHandle_t ) ( int ) ( intp ) ptr;
}

inline void* MDLHandleToVirtual( MDLHandle_t hndl )
{
return (void*)(uintp)hndl;
}

enum
{
MDLHANDLE_INVALID = (MDLHandle_t)~0
Expand Down
11 changes: 10 additions & 1 deletion public/studio.h
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,7 @@ struct studiohdr_t
const studiohdr_t *FindModel( void **cache, char const *modelname ) const;

// implementation specific back pointer to virtual data
int virtualModel;
void* virtualModel;
virtualmodel_t *GetVirtualModel( void ) const;

// for demand loaded animation blocks
Expand Down Expand Up @@ -2356,6 +2356,15 @@ struct studiohdr_t
inline int BoneFlexDriverCount() const { return studiohdr2index ? pStudioHdr2()->m_nBoneFlexDriverCount : 0; }
inline const mstudioboneflexdriver_t* BoneFlexDriver( int i ) const { Assert( i >= 0 && i < BoneFlexDriverCount() ); return studiohdr2index ? pStudioHdr2()->pBoneFlexDriver( i ) : nullptr; }

#ifdef PLATFORM_64BITS
void* VirtualModel() const { return studiohdr2index ? (void *)( pStudioHdr2()->virtualModel ) : nullptr; }
void SetVirtualModel( void* ptr ) { Assert( studiohdr2index ); if ( studiohdr2index ) { pStudioHdr2()->virtualModel = ptr; } }
#else
void* VirtualModel() const { return virtualModel; }
void SetVirtualModel( void* ptr ) { virtualModel = ptr; }
#endif


// NOTE: No room to add stuff? Up the .mdl file format version
// [and move all fields in studiohdr2_t into studiohdr_t and kill studiohdr2_t],
// or add your stuff to studiohdr2_t. See NumSrcBoneTransforms/SrcBoneTransform for the pattern to use.
Expand Down
Loading