//-----------------------------------------------------------------------------
// The animation events will create particles on the attachment points
//-----------------------------------------------------------------------------
void C_EnvParticleScript::FireEvent( const Vector& origin, const QAngle& angles, int event, const char *options )
{
	// Handle events to create + destroy particles
	switch( event )
	{
	case CL_EVENT_SPRITEGROUP_CREATE:
		{
			char pAttachmentName[256];
			char pSpriteName[256];
			int nArgs = sscanf( options, "%255s %255s", pAttachmentName, pSpriteName );
			if ( nArgs == 2 )
			{
				CreateParticle( pAttachmentName, pSpriteName );
			}
		}
		return;

	case CL_EVENT_SPRITEGROUP_DESTROY:
		{
			char pAttachmentName[256];
			int nArgs = sscanf( options, "%255s", pAttachmentName );
			if ( nArgs == 1 )
			{
				DestroyAllParticles( pAttachmentName );
			}
		}
		return;
	}

	// Fall back
	BaseClass::FireEvent( origin, angles, event, options );
}
예제 #2
0
// Destroy all particles in the system, drop a particle onto the fixture and
// keep track of the number of contacts with the fixture in addition to the
// stuck particle candiates.
void BodyContactTests::DropParticle()
{
	// Reset counters.
	m_contacts = 0;
	m_stuck = 0;
	DestroyAllParticles();

	const float32 timeStep = 1.0f / 60.0f;
	const int32 timeout = (int32)(1.0f / timeStep) * 10; // 10 "seconds"
	const int32 velocityIterations = 6;
	const int32 positionIterations = 2;

	// Step once to eliminate particles.
	m_world->Step(timeStep, velocityIterations, positionIterations);

	b2ParticleDef pd;
	pd.position.Set(0.0f, 33.0f);
	pd.velocity.Set(0.0f, -1.0f);
	m_particleSystem->CreateParticle(pd);

	for (int32 i = 0; i < timeout; ++i)
	{
		m_world->Step(timeStep, velocityIterations, positionIterations);
		m_contacts += m_particleSystem->GetBodyContactCount();
		int32 stuck = m_particleSystem->GetStuckCandidateCount();
		if (stuck)
		{
			m_stuck += stuck;
			// Should always be particle 0.
			EXPECT_EQ(*(m_particleSystem->GetStuckCandidates()), 0);
		}
	}
}
//-----------------------------------------------------------------------------
// Starts up the particle system
//-----------------------------------------------------------------------------
void C_EnvParticleScript::OnDataChanged( DataUpdateType_t updateType )
{		
	BaseClass::OnDataChanged( updateType );

	if( updateType == DATA_UPDATE_CREATED )
	{
		ParticleMgr()->AddEffect( &m_ParticleEffect, this );
		g_pClientLeafSystem->EnableRendering( RenderHandle(), false );
	}

	if ( m_nOldSequence != GetSequence() )
	{
		DestroyAllParticles();
	}
}