DEADSOFTWARE

render: separate animation drawing from game code
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 20 Jun 2021 10:17:40 +0000 (13:17 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 29 Jun 2021 09:51:12 +0000 (12:51 +0300)
12 files changed:
src/game/Doom2DF.lpr
src/game/g_gfx.pas
src/game/g_textures.pas
src/game/opengl/r_animations.pas [new file with mode: 0644]
src/game/opengl/r_gfx.pas
src/game/opengl/r_items.pas
src/game/opengl/r_map.pas
src/game/opengl/r_monsters.pas
src/game/opengl/r_panel.pas
src/game/opengl/r_player.pas
src/game/opengl/r_playermodel.pas
src/game/opengl/r_weapons.pas

index cf27ff71078ad20a34d36494031553f6bb5b37d9..13d80a68c135550367fd68f8290b131028036950 100644 (file)
@@ -152,6 +152,7 @@ uses
   g_touch in 'sdl2/g_touch.pas',
 {$ENDIF}
 
+  r_animations in 'opengl/r_animations.pas',
   r_console in 'opengl/r_console.pas',
   r_game in 'opengl/r_game.pas',
   r_gfx in 'opengl/r_gfx.pas',
@@ -163,10 +164,10 @@ uses
   r_panel in 'opengl/r_panel.pas',
   r_player in 'opengl/r_player.pas',
   r_playermodel in 'opengl/r_playermodel.pas',
+  r_render in 'opengl/r_render.pas',
   r_texture in 'opengl/r_texture.pas',
   r_weapons in 'opengl/r_weapons.pas',
   r_window in 'opengl/r_window.pas',
-  r_render in 'opengl/r_render.pas',
 
 {$IFDEF USE_FMOD}
   fmod in '../lib/FMOD/fmod.pas',
index 2a77c0310d554266aeebb5a50b1c852df7a48254..9c58759a071c0ace4bc29776649bf51d7c5998b3 100644 (file)
@@ -135,7 +135,7 @@ function awmIsSetHolmes (x, y: Integer): Boolean; inline;
 implementation
 
 uses
-  g_map, g_panel, g_basic, Math,
+  g_map, g_panel, g_basic, Math, r_animations,
   g_options, g_console, SysUtils, g_triggers, MAPDEF,
   g_game, g_language, g_net, utils, xprofiler;
 
index 773260fb19102e687447ceac187ff7a9f25595e5..e95fc6d73312eea7fac07bfe042d510896fd9ded 100644 (file)
@@ -53,9 +53,6 @@ type
     constructor Create (aframesID: LongWord; aloop: Boolean; aspeed: Byte);
     destructor  Destroy (); override;
 
-    procedure draw (x, y: Integer; mirror: TMirrorType);
-    procedure drawEx (x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt);
-
     procedure reset ();
     procedure update ();
     procedure enable ();
@@ -82,6 +79,8 @@ type
     property framesId: LongWord read mId;
     property width: Word read mWidth;
     property height: Word read mHeight;
+
+    property id: LongWord read mId;
   end;
 
 
@@ -112,6 +111,16 @@ procedure g_Frames_DeleteAll ();
 
 procedure DumpTextureNames ();
 
+  type (* private state *)
+    TFrames = record
+      texturesID: array of LongWord;
+      name: AnsiString;
+      frameWidth, frameHeight: Word;
+      used: Boolean;
+    end;
+
+  var (* private state *)
+    framesArray: array of TFrames = nil;
 
 implementation
 
@@ -127,16 +136,8 @@ type
     used: Boolean;
   end;
 
-  TFrames = record
-    texturesID: array of LongWord;
-    name: AnsiString;
-    frameWidth, frameHeight: Word;
-    used: Boolean;
-  end;
-
 var
   texturesArray: array of _TTexture = nil;
-  framesArray: array of TFrames = nil;
 
 
 const
@@ -760,14 +761,6 @@ begin
 end;
 
 
-procedure TAnimation.draw (x, y: Integer; mirror: TMirrorType);
-begin
-  if (not mEnabled) then exit;
-  e_DrawAdv(framesArray[mId].TexturesID[mCurrentFrame], x, y, mAlpha, true, mBlending, 0, nil, mirror);
-  //e_DrawQuad(X, Y, X+FramesArray[ID].FrameWidth-1, Y+FramesArray[ID].FrameHeight-1, 0, 255, 0);
-end;
-
-
 procedure TAnimation.update ();
 begin
   if (not mEnabled) then exit;
@@ -833,13 +826,6 @@ procedure TAnimation.disable (); begin mEnabled := false; end;
 procedure TAnimation.enable (); begin mEnabled := true; end;
 
 
-procedure TAnimation.drawEx (x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt);
-begin
-  if (not mEnabled) then exit;
-  e_DrawAdv(framesArray[mId].TexturesID[mCurrentFrame], x, y, mAlpha, true, mBlending, angle, @rpoint, mirror);
-end;
-
-
 function TAnimation.totalFrames (): Integer; inline; begin result := Length(framesArray[mId].TexturesID); end;
 
 
diff --git a/src/game/opengl/r_animations.pas b/src/game/opengl/r_animations.pas
new file mode 100644 (file)
index 0000000..71d752a
--- /dev/null
@@ -0,0 +1,41 @@
+(* Copyright (C)  Doom 2D: Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License ONLY.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../../shared/a_modes.inc}
+unit r_animations;
+
+interface
+
+  uses g_base, g_textures, MAPDEF; // TMirrorType, TAnimation, TDFPoint
+
+  procedure r_Animation_Draw (t: TAnimation; x, y: Integer; mirror: TMirrorType);
+  procedure r_Animation_DrawEx (t: TAnimation; x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt);
+
+implementation
+
+  uses r_graphics;
+
+  procedure r_Animation_Draw (t: TAnimation; x, y: Integer; mirror: TMirrorType);
+  begin
+    if t.enabled then
+      e_DrawAdv(framesArray[t.id].TexturesID[t.currentFrame], x, y, t.alpha, true, t.blending, 0, nil, mirror)
+  end;
+
+  procedure r_Animation_DrawEx (t: TAnimation; x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt);
+  begin
+    if t.enabled then
+      e_DrawAdv(framesArray[t.id].TexturesID[t.currentFrame], x, y, t.alpha, true, t.blending, angle, @rpoint, mirror)
+  end;
+
+end.
index 293e3aa174f0171f26be3f375135519062fa81a4..0bd271a1f7840b3802552a83c058abac072860f4 100644 (file)
@@ -25,7 +25,7 @@ implementation
     {$INCLUDE ../nogl/noGLuses.inc}
     SysUtils, Classes, Math,
     utils,
-    g_base, r_graphics, g_options,
+    g_base, r_graphics, g_options, r_animations,
     g_game,
     g_gfx
   ;
@@ -81,7 +81,7 @@ begin
         begin
           fx := nlerp(oldx, x, gLerpFactor);
           fy := nlerp(oldy, y, gLerpFactor);
-          Animation.Draw(x, y, TMirrorType.None);
+          r_Animation_Draw(Animation, x, y, TMirrorType.None);
         end;
       end;
     end;
index 6e3dfee703f939d272ffa52604a0c3a1bd005d5d..a317d857744e99437707f77f50ce3576db86212e 100644 (file)
@@ -24,7 +24,7 @@ implementation
 
   uses
     SysUtils, Classes, Math,
-    r_graphics,
+    r_graphics, r_animations,
     MAPDEF,
     g_base, g_basic, g_game,
     g_items
@@ -55,7 +55,7 @@ begin
         end
         else
         begin
-          Animation.Draw(fX, fY, TMirrorType.None);
+          r_Animation_Draw(Animation, fX, fY, TMirrorType.None);
         end;
 
         if g_debug_Frames then
index ef75c14c223452db1e12a37d1c66411b552b21aa..525bf35e9dc09d0b1f88406659b09038589e6637 100644 (file)
@@ -30,7 +30,7 @@ implementation
   uses
     {$INCLUDE ../nogl/noGLuses.inc}
     SysUtils, Classes, Math,
-    r_graphics,
+    r_graphics, r_animations,
     g_base, g_basic, g_game, g_options,
     g_panel, g_map,
     r_panel
@@ -129,7 +129,7 @@ begin
             dx := 1;
           end;
 
-        Animation.Draw(Obj.X+dx, Obj.Y+1, Mirror);
+        r_Animation_Draw(Animation, Obj.X + dx, Obj.Y + 1, Mirror);
 
         if g_debug_Frames then
         begin
index 9a747455ecc9e5ffc71d9e04d4682c509212b3cd..c55e143ed92fba001467dbe7a596109d97028ce9 100644 (file)
@@ -24,7 +24,7 @@ implementation
 
   uses
     SysUtils, Classes, Math,
-    r_graphics, g_options,
+    r_graphics, g_options, r_animations,
     MAPDEF,
     g_base, g_basic, g_game, g_phys,
     g_monsters
@@ -44,7 +44,7 @@ implementation
       if MonsterType = MONSTER_VILE then
         if MonsterState = MONSTATE_SHOOT then
           if GetPos(MonsterTargetUID, @o) then
-            VileFireAnim.Draw(o.X + o.Rect.X + (o.Rect.Width div 2) - 32, o.Y + o.Rect.Y + o.Rect.Height - 128, TMirrorType.None);
+            r_Animation_Draw(VileFireAnim, o.X + o.Rect.X + (o.Rect.Width div 2) - 32, o.Y + o.Rect.Y + o.Rect.Height - 128, TMirrorType.None);
 
       // Не в области рисования не ресуем:
       //FIXME!
@@ -93,8 +93,7 @@ implementation
           dy := MONSTER_ANIMTABLE[MonsterType].AnimDeltaRight[MonsterAnim].Y;
         end;
 
-        // Рисуем:
-        DirAnim[MonsterAnim, GameDirection].Draw(fX + dx, fY + dy, m);
+        r_Animation_Draw(DirAnim[MonsterAnim, GameDirection], fX + dx, fY + dy, m);
       end;
 
       if g_debug_Frames then
index 5160510d65026345c4a4b07ca1e4b956e21c9604..c9de77c350ddd6c333686c092f056b1e03c1fa8c 100644 (file)
@@ -27,7 +27,7 @@ implementation
   uses
     {$INCLUDE ../nogl/noGLuses.inc}
     SysUtils, Classes, Math,
-    r_graphics, g_options,
+    r_graphics, g_options, r_animations,
     g_base, g_basic, g_textures
   ;
 
@@ -46,7 +46,7 @@ implementation
             Exit;
           for xx := 0 to Width div TextureWidth - 1 do
             for yy := 0 to Height div TextureHeight - 1 do
-              TextureIDs[FCurTexture].AnTex.Draw(X + xx * TextureWidth, Y + yy * TextureHeight, TMirrorType.None);
+              r_Animation_Draw(TextureIDs[FCurTexture].AnTex, X + xx * TextureWidth, Y + yy * TextureHeight, TMirrorType.None);
         end
         else
         begin
index bb25f29eebfb6c6eec199fd8e812c5072d910c06..32e7ca871dc1b279f36f4f8a308784a031449d5b 100644 (file)
@@ -46,7 +46,7 @@ implementation
 {$IFDEF ENABLE_HOLMES}
     g_holmes,
 {$ENDIF}
-    r_playermodel, r_graphics
+    r_playermodel, r_graphics, r_animations
   ;
 
   procedure r_Player_DrawAll;
@@ -331,7 +331,7 @@ begin
 
     if p.PunchAnim <> nil then
     begin
-      p.PunchAnim.Draw(fX + IfThen(p.Direction = TDirection.D_LEFT, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15), fY + fSlope + p.Obj.Rect.Y - 11, Mirror);
+      r_Animation_Draw(p.PunchAnim, fX + IfThen(p.Direction = TDirection.D_LEFT, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15), fY + fSlope + p.Obj.Rect.Y - 11, Mirror);
       if p.PunchAnim.played then
       begin
         p.PunchAnim.Free;
@@ -795,12 +795,12 @@ begin
   p.Obj.lerp(gLerpFactor, fX, fY);
 
   if p.Animation <> nil then
-    p.Animation.Draw(fX, fY, TMirrorType.None);
+    r_Animation_Draw(p.Animation, fX, fY, TMirrorType.None);
 
   if p.AnimationMask <> nil then
   begin
     e_Colors := p.Color;
-    p.AnimationMask.Draw(fX, fY, TMirrorType.None);
+    r_Animation_Draw(p.AnimationMask, fX, fY, TMirrorType.None);
     e_Colors.R := 255;
     e_Colors.G := 255;
     e_Colors.B := 255;
index 2f40e9fea9f8aa6cf7c8769c46105ee2c8b55cb1..fc1576069450c8e54e812952e8cee5140f0a57fa 100644 (file)
@@ -28,7 +28,7 @@ implementation
   uses
     SysUtils, Classes, Math,
     MAPDEF,
-    r_graphics, g_options,
+    r_graphics, g_options, r_animations,
     g_base, g_basic, g_map, g_weapons, g_textures
   ;
 
@@ -79,7 +79,7 @@ begin
     p.X := IfThen(pm.Direction = TDirection.D_LEFT, FLAG_BASEPOINT.X, 64 - FLAG_BASEPOINT.X);
     p.Y := FLAG_BASEPOINT.Y;
 
-    pm.FlagAnim.DrawEx(X+IfThen(pm.Direction = TDirection.D_LEFT, pm.FlagPoint.X-1, 2*FLAG_BASEPOINT.X-pm.FlagPoint.X+1)-FLAG_BASEPOINT.X,
+    r_Animation_DrawEx(pm.FlagAnim, X+IfThen(pm.Direction = TDirection.D_LEFT, pm.FlagPoint.X-1, 2*FLAG_BASEPOINT.X-pm.FlagPoint.X+1)-FLAG_BASEPOINT.X,
                      Y+pm.FlagPoint.Y-FLAG_BASEPOINT.Y+1, Mirror, p,
                      IfThen(pm.Direction = TDirection.D_RIGHT, pm.FlagAngle, -pm.FlagAngle));
   end;
@@ -118,12 +118,12 @@ begin
   if (pm.Direction = TDirection.D_LEFT) and (pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation] <> nil) then
   begin
     pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation].Alpha := Alpha;
-    pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation].Draw(X, Y, TMirrorType.None);
+    r_Animation_Draw(pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation], X, Y, TMirrorType.None);
   end
   else
   begin
     pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation].Alpha := Alpha;
-    pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation].Draw(X, Y, Mirror);
+    r_Animation_Draw(pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation], X, Y, Mirror);
   end;
 
 // Маска модели:
@@ -132,12 +132,12 @@ begin
   if (pm.Direction = TDirection.D_LEFT) and (pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation] <> nil) then
   begin
     pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation].Alpha := Alpha;
-    pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation].Draw(X, Y, TMirrorType.None);
+    r_Animation_Draw(pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation], X, Y, TMirrorType.None);
   end
   else
   begin
     pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation].Alpha := Alpha;
-    pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation].Draw(X, Y, Mirror);
+    r_Animation_Draw(pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation], X, Y, Mirror);
   end;
 
   e_Colors.R := 255;
index 38882f1689a78935f91b9ba909207e534fa72629..94d1d4ade21ae5e423c512a020269bc8d431763d 100644 (file)
@@ -24,7 +24,7 @@ implementation
   uses
     SysUtils, Classes, Math,
     MAPDEF,
-    r_graphics,
+    r_graphics, r_animations,
     g_base, g_basic, g_game,
     g_weapons
   ;
@@ -53,9 +53,9 @@ implementation
           if Animation <> nil then
           begin
             if Shots[i].ShotType in [WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE] then
-              Animation.DrawEx(fX, fY, TMirrorType.None, p, a)
+              r_Animation_DrawEx(Animation, fX, fY, TMirrorType.None, p, a)
             else
-              Animation.Draw(fX, fY, TMirrorType.None);
+              r_Animation_Draw(Animation, fX, fY, TMirrorType.None);
           end
           else if TextureID <> 0 then
           begin