MCPcopy Create free account
hub / github.com/carbonengine/trinity / UpdateSimulation

Method UpdateSimulation

trinity/Particle/Tr2ParticleSystem.cpp:555–806  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Updates per-particle data (age, positions, etc.), removes dead particles, emits new particles with "emit during lifetime" and "emit on death" emitters. This function can be called asyncronously. Arguments: arguments - Child emitter update arguments dt - simulation time interval --------------------

Source from the content-addressed store, hash-verified

553// dt - simulation time interval
554// --------------------------------------------------------------------------------------
555void Tr2ParticleSystem::UpdateSimulation( const ITr2GenericEmitter::UpdateArguments& arguments, float dt )
556{
557 // Update lifetime and remove dead particles
558 if( m_applyAging && HasElement( Tr2ParticleElementDeclarationName::LIFETIME ) )
559 {
560 float* lifetime = nullptr;
561 unsigned lifetimeStride;
562 GetElementStream( Tr2ParticleElementDeclarationName::LIFETIME, lifetime, lifetimeStride );
563
564 float* position = nullptr;
565 unsigned positionStride;
566 GetElementStream( Tr2ParticleElementDeclarationName::POSITION, position, positionStride );
567
568 float* velocity = nullptr;
569 unsigned velocityStride;
570 GetElementStream( Tr2ParticleElementDeclarationName::VELOCITY, velocity, velocityStride );
571
572 if( m_insertDeleteMutex )
573 {
574 m_insertDeleteMutex->Acquire();
575 }
576
577 for( unsigned i = 0; i < m_aliveCount; ++i )
578 {
579 lifetime[0] += dt / lifetime[1];
580 if( lifetime[0] >= 1.0f )
581 {
582 if( m_emissionOnDeathEmitter )
583 {
584 m_emissionOnDeathEmitter->SpawnParticles( arguments,
585 reinterpret_cast<Vector3*>( position ),
586 reinterpret_cast<Vector3*>( velocity ) );
587 }
588
589 m_aliveCount -= 1;
590 if( i < m_aliveCount )
591 {
592 for( unsigned j = 0; j < Tr2ParticleElementData::COUNT; ++j )
593 {
594 std::copy( m_buffers[j] + m_aliveCount * m_vertexSizes[j],
595 m_buffers[j] + ( m_aliveCount + 1 ) * m_vertexSizes[j],
596 m_buffers[j] + i * m_vertexSizes[j] );
597 }
598 }
599
600 --i;
601 }
602 else
603 {
604 lifetime += lifetimeStride;
605 if( position )
606 {
607 position += positionStride;
608 }
609 if( velocity )
610 {
611 velocity += velocityStride;
612 }

Callers

nothing calls this directly

Calls 10

Tr2ParallelForFunction · 0.85
ReleaseMethod · 0.80
emptyMethod · 0.80
Vector3Class · 0.50
SpawnParticlesMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
UpdateMethod · 0.45
GetForceMethod · 0.45
ApplyConstraintMethod · 0.45

Tested by

no test coverage detected