mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-14 12:46:58 +00:00
add source-sdk-2013
This commit is contained in:
+43
-70
@@ -97,8 +97,8 @@ CParticleSubTextureGroup::~CParticleSubTextureGroup()
|
||||
|
||||
CParticleSubTexture::CParticleSubTexture()
|
||||
{
|
||||
m_tCoordMins[0] = m_tCoordMins[1] = 0;
|
||||
m_tCoordMaxs[0] = m_tCoordMaxs[1] = 1;
|
||||
m_tCoordMins[0] = m_tCoordMins[0] = 0;
|
||||
m_tCoordMaxs[0] = m_tCoordMaxs[0] = 1;
|
||||
m_pGroup = &m_DefaultGroup;
|
||||
m_pMaterial = NULL;
|
||||
|
||||
@@ -235,8 +235,8 @@ inline void CParticleEffectBinding::StartDrawMaterialParticles(
|
||||
// Setup the ParticleDraw and bind the material.
|
||||
if( bWireframe )
|
||||
{
|
||||
IMaterial *pMaterialWire = m_pParticleMgr->m_pMaterialSystem->FindMaterial( "debug/debugparticlewireframe", TEXTURE_GROUP_OTHER );
|
||||
pRenderContext->Bind( pMaterialWire, NULL );
|
||||
IMaterial *pMaterial = m_pParticleMgr->m_pMaterialSystem->FindMaterial( "debug/debugparticlewireframe", TEXTURE_GROUP_OTHER );
|
||||
pRenderContext->Bind( pMaterial, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -470,11 +470,8 @@ int CParticleEffectBinding::DrawModel( int flags )
|
||||
|
||||
if ( bDraw )
|
||||
{
|
||||
if ( debugoverlay )
|
||||
{
|
||||
debugoverlay->AddBoxOverlay( center, mins, maxs, QAngle( 0, 0, 0 ), r, g, b, 16, 0 );
|
||||
debugoverlay->AddTextOverlayRGB( center, 0, 0, r, g, b, 64, "%s:(%d)", m_pSim->GetEffectName(), m_nActiveParticles );
|
||||
}
|
||||
debugoverlay->AddBoxOverlay( center, mins, maxs, QAngle( 0, 0, 0 ), r, g, b, 16, 0 );
|
||||
debugoverlay->AddTextOverlayRGB( center, 0, 0, r, g, b, 64, "%s:(%d)", m_pSim->GetEffectName(), m_nActiveParticles );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1543,15 +1540,12 @@ static ConVar r_threaded_particles( "r_threaded_particles", "1" );
|
||||
|
||||
static float s_flThreadedPSystemTimeStep;
|
||||
|
||||
static void ProcessPSystem( ParticleSimListEntry_t& pSimListEntry )
|
||||
static void ProcessPSystem( CNewParticleEffect *&pNewEffect )
|
||||
{
|
||||
// Enable FP exceptions here when FP_EXCEPTIONS_ENABLED is defined,
|
||||
// to help track down bad math.
|
||||
FPExceptionEnabler enableExceptions;
|
||||
|
||||
CNewParticleEffect* pNewEffect = pSimListEntry.m_pNewParticleEffect;
|
||||
bool updateBboxOnly = pSimListEntry.m_bBoundingBoxOnly;
|
||||
|
||||
// If this is a new effect, then update its bbox so it goes in the
|
||||
// right leaves (if it has particles).
|
||||
int bFirstUpdate = pNewEffect->GetNeedsBBoxUpdate();
|
||||
@@ -1570,12 +1564,12 @@ static void ProcessPSystem( ParticleSimListEntry_t& pSimListEntry )
|
||||
|
||||
if ( pNewEffect->GetFirstFrameFlag() )
|
||||
{
|
||||
pNewEffect->Simulate( 0.0f, updateBboxOnly );
|
||||
pNewEffect->Simulate( 0.0f );
|
||||
pNewEffect->SetFirstFrameFlag( false );
|
||||
}
|
||||
else if ( pNewEffect->ShouldSimulate() )
|
||||
{
|
||||
pNewEffect->Simulate( s_flThreadedPSystemTimeStep, updateBboxOnly );
|
||||
pNewEffect->Simulate( s_flThreadedPSystemTimeStep );
|
||||
}
|
||||
|
||||
if ( pNewEffect->IsFinished() )
|
||||
@@ -1586,7 +1580,7 @@ static void ProcessPSystem( ParticleSimListEntry_t& pSimListEntry )
|
||||
|
||||
|
||||
int CParticleMgr::ComputeParticleDefScreenArea( int nInfoCount, RetireInfo_t *pInfo, float *pTotalArea, CParticleSystemDefinition* pDef,
|
||||
const CViewSetup& viewParticle, const VMatrix &worldToPixels, float flFocalDist )
|
||||
const CViewSetup& view, const VMatrix &worldToPixels, float flFocalDist )
|
||||
{
|
||||
int nCollection = 0;
|
||||
float flCullCost = pDef->GetCullFillCost();
|
||||
@@ -1595,7 +1589,7 @@ int CParticleMgr::ComputeParticleDefScreenArea( int nInfoCount, RetireInfo_t *pI
|
||||
*pTotalArea = 0.0f;
|
||||
|
||||
#ifdef DBGFLAG_ASSERT
|
||||
float flMaxPixels = viewParticle.width * viewParticle.height;
|
||||
float flMaxPixels = view.width * view.height;
|
||||
#endif
|
||||
|
||||
CParticleCollection *pCollection = pDef->FirstCollection();
|
||||
@@ -1617,16 +1611,16 @@ int CParticleMgr::ComputeParticleDefScreenArea( int nInfoCount, RetireInfo_t *pI
|
||||
vecCenter = pCollection->GetControlPointAtCurrentTime( pDef->GetCullControlPoint() );
|
||||
|
||||
Vector3DMultiplyPositionProjective( worldToPixels, vecCenter, vecScreenCenter );
|
||||
float lSqr = vecCenter.DistToSqr( viewParticle.origin );
|
||||
float lSqr = vecCenter.DistToSqr( view.origin );
|
||||
|
||||
float flProjRadius = ( lSqr > flCullRadiusSqr ) ? 0.5f * flFocalDist * flCullRadius / sqrt( lSqr - flCullRadiusSqr ) : 1.0f;
|
||||
flProjRadius *= viewParticle.width;
|
||||
flProjRadius *= view.width;
|
||||
|
||||
float flMinX = MAX( viewParticle.x, vecScreenCenter.x - flProjRadius );
|
||||
float flMaxX = MIN( viewParticle.x + viewParticle.width, vecScreenCenter.x + flProjRadius );
|
||||
float flMinX = MAX( view.x, vecScreenCenter.x - flProjRadius );
|
||||
float flMaxX = MIN( view.x + view.width, vecScreenCenter.x + flProjRadius );
|
||||
|
||||
float flMinY = MAX( viewParticle.y, vecScreenCenter.y - flProjRadius );
|
||||
float flMaxY = MIN( viewParticle.y + viewParticle.height, vecScreenCenter.y + flProjRadius );
|
||||
float flMinY = MAX( view.y, vecScreenCenter.y - flProjRadius );
|
||||
float flMaxY = MIN( view.y + view.height, vecScreenCenter.y + flProjRadius );
|
||||
|
||||
float flArea = ( flMaxX - flMinX ) * ( flMaxY - flMinY );
|
||||
Assert( flArea <= flMaxPixels );
|
||||
@@ -1688,9 +1682,9 @@ bool CParticleMgr::RetireParticleCollections( CParticleSystemDefinition* pDef,
|
||||
}
|
||||
|
||||
// Next, see if there are new particle systems that need early retirement
|
||||
static ConVar cl_particle_retire_cost( "cl_particle_retire_cost", "0", FCVAR_CHEAT | FCVAR_ALLOWED_IN_COMPETITIVE );
|
||||
static ConVar cl_particle_retire_cost( "cl_particle_retire_cost", "0", FCVAR_CHEAT );
|
||||
|
||||
bool CParticleMgr::EarlyRetireParticleSystems( int nCount, ParticleSimListEntry_t *ppEffects )
|
||||
bool CParticleMgr::EarlyRetireParticleSystems( int nCount, CNewParticleEffect **ppEffects )
|
||||
{
|
||||
// NOTE: Doing a cheap and hacky estimate of worst-case fillrate
|
||||
const CViewSetup *pViewSetup = view->GetPlayerViewSetup();
|
||||
@@ -1705,14 +1699,14 @@ bool CParticleMgr::EarlyRetireParticleSystems( int nCount, ParticleSimListEntry_
|
||||
CParticleSystemDefinition **ppDefs = (CParticleSystemDefinition**)stackalloc( nCount * sizeof(CParticleSystemDefinition*) );
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
CParticleSystemDefinition *pDef = ppEffects[i].m_pNewParticleEffect->m_pDef;
|
||||
CParticleSystemDefinition *pDef = ppEffects[i]->m_pDef;
|
||||
|
||||
// Skip stuff that doesn't have a cull radius set
|
||||
if ( pDef->GetCullRadius() == 0.0f )
|
||||
continue;
|
||||
|
||||
// Only perform the cull check on creation
|
||||
if ( !ppEffects[i].m_pNewParticleEffect->GetFirstFrameFlag() )
|
||||
if ( !ppEffects[i]->GetFirstFrameFlag() )
|
||||
continue;
|
||||
|
||||
if ( pDef->HasRetirementBeenChecked( gpGlobals->framecount ) )
|
||||
@@ -1720,7 +1714,7 @@ bool CParticleMgr::EarlyRetireParticleSystems( int nCount, ParticleSimListEntry_
|
||||
|
||||
pDef->MarkRetirementCheck( gpGlobals->framecount );
|
||||
|
||||
ppDefs[nDefCount++] = ppEffects[i].m_pNewParticleEffect->m_pDef;
|
||||
ppDefs[nDefCount++] = ppEffects[i]->m_pDef;
|
||||
}
|
||||
|
||||
if ( nDefCount == 0 )
|
||||
@@ -1728,7 +1722,7 @@ bool CParticleMgr::EarlyRetireParticleSystems( int nCount, ParticleSimListEntry_
|
||||
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
ppEffects[i].m_pNewParticleEffect->MarkShouldPerformCullCheck( true );
|
||||
ppEffects[i]->MarkShouldPerformCullCheck( true );
|
||||
}
|
||||
|
||||
Vector vecCameraForward;
|
||||
@@ -1755,45 +1749,28 @@ bool CParticleMgr::EarlyRetireParticleSystems( int nCount, ParticleSimListEntry_
|
||||
|
||||
for ( int i = 0; i < nCount; ++i )
|
||||
{
|
||||
ppEffects[i].m_pNewParticleEffect->MarkShouldPerformCullCheck( false );
|
||||
ppEffects[i]->MarkShouldPerformCullCheck( false );
|
||||
}
|
||||
return bRetiredCollections;
|
||||
}
|
||||
|
||||
static ConVar particle_sim_alt_cores( "particle_sim_alt_cores", "2" );
|
||||
|
||||
void CParticleMgr::BuildParticleSimList( CUtlVector< ParticleSimListEntry_t > &list )
|
||||
void CParticleMgr::BuildParticleSimList( CUtlVector< CNewParticleEffect* > &list )
|
||||
{
|
||||
float flNow = g_pParticleSystemMgr->GetLastSimulationTime();
|
||||
for( CNewParticleEffect *pNewEffect=m_NewEffects.m_pHead; pNewEffect;
|
||||
pNewEffect=pNewEffect->m_pNext )
|
||||
{
|
||||
bool bSkip = false;
|
||||
bool bNeedsBboxUpdate = false;
|
||||
|
||||
if ( flNow >= pNewEffect->m_flNextSleepTime && pNewEffect->m_nActiveParticles > 0 )
|
||||
bSkip = true;
|
||||
continue;
|
||||
if ( pNewEffect->GetRemoveFlag() )
|
||||
bSkip = true;
|
||||
|
||||
if ( !bSkip && g_bMeasureParticlePerformance )
|
||||
continue;
|
||||
if ( g_bMeasureParticlePerformance )
|
||||
{
|
||||
g_nNumParticlesSimulated += pNewEffect->m_nActiveParticles;
|
||||
}
|
||||
|
||||
// Particles that are attached to moving things will need to update their bboxes even if they
|
||||
// otherwise would like to skip the updates. Check that here.
|
||||
if (bSkip)
|
||||
{
|
||||
bNeedsBboxUpdate = pNewEffect->HasMoved();
|
||||
bSkip = !bNeedsBboxUpdate;
|
||||
}
|
||||
|
||||
if (!bSkip)
|
||||
{
|
||||
ParticleSimListEntry_t entry = { pNewEffect, bNeedsBboxUpdate };
|
||||
list.AddToTail( entry );
|
||||
}
|
||||
list.AddToTail( pNewEffect );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1835,26 +1812,22 @@ void CParticleMgr::UpdateNewEffects( float flTimeDelta )
|
||||
int nParticleStatsTriggerCount = cl_particle_stats_trigger_count.GetInt();
|
||||
|
||||
BeginSimulateParticles();
|
||||
CUtlVector<CNewParticleEffect *> particlesToSimulate;
|
||||
BuildParticleSimList( particlesToSimulate );
|
||||
s_flThreadedPSystemTimeStep = flTimeDelta;
|
||||
|
||||
// first, run non-reentrant part to get CP updates from entities
|
||||
// This is done on all particles, because it updates control point locations which we need to determine whether or not we should
|
||||
// do full simulation later.
|
||||
for (CNewParticleEffect *pNewEffect = m_NewEffects.m_pHead; pNewEffect;
|
||||
pNewEffect = pNewEffect->m_pNext)
|
||||
{
|
||||
// this one can call into random entity code which may not be thread-safe
|
||||
pNewEffect->Update( s_flThreadedPSystemTimeStep );
|
||||
if ( nParticleStatsTriggerCount > 0 )
|
||||
{
|
||||
nParticleActiveParticlesCount += CountParticleSystemActiveParticles( pNewEffect );
|
||||
}
|
||||
}
|
||||
|
||||
CUtlVector<ParticleSimListEntry_t> particlesToSimulate;
|
||||
BuildParticleSimList(particlesToSimulate);
|
||||
int nCount = particlesToSimulate.Count();
|
||||
|
||||
// first, run non-reentrant part to get CP updates from entities
|
||||
for( int i=0; i<nCount; i++ )
|
||||
{
|
||||
// this one can call into random entity code which may not be thread-safe
|
||||
particlesToSimulate[i]->Update( s_flThreadedPSystemTimeStep );
|
||||
if ( nParticleStatsTriggerCount > 0 )
|
||||
{
|
||||
nParticleActiveParticlesCount += CountParticleSystemActiveParticles( particlesToSimulate[i] );
|
||||
}
|
||||
}
|
||||
|
||||
// See if there are new particle systems that need early retirement
|
||||
// This has to happen after the first update
|
||||
@@ -1888,7 +1861,7 @@ void CParticleMgr::UpdateNewEffects( float flTimeDelta )
|
||||
{
|
||||
nAltCore = 2;
|
||||
}
|
||||
CParallelProcessor<ParticleSimListEntry_t, CFuncJobItemProcessor<ParticleSimListEntry_t> > processor( "CParticleMgr::UpdateNewEffects" );
|
||||
CParallelProcessor<CNewParticleEffect*, CFuncJobItemProcessor<CNewParticleEffect*> > processor( "CParticleMgr::UpdateNewEffects" );
|
||||
processor.m_ItemProcessor.Init( ProcessPSystem, NULL, NULL );
|
||||
processor.Run( particlesToSimulate.Base(), nCount, INT_MAX, m_pThreadPool[nAltCore-1] );
|
||||
}
|
||||
@@ -1899,7 +1872,7 @@ void CParticleMgr::UpdateNewEffects( float flTimeDelta )
|
||||
for( int i=0; i<nCount; i++)
|
||||
{
|
||||
// this one can call into random entity code which may not be thread-safe
|
||||
particlesToSimulate[i].m_pNewParticleEffect->DetectChanges();
|
||||
particlesToSimulate[i]->DetectChanges();
|
||||
}
|
||||
|
||||
EndSimulateParticles();
|
||||
|
||||
Reference in New Issue
Block a user