Exemplo n.º 1
0
int Update::registerEvent(boost::posix_time::time_duration time, gameplay::EventAction eventAction)
{
    boost::lock_guard<boost::mutex> lock(eventMutex);
    TimedEvent* event = new TimedEvent(time, eventAction);
    event->init();
    timedEvents[event->getID()] = event;
    return event->getID();
}
Exemplo n.º 2
0
int Update::registerEvent(boost::posix_time::time_duration time, script::lua_functor_t luaFunctor, script::lua_functor_t progressFunction)
{
    boost::lock_guard<boost::mutex> lock(eventMutex);
    TimedEvent* event = new TimedEvent(time, luaFunctor, progressFunction);
    event->init();
    timedEvents[event->getID()] = event;
    return event->getID();
}
Exemplo n.º 3
0
int Update::registerEvent(boost::posix_time::time_duration time, boost::function<void (int)> intFunction,boost::function<void (float)> progressFunction, int num)
{
    boost::lock_guard<boost::mutex> lock(eventMutex);
    TimedEvent* event = new TimedEvent(time, intFunction,progressFunction,num);
    event->init();
    timedEvents[event->getID()] = event;
    return event->getID();
}
Exemplo n.º 4
0
int Update::registerEvent(boost::posix_time::time_duration time, boost::function<void (void)> voidFunction)
{
    boost::lock_guard<boost::mutex> lock(eventMutex);
    TimedEvent* event = new TimedEvent(time, voidFunction);
    event->init();
    timedEvents[event->getID()] = event;
    return event->getID();
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : bnewentity - 
//-----------------------------------------------------------------------------
void C_EntityFlame::OnDataChanged( DataUpdateType_t updateType )
{
	if ( updateType == DATA_UPDATE_CREATED )
	{
		SetupEntityRenderHandle( RENDER_GROUP_TRANSLUCENT_ENTITY );

		C_BaseEntity *pEnt = m_hEntAttached;
		
		// FIXME: this should be IsBaseAnimating
		if (pEnt->IsBaseCombatCharacter())
		{
			AttachToHitBoxes();
		}
		else
		{
			m_ParticleSpawn.Init( 60 ); //Events per second

			m_pEmitter = CEmberEffect::Create("C_EntityFlame::Create");
			
			Assert( m_pEmitter.IsValid() );
			if ( m_pEmitter.IsValid() )
			{
				for ( int i = 1; i < NUM_FLAMELETS+1; i++ )
				{
					m_MaterialHandle[i-1] = m_pEmitter->GetPMaterial( VarArgs( "sprites/flamelet%d", i ) );
				}

				m_pEmitter->SetSortOrigin( GetAbsOrigin() );
			}
		}
	}
}
Exemplo n.º 6
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : fTimeDelta - 
//-----------------------------------------------------------------------------
void C_Plasma::Update( void )
{
	//Update all our parts
	UpdateScale();
	UpdateAnimation();
	UpdateFlames();

	if (m_flScaleRegister > 0.1)
	{
		float tempDelta = gpGlobals->frametime;
		while( m_tDecalSpawn.NextEvent( tempDelta ) )
		{
			// Add decal to floor
			C_BaseEntity *ent = cl_entitylist->GetEnt( 0 );
			if ( ent )
			{
				int index = decalsystem->GetDecalIndexForName( "PlasmaGlowFade" );
				if ( index >= 0 )
				{
					effects->DecalShoot( index, 0, ent->GetModel(), ent->GetAbsOrigin(), ent->GetAbsAngles(), GetAbsOrigin(), 0, 0 );
				}
			}
		}
	}
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_FireSmoke::Update( void )
{
	//If we haven't already, find the clip plane for smoke effects
	if ( ( m_nFlags & bitsFIRESMOKE_SMOKE ) && ( m_bClipTested == false ) )
	{
		FindClipPlane();
	}

	//Update all our parts
	UpdateEffects();
	UpdateScale();
	UpdateAnimation();
	UpdateFlames();

	//See if we should emit smoke
	if ( m_nFlags & bitsFIRESMOKE_SMOKE )
	{
		float tempDelta = Helper_GetFrameTime();

		while( m_tParticleSpawn.NextEvent( tempDelta ) )
		{
			SpawnSmoke();
		}
	}
}
//-----------------------------------------------------------------------------
// Purpose: Starts the effect
// Input  : *pParticleMgr - 
//			*pArgs - 
//-----------------------------------------------------------------------------
void C_SteamJet::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs)
{

#ifdef GE_DLL
	// If the client doesn't want the heat wave effect for explosions disable starting
	if ( m_bIsForExplosion && cl_ge_noexpheatwave.GetBool() )
		return;
#endif

	pParticleMgr->AddEffect( &m_ParticleEffect, this );
	
	switch(m_nType)
	{
	case STEAM_NORMAL:
	default:
		m_MaterialHandle = g_Mat_DustPuff[0];
		break;

	case STEAM_HEATWAVE:
		m_MaterialHandle = m_ParticleEffect.FindOrAddMaterial("sprites/heatwave");
		break;
	}

	m_ParticleSpawn.Init(m_Rate);
	m_Lifetime = m_JetLength / m_Speed;
	m_pParticleMgr = pParticleMgr;

	UpdateLightingRamp();
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_ExtinguisherJet::Start( void )
{
	SetupEntityRenderHandle( RENDER_GROUP_TRANSLUCENT_ENTITY );

	m_ParticleSpawn.Init( 100 ); //Events per second

	//Create the basic emitter
	m_pEmitter = CSimpleEmitter::Create("C_ExtinguisherJet::m_pEmitter");
	
	Assert( m_pEmitter.IsValid() );
	if ( m_pEmitter.IsValid() )
	{
		m_MaterialHandle = m_pEmitter->GetPMaterial( "particle/particle_smokegrenade" );
		m_pEmitter->SetSortOrigin( GetAbsOrigin() );
	}

	//Create the "ember" emitter for the smaller flecks
	m_pEmberEmitter = CEmberEffect::Create( "C_ExtinguisherJet::m_pEmberEmitter" );

	Assert( m_pEmberEmitter.IsValid() );
	if ( m_pEmberEmitter.IsValid() )
	{
		m_EmberMaterialHandle = m_pEmberEmitter->GetPMaterial( "particle/particle_smokegrenade" );
		m_pEmberEmitter->SetSortOrigin( GetAbsOrigin() );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_ObjectEMPGenerator::ClientThink( void )
{
	// Add particles at the target.
	float flCur = gpGlobals->frametime;
	while ( m_ParticleEvent.NextEvent( flCur ) )
	{
		Vector vPos = WorldSpaceCenter( );
		Vector vOffset = RandomVector( -1, 1 );
		VectorNormalize( vOffset );
		vPos += vOffset * RandomFloat( 0, 50 );
		
		SimpleParticle *pParticle = m_pEmitter->AddSimpleParticle( m_hParticleMaterial, vPos );
		if ( pParticle )
		{
			// Move the points along the path.
			pParticle->m_vecVelocity.Init();
			pParticle->m_flRoll = 0;
			pParticle->m_flRollDelta = 0;
			pParticle->m_flDieTime = 0.4f;
			pParticle->m_flLifetime = 0;
			pParticle->m_uchColor[0] = 255; 
			pParticle->m_uchColor[1] = 255;
			pParticle->m_uchColor[2] = 255;
			pParticle->m_uchStartAlpha = 32;
			pParticle->m_uchEndAlpha = 0;
			pParticle->m_uchStartSize = 6;
			pParticle->m_uchEndSize = 4;
			pParticle->m_iFlags = 0;
		}
	}
}
Exemplo n.º 11
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_ExtinguisherJet::Start( void )
{
	AddToLeafSystem( RENDER_GROUP_TRANSLUCENT_ENTITY );

	m_ParticleSpawn.Init( 100 ); //Events per second

	//Create the basic emitter
	m_pEmitter = CSimpleEmitter::Create("C_ExtinguisherJet::m_pEmitter");
	
	Assert( m_pEmitter.IsValid() );
	if ( m_pEmitter.IsValid() )
	{
		m_MaterialHandle = g_Mat_DustPuff[0];
		m_pEmitter->SetSortOrigin( GetAbsOrigin() );
	}

	//Create the "ember" emitter for the smaller flecks
	m_pEmberEmitter = CEmberEffect::Create( "C_ExtinguisherJet::m_pEmberEmitter" );

	Assert( m_pEmberEmitter.IsValid() );
	if ( m_pEmberEmitter.IsValid() )
	{
		m_EmberMaterialHandle = g_Mat_DustPuff[0];
		m_pEmberEmitter->SetSortOrigin( GetAbsOrigin() );
	}
}
Exemplo n.º 12
0
//-----------------------------------------------------------------------------
// Purpose: Starts the effect
// Input  : *pParticleMgr - 
//			*pArgs - 
//-----------------------------------------------------------------------------
void C_SmokeStack::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs)
{
	pParticleMgr->AddEffect( &m_ParticleEffect, this );
	
	// Figure out the material name.
	char str[512] = "unset_material";
	const model_t *pModel = modelinfo->GetModel( m_iMaterialModel );
	if ( pModel )
	{
		Q_strncpy( str, modelinfo->GetModelName( pModel ), sizeof( str ) );

		// Get rid of the extension because the material system doesn't want it.
		char *pExt = Q_stristr( str, ".vmt" );
		if ( pExt )
			pExt[0] = 0;
	}

	m_MaterialHandle[0] = m_ParticleEffect.FindOrAddMaterial( str );

	int iCount = 1;
	char szNames[512];

	int iLength = Q_strlen( str );
	str[iLength-1] = '\0';

	Q_snprintf( szNames, sizeof( szNames ), "%s%d.vmt", str, iCount );

	while ( filesystem->FileExists( VarArgs( "materials/%s", szNames ) ) && iCount < SMOKESTACK_MAX_MATERIALS )
	{
		char *pExt = Q_stristr( szNames, ".vmt" );
		if ( pExt )
			pExt[0] = 0;

		m_MaterialHandle[iCount] = m_ParticleEffect.FindOrAddMaterial( szNames );
		iCount++;
	}

	m_iMaxFrames = iCount-1;

	m_ParticleSpawn.Init( mat_reduceparticles.GetBool() ? m_Rate / 4 : m_Rate ); // Obey mat_reduceparticles in episodic

	m_InvLifetime = m_Speed / m_JetLength;

	m_pParticleMgr = pParticleMgr;

	// Figure out how we need to draw.
	IMaterial *pMaterial = pParticleMgr->PMaterialToIMaterial( m_MaterialHandle[0] );
	if( pMaterial )
	{
		m_Renderer.Init( pParticleMgr, pMaterial );
	}
	
	QueueLightParametersInRenderer();

	// For the first N seconds, always simulate so it can build up the smokestack.
	// Afterwards, we set it to freeze when it's not being rendered.
	m_ParticleEffect.SetAlwaysSimulate( true );
	SetNextClientThink( gpGlobals->curtime + 5 );
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_HopwireExplosion::StartExplosion( void )
{
	m_FXCoreScale.Init( 300.0f, 500.0f, 2.0f, INTERP_SPLINE );
	m_FXCoreAlpha.Init( 0.0f, 0.1f, 1.5f, INTERP_SPLINE );

	// Particle timer
	m_ParticleTimer.Init( 60 );
}
Exemplo n.º 14
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : fTimeDelta - 
//-----------------------------------------------------------------------------
void C_SmokeStack::Update(float fTimeDelta)
{
    if (!m_pParticleMgr)
    {
        assert(false);
        return;
    }

    // Don't spawn particles unless we're visible.
    if (m_bEmit && (m_ParticleEffect.WasDrawnPrevFrame() || m_ParticleEffect.GetAlwaysSimulate()))
    {
        // Add new particles.																	
        Vector forward, right, up;
        AngleVectors(GetAbsAngles(), &forward, &right, &up);

        float tempDelta = fTimeDelta;
        while (m_ParticleSpawn.NextEvent(tempDelta))
        {
            int iRandomFrame = random->RandomInt(0, m_iMaxFrames);

            iRandomFrame = 0;

            // Make a new particle.
            if (SmokeStackParticle *pParticle = (SmokeStackParticle*) m_ParticleEffect.AddParticle(sizeof(SmokeStackParticle), m_MaterialHandle[iRandomFrame]))
            {
                float angle = FRand(0, 2.0f*M_PI_F);

                pParticle->m_Pos = GetAbsOrigin() +
                    right * (cos(angle) * m_flBaseSpread) +
                    forward * (sin(angle) * m_flBaseSpread);

                pParticle->m_Velocity =
                    FRand(-m_SpreadSpeed, m_SpreadSpeed) * right +
                    FRand(-m_SpreadSpeed, m_SpreadSpeed) * forward +
                    m_Speed * up;

                pParticle->m_vAccel = m_vWind;
                pParticle->m_Lifetime = 0;
                pParticle->m_flAngle = 0.0f;

                pParticle->m_flRollDelta = random->RandomFloat(-m_flRollSpeed, m_flRollSpeed);
                pParticle->m_flSortPos = pParticle->m_Pos.z;
            }
        }
    }

    // Setup the twist matrix.
    float flTwist = (m_flTwist * (M_PI_F * 2.f) / 360.0f) * Helper_GetFrameTime();
    if ((m_bTwist = !!flTwist))
    {
        m_TwistMat[0][0] = cos(flTwist);
        m_TwistMat[0][1] = sin(flTwist);
        m_TwistMat[1][0] = -sin(flTwist);
        m_TwistMat[1][1] = cos(flTwist);
    }

    QueueLightParametersInRenderer();
}
void C_ParticleFire::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs)
{
	m_pParticleMgr = pParticleMgr;
	m_pParticleMgr->AddEffect( &m_ParticleEffect, this );
	m_MaterialHandle = m_ParticleEffect.FindOrAddMaterial("particle/particle_fire");

	// Start 
	m_nEmitters = 0;
	m_EmitterSpawn.Init(15);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input  : fTimeDelta -
//-----------------------------------------------------------------------------
void C_EntityParticleTrail::Update( float fTimeDelta )
{
    float tempDelta = fTimeDelta;
    studiohdr_t *pStudioHdr;
    mstudiohitboxset_t *set;
    matrix3x4_t	*hitboxbones[MAXSTUDIOBONES];

    C_BaseEntity *pMoveParent = GetMoveParent();
    if ( !pMoveParent )
        return;

    C_BaseAnimating *pAnimating = pMoveParent->GetBaseAnimating();
    if (!pAnimating)
        goto trailNoHitboxes;

    if ( !pAnimating->HitboxToWorldTransforms( hitboxbones ) )
        goto trailNoHitboxes;

    pStudioHdr = modelinfo->GetStudiomodel( pAnimating->GetModel() );
    if (!pStudioHdr)
        goto trailNoHitboxes;

    set = pStudioHdr->pHitboxSet( pAnimating->GetHitboxSet() );
    if ( !set )
        goto trailNoHitboxes;

    //Add new particles
    while ( m_teParticleSpawn.NextEvent( tempDelta ) )
    {
        int nHitbox = random->RandomInt( 0, set->numhitboxes - 1 );
        mstudiobbox_t *pBox = set->pHitbox(nHitbox);

        AddParticle( tempDelta, pBox->bbmin, pBox->bbmax, *hitboxbones[pBox->bone] );
    }
    return;

trailNoHitboxes:
    while ( m_teParticleSpawn.NextEvent( tempDelta ) )
    {
        AddParticle( tempDelta, pMoveParent->CollisionProp()->OBBMins(), pMoveParent->CollisionProp()->OBBMaxs(), pMoveParent->EntityToWorldTransform() );
    }
}
Exemplo n.º 17
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : updateType - 
//-----------------------------------------------------------------------------
void C_AlyxEmpEffect::OnDataChanged( DataUpdateType_t updateType )
{
	BaseClass::OnDataChanged( updateType );

	if ( updateType == DATA_UPDATE_CREATED )
	{
		m_tParticleSpawn.Init( 32 );
		SetNextClientThink( CLIENT_THINK_ALWAYS );
		SetupEmitters();
	}
}
Exemplo n.º 18
0
//-----------------------------------------------------------------------------
// Purpose: Client-side think function for the entity
//-----------------------------------------------------------------------------
void C_Sparkler::ClientThink( void )
{
	// We must have a valid emitter
	if ( m_hEmitter == NULL )
		return;

	// We must be allowed to emit particles by the server
	if ( m_bEmit == false )
		return;

	SimpleParticle *pParticle;

	float curTime = gpGlobals->frametime;

	// Add as many particles as required this frame
	while ( m_tParticleTimer.NextEvent( curTime ) )
	{
		// Create the particle
		pParticle = m_hEmitter->AddSimpleParticle( m_hMaterial, GetAbsOrigin() );

		if ( pParticle == NULL )
			return;

		// Setup our size
		pParticle->m_uchStartSize = (unsigned char) m_flScale;
		pParticle->m_uchEndSize = 0;

		// Setup our roll
		pParticle->m_flRoll = random->RandomFloat( 0, 2*M_PI );
		pParticle->m_flRollDelta = random->RandomFloat( -DEG2RAD( 180 ), DEG2RAD( 180 ) );

		// Set our color
		pParticle->m_uchColor[0] = 255;
		pParticle->m_uchColor[1] = 255;
		pParticle->m_uchColor[2] = 255;

		// Setup our alpha values
		pParticle->m_uchStartAlpha = 255;
		pParticle->m_uchEndAlpha = 255;
		
		// Obtain a random direction
		Vector velocity = RandomVector( -1.0f, 1.0f );
		VectorNormalize( velocity );

		// Obtain a random speed
		float speed = random->RandomFloat( 4.0f, 8.0f ) * m_flScale;

		// Set our velocity
		pParticle->m_vecVelocity = velocity * speed;

		// Die in a short range of time
		pParticle->m_flDieTime = random->RandomFloat( 0.25f, 0.5f );
	}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input  : *pParticleMgr -
//			*pArgs -
//-----------------------------------------------------------------------------
void C_EntityParticleTrail::Start( )
{
    if( ParticleMgr()->AddEffect( &m_ParticleEffect, this ) == false )
        return;

    const char *pMaterialName = GetMaterialNameFromIndex( m_iMaterialName );
    if ( !pMaterialName )
        return;

    m_hMaterial	= ParticleMgr()->GetPMaterial( pMaterialName );
    m_teParticleSpawn.Init( 150 );
}
Exemplo n.º 20
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 );
			}
		}
	}
}
Exemplo n.º 21
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : bool - 
//-----------------------------------------------------------------------------
void C_Flare::OnDataChanged( DataUpdateType_t updateType )
{
	if ( updateType == DATA_UPDATE_CREATED )
	{
		SetSortOrigin( GetAbsOrigin() );
		if ( m_bSmoke )
		{
			m_teSmokeSpawn.Init( 8 );
		}
	}

	BaseClass::OnDataChanged( updateType );
}
Exemplo n.º 22
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : updateType - 
//-----------------------------------------------------------------------------
void C_MortarShell::OnDataChanged( DataUpdateType_t updateType )
{
	BaseClass::OnDataChanged( updateType );

	if ( updateType == DATA_UPDATE_CREATED )
	{
		m_flStarttime = gpGlobals->curtime;
		AddToLeafSystem( RENDER_GROUP_TRANSLUCENT_ENTITY );

		m_pEmitter = CSimpleEmitter::Create( "C_EntityDissolve" );
		m_pEmitter->SetSortOrigin( GetAbsOrigin() );

		m_ParticleEvent.Init( 128 );
	}
}
Exemplo n.º 23
0
/* Call timed event at front of queue, whose time is <= `now'.
 * Returns true if an event handler was called. (false if time isn't up yet)
 */
bool TimeQueue::call_timer(uint32 now)
{
    if(empty())
        return(false);
    TimedEvent *tevent = tq.front();
    if(tevent->defunct)
    {
        assert(pop_timer() == tevent);
        delete_timer(tevent);
        return(false);
    }
    if(tevent->time > now)
        return(false);

    //dequeue event here
    pop_timer(); // remove timer in case we have recursion in the timed() call.

    tevent->timed(now); // fire

    //re-queue if repeating timer.

    if(tevent->repeat_count != 0) // repeat! same delay, add time
    {
        // use updated time so it isn't repeated too soon
        tevent->set_time();
//            tevent->time = clock->get_ticks() + tevent->delay;
//            tevent->time = now + tevent->delay;
        add_timer(tevent);
        if(tevent->repeat_count > 0) // don't reduce count if infinite (-1)
            --tevent->repeat_count;
    }
    else
        delete_timer(tevent); // if not repeated, safe to delete

    return(true);
}
Exemplo n.º 24
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : flPerc - 
//-----------------------------------------------------------------------------
void C_MortarShell::AddRisingParticles( float flPerc )
{
	SimpleParticle *sParticle;

	Vector offset;
	float radius = m_flRadius * 0.25f * flPerc;

	float val = RemapValClamped( gpGlobals->curtime, m_flStarttime, m_flStarttime + m_flLifespan, 0.0f, 1.0f );

	float flCur = gpGlobals->frametime;

	// Anime ground effects
	while ( m_ParticleEvent.NextEvent( flCur ) )
	{
		offset.x = random->RandomFloat( -radius, radius );
		offset.y = random->RandomFloat( -radius, radius );
		offset.z = random->RandomFloat( -8.0f, 8.0f );

		offset += GetAbsOrigin();

		sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/spark" ), offset );
		
		if ( sParticle == NULL )
			return;

		sParticle->m_vecVelocity = Vector( Helper_RandomFloat( -4.0f, 4.0f ), Helper_RandomFloat( -4.0f, 4.0f ), Helper_RandomFloat( 32.0f, 256.0f ) * Bias( val, 0.25f ) );
		
		sParticle->m_uchStartSize	= random->RandomFloat( 4, 8 ) * flPerc;

		sParticle->m_flDieTime = random->RandomFloat( 0.5f, 1.0f );
		
		sParticle->m_flLifetime		= 0.0f;

		sParticle->m_flRoll			= Helper_RandomInt( 0, 360 );

		float alpha = 255 * flPerc;

		sParticle->m_flRollDelta	= Helper_RandomFloat( -8.0f * flPerc, 8.0f * flPerc );
		sParticle->m_uchColor[0]	= alpha;
		sParticle->m_uchColor[1]	= alpha;
		sParticle->m_uchColor[2]	= alpha;
		sParticle->m_uchStartAlpha	= alpha;
		sParticle->m_uchEndAlpha	= 0;
		sParticle->m_uchEndSize		= 0;
	}
}
Exemplo n.º 25
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : flPerc - 
//-----------------------------------------------------------------------------
void C_MortarShell::AddExplodingParticles( float flPerc )
{
	SimpleParticle *sParticle;

	Vector offset;
	float radius = 48.0f * flPerc;

	float flCur = gpGlobals->frametime;

	// Anime ground effects
	while ( m_ParticleEvent.NextEvent( flCur ) )
	{
		offset.x = random->RandomFloat( -radius, radius );
		offset.y = random->RandomFloat( -radius, radius );
		offset.z = random->RandomFloat( -8.0f, 8.0f );

		offset += GetAbsOrigin();

		sParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_pEmitter->GetPMaterial( "effects/spark" ), offset );
		
		if ( sParticle == NULL )
			return;

		sParticle->m_vecVelocity = RandomVector( -1.0f, 1.0f ) + Vector( 0, 0, 1 );
		sParticle->m_vecVelocity *= ( 750.0f * flPerc );
		
		sParticle->m_uchStartSize	= random->RandomFloat( 2, 4 ) * flPerc;

		sParticle->m_flDieTime = random->RandomFloat( 0.25f, 0.5f );
		
		sParticle->m_flLifetime		= 0.0f;

		sParticle->m_flRoll			= Helper_RandomInt( 0, 360 );

		float alpha = 255 * flPerc;

		sParticle->m_flRollDelta	= Helper_RandomFloat( -8.0f * flPerc, 8.0f * flPerc );
		sParticle->m_uchColor[0]	= alpha;
		sParticle->m_uchColor[1]	= alpha;
		sParticle->m_uchColor[2]	= alpha;
		sParticle->m_uchStartAlpha	= alpha;
		sParticle->m_uchEndAlpha	= 0;
		sParticle->m_uchEndSize		= 0;
	}
}
Exemplo n.º 26
0
//-----------------------------------------------------------------------------
// Purpose: Starts the effect
// Input  : *pParticleMgr - 
//			*pArgs - 
//-----------------------------------------------------------------------------
void C_SteamJet::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs)
{
	pParticleMgr->AddEffect( &m_ParticleEffect, this );
	
	switch(m_nType)
	{
	case STEAM_NORMAL:
	default:
		m_MaterialHandle = m_ParticleEffect.FindOrAddMaterial("particle/particle_smokegrenade");
		break;

	case STEAM_HEATWAVE:
		m_MaterialHandle = m_ParticleEffect.FindOrAddMaterial("sprites/heatwave");
		break;
	}

	m_ParticleSpawn.Init(m_Rate);
	m_Lifetime = m_JetLength / m_Speed;
	m_pParticleMgr = pParticleMgr;

	UpdateLightingRamp();
}
Exemplo n.º 27
0
//-----------------------------------------------------------------------------
// Purpose: Starts the effect
// Input  : *pParticleMgr - 
//			*pArgs - 
//-----------------------------------------------------------------------------
void C_SmokeStack::Start(CParticleMgr *pParticleMgr, IPrototypeArgAccess *pArgs)
{
    pParticleMgr->AddEffect(&m_ParticleEffect, this);

    // Figure out the material name.
    char str[512] = "unset_material";
    const model_t *pModel = modelinfo->GetModel(m_iMaterialModel);
    if (pModel)
    {
        Q_strncpy(str, modelinfo->GetModelName(pModel), sizeof(str));

        // Get rid of the extension because the material system doesn't want it.
        char *pExt = Q_stristr(str, ".vmt");
        if (pExt)
            pExt[0] = 0;
    }

    m_MaterialHandle[0] = m_ParticleEffect.FindOrAddMaterial(str);

    m_ParticleSpawn.Init( m_Rate );

    m_InvLifetime = m_Speed / m_JetLength;

    m_pParticleMgr = pParticleMgr;

    // Figure out how we need to draw.
    IMaterial *pMaterial = pParticleMgr->PMaterialToIMaterial( m_MaterialHandle[0] );
    if( pMaterial )
    {
        m_Renderer.Init( pParticleMgr, pMaterial );
    }

    QueueLightParametersInRenderer();

    // For the first N seconds, always simulate so it can build up the smokestack.
    // Afterwards, we set it to freeze when it's not being rendered.
    m_ParticleEffect.SetAlwaysSimulate( true );
    SetNextClientThink( gpGlobals->curtime + 5 );
}
Exemplo n.º 28
0
//-----------------------------------------------------------------------------
// Purpose: Called when data changes on the server
//-----------------------------------------------------------------------------
void C_Sparkler::OnDataChanged( DataUpdateType_t updateType )
{
	// NOTE: We MUST call the base classes' implementation of this function
	BaseClass::OnDataChanged( updateType );
	
	// Setup our entity's particle system on creation
	if ( updateType == DATA_UPDATE_CREATED )
	{
		// Creat the emitter
		m_hEmitter = CSimpleEmitter::Create( "env_sparkler" );

		// Obtain a reference handle to our particle's desired material
		if ( m_hEmitter.IsValid() )
		{
			m_hMaterial = m_hEmitter->GetPMaterial( "effects/yellowflare" );
		}

		// Spawn 128 particles per second
		m_tParticleTimer.Init( 128 );

		// Call our ClientThink() function once every client frame
		SetNextClientThink( CLIENT_THINK_ALWAYS );
	}
}
Exemplo n.º 29
0
void EventableObjectHolder::Update(time_t time_difference)
{
	m_lock.Acquire();			// <<<<

	/* Insert any pending objects in the insert pool. */
	m_insertPoolLock.Acquire();
	InsertableQueue::iterator iqi;
	InsertableQueue::iterator iq2 = m_insertPool.begin();
	while(iq2 != m_insertPool.end())
	{
		iqi = iq2++;
		if((*iqi)->deleted || (*iqi)->instanceId != mInstanceId)
			(*iqi)->DecRef();
		else
			m_events.push_back( (*iqi) );

		m_insertPool.erase(iqi);
	}
	m_insertPoolLock.Release();

	/* Now we can proceed normally. */
	EventList::iterator itr = m_events.begin();
	EventList::iterator it2;
	TimedEvent * ev;

	while(itr != m_events.end())
	{
		it2 = itr++;

		if((*it2)->instanceId != mInstanceId || (*it2)->deleted || 
			( mInstanceId == WORLD_INSTANCE && (*it2)->eventFlag & EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT))
		{
			// remove from this list.
			(*it2)->DecRef();
			m_events.erase(it2);
			continue;
		}

		// Event Update Procedure
		ev = *it2;

		if((uint32)ev->currTime <= time_difference)
		{
			// execute the callback
			if(ev->eventFlag & EVENT_FLAG_DELETES_OBJECT)
			{
				ev->deleted = true;
				ev->cb->execute();
				m_events.erase(it2);
				ev->DecRef();
				continue;
			}
			else
				ev->cb->execute();

			// check if the event is expired now.
            if(ev->repeats && --ev->repeats == 0)
			{
				// Event expired :>
				
				/* remove the event from the object */
				/*obj = (EventableObject*)ev->obj;
				obj->event_RemoveByPointer(ev);*/

				/* remove the event from here */
				ev->deleted = true;
				ev->DecRef();
				m_events.erase(it2);

				continue;
			}
			else if(ev->deleted)
			{
				// event is now deleted
				ev->DecRef(); //this was added on "addevent"
				m_events.erase(it2);
				continue;
			}

			// event has to repeat again, reset the timer
			ev->currTime = ev->msTime;
		}
		else
		{
			// event is still "waiting", subtract time difference
			ev->currTime -= time_difference;
		}
	}

	m_lock.Release();
}
Exemplo n.º 30
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : fTimeDelta - 
//-----------------------------------------------------------------------------
void C_ExtinguisherJet::Update( float fTimeDelta )
{
	if ( m_bEmit == false )
		return;

	C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();

	if ( m_bUseMuzzlePoint )
	{
		C_BaseViewModel *vm = player ? player->GetViewModel( 0 ) : NULL;

		if ( vm )
		{
			int iAttachment = vm->LookupAttachment( "muzzle" );
			Vector origin;
			QAngle angles;
			vm->GetAttachment( iAttachment, origin, angles );

			Assert( !GetMoveParent() );
			SetLocalOrigin( origin );
			SetLocalAngles( angles );
		}
	}

	trace_t	tr;
	Vector	shotDir, vRight, vUp;

	AngleVectors( GetAbsAngles(), &shotDir, &vRight, &vUp );
	
	//FIXME: Muzzle point is incorrect on the model!
	if ( m_bUseMuzzlePoint )
	{
		shotDir.Negate();
	}

	Vector	endPoint = GetAbsOrigin() + ( shotDir * 150.0f );
	
	UTIL_TraceLine( GetAbsOrigin(), endPoint, MASK_SHOT, NULL, COLLISION_GROUP_NONE, &tr );

	bool	hitWall = ( tr.fraction < 1.0f );

	//Add normal jet
	if ( m_pEmitter.IsValid() )
	{
		SimpleParticle	*pParticle;

		m_pEmitter->SetSortOrigin( GetAbsOrigin() );
	
		float tempDelta = fTimeDelta;
		
		//FIXME: All particles need to be within this loop
		while( m_ParticleSpawn.NextEvent( tempDelta ) )
		{
			pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() );

			if ( pParticle )
			{
				pParticle->m_flDieTime	= 0.2f;
				pParticle->m_flLifetime	= 0.0f;
				
				pParticle->m_flRoll		= random->RandomInt( 0, 360 );
				pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f );
				
				pParticle->m_uchStartSize	= 1;
				pParticle->m_uchEndSize		= random->RandomInt( 32, 48 );
				pParticle->m_uchStartAlpha	= random->RandomInt( 128, 164 );
				pParticle->m_uchEndAlpha	= 0;
				
				int	cScale = random->RandomInt( 192, 255 );
				pParticle->m_uchColor[0]	= cScale;
				pParticle->m_uchColor[1]	= cScale;
				pParticle->m_uchColor[2]	= cScale;

				Vector	dir;
				QAngle  ofsAngles;

				ofsAngles.Random( -8.0f, 8.0f );
				ofsAngles += GetAbsAngles();

				AngleVectors( ofsAngles, &dir );

				if ( m_bUseMuzzlePoint )
				{
					dir.Negate();
				}

				pParticle->m_vecVelocity	= dir * random->RandomInt( 400, 800 );
			}

			//Add muzzle effect
			pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, GetAbsOrigin() );

			if ( pParticle )
			{
				pParticle->m_flDieTime	= 0.1f;
				pParticle->m_flLifetime	= 0.0f;
				
				pParticle->m_flRoll		= random->RandomInt( 0, 360 );
				pParticle->m_flRollDelta= random->RandomFloat( -4.0f, 4.0f );
				
				pParticle->m_uchStartSize	= 1;
				pParticle->m_uchEndSize		= random->RandomInt( 8, 16 );
				pParticle->m_uchStartAlpha	= random->RandomInt( 128, 255 );
				pParticle->m_uchEndAlpha	= 0;
				
				int	cScale = random->RandomInt( 192, 255 );
				pParticle->m_uchColor[0]	= cScale;
				pParticle->m_uchColor[1]	= cScale;
				pParticle->m_uchColor[2]	= cScale;

				Vector	dir;
				QAngle  ofsAngles;

				ofsAngles.Random( -64.0f, 64.0f );
				ofsAngles += GetAbsAngles();

				AngleVectors( ofsAngles, &dir );

				if ( m_bUseMuzzlePoint )
				{
					dir.Negate();
				}

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

			//Add a wall effect if needed
			if ( hitWall )
			{
				AddExtinguisherDecal( tr );

				Vector	offDir;

				offDir.Random( -16.0f, 16.0f );

				pParticle = (SimpleParticle *) m_pEmitter->AddParticle( sizeof(SimpleParticle), m_MaterialHandle, ( tr.endpos + ( tr.plane.normal * 8.0f ) ) + offDir );

				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( 8, 16 );
					pParticle->m_uchEndSize		= random->RandomInt( 24, 32 );
					pParticle->m_uchStartAlpha	= random->RandomInt( 64, 128 );
					pParticle->m_uchEndAlpha	= 0;
					
					int	cScale = random->RandomInt( 192, 255 );
					pParticle->m_uchColor[0]	= cScale;
					pParticle->m_uchColor[1]	= cScale;
					pParticle->m_uchColor[2]	= cScale;

					Vector	rDir;

					rDir = tr.plane.normal;
					rDir[0] += random->RandomFloat( -0.9f, 0.9f );
					rDir[1] += random->RandomFloat( -0.9f, 0.9f );
					rDir[2] += random->RandomFloat( -0.9f, 0.9f );

					pParticle->m_vecVelocity = rDir * random->RandomInt( 32, 64 );
				}			
			}

			//Add small ember-like particles
			if ( random->RandomInt( 0, 1 ) == 0 )
			{
				m_pEmberEmitter->SetSortOrigin( GetAbsOrigin() );

				pParticle = (SimpleParticle *) m_pEmberEmitter->AddParticle( sizeof(SimpleParticle), m_pEmberEmitter->GetPMaterial( "particle/particle_smokegrenade" ), GetAbsOrigin() );
				
				assert(pParticle);

				if ( pParticle )
				{
					pParticle->m_flLifetime		= 0.0f;
					pParticle->m_flDieTime		= 1.0f;

					pParticle->m_flRoll			= 0;
					pParticle->m_flRollDelta	= 0;

					pParticle->m_uchColor[0]	= 255;
					pParticle->m_uchColor[1]	= 255;
					pParticle->m_uchColor[2]	= 255;
					pParticle->m_uchStartAlpha	= 255;
					pParticle->m_uchEndAlpha	= 0;
					pParticle->m_uchStartSize	= 1;
					pParticle->m_uchEndSize		= 0;
					
					Vector	dir;
					QAngle  ofsAngles;

					ofsAngles.Random( -8.0f, 8.0f );
					ofsAngles += GetAbsAngles();

					AngleVectors( ofsAngles, &dir );

					if ( m_bUseMuzzlePoint )
					{
						dir.Negate();
					}

					pParticle->m_vecVelocity	= dir * random->RandomInt( 400, 800 );
				}
			}
		}
	}

	// Inner beam

	CBeamSegDraw	beamDraw;
	CBeamSeg		seg;
	const int		numPoints = 4;
	Vector			beamPoints[numPoints];

	beamPoints[0] = GetAbsOrigin();

	// Create our beam points
	int i;
	for ( i = 0; i < numPoints; i++ )
	{
		beamPoints[i] = GetAbsOrigin() + ( shotDir * (32*i*i) );

		beamPoints[i] += vRight * sin( gpGlobals->curtime * 4.0f ) * (2.0f*i);
		beamPoints[i] += vUp * sin( gpGlobals->curtime * 8.0f ) * (1.0f*i);
		beamPoints[i] += shotDir * sin( gpGlobals->curtime * (16.0f*i) ) * (1.0f*i);
	}

	IMaterial *pMat = materials->FindMaterial( "particle/particle_smokegrenade", NULL );

	beamDraw.Start( numPoints, pMat );

	//Setup and draw those points	
	for( i = 0; i < numPoints; i++ )
	{
		float	t = (float) i / (numPoints - 1);
		float	color = 1.0f * (1.0f - t);

		seg.m_vColor		= Vector( color, color, color );
		seg.m_vPos			= beamPoints[i];
		seg.m_flTexCoord	= (float)i/(float)(numPoints-1) - ((gpGlobals->curtime - (int)gpGlobals->curtime) * 4.0f );
		seg.m_flWidth		= 4.0f + ( (64.0f*t) * (fabs( sin( gpGlobals->curtime * 16.0f ) )) );
		seg.m_flAlpha		= color;

		beamDraw.NextSeg( &seg );
	}
	
	beamDraw.End();
}