diff --git a/rts/Sim/Units/Scripts/UnitScript.cpp b/rts/Sim/Units/Scripts/UnitScript.cpp index a50f0240ee..3b7034762a 100644 --- a/rts/Sim/Units/Scripts/UnitScript.cpp +++ b/rts/Sim/Units/Scripts/UnitScript.cpp @@ -189,6 +189,38 @@ void CUnitScript::TickAnims(int tickRate, const TickAnimFunc& tickAnimFunc, Anim } } +/** + * @brief Called by the engine when we are registered as animating. + If we return false there are no active animations left. + * @param deltaTime int delta time to update + * @return true if there are still active animations + */ +bool CUnitScript::Tick(int deltaTime) +{ + ZoneScoped; + // vector of indexes of finished animations, + // so we can get rid of them in constant time + static AnimContainerType doneAnims[AMove + 1]; + + // tick-functions; these never change address + static constexpr TickAnimFunc tickAnimFuncs[AMove + 1] = { &CUnitScript::TickTurnAnim, &CUnitScript::TickSpinAnim, &CUnitScript::TickMoveAnim }; + + for (int animType = ATurn; animType <= AMove; animType++) { + TickAnims(1000 / deltaTime, tickAnimFuncs[animType], anims[animType], doneAnims[animType]); + } + + // Tell listeners to unblock, and remove finished animations from the unit/script. + for (int animType = ATurn; animType <= AMove; animType++) { + for (AnimInfo& ai: doneAnims[animType]) { + AnimFinished(static_cast(animType), ai.piece, ai.axis); + } + + doneAnims[animType].clear(); + } + + return (HaveAnimations()); +} + /** * @brief The multithreaded first half of the original CUnitScript::Tick function first does the heavy lifting of calculating all new piece positions according to the animations diff --git a/rts/Sim/Units/Scripts/UnitScript.h b/rts/Sim/Units/Scripts/UnitScript.h index 459f5afd45..f94d7d84f2 100644 --- a/rts/Sim/Units/Scripts/UnitScript.h +++ b/rts/Sim/Units/Scripts/UnitScript.h @@ -112,6 +112,7 @@ class CUnitScript CUnit* GetUnit() { return unit; } const CUnit* GetUnit() const { return unit; } + bool Tick(int tickRate); void TickAllAnims(int tickRate); bool TickAnimFinished(int tickRate); // note: must copy-and-set here (LMP dirty flag, etc)