DEADSOFTWARE

render: draw flag animation using TAnimationState
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 16 Jan 2022 18:49:28 +0000 (21:49 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 9 Jun 2023 07:52:35 +0000 (10:52 +0300)
src/game/g_map.pas
src/game/opengl/r_map.pas
src/game/opengl/r_render.pas

index d120dfcd6928f48bf7a3749c0cc5d36219bbfd96..92da4f4b9121206d5dd0d0576735be5ed5746bcf 100644 (file)
@@ -52,7 +52,6 @@ type
     State:       Byte;
     Count:       Integer;
     CaptureTime: LongWord;
-    Animation:   TAnimation;
     Direction:   TDirection;
     NeedSend:    Boolean;
   end;
@@ -1079,7 +1078,6 @@ end;
 procedure CreateArea(Area: TDynRecord);
 var
   a: Integer;
-  id: DWORD = 0;
 begin
   case Area.AreaType of
     AREA_DMPOINT, AREA_PLAYERPOINT1, AREA_PLAYERPOINT2,
@@ -1119,14 +1117,7 @@ begin
 
       with gFlags[a] do
       begin
-        case a of
-          FLAG_RED: g_Frames_Get(id, 'FRAMES_FLAG_RED');
-          FLAG_BLUE: g_Frames_Get(id, 'FRAMES_FLAG_BLUE');
-        end;
-
-        Animation := TAnimation.Create(id, True, 8);
         Obj.Rect := FLAGRECT;
-
         g_Map_ResetFlag(a);
       end;
     end;
@@ -2205,8 +2196,6 @@ begin
       begin
         with gFlags[a] do
         begin
-          if gFlags[a].Animation <> nil then gFlags[a].Animation.Update();
-
           Obj.oldX := Obj.X;
           Obj.oldY := Obj.Y;
 
index 0f508d70a58a71ec51239be52a162bf7477d30a1..d34100da06db6f9ccf48591bf9177694cc057f4f 100644 (file)
@@ -19,7 +19,16 @@ interface
 
   uses g_panel, MAPDEF; // TPanel, TDFColor
 
+  procedure r_Map_Initialize;
+  procedure r_Map_Finalize;
+
+  procedure r_Map_Load;
+  procedure r_Map_Free;
+
   procedure r_Map_LoadTextures;
+  // TODO procedure r_Map_FreeTextures
+
+  procedure r_Map_Update;
 
   procedure r_Map_DrawBack (dx, dy: Integer);
   procedure r_Map_DrawPanels (PanelType: Word; hasAmbient: Boolean; constref ambColor: TDFColor); // unaccelerated
@@ -35,7 +44,7 @@ implementation
   uses
     {$INCLUDE ../nogl/noGLuses.inc}
     SysUtils, Classes, Math, e_log, wadreader, CONFIG, utils,
-    r_graphics, r_animations, r_textures,
+    r_graphics, r_animations, r_textures, g_textures,
     g_base, g_basic, g_game, g_options,
     g_map
   ;
@@ -46,6 +55,31 @@ implementation
       Width, Height: WORD;
       Anim: Boolean;
     end;
+    FlagFrames: array [FLAG_RED..FLAG_BLUE] of DWORD;
+    FlagAnim: TAnimationState;
+
+  procedure r_Map_Initialize;
+  begin
+    FlagAnim := TAnimationState.Create(True, 8, 5);
+  end;
+
+  procedure r_Map_Finalize;
+  begin
+    FlagAnim.Free;
+    FlagAnim := nil;
+  end;
+
+  procedure r_Map_Load;
+  begin
+    g_Frames_CreateWAD(@FlagFrames[FLAG_RED], 'FRAMES_FLAG_RED', GameWAD + ':TEXTURES\FLAGRED', 64, 64, 5, False);
+    g_Frames_CreateWAD(@FlagFrames[FLAG_BLUE], 'FRAMES_FLAG_BLUE', GameWAD + ':TEXTURES\FLAGBLUE', 64, 64, 5, False);
+  end;
+
+  procedure r_Map_Free;
+  begin
+    g_Frames_DeleteByName('FRAMES_FLAG_RED');
+    g_Frames_DeleteByName('FRAMES_FLAG_BLUE');
+  end;
 
   procedure r_Map_LoadTextures;
     const
@@ -218,47 +252,29 @@ begin
     e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
 end;
 
-procedure r_Map_DrawFlags();
-var
-  i, dx: Integer;
-  tx, ty: Integer;
-  Mirror: TMirrorType;
-begin
-  if gGameSettings.GameMode <> GM_CTF then
-    Exit;
-
-  for i := FLAG_RED to FLAG_BLUE do
-    with gFlags[i] do
-      if State <> FLAG_STATE_CAPTURED then
+  procedure r_Map_DrawFlags;
+    var i, dx, tx, ty: Integer; Mirror: TMirrorType; f: PFlag;
+  begin
+    if gGameSettings.GameMode = GM_CTF then
+    begin
+      for i := FLAG_RED to FLAG_BLUE do
       begin
-        if State = FLAG_STATE_NONE then
-          continue;
-
-        Obj.lerp(gLerpFactor, tx, ty);
-
-        if Direction = TDirection.D_LEFT then
-          begin
-            Mirror := TMirrorType.Horizontal;
-            dx := -1;
-          end
-        else
-          begin
-            Mirror := TMirrorType.None;
-            dx := 1;
-          end;
-
-        r_Animation_Draw(Animation, tx + dx, ty + 1, Mirror);
-
-        if g_debug_Frames then
+        f := @gFlags[i];
+        if not (f.State in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) then
         begin
-          e_DrawQuad(Obj.X+Obj.Rect.X,
-                     Obj.Y+Obj.Rect.Y,
-                     Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
-                     Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
-                     0, 255, 0);
-        end;
-      end;
-end;
+          f.Obj.lerp(gLerpFactor, tx, ty);
+          if f.Direction = TDirection.D_LEFT then
+            Mirror :=  TMirrorType.Horizontal
+          else
+            Mirror := TMirrorType.None;
+          dx := IfThen(f.Direction = TDirection.D_LEFT, -1, +1);
+          r_AnimationState_Draw(FlagFrames[i], FlagAnim, tx + dx, ty + 1, Mirror);
+          if g_debug_Frames then
+            e_DrawQuad(tx + f.Obj.Rect.X, ty + f.Obj.Rect.Y, tx + f.Obj.Rect.X + f.Obj.Rect.Width - 1, ty + f.Obj.Rect.Y + f.Obj.Rect.Height - 1, 0, 255, 0)
+        end
+      end
+    end
+  end;
 
   procedure Panel_Lerp (p: TPanel; t: Single; out tX, tY, tW, tH: Integer);
   begin
@@ -384,4 +400,9 @@ end;
     end
   end;
 
+  procedure r_Map_Update;
+  begin
+    FlagAnim.Update
+  end;
+
 end.
index b26d0ecbea851752387b952675dc49f0e074789a..50e5892e9ee0366ce0f9359cafd67f66e4b408be 100644 (file)
@@ -37,7 +37,7 @@ implementation
     e_log, g_system,
     g_game, g_options, g_console,
     r_window, r_graphics, r_console, r_playermodel,
-    r_weapons, r_items, r_gfx, r_monsters
+    r_weapons, r_items, r_gfx, r_monsters, r_map
   ;
 
   var
@@ -78,6 +78,7 @@ implementation
 
   procedure r_Render_Load;
   begin
+    r_Map_Load;
     r_PlayerModel_Load;
     r_Monsters_Load;
     r_Weapon_Load;
@@ -92,6 +93,7 @@ implementation
     r_Weapon_Free;
     r_Monsters_Free;
     r_PlayerModel_Free;
+    r_Map_Free;
   end;
 
   procedure r_Render_Initialize;
@@ -102,10 +104,12 @@ implementation
     r_Window_Initialize;
     r_Console_Init;
     r_PlayerModel_Initialize;
+    r_Map_Initialize;
   end;
 
   procedure r_Render_Finalize;
   begin
+    r_Map_Finalize;
     r_PlayerModel_Finalize;
     FreeGL;
     e_ReleaseEngine
@@ -113,6 +117,7 @@ implementation
 
   procedure r_Render_Update;
   begin
+    r_Map_Update;
     r_PlayerModel_Update;
   end;