コード例 #1
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_EntityFlame::Simulate( void )
{
	if (m_bAttachedToHitboxes)
	{
		UpdateHitBoxFlames();
	}
	else
	{
		m_pEmitter->SetSortOrigin( GetAbsOrigin() );

		float tempDelta = gpGlobals->frametime;
		
		SimpleParticle *pParticle;

		Vector	offset;

		while( m_ParticleSpawn.NextEvent( tempDelta ) )
		{
			offset.Random( -m_flSize, m_flSize );

			pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle[random->RandomInt( 0, NUM_FLAMELETS-1 )], GetAbsOrigin() + offset );

			if ( pParticle )
			{
				pParticle->m_flDieTime	= 0.4f;
				pParticle->m_flLifetime	= 0.0f;
				
				pParticle->m_flRoll		= random->RandomInt( 0, 360 );
				pParticle->m_flRollDelta= random->RandomFloat( -2.0f, 2.0f );
				
				pParticle->m_uchStartSize	= random->RandomInt( 4, 6 );
				pParticle->m_uchEndSize		= random->RandomInt( 12, 16 );
				pParticle->m_uchStartAlpha	= 255;
				pParticle->m_uchEndAlpha	= 0;
				
				int	cScale = 255;//random->RandomInt( 192, 255 );
				pParticle->m_uchColor[0]	= cScale;
				pParticle->m_uchColor[1]	= cScale;
				pParticle->m_uchColor[2]	= cScale;
				
				Vector dir;

				dir.x = random->RandomFloat( -1.0f, 1.0f );
				dir.y = random->RandomFloat( -1.0f, 1.0f );
				dir.z = random->RandomFloat( 0.5f, 1.0f );

				pParticle->m_vecVelocity	= dir * random->RandomInt( 4, 32 );
				pParticle->m_vecVelocity[2] = random->RandomInt( 32, 64 );
			}
		}
	}
}
コード例 #2
0
ファイル: c_fire_smoke.cpp プロジェクト: paralin/hl2sdk
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_EntityFlame::Simulate( void )
{
	if ( gpGlobals->frametime <= 0.0f )
		return;

#ifdef HL2_EPISODIC 
	// Server side flames need to shrink and die
	if ( !m_bCreatedClientside && !m_bStartedFading )
	{
		float flTTL = (m_flLifetime - gpGlobals->curtime);
		if ( flTTL < 2.0 )
		{
			for (int i = 0; i < NUM_HITBOX_FIRES; i++)
			{
				if ( m_pFireSmoke[i] )
				{
					m_pFireSmoke[i]->m_flScaleStart = m_pFireSmoke[i]->m_flScaleEnd;
					m_pFireSmoke[i]->m_flScaleEnd = 0.00001;
					m_pFireSmoke[i]->m_flScaleTimeStart = gpGlobals->curtime;
					m_pFireSmoke[i]->m_flScaleTimeEnd = m_flLifetime;
					m_pFireSmoke[i]->m_flScaleRegister = -1;
				}
			}

			m_bStartedFading = true;
		}
	}

	if ( IsEffectActive(EF_BRIGHTLIGHT) || IsEffectActive(EF_DIMLIGHT) )
	{
		dlight_t *dl = effects->CL_AllocDlight ( index );
		dl->origin = GetAbsOrigin();
 		dl->origin[2] += 16;
		dl->color.r = 254;
		dl->color.g = 174;
		dl->color.b = 10;
		dl->radius = random->RandomFloat(400,431);
		dl->die = gpGlobals->curtime + 0.001;

 		if ( m_pFireSmoke[0] )
		{
			if ( m_pFireSmoke[0]->m_flScaleRegister == -1 )
			{
				// We've started shrinking, but UpdateScale() hasn't been
				// called since then. We want to use the Start scale instead.
				dl->radius *= m_pFireSmoke[0]->m_flScaleStart;
			}
			else
			{
				dl->radius *= m_pFireSmoke[0]->m_flScaleRegister;
			}
		}
	}
#endif // HL2_EPISODIC 

	if ( m_bAttachedToHitboxes )
	{
		UpdateHitBoxFlames();
	}
	else if ( !!m_pEmitter )
	{
		m_pEmitter->SetSortOrigin( GetAbsOrigin() );

		SimpleParticle *pParticle;

		Vector	offset;

		Vector	moveDiff	= GetAbsOrigin() - m_vecLastPosition;
		float	moveLength	= VectorNormalize( moveDiff );

		int	numPuffs = moveLength / (m_flSize*0.5f);

		numPuffs = clamp( numPuffs, 1, 8 );

		Vector			offsetColor;
		float			step = moveLength / numPuffs;

		//Fill in the gaps
		for ( int i = 1; i < numPuffs+1; i++ )
		{
			offset = m_vecLastPosition + ( moveDiff * step * i );

			pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle[random->RandomInt( 0, NUM_FLAMELETS-1 )], offset );

			if ( pParticle )
			{
				pParticle->m_flDieTime	= 0.4f;
				pParticle->m_flLifetime	= 0.0f;
				
				pParticle->m_flRoll		= random->RandomInt( 0, 360 );
				pParticle->m_flRollDelta= random->RandomFloat( -2.0f, 2.0f );
				
				pParticle->m_uchStartSize	= random->RandomInt( m_flSize*0.25f, m_flSize*0.5f );
				pParticle->m_uchEndSize		= pParticle->m_uchStartSize * 2.0f;
				pParticle->m_uchStartAlpha	= 255;
				pParticle->m_uchEndAlpha	= 0;
				
				pParticle->m_uchColor[0] = pParticle->m_uchColor[1]	= pParticle->m_uchColor[2]	= 255;
				
				Vector dir;

				dir.x = random->RandomFloat( -1.0f, 1.0f );
				dir.y = random->RandomFloat( -1.0f, 1.0f );
				dir.z = random->RandomFloat( 0.5f, 1.0f );

				pParticle->m_vecVelocity	= dir * random->RandomInt( 4, 32 );
				pParticle->m_vecVelocity[2] = random->RandomInt( 32, 64 );
			}
		}
	}

	m_vecLastPosition = GetRenderOrigin();
}