From 7dcc180b241667692165effa2ec7d03a7fcfa855 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 17 Jul 2022 14:33:03 +0300 Subject: [PATCH] anim: add get time from state function (unused now) --- src/game/g_animations.pas | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/game/g_animations.pas b/src/game/g_animations.pas index efa32ec..0135b15 100644 --- a/src/game/g_animations.pas +++ b/src/game/g_animations.pas @@ -79,6 +79,7 @@ interface procedure g_Anim_GetFrameFromState (const s: TAnimState; backanim: Boolean; out frame: LongInt); procedure g_Anim_GetInterplatedFrameFromState (const s: TAnimState; newlength: LongInt; out frame: LongInt); + procedure g_Anim_GetTimeFromState (const s: TAnimState; out curtime, fulltime: LongInt); implementation @@ -323,4 +324,17 @@ implementation ASSERT(frame < newlength); end; + procedure g_Anim_GetTimeFromState (const s: TAnimState; out curtime, fulltime: LongInt); + var delay, curframe, curcount: LongInt; + begin + ASSERT(s.length > 0); + (* 1. normalize state values *) + delay := MAX(1, s.speed); + curframe := MIN(MAX(s.CurrentFrame, 0), s.length - 1); + curcount := MIN(MAX(s.CurrentCounter, 0), delay - 1); + (* 2. calc current time (normalized) *) + fulltime := s.length * delay; + curtime := MIN(curframe * delay + curcount, fulltime); + end; + end. -- 2.29.2