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

Method Update

trinity/Particle/Tr2ParticleSystem.cpp:485–544  ·  view source on GitHub ↗

-------------------------------------------------------------------------------------- Description: Per-frame update method for the system. Updates particle system state. Arguments: globalArguments - Child emitter update arguments --------------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

483// globalArguments - Child emitter update arguments
484// --------------------------------------------------------------------------------------
485void Tr2ParticleSystem::Update( const ITr2GenericEmitter::UpdateArguments& globalArguments )
486{
487 CCP_STATS_ZONE( __FUNCTION__ );
488
489 auto arguments = globalArguments;
490 arguments.parentTransform = m_worldTransform;
491
492
493 if( m_previousDataOutdated )
494 {
495 float* gpuBuffer = m_buffers[Tr2ParticleElementData::GPU];
496 uint32_t gpuDataSize = m_vertexSizes[Tr2ParticleElementData::GPU];
497 uint32_t gpuDataHalfSize = gpuDataSize >> 1;
498
499 for( uint32_t i = 0; i < m_aliveCount; ++i )
500 {
501 //Save the current data so we have the previous frame's data for motion vectors
502 //This kinda has to be done regardless of if we tick or not, to make sure it's always up to date for rendering...
503 std::copy(
504 gpuBuffer + i * gpuDataSize,
505 gpuBuffer + i * gpuDataSize + gpuDataHalfSize,
506 gpuBuffer + i * gpuDataSize + gpuDataHalfSize );
507 }
508
509 m_previousDataOutdated = false;
510 }
511
512 // if we're offscreen or very small, we can tick less frequently
513 if( m_updatePeriod > 1 )
514 {
515 ++m_updatePeriodClock;
516 m_updatePeriodClock %= m_updatePeriod;
517 if( m_updatePeriodClock != 0 )
518 {
519 return;
520 }
521 }
522
523 if( m_lastUpdate == 0 )
524 {
525 m_lastUpdate = arguments.time;
526 }
527 float dt = std::min( TimeAsFloat( arguments.time - m_lastUpdate ), 1.0f / 3.0f );
528 m_lastUpdate = arguments.time;
529
530 //include considerable hysteresis in toggling sorting.
531 //Things to consider:
532 // frametime breakpoints as global constant/setting/per-system?
533 // re-enable a limited number of systems per frame?
534 if( dt > 0.035f && m_sortingAllowed )
535 {
536 m_sortingAllowed = false;
537 }
538 else if( !m_sortingAllowed && dt < 0.02f )
539 {
540 m_sortingAllowed = true;
541 }
542

Callers 2

UpdateSimulationMethod · 0.45
UpdateAllSystemsMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected