Skip to content

Commit

Permalink
amd64: fix multithread, fix vgui, fix physmodels
Browse files Browse the repository at this point in the history
  • Loading branch information
nillerusr committed Jun 4, 2022
1 parent 01413fd commit 9ee21ec
Show file tree
Hide file tree
Showing 63 changed files with 5,665 additions and 2,454 deletions.
3 changes: 2 additions & 1 deletion common/GameUI/scriptobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "filesystem.h"
#include "tier1/convar.h"
#include "cdll_int.h"
#include "vcrmode.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down Expand Up @@ -1150,4 +1151,4 @@ void CInfoDescription::WriteFileHeader( FileHandle_t fp )
g_pFullFileSystem->FPrintf( fp, "//\r\n//\r\n// Cvar\t-\tSetting\r\n\r\n" );
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
45 changes: 2 additions & 43 deletions datacache/mdlcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1973,39 +1973,18 @@ 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)
#ifndef PLATFORM_64BITS
pStudioHdrIn->SetVirtualModel( MDLHandleToVirtual( handle ) );
#endif
pStudioHdrIn->SetVirtualModel( MDLHandleToVirtual( handle ) );

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

// allocate cache space
MemAlloc_PushAllocDbgInfo( "Models:StudioHdr", 0);
#ifdef PLATFORM_64BITS
studiohdr_t *pHdr = (studiohdr_t *)AllocData( MDLCACHE_STUDIOHDR, pStudioHdrIn->length + sizeof(studiohdr_shim64_index) );
#else
studiohdr_t *pHdr = (studiohdr_t *)AllocData( MDLCACHE_STUDIOHDR, pStudioHdrIn->length );
#endif
MemAlloc_PopAllocDbgInfo();
if ( !pHdr )
return NULL;

#ifdef PLATFORM_64BITS
// MoeMod : fix shim64 index
studiohdr_shim64_index *pHdrIndex = (studiohdr_shim64_index *)(((byte *)pHdr)+ pStudioHdrIn->length);
pHdrIndex->virtualModel = nullptr;
pHdrIndex->animblockModel = nullptr;
pHdrIndex->pVertexBase = nullptr;
pHdrIndex->pIndexBase = nullptr;
pStudioHdrIn->index_ptr_virtualModel = (byte *)&pHdrIndex->virtualModel - (byte *)pHdr;
pStudioHdrIn->index_ptr_animblockModel = (byte *)&pHdrIndex->animblockModel - (byte *)pHdr;
pStudioHdrIn->index_ptr_pVertexBase = (byte *)&pHdrIndex->pVertexBase - (byte *)pHdr;
pStudioHdrIn->index_ptr_pIndexBase = (byte *)&pHdrIndex->pIndexBase - (byte *)pHdr;
pStudioHdrIn->SetVirtualModel( MDLHandleToVirtual( handle ) );
CacheData( &m_MDLDict[handle]->m_MDLCache, pHdr, pStudioHdrIn->length + sizeof(studiohdr_shim64_index), GetModelName( handle ), MDLCACHE_STUDIOHDR, MakeCacheID( handle, MDLCACHE_STUDIOHDR) );
#else
CacheData( &m_MDLDict[handle]->m_MDLCache, pHdr, pStudioHdrIn->length, GetModelName( handle ), MDLCACHE_STUDIOHDR, MakeCacheID( handle, MDLCACHE_STUDIOHDR) );
#endif

if ( mod_lock_mdls_on_load.GetBool() )
{
Expand Down Expand Up @@ -2103,27 +2082,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)
#if PLATFORM_64BITS
int length = buf.Size();
{
studiohdr_shim64_index shim;
buf.Put( &shim, sizeof(shim) );
}
studiohdr_shim64_index *pHdrIndex = (studiohdr_shim64_index *)(((byte *)buf.PeekGet())+ length);
pStudioHdr = (studiohdr_t*)buf.PeekGet();

pHdrIndex->virtualModel = nullptr;
pHdrIndex->animblockModel = nullptr;
pHdrIndex->pVertexBase = nullptr;
pHdrIndex->pIndexBase = nullptr;
pStudioHdr->index_ptr_virtualModel = (byte *)&pHdrIndex->virtualModel - (byte *)pStudioHdr;
pStudioHdr->index_ptr_animblockModel = (byte *)&pHdrIndex->animblockModel - (byte *)pStudioHdr;
pStudioHdr->index_ptr_pVertexBase = (byte *)&pHdrIndex->pVertexBase - (byte *)pStudioHdr;
pStudioHdr->index_ptr_pIndexBase = (byte *)&pHdrIndex->pIndexBase - (byte *)pStudioHdr;
pStudioHdr->SetVirtualModel( MDLHandleToVirtual( handle ) );
#else
pStudioHdr->SetVirtualModel( MDLHandleToVirtual( handle ) );
#endif
pStudioHdr->SetVirtualModel( MDLHandleToVirtual( handle ) );

// Make sure all dependent files are valid
if ( !VerifyHeaders( pStudioHdr ) )
Expand Down
2 changes: 1 addition & 1 deletion engine/cmodel_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ bool CollisionBSPData_Load( const char *pName, CCollisionBSPData *pBSPData )
CollisionBSPData_LoadPhysics( pBSPData );

COM_TimestampedLog( " CollisionBSPData_LoadDispInfo" );
CollisionBSPData_LoadDispInfo( pBSPData );
CollisionBSPData_LoadDispInfo( pBSPData );

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion engine/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ Handles cursor positioning, line wrapping, etc
*/
static bool g_fColorPrintf = false;
static bool g_bInColorPrint = false;
extern CThreadLocalInt<> g_bInSpew;
extern CTHREADLOCALINT g_bInSpew;

void Con_Printf( const char *fmt, ... );

Expand Down
8 changes: 4 additions & 4 deletions engine/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,14 +924,14 @@ void CDownloadManager::StartNewDownload()
m_lastPercent = 0;

// Start the thread
uintp threadID;
uintp threadID;
VCRHook_CreateThread(NULL, 0,
#ifdef POSIX
(void *)
#endif
DownloadThread, m_activeRequest, 0, &threadID );

ThreadDetach( ( ThreadHandle_t )threadID );
ReleaseThreadHandle( ( ThreadHandle_t )threadID );
}
else
{
Expand Down Expand Up @@ -1072,14 +1072,14 @@ class CDownloadSystem : public IDownloadSystem
public:
virtual uintp CreateDownloadThread( RequestContext_t *pContext )
{
uintp nThreadID;
uintp nThreadID;
VCRHook_CreateThread(NULL, 0,
#ifdef POSIX
(void*)
#endif
DownloadThread, pContext, 0, (uintp *)&nThreadID );

ThreadDetach( ( ThreadHandle_t )nThreadID );
ReleaseThreadHandle( ( ThreadHandle_t )nThreadID );
return nThreadID;
}
};
Expand Down
1 change: 1 addition & 0 deletions engine/hltvdemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "host.h"
#include "server.h"
#include "networkstringtableclient.h"
#include "vcrmode.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down
14 changes: 7 additions & 7 deletions engine/r_decal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,7 +2003,7 @@ void R_DrawDecalsAllImmediate_GatherDecals( IMatRenderContext *pRenderContext, i

intp iHead = g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_iHead;

intp iElement = iHead;
intp iElement = iHead;
while ( iElement != g_aDecalSortPool.InvalidIndex() )
{
decal_t *pDecal = g_aDecalSortPool.Element( iElement );
Expand Down Expand Up @@ -2154,11 +2154,11 @@ void R_DrawDecalsAllImmediate( IMatRenderContext *pRenderContext, int iGroup, in
{
if ( g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_nCheckCount != nCheckCount )
continue;

intp iHead = g_aDecalSortTrees[iSortTree].m_aDecalSortBuckets[iGroup][iTreeType].Element( iBucket ).m_iHead;

int nCount;
intp iElement = iHead;
intp iElement = iHead;
while ( iElement != g_aDecalSortPool.InvalidIndex() )
{
decal_t *pDecal = g_aDecalSortPool.Element( iElement );
Expand Down Expand Up @@ -2330,7 +2330,7 @@ void R_DrawDecalsAll_GatherDecals( IMatRenderContext *pRenderContext, int iGroup
if ( bucket.m_nCheckCount != nCheckCount )
continue;

intp iHead = bucket.m_iHead;
intp iHead = bucket.m_iHead;
if ( !g_aDecalSortPool.IsValidIndex( iHead ) )
continue;

Expand Down Expand Up @@ -2647,7 +2647,7 @@ void R_DrawDecalsAll( IMatRenderContext *pRenderContext, int iGroup, int iTreeTy
if ( bucket.m_nCheckCount != nCheckCount )
continue;

int iHead = bucket.m_iHead;
intp iHead = bucket.m_iHead;
if ( !g_aDecalSortPool.IsValidIndex( iHead ) )
continue;

Expand All @@ -2666,7 +2666,7 @@ void R_DrawDecalsAll( IMatRenderContext *pRenderContext, int iGroup, int iTreeTy
bool bBatchInit = true;

int nCount;
int iElement = iHead;
intp iElement = iHead;
while ( iElement != g_aDecalSortPool.InvalidIndex() )
{
decal_t *pDecal = g_aDecalSortPool.Element( iElement );
Expand Down
6 changes: 3 additions & 3 deletions engine/spatialpartition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class CVoxelTree
CVoxelHash* m_pVoxelHash;
CLeafList m_aLeafList; // Pool - Linked list(multilist) of leaves per entity.
int m_TreeId;
CThreadLocalPtr<CPartitionVisits> m_pVisits;
CTHREADLOCALPTR(CPartitionVisits) m_pVisits;
CSpatialPartition * m_pOwner;
CUtlVector<unsigned short> m_AvailableVisitBits;
unsigned short m_nNextVisitBit;
Expand Down Expand Up @@ -1775,7 +1775,7 @@ void CVoxelTree::Shutdown( void )
//-----------------------------------------------------------------------------
void CVoxelTree::InsertIntoTree( SpatialPartitionHandle_t hPartition, const Vector& mins, const Vector& maxs )
{
bool bWasReading = ( m_pVisits != NULL );
bool bWasReading = ( m_pVisits != static_cast<void*>(nullptr) );
if ( bWasReading )
{
// If we're recursing in this thread, need to release our read lock to allow ourselves to write
Expand Down Expand Up @@ -1832,7 +1832,7 @@ void CVoxelTree::RemoveFromTree( SpatialPartitionHandle_t hPartition )
int nLevel = info.m_nLevel[GetTreeId()];
if ( nLevel >= 0 )
{
bool bWasReading = ( m_pVisits != NULL );
bool bWasReading = ( m_pVisits != static_cast<void*>(nullptr) );
if ( bWasReading )
{
// If we're recursing in this thread, need to release our read lock to allow ourselves to write
Expand Down
2 changes: 1 addition & 1 deletion engine/sys_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ void Sys_ShutdownAuthentication( void )
//-----------------------------------------------------------------------------
// Debug library spew output
//-----------------------------------------------------------------------------
CThreadLocalInt<> g_bInSpew;
CTHREADLOCALINT g_bInSpew;

#include "tier1/fmtstr.h"

Expand Down
5 changes: 3 additions & 2 deletions engine/tmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ void TextMessageParse( byte *pMemFile, int fileSize )

client_textmessage_t textMessages[ MAX_MESSAGES ];

int i, nameHeapSize, textHeapSize, messageSize, nameOffset;
int i, nameHeapSize, textHeapSize, messageSize;
intp nameOffset;

lastNamePos = 0;
lineNumber = 0;
Expand Down Expand Up @@ -633,4 +634,4 @@ client_textmessage_t *TextMessageGet( const char *pName )
}

return NULL;
}
}
1 change: 1 addition & 0 deletions engine/vengineserver_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "replay_internal.h"
#include "replayserver.h"
#include "replay/iserverengine.h"
#include "vcrmode.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
Expand Down
2 changes: 1 addition & 1 deletion filesystem/basefilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ const char *CBaseFileSystem::GetWritePath( const char *pFilename, const char *pa
//-----------------------------------------------------------------------------
// Reads/writes files to utlbuffers. Attempts alignment fixups for optimal read
//-----------------------------------------------------------------------------
CThreadLocal<char *> g_pszReadFilename;
CTHREADLOCAL(char *) g_pszReadFilename;
bool CBaseFileSystem::ReadToBuffer( FileHandle_t fp, CUtlBuffer &buf, int nMaxBytes, FSAllocFunc_t pfnAlloc )
{
SetBufferSize( fp, 0 ); // TODO: what if it's a pack file? restore buffer size?
Expand Down
25 changes: 23 additions & 2 deletions game/client/detailobjectsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,16 @@ void CDetailObjectSystem::RenderFastSprites( const Vector &viewOrigin, const Vec
color[2] = pquad->m_RGBColor[0][2];
color[3] = pColorsCasted[MANTISSA_LSB_OFFSET];

DetailPropSpriteDict_t *pDict = pquad->m_pSpriteDefs[0];
DetailPropSpriteDict_t *pDict;
#ifdef PLATFORM_64BITS
if( nSubIdx == 1 )
pDict = ((FastSpriteQuadBuildoutBufferNonSIMDView_t*)((intp)pquad+4))->m_pSpriteDefs[0];
else if( nSubIdx == 3 )
pDict = ((FastSpriteQuadBuildoutBufferNonSIMDView_t*)((intp)pquad-4))->m_pSpriteDefs[0];
else
#endif
pDict = pquad->m_pSpriteDefs[0];


meshBuilder.Position3f( pquad->m_flX0[0], pquad->m_flY0[0], pquad->m_flZ0[0] );
meshBuilder.Color4ubv( color );
Expand Down Expand Up @@ -2545,6 +2554,7 @@ void CDetailObjectSystem::RenderFastTranslucentDetailObjectsInLeaf( const Vector
int nToDraw = MIN( nCount, nQuadsRemaining );
nCount -= nToDraw;
nQuadsRemaining -= nToDraw;

while( nToDraw-- )
{
// draw the sucker
Expand All @@ -2553,17 +2563,28 @@ void CDetailObjectSystem::RenderFastTranslucentDetailObjectsInLeaf( const Vector

FastSpriteQuadBuildoutBufferNonSIMDView_t const *pquad = pQuadBuffer+nSIMDIdx;


// voodoo - since everything is in 4s, offset structure pointer by a couple of floats to handle sub-index
pquad = (FastSpriteQuadBuildoutBufferNonSIMDView_t const *) ( ( (intp) ( pquad ) )+ ( nSubIdx << 2 ) );

uint8 const *pColorsCasted = reinterpret_cast<uint8 const *> ( pquad->m_Alpha );


uint8 color[4];
color[0] = pquad->m_RGBColor[0][0];
color[1] = pquad->m_RGBColor[0][1];
color[2] = pquad->m_RGBColor[0][2];
color[3] = pColorsCasted[MANTISSA_LSB_OFFSET];

DetailPropSpriteDict_t *pDict = pquad->m_pSpriteDefs[0];
DetailPropSpriteDict_t *pDict;
#ifdef PLATFORM_64BITS
if( nSubIdx == 1 )
pDict = ((FastSpriteQuadBuildoutBufferNonSIMDView_t*)((intp)pquad+4))->m_pSpriteDefs[0];
else if( nSubIdx == 3 )
pDict = ((FastSpriteQuadBuildoutBufferNonSIMDView_t*)((intp)pquad-4))->m_pSpriteDefs[0];
else
#endif
pDict = pquad->m_pSpriteDefs[0];

meshBuilder.Position3f( pquad->m_flX0[0], pquad->m_flY0[0], pquad->m_flZ0[0] );
meshBuilder.Color4ubv( color );
Expand Down
15 changes: 11 additions & 4 deletions game/server/basecombatcharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,10 @@ CBaseCombatCharacter::CBaseCombatCharacter( void )
}

// not standing on a nav area yet
#ifdef MEXT_BOT
m_lastNavArea = NULL;
#endif

m_registeredNavTeam = TEAM_INVALID;

for (int i = 0; i < MAX_WEAPONS; i++)
Expand Down Expand Up @@ -3481,39 +3484,43 @@ void CBaseCombatCharacter::UpdateLastKnownArea( void )
//-----------------------------------------------------------------------------
bool CBaseCombatCharacter::IsAreaTraversable( const CNavArea *area ) const
{
#ifdef NEXT_BOT
return area ? !area->IsBlocked( GetTeamNumber() ) : false;
#endif
return false;
}


//-----------------------------------------------------------------------------
// Purpose: Leaving the nav mesh
//-----------------------------------------------------------------------------
void CBaseCombatCharacter::ClearLastKnownArea( void )
{
#ifdef NEXT_BOT
OnNavAreaChanged( NULL, m_lastNavArea );

if ( m_lastNavArea )
{
m_lastNavArea->DecrementPlayerCount( m_registeredNavTeam, entindex() );
m_lastNavArea->OnExit( this, NULL );
m_lastNavArea = NULL;
m_registeredNavTeam = TEAM_INVALID;
}
#endif
}


//-----------------------------------------------------------------------------
// Purpose: Handling editor removing the area we're standing upon
//-----------------------------------------------------------------------------
void CBaseCombatCharacter::OnNavAreaRemoved( CNavArea *removedArea )
{
#ifdef NEXT_BOT
if ( m_lastNavArea == removedArea )
{
ClearLastKnownArea();
}
#endif
}


//-----------------------------------------------------------------------------
// Purpose: Changing team, maintain associated data
//-----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 9ee21ec

Please sign in to comment.