Skip to content

Commit

Permalink
Revert "Amend ff2d8cc"
Browse files Browse the repository at this point in the history
This reverts commit 8c65213.
  • Loading branch information
lhog committed Mar 23, 2024
1 parent 5de3191 commit 1b70157
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions rts/Sim/Units/Scripts/UnitScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>(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
Expand Down
1 change: 1 addition & 0 deletions rts/Sim/Units/Scripts/UnitScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1b70157

Please sign in to comment.