X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_animations.pas;h=0135b15ec0c2587fd2e734e3dacfaa98951e60a1;hb=7dcc180b241667692165effa2ec7d03a7fcfa855;hp=efa32ec8e2c5d94ca8886abf344e8a0881a40328;hpb=900602ca89dd54d7a093b44d0e9106bb9e0e3b27;p=d2df-sdl.git 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.