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>
Sun, 16 Jan 2022 18:49:28 +0000 (21:49 +0300)
src/game/g_map.pas
src/game/opengl/r_map.pas
src/game/opengl/r_render.pas

index f53fd1500ec723ef7bdcfca6c93aa7c37dbfc24b..2ca5bb67c604fc8f1f03c53aa87575eb260524e2 100644 (file)
@@ -52,7 +52,6 @@ type
     State:       Byte;
     Count:       Integer;
     CaptureTime: LongWord;
-    Animation:   TAnimation;
     Direction:   TDirection;
   end;
 
@@ -1078,7 +1077,6 @@ end;
 procedure CreateArea(Area: TDynRecord);
 var
   a: Integer;
-  id: DWORD = 0;
 begin
   case Area.AreaType of
     AREA_DMPOINT, AREA_PLAYERPOINT1, AREA_PLAYERPOINT2,
@@ -1118,14 +1116,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;
@@ -2204,8 +2195,6 @@ begin
       begin
         with gFlags[a] do
         begin
-          if gFlags[a].Animation <> nil then gFlags[a].Animation.Update();
-
           m := g_Obj_Move(@Obj, True, True);
 
           if gTime mod (GAME_TICK*2) <> 0 then Continue;
index 50d06d03c88d3cf55380a11864f44df446fb4754..1970ac3baf39de4462a1fe43818ba205734b3463 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,44 +252,28 @@ begin
     e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
 end;
 
-procedure r_Map_DrawFlags();
-var
-  i, dx: 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: 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;
-
-        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, Obj.X + dx, Obj.Y + 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;
+          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, f.Obj.X + dx, f.Obj.Y + 1, Mirror);
+          if g_debug_Frames then
+            e_DrawQuad(f.Obj.X + f.Obj.Rect.X, f.Obj.Y + f.Obj.Rect.Y, f.Obj.X + f.Obj.Rect.X + f.Obj.Rect.Width - 1, f.Obj.Y + f.Obj.Rect.Y + f.Obj.Rect.Height - 1, 0, 255, 0)
+        end
+      end
+    end
+  end;
 
   procedure r_Panel_Draw (constref p: TPanel; hasAmbient: Boolean; constref ambColor: TDFColor);
     var xx, yy: Integer; NoTextureID, TextureID, FramesID: DWORD; NW, NH: Word; Texture: Cardinal; IsAnim: Boolean; w, h: Integer;
@@ -361,4 +379,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;