Skip to content
Closed
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
7 changes: 4 additions & 3 deletions engine/audio/private/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../../client.h"
#include "../../cl_main.h"
#include "tier1/utldict.h"
#include "tier1/utlmapmt.h"
#include "mempool.h"
#include "../../enginetrace.h" // for traceline
#include "../../public/bspflags.h" // for traceline
Expand Down Expand Up @@ -299,13 +300,13 @@ static float s_lastsoundtime = 0.0f;

bool s_bOnLoadScreen = false;

static CClassMemoryPool< CSfxTable > s_SoundPool( MAX_SFX );
static CClassMemoryPoolMT< CSfxTable > s_SoundPool( MAX_SFX );
struct SfxDictEntry
{
CSfxTable *pSfx;
};

static CUtlMap< FileNameHandle_t, SfxDictEntry > s_Sounds( 0, 0, DefLessFunc( FileNameHandle_t ) );
static CUtlMapMT< FileNameHandle_t, SfxDictEntry > s_Sounds( 0, 0, DefLessFunc( FileNameHandle_t ) );

class CDummySfx : public CSfxTable
{
Expand Down Expand Up @@ -578,7 +579,7 @@ class CResourcePreloadSound : public CResourcePreload
}

private:
CUtlSymbolTable m_SoundNames;
CUtlSymbolTableMT m_SoundNames;
};
static CResourcePreloadSound s_ResourcePreloadSound;

Expand Down
4 changes: 2 additions & 2 deletions engine/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ rotates through a bunch of string buffers of 512 bytes each
*/
char *tmpstr512()
{
static char string[32][512];
static int curstring = 0;
static thread_local char string[32][512];
static thread_local int curstring = 0;
curstring = ( curstring + 1 ) & 31;
return string[curstring];
}
Expand Down
17 changes: 17 additions & 0 deletions engine/decals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ struct DecalEntry
// This stores the list of all decals
CUtlMap< FileNameHandle_t, DecalEntry > g_DecalDictionary( 0, 0, DefLessFunc( FileNameHandle_t ) );

// We could now use the CUtlMapMT but g_DecalLookup also exists and its easier to lock both and also reduces how many locks we create/destroy
#if defined(WIN32) || defined(_WIN32)
CThreadSpinRWLock g_DecalMutex;
#else
CThreadRWLock g_DecalMutex;
#endif

// This is a list of indices into the dictionary.
// This list is indexed by network id, so it maps network ids to decal dictionary entries
CUtlVector< int > g_DecalLookup;
Expand All @@ -56,6 +63,8 @@ int Draw_DecalMax( void )
// called from gl_rsurf.cpp
IMaterial *Draw_DecalMaterial( int index )
{
AUTO_LOCK_READ( g_DecalMutex );

if ( index < 0 || index >= g_DecalLookup.Count() )
return NULL;

Expand All @@ -70,6 +79,8 @@ IMaterial *Draw_DecalMaterial( int index )
#ifndef SWDS
void Draw_DecalSetName( int decal, const char *name )
{
AUTO_LOCK_WRITE( g_DecalMutex );

while ( decal >= g_DecalLookup.Count() )
{
MEM_ALLOC_CREDIT();
Expand Down Expand Up @@ -105,6 +116,8 @@ void Draw_DecalSetName( int decal, const char *name )
// used for save/restore
int Draw_DecalIndexFromName( const char *name, bool *found )
{
AUTO_LOCK_READ( g_DecalMutex );

Assert( found );

FileNameHandle_t fnHandle = g_pFileSystem->FindOrAddFileName( name );
Expand All @@ -129,6 +142,8 @@ int Draw_DecalIndexFromName( const char *name, bool *found )

const char *Draw_DecalNameFromIndex( int index )
{
AUTO_LOCK_READ( g_DecalMutex );

#if !defined(SWDS)
return g_DecalDictionary[index].material ? g_DecalDictionary[index].material->GetName() : "";
#else
Expand All @@ -148,6 +163,8 @@ void Decal_Init( void )
//-----------------------------------------------------------------------------
void Decal_Shutdown( void )
{
AUTO_LOCK_WRITE( g_DecalMutex );

for ( int index = g_DecalDictionary.FirstInorder(); index != g_DecalDictionary.InvalidIndex(); index = g_DecalDictionary.NextInorder(index) )
{
IMaterial *mat = g_DecalDictionary[index].material;
Expand Down
20 changes: 16 additions & 4 deletions engine/l_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ class CModelRender : public IVModelRender,

// Model instance data
CUtlLinkedList< ModelInstance_t, ModelInstanceHandle_t > m_ModelInstances;
CThreadFastMutex m_ModelInstancesMutex;

// current active model
studiohdr_t *m_pStudioHdr;
Expand Down Expand Up @@ -1250,8 +1251,8 @@ LightingState_t *CModelRender::TimeAverageLightingState( ModelInstanceHandle_t h
inst.m_flLightingTime = cl.GetTime();
}

static LightingState_t actualLightingState;
static dworldlight_t s_WorldLights[MAXLOCALLIGHTS];
static thread_local LightingState_t actualLightingState;
static thread_local dworldlight_t s_WorldLights[MAXLOCALLIGHTS];

// I'm creating the equation v = vf - (vf-vi)e^-at
// where vf = this frame's lighting value, vi = current time averaged lighting value
Expand Down Expand Up @@ -1599,7 +1600,7 @@ void CModelRender::StudioSetupLighting( const DrawModelState_t &state, const Vec
{
pRenderContext->SetAmbientLight( 1.0, 1.0, 1.0 );

static Vector white[6] =
static const Vector white[6] =
{
Vector( 1.0, 1.0, 1.0 ),
Vector( 1.0, 1.0, 1.0 ),
Expand All @@ -1620,7 +1621,7 @@ void CModelRender::StudioSetupLighting( const DrawModelState_t &state, const Vec
{
float add = r_itemblinkmax.GetFloat() * ( FastCos( r_itemblinkrate.GetFloat() * Sys_FloatTime() ) + 1.0f );
Vector additiveColor( add, add, add );
static Vector temp[6];
static thread_local Vector temp[6];
int i;
for( i = 0; i < 6; i++ )
{
Expand Down Expand Up @@ -1868,6 +1869,7 @@ struct ModelDebugOverlayData_t
};

static CUtlVector<ModelDebugOverlayData_t> s_SavedModelInfo;
static CThreadFastMutex s_SavedModelInfoMutex;

void DrawModelDebugOverlay( const DrawModelInfo_t& info, const DrawModelResults_t &results, const Vector &origin, float r = 1.0f, float g = 1.0f, float b = 1.0f )
{
Expand Down Expand Up @@ -1941,6 +1943,8 @@ void DrawModelDebugOverlay( const DrawModelInfo_t& info, const DrawModelResults_

void AddModelDebugOverlay( const DrawModelInfo_t& info, const DrawModelResults_t &results, const Vector& origin )
{
AUTO_LOCK( s_SavedModelInfoMutex );

ModelDebugOverlayData_t &tmp = s_SavedModelInfo[s_SavedModelInfo.AddToTail()];
tmp.m_ModelInfo = info;
tmp.m_ModelResults = results;
Expand All @@ -1949,6 +1953,8 @@ void AddModelDebugOverlay( const DrawModelInfo_t& info, const DrawModelResults_t

void ClearSaveModelDebugOverlays( void )
{
AUTO_LOCK( s_SavedModelInfoMutex );

s_SavedModelInfo.RemoveAll();
}

Expand All @@ -1957,6 +1963,8 @@ static ConVar r_drawmodelstatsoverlaymax( "r_drawmodelstatsoverlaymax", "1.5", F

void DrawSavedModelDebugOverlays( void )
{
AUTO_LOCK( s_SavedModelInfoMutex );

if( s_SavedModelInfo.Count() == 0 )
{
return;
Expand Down Expand Up @@ -4231,6 +4239,10 @@ ModelInstanceHandle_t CModelRender::CreateInstance( IClientRenderable *pRenderab
{
Assert( pRenderable );

// RaphaelIT7: Perferably, we make everything threadsafe so that we only need to lock until instance.m_FirstShadow
// But currently most functions are not threadsafe all and will crash if we don't block to 1 thread at a time.
AUTO_LOCK( m_ModelInstancesMutex );

// ensure all components are available
model_t *pModel = (model_t*)pRenderable->GetModel();

Expand Down
3 changes: 3 additions & 0 deletions engine/lightcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2195,8 +2195,11 @@ static ITexture *FindEnvCubemapForPoint( const Vector& origin )
//-----------------------------------------------------------------------------
// Create static light cache entry
//-----------------------------------------------------------------------------
static CThreadMutex g_pPropCacheMutex;
LightCacheHandle_t CreateStaticLightingCache( const Vector& origin, const Vector& mins, const Vector& maxs )
{
AUTO_LOCK( g_pPropCacheMutex );

PropLightcache_t* pcache = s_PropCache.Alloc();

pcache->m_LightingOrigin = origin;
Expand Down
Loading