-------------------------------------------------------------------------------------- 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 --------------------
| 553 | // dt - simulation time interval |
| 554 | // -------------------------------------------------------------------------------------- |
| 555 | void 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 | } |
nothing calls this directly
no test coverage detected