Skip to content

(Temporary workaround) Fix issues with dynamic models on listen servers #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions src/game/client/cdll_client_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,17 @@ void CHLClient::ResetStringTablePointers()
#endif
}

static void ClearClientDynamicModelList()
{
// engine bugfix: clear out client dynamic model list for listen servers
// TODO remove this when the engine is updated
struct CModelInfo : IVModelInfoClient
{
CUtlVector< model_t* > m_vecDynamicModels;
};
static_cast<CModelInfo*>( modelinfo )->m_vecDynamicModels.Purge();
}

//-----------------------------------------------------------------------------
// Purpose: Per level de-init
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1756,6 +1767,8 @@ void CHLClient::LevelShutdown( void )

messagechars->Clear();

ClearClientDynamicModelList();

#ifndef TF_CLIENT_DLL
// don't want to do this for TF2 because we have particle systems in our
// character loadout screen that can be viewed when we're not connected to a server
Expand Down
25 changes: 24 additions & 1 deletion src/game/server/baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ IMPLEMENT_SERVERCLASS_ST_NOBASE( CBaseEntity, DT_BaseEntity )

END_SEND_TABLE()

static bool g_bInRegisterModelLoadCallback = false;
static void MarkDynamicModelLoadedStringTable( const model_t* pModel )
{
// engine bugfix: ensure this dynamic model is marked as loaded in the string table
// TODO remove this when the engine is updated
extern INetworkStringTable* g_pStringTableDynamicModels;
if ( g_pStringTableDynamicModels )
{
const char* pModelName = modelinfo->GetModelName( pModel );
int nIdx = g_pStringTableDynamicModels->FindStringIndex( pModelName );
if ( nIdx != INVALID_STRING_INDEX )
{
bool bLoaded = true;
g_pStringTableDynamicModels->SetStringUserData( nIdx, sizeof( bLoaded ), &bLoaded );
}
}
}

// dynamic models
class CBaseEntityModelLoadProxy
Expand All @@ -328,7 +345,12 @@ class CBaseEntityModelLoadProxy
public:
explicit CBaseEntityModelLoadProxy( CBaseEntity *pEntity ) : m_pHandler( new Handler( pEntity ) ) { }
~CBaseEntityModelLoadProxy() { delete m_pHandler; }
void Register( int nModelIndex ) const { modelinfo->RegisterModelLoadCallback( nModelIndex, m_pHandler ); }
void Register( int nModelIndex ) const
{
g_bInRegisterModelLoadCallback = true;
modelinfo->RegisterModelLoadCallback( nModelIndex, m_pHandler );
g_bInRegisterModelLoadCallback = false;
}
operator CBaseEntity * () const { return m_pHandler->m_pEntity; }

private:
Expand All @@ -340,6 +362,7 @@ static CUtlHashtable< CBaseEntityModelLoadProxy, empty_t, PointerHashFunctor, Po

void CBaseEntityModelLoadProxy::Handler::OnModelLoadComplete( const model_t *pModel )
{
MarkDynamicModelLoadedStringTable( pModel );
m_pEntity->OnModelLoadComplete( pModel );
sg_DynamicLoadHandlers.Remove( m_pEntity ); // NOTE: destroys *this!
}
Expand Down
4 changes: 4 additions & 0 deletions src/game/server/gameinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ INetworkStringTable *g_pStringTableServerPopFiles = NULL;
INetworkStringTable *g_pStringTableServerMapCycleMvM = NULL;
#endif

INetworkStringTable* g_pStringTableDynamicModels = NULL;

CStringTableSaveRestoreOps g_VguiScreenStringOps;

// Holds global variables shared between engine and game.
Expand Down Expand Up @@ -1453,6 +1455,8 @@ void CServerGameDLL::CreateNetworkStringTables( void )
g_pStringTableServerMapCycleMvM = networkstringtable->CreateStringTable( "ServerMapCycleMvM", 128 );
#endif

g_pStringTableDynamicModels = networkstringtable->FindTable( "DynamicModels" );

bool bPopFilesValid = true;
(void)bPopFilesValid; // Avoid unreferenced variable warning

Expand Down