DEADSOFTWARE

render: use TAnimationState instead of TAnimation
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 16 Jan 2022 22:39:30 +0000 (01:39 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 16 Jan 2022 22:39:30 +0000 (01:39 +0300)
src/game/g_map.pas
src/game/g_panel.pas
src/game/opengl/r_panel.pas

index a33ceda485c5bef327fed088b944340dc0796151..026ef9bfc35760de0b8ae1fcf6d202b471429967 100644 (file)
@@ -242,6 +242,8 @@ type
 var
   mapGrid: TPanelGrid = nil; // DO NOT USE! public for debugging only!
 
 var
   mapGrid: TPanelGrid = nil; // DO NOT USE! public for debugging only!
 
+var (* private state *)
+  Textures: TLevelTextureArray = nil;
 
 implementation
 
 
 implementation
 
@@ -523,7 +525,6 @@ begin
 end;
 
 var
 end;
 
 var
-  Textures: TLevelTextureArray = nil;
   TextNameHash: THashStrInt = nil; // key: texture name; value: index in `Textures`
   BadTextNameHash: THashStrInt = nil; // set; so we won't spam with non-existing texture messages
   RespawnPoints: array of TRespawnPoint;
   TextNameHash: THashStrInt = nil; // key: texture name; value: index in `Textures`
   BadTextNameHash: THashStrInt = nil; // set; so we won't spam with non-existing texture messages
   RespawnPoints: array of TRespawnPoint;
index aa68298361c09555e490a5b73c0beb3fcc7a8d0d..d3e4414dc0832afd57c95d541cc5e018e8d858e1 100644 (file)
@@ -23,16 +23,16 @@ uses
   MAPDEF, g_textures, xdynrec;
 
 type
   MAPDEF, g_textures, xdynrec;
 
 type
-  TAddTextureArray = Array of
-    record
-      Texture: Cardinal;
-      Anim: Boolean;
-    end;
+  TAddTextureArray = array of record
+    Texture: Cardinal; // Textures[Texture]
+    Anim: Boolean;
+  end;
 
   ATextureID = array of record
 
   ATextureID = array of record
+    Texture: Cardinal; // Textures[Texture]
     case Anim: Boolean of
     case Anim: Boolean of
-      False: (Tex: Cardinal);
-      True:  (AnTex: TAnimation);
+      False: ();
+      True:  (AnTex: TAnimationState);
   end;
 
   PPanel = ^TPanel;
   end;
 
   PPanel = ^TPanel;
@@ -309,6 +309,8 @@ begin
     SetLength(FTextureIDs, 1);
     FTextureIDs[0].Anim := False;
 
     SetLength(FTextureIDs, 1);
     FTextureIDs[0].Anim := False;
 
+{
+    // !!! set this
     case PanelRec.PanelType of
       PANEL_WATER:
         FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_WATER);
     case PanelRec.PanelType of
       PANEL_WATER:
         FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_WATER);
@@ -317,6 +319,7 @@ begin
       PANEL_ACID2:
         FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_ACID2);
     end;
       PANEL_ACID2:
         FTextureIDs[0].Tex := LongWord(TEXTURE_SPECIAL_ACID2);
     end;
+}
 
     FCurTexture := 0;
     Exit;
 
     FCurTexture := 0;
     Exit;
@@ -334,19 +337,14 @@ begin
 
   for i := 0 to Length(FTextureIDs)-1 do
   begin
 
   for i := 0 to Length(FTextureIDs)-1 do
   begin
+    FTextureIDs[i].Texture := AddTextures[i].Texture;
     FTextureIDs[i].Anim := AddTextures[i].Anim;
     if FTextureIDs[i].Anim then
     FTextureIDs[i].Anim := AddTextures[i].Anim;
     if FTextureIDs[i].Anim then
-      begin // Àíèìèðîâàííàÿ òåêñòóðà
-        FTextureIDs[i].AnTex :=
-           TAnimation.Create(Textures[AddTextures[i].Texture].FramesID,
-                             True, Textures[AddTextures[i].Texture].Speed);
-        FTextureIDs[i].AnTex.Blending := ByteBool(PanelRec.Flags and PANEL_FLAG_BLENDING);
-        FTextureIDs[i].AnTex.Alpha := PanelRec.Alpha;
-      end
-    else
-      begin // Îáû÷íàÿ òåêñòóðà
-        FTextureIDs[i].Tex := Textures[AddTextures[i].Texture].TextureID;
-      end;
+    begin // Àíèìèðîâàííàÿ òåêñòóðà
+      FTextureIDs[i].AnTex := TAnimationState.Create(True, Textures[AddTextures[i].Texture].Speed, Textures[AddTextures[i].Texture].FramesCount);
+      FTextureIDs[i].AnTex.Blending := ByteBool(PanelRec.Flags and PANEL_FLAG_BLENDING);
+      FTextureIDs[i].AnTex.Alpha := PanelRec.Alpha;
+    end
   end;
 
 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
   end;
 
 // Òåêñòóð íåñêîëüêî - íóæíî ñîõðàíÿòü òåêóùóþ:
@@ -889,14 +887,20 @@ end;
 function TPanel.GetTextureID(): DWORD;
 begin
   Result := LongWord(TEXTURE_NONE);
 function TPanel.GetTextureID(): DWORD;
 begin
   Result := LongWord(TEXTURE_NONE);
-
   if (FCurTexture >= 0) then
   begin
   if (FCurTexture >= 0) then
   begin
+    if FTextureIDs[FCurTexture].Anim then
+      Result := Textures[FTextureIDs[FCurTexture].Texture].FramesID
+    else
+      Result := Textures[FTextureIDs[FCurTexture].Texture].TextureID
+{
+    // !!! old behavior
     if FTextureIDs[FCurTexture].Anim then
       Result := FTextureIDs[FCurTexture].AnTex.FramesID
     else
       Result := FTextureIDs[FCurTexture].Tex;
     if FTextureIDs[FCurTexture].Anim then
       Result := FTextureIDs[FCurTexture].AnTex.FramesID
     else
       Result := FTextureIDs[FCurTexture].Tex;
-  end;
+}
+  end
 end;
 
 function TPanel.GetTextureCount(): Integer;
 end;
 
 function TPanel.GetTextureCount(): Integer;
index a8446312d03a6a6d66180ae16bf656de4e14eedc..de73d72de726c4ebabb72aafbb6572618e5255f6 100644 (file)
@@ -28,63 +28,64 @@ implementation
     {$INCLUDE ../nogl/noGLuses.inc}
     SysUtils, Classes, Math,
     r_graphics, g_options, r_animations, r_textures,
     {$INCLUDE ../nogl/noGLuses.inc}
     SysUtils, Classes, Math,
     r_graphics, g_options, r_animations, r_textures,
-    g_base, g_basic
+    g_base, g_basic, g_map
   ;
 
   // TODO: remove WITH operator
 
   procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
   ;
 
   // TODO: remove WITH operator
 
   procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
-    var xx, yy: Integer; NoTextureID: DWORD; NW, NH: Word;
+    var xx, yy: Integer; NoTextureID, TextureID, FramesID: DWORD; NW, NH: Word; Texture: Cardinal; IsAnim: Boolean;
   begin
   begin
-    with p do
+    if {p.Enabled and} (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
     begin
     begin
-      if {Enabled and} (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
+      Texture := p.TextureIDs[p.FCurTexture].Texture;
+      IsAnim := p.TextureIDs[p.FCurTexture].Anim;
+      if IsAnim then
       begin
       begin
-        if TextureIDs[FCurTexture].Anim then
+        if p.TextureIDs[p.FCurTexture].AnTex <> nil then
         begin
         begin
-          if TextureIDs[FCurTexture].AnTex = nil then
-            Exit;
-          for xx := 0 to Width div TextureWidth - 1 do
-            for yy := 0 to Height div TextureHeight - 1 do
-              r_Animation_Draw(TextureIDs[FCurTexture].AnTex, X + xx * TextureWidth, Y + yy * TextureHeight, TMirrorType.None);
+          FramesID := Textures[Texture].FramesID;
+          for xx := 0 to p.Width div p.TextureWidth - 1 do
+            for yy := 0 to p.Height div p.TextureHeight - 1 do
+              r_AnimationState_Draw(FramesID, p.TextureIDs[p.FCurTexture].AnTex, p.X + xx * p.TextureWidth, p.Y + yy * p.TextureHeight, TMirrorType.None);
         end
         end
-        else
-        begin
-          case TextureIDs[FCurTexture].Tex of
-            LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 0, 0, 255, 0, TBlending.Filter);
-            LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 0, 230, 0, 0, TBlending.Filter);
-            LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(X, Y, X + Width - 1, Y + Height - 1, 230, 0, 0, 0, TBlending.Filter);
-            LongWord(TEXTURE_NONE):
-              if g_Texture_Get('NOTEXTURE', NoTextureID) then
-              begin
-                e_GetTextureSize(NoTextureID, @NW, @NH);
-                e_DrawFill(NoTextureID, X, Y, Width div NW, Height div NH, 0, False, False);
-              end
-              else
-              begin
-                xx := X + (Width div 2);
-                yy := Y + (Height div 2);
-                e_DrawFillQuad(X, Y, xx, yy, 255, 0, 255, 0);
-                e_DrawFillQuad(xx, Y, X + Width - 1, yy, 255, 255, 0, 0);
-                e_DrawFillQuad(X, yy, xx, Y + Height - 1, 255, 255, 0, 0);
-                e_DrawFillQuad(xx, yy, X + Width - 1, Y + Height - 1, 255, 0, 255, 0);
-              end;
-            else
+      end
+      else
+      begin
+        TextureID := Textures[Texture].TextureID; // GL texture
+        case TextureID of
+          LongWord(TEXTURE_SPECIAL_WATER): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 0, 255, 0, TBlending.Filter);
+          LongWord(TEXTURE_SPECIAL_ACID1): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 0, 230, 0, 0, TBlending.Filter);
+          LongWord(TEXTURE_SPECIAL_ACID2): e_DrawFillQuad(p.X, p.Y, p.X + p.Width - 1, p.Y + p.Height - 1, 230, 0, 0, 0, TBlending.Filter);
+          LongWord(TEXTURE_NONE):
+            if g_Texture_Get('NOTEXTURE', NoTextureID) then
             begin
             begin
-              if not movingActive then
-                e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending, hasAmbient)
-              else
-                e_DrawFillX(TextureIDs[FCurTexture].Tex, X, Y, Width, Height, Alpha, True, Blending, g_dbg_scale, hasAmbient);
-              if hasAmbient then
-                e_AmbientQuad(X, Y, Width, Height, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
+              e_GetTextureSize(NoTextureID, @NW, @NH);
+              e_DrawFill(NoTextureID, p.X, p.Y, p.Width div NW, p.Height div NH, 0, False, False);
             end
             end
-          end
+            else
+            begin
+              xx := p.X + (p.Width div 2);
+              yy := p.Y + (p.Height div 2);
+              e_DrawFillQuad(p.X, p.Y, xx, yy, 255, 0, 255, 0);
+              e_DrawFillQuad(xx, p.Y, p.X + p.Width - 1, yy, 255, 255, 0, 0);
+              e_DrawFillQuad(p.X, yy, xx, p.Y + p.Height - 1, 255, 255, 0, 0);
+              e_DrawFillQuad(xx, yy, p.X + p.Width - 1, p.Y + p.Height - 1, 255, 0, 255, 0);
+            end;
+        else
+          if not p.movingActive then
+            e_DrawFill(TextureID, p.X, p.Y, p.Width div p.TextureWidth, p.Height div p.TextureHeight, p.Alpha, True, p.Blending, hasAmbient)
+          else
+            e_DrawFillX(TextureID, p.X, p.Y, p.Width, p.Height, p.Alpha, True, p.Blending, g_dbg_scale, hasAmbient);
+          if hasAmbient then
+            e_AmbientQuad(p.X, p.Y, p.Width, p.Height, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
         end
       end
     end
   end;
 
   procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
         end
       end
     end
   end;
 
   procedure r_Panel_DrawShadowVolume (constref p: TPanel; lightX, lightY: Integer; radius: Integer);
+    var Texture: Cardinal;
 
     procedure extrude (x: Integer; y: Integer);
     begin
 
     procedure extrude (x: Integer; y: Integer);
     begin
@@ -105,32 +106,30 @@ implementation
     end;
 
   begin
     end;
 
   begin
-    with p do
+    if radius < 4 then exit;
+    if p.Enabled and (p.FCurTexture >= 0) and (p.Width > 0) and (p.Height > 0) and (p.Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
     begin
     begin
-      if radius < 4 then exit;
-      if Enabled and (FCurTexture >= 0) and (Width > 0) and (Height > 0) and (Alpha < 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
+      if not p.TextureIDs[p.FCurTexture].Anim then
       begin
       begin
-        if not TextureIDs[FCurTexture].Anim then
-        begin
-          case TextureIDs[FCurTexture].Tex of
-            LongWord(TEXTURE_SPECIAL_WATER): exit;
-            LongWord(TEXTURE_SPECIAL_ACID1): exit;
-            LongWord(TEXTURE_SPECIAL_ACID2): exit;
-            LongWord(TEXTURE_NONE): exit;
-          end;
+        Texture := p.TextureIDs[p.FCurTexture].Texture;
+        case Textures[Texture].TextureID of
+          LongWord(TEXTURE_SPECIAL_WATER): exit;
+          LongWord(TEXTURE_SPECIAL_ACID1): exit;
+          LongWord(TEXTURE_SPECIAL_ACID2): exit;
+          LongWord(TEXTURE_NONE): exit;
         end;
         end;
-        if (X + Width < lightX - radius) then exit;
-        if (Y + Height < lightY - radius) then exit;
-        if (X > lightX + radius) then exit;
-        if (Y > lightY + radius) then exit;
-        //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending);
-        glBegin(GL_QUADS);
-          drawLine(x,         y,          x + width, y); // top
-          drawLine(x + width, y,          x + width, y + height); // right
-          drawLine(x + width, y + height, x,         y + height); // bottom
-          drawLine(x,         y + height, x,         y); // left
-        glEnd;
-      end
+      end;
+      if (p.X + p.Width < lightX - radius) then exit;
+      if (p.Y + p.Height < lightY - radius) then exit;
+      if (p.X > lightX + radius) then exit;
+      if (p.Y > lightY + radius) then exit;
+      //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending);
+      glBegin(GL_QUADS);
+        drawLine(p.x,           p.y,            p.x + p.width, p.y); // top
+        drawLine(p.x + p.width, p.y,            p.x + p.width, p.y + p.height); // right
+        drawLine(p.x + p.width, p.y + p.height, p.x,           p.y + p.height); // bottom
+        drawLine(p.x,           p.y + p.height, p.x,           p.y); // left
+      glEnd;
     end
   end;
 
     end
   end;