From: DeaDDooMER Date: Sun, 17 Jul 2022 11:33:03 +0000 (+0300) Subject: anim: add get time from state function (unused now) X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=7dcc180b241667692165effa2ec7d03a7fcfa855 anim: add get time from state function (unused now) --- 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.