DEADSOFTWARE

panels: handle panel animation in render (bump protocol)
[d2df-sdl.git] / src / game / renders / opengl / r_map.pas
index 07028727cabe135dfabf24efd119bad1868fe4bc..786bd5409728417dc9f342797999f857a85f94b7 100644 (file)
@@ -45,7 +45,7 @@ interface
 implementation
 
   uses
-    Math,
+    Math, SysUtils,
     {$IFDEF USE_GLES1}
       GLES11,
     {$ELSE}
@@ -67,7 +67,7 @@ implementation
     {$IFDEF ENABLE_GFX}
       g_gfx,
     {$ENDIF}
-    r_textures, r_draw
+    r_textures, r_draw, r_common
   ;
 
   const
@@ -219,7 +219,9 @@ implementation
     );
 {$ENDIF}
 
+    PunchAnim: TAnimInfo = (loop: false; delay: 1; frames: 4; back: false);
     FlagAnim: TAnimInfo = (loop: true; delay: 8; frames: 5; back: false);
+    VileFireAnim: TAnimInfo = (loop: true; delay:  2; frames: 8; back: false);
 
   type
     TBinHeapPanelDrawCmp = class
@@ -236,6 +238,7 @@ implementation
     RenTextures: array of record
       spec: LongInt;
       tex: TGLMultiTexture;
+      anim: TAnimInfo;
     end;
     Items: array [0..ITEM_LAST] of record
       tex: TGLMultiTexture;
@@ -422,7 +425,7 @@ implementation
       for j := 0 to ANIM_LAST do
         for d := TDirection.D_LEFT to TDirection.D_RIGHT do
           r_Map_LoadMonsterAnim(i, j, d);
-    VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, 8, False, False);
+    VileFire := r_Textures_LoadMultiFromFileAndInfo(GameWAD + ':TEXTURES/FIRE', 64, 128, VileFireAnim.frames, VileFireAnim.back);
     // --------- player models --------- //
     if PlayerModelsArray <> nil then
     begin
@@ -459,7 +462,7 @@ implementation
     for b := false to true do
     begin
       for i := 0 to 2 do
-        PunchTextures[b, i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, 4, false);
+        PunchTextures[b, i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, PunchAnim.frames, PunchAnim.back);
     end;
     // --------- other --------- //
     InvulPenta := r_Textures_LoadFromFile(GameWad + ':TEXTURES/PENTA');
@@ -545,7 +548,8 @@ implementation
   end;
 
   procedure r_Map_LoadTextures;
-    var i, n: Integer;
+    const DefaultAnimInfo: TAnimInfo = (loop: true; delay: 1; frames: 1; back: false);
+    var i, n: Integer; txt: TAnimTextInfo;
   begin
     if Textures <> nil then
     begin
@@ -553,6 +557,7 @@ implementation
       SetLength(RenTextures, n);
       for i := 0 to n - 1 do
       begin
+        txt.anim := DefaultAnimInfo;
         RenTextures[i].tex := nil;
         case Textures[i].TextureName of
           TEXTURE_NAME_WATER: RenTextures[i].spec := TEXTURE_SPECIAL_WATER;
@@ -560,10 +565,13 @@ implementation
           TEXTURE_NAME_ACID2: RenTextures[i].spec := TEXTURE_SPECIAL_ACID2;
           else
             RenTextures[i].spec := 0;
-            RenTextures[i].tex := r_Textures_LoadMultiFromFile(Textures[i].FullName);
+            e_LogWritefln('r_Map_LoadTextures: begin load texture: %s', [Textures[i].FullName]);
+            RenTextures[i].tex := r_Textures_LoadMultiTextFromFile(Textures[i].FullName, txt);
+            e_LogWritefln('r_Map_LoadTextures: end load texture: %s', [Textures[i].FullName]);
             if RenTextures[i].tex = nil then
               e_LogWritefln('r_Map_LoadTextures: failed to load texture: %s', [Textures[i].FullName]);
         end;
+        RenTextures[i].anim := txt.anim;
       end;
     end;
     if gMapInfo.SkyFullName <> '' then
@@ -586,22 +594,29 @@ implementation
   end;
 
   procedure r_Map_DrawPanel (p: TPanel);
-    var Texture: Integer; t: TGLMultiTexture;
+    var Texture: Integer; t: TGLMultiTexture; tex: TGLTexture; count, frame: LongInt; a: TAnimInfo;
   begin
     ASSERT(p <> nil);
     if p.FCurTexture >= 0 then
     begin
       Texture := p.TextureIDs[p.FCurTexture].Texture;
       t := RenTextures[Texture].tex;
-
       if (RenTextures[Texture].spec = 0) or (t <> nil) then
       begin
-        if t = nil then
-          r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending)
-        else if p.TextureIDs[p.FCurTexture].AnTex.IsValid() then
-          r_Draw_MultiTextureRepeat(t, p.TextureIDs[p.FCurTexture].AnTex, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending)
+        count := 0; frame := 0;
+        if p.AnimTime <= gTime then
+        begin
+          a := RenTextures[Texture].anim;
+          a.loop := p.AnimLoop;
+          g_Anim_GetFrameByTime(a, (gTime - p.AnimTime) DIV GAME_TICK, count, frame);
+        end;
+        if t <> nil then
+        begin
+          tex := t.GetTexture(frame);
+          r_Draw_TextureRepeat(tex, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending);
+        end
         else
-          r_Draw_TextureRepeat(t.GetTexture(0), p.x, p.y, p.width, p.height, false, 255, 255, 255, 255 - p.alpha, p.blending)
+          r_Draw_TextureRepeat(nil, p.x, p.y, p.width, p.height, false, 255, 255, 255, 255, false);
       end;
 
       if t = nil then
@@ -688,12 +703,16 @@ implementation
   end;
 
   procedure r_Map_DrawMonsterAttack (constref mon: TMonster);
-    var o: TObj;
+    var o: TObj; count, frame: LongInt; tex: TGLTexture;
   begin
     if VileFire <> nil then
       if (mon.MonsterType = MONSTER_VILE) and (mon.MonsterState = MONSTATE_SHOOT) then
-        if mon.VileFireAnim.IsValid() and GetPos(mon.MonsterTargetUID, @o) then
-          r_Draw_MultiTextureRepeat(VileFire, mon.VileFireAnim, o.x + o.rect.x + (o.rect.width div 2) - VILEFIRE_DX, o.y + o.rect.y + o.rect.height - VILEFIRE_DY, VileFire.width, VileFire.height, False, 255, 255, 255, 255, false);
+        if (mon.VileFireTime <= gTime) and GetPos(mon.MonsterTargetUID, @o) then
+        begin
+          g_Anim_GetFrameByTime(VileFireAnim, (gTime - mon.VileFireTime) DIV GAME_TICK, count, frame);
+          tex := VileFire.GetTexture(frame);
+          r_Draw_TextureRepeat(tex, o.x + o.rect.x + (o.rect.width div 2) - VILEFIRE_DX, o.y + o.rect.y + o.rect.height - VILEFIRE_DY, tex.width, tex.height, False, 255, 255, 255, 255, false);
+        end;
   end;
 
   procedure r_Map_DrawMonster (constref mon: TMonster);
@@ -815,7 +834,7 @@ implementation
   end;
 
   procedure r_Map_DrawPlayer (p, drawed: TPlayer);
-    var fX, fY, fSlope, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; alpha: Byte;
+    var fX, fY, fSlope, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; alpha: Byte; count, frame: LongInt;
   begin
     if p.alive then
     begin
@@ -825,21 +844,26 @@ implementation
       fSlope := nlerp(p.SlopeOld, p.obj.slopeUpLeft, gLerpFactor);
 
       (* punch effect *)
-      if p.PunchAnim.IsValid() and p.PunchAnim.enabled then
+      if p.PunchTime <= gTime then
       begin
-        b := R_BERSERK in p.FRulez;
-        if p.FKeys[KEY_DOWN].pressed then
-          t := PunchTextures[b, 2]
-        else if p.FKeys[KEY_UP].pressed then
-          t := PunchTextures[b, 1]
-        else
-          t := PunchTextures[b, 0];
-        if t <> nil then
+        g_Anim_GetFrameByTime(PunchAnim, (gTime - p.PunchTime) DIV GAME_TICK, count, frame);
+        if count < 1 then
         begin
-          flip := p.Direction = TDirection.D_LEFT;
-          ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ???
-          ay := p.Obj.Rect.Y - 11;
-          r_Draw_MultiTextureRepeat(t, p.PunchAnim, fx + ax, fy + fSlope + ay, t.width, t.height, flip, 255, 255, 255, 255, false)
+          b := R_BERSERK in p.FRulez;
+          if p.FKeys[KEY_DOWN].pressed then
+            t := PunchTextures[b, 2]
+          else if p.FKeys[KEY_UP].pressed then
+            t := PunchTextures[b, 1]
+          else
+            t := PunchTextures[b, 0];
+          if t <> nil then
+          begin
+            flip := p.Direction = TDirection.D_LEFT;
+            ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ???
+            ay := p.Obj.Rect.Y - 11;
+            tex := t.GetTexture(frame);
+            r_Draw_TextureRepeat(tex, fx + ax, fy + fSlope + ay, tex.width, tex.height, flip, 255, 255, 255, 255, false)
+          end;
         end;
       end;