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

Method PlayAnimation

trinity/Eve/Turret/EveTurretSet.cpp:2578–2756  ·  view source on GitHub ↗

-------------------------------------------------------------------------------- Description: Play an animation to a single turret Arguments: turretIndex - which turret is going to get this anim animName - animation name like it says in the gr2 file, which will be played now animNameIdle - animation name like it says in the gr2 file, which will be played in loop after animName delay - wait time in

Source from the content-addressed store, hash-verified

2576// Length of animation in seconds or 0.f if error
2577// --------------------------------------------------------------------------------
2578float EveTurretSet::PlayAnimation( unsigned int turretIndex, const std::string& animName, const std::string& animNameIdle, float delay )
2579{
2580 float animLength = 0.f;
2581
2582 // if we don't have a geometry or a shader, animation is useless and probably unwanted
2583 if( !m_geometryResource || !m_turretEffect )
2584 {
2585 return 0.f;
2586 }
2587
2588 // if this one still is getting loaded, buffer the animation play request
2589 if( !m_geometryResource->IsPrepared() )
2590 {
2591 AnimationRequest ar;
2592 ar.turretIndex = turretIndex;
2593 ar.animName = animName;
2594 ar.animNameIdle = animNameIdle;
2595 m_animationQueue.push_back( ar );
2596 return 0.f;
2597 }
2598
2599 if( !m_geometryResource->IsGood() )
2600 {
2601 return 0.f;
2602 }
2603
2604 if( IsUsingCMF( m_geometryResource ) )
2605 {
2606 auto cmfData = m_geometryResource->GetCMFData();
2607 if( cmfData )
2608 {
2609 // there can be more animations in one res, so find right one
2610 size_t animIx = cmfData->animations.size();
2611 if( !animName.empty() )
2612 {
2613 auto animation = std::find_if( cmfData->animations.begin(), cmfData->animations.end(), [&animName]( const cmf::Animation& anim ) {
2614 return cmf::ToStdStringView( anim.name ) == animName;
2615 } );
2616 if( animation == cmfData->animations.end() )
2617 {
2618 return 0.f;
2619 }
2620 animIx = std::distance( cmfData->animations.begin(), animation );
2621 }
2622
2623 size_t idleIx = cmfData->animations.size();
2624 if( !animNameIdle.empty() )
2625 {
2626 auto animation = std::find_if( cmfData->animations.begin(), cmfData->animations.end(), [&animNameIdle]( const cmf::Animation& anim ) {
2627 return cmf::ToStdStringView( anim.name ) == animNameIdle;
2628 } );
2629 if( animation == cmfData->animations.end() )
2630 {
2631 return 0.f;
2632 }
2633 idleIx = std::distance( cmfData->animations.begin(), animation );
2634 }
2635

Callers

nothing calls this directly

Calls 8

IsUsingCMFFunction · 0.85
sizeMethod · 0.80
emptyMethod · 0.80
GetGrannyInfoMethod · 0.80
IsGoodMethod · 0.45
GetCMFDataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected