DEADSOFTWARE

render: separate weapon shots logic and drawing
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Tue, 8 Jun 2021 02:44:59 +0000 (05:44 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 9 Jun 2023 07:41:50 +0000 (10:41 +0300)
src/game/Doom2DF.lpr
src/game/g_weapons.pas
src/game/opengl/r_game.pas
src/game/opengl/r_weapons.pas [new file with mode: 0644]

index 0d2c38a72ffe410058a00fe759c92624082a2fa9..179df4e35cc588c3e711d1efd4c4b910f2d8a692 100644 (file)
@@ -160,6 +160,7 @@ uses
   r_map in 'opengl/r_map.pas',
   r_monsters in 'opengl/r_monsters.pas',
   r_panel in 'opengl/r_panel.pas',
+  r_weapons in 'opengl/r_weapons.pas',
 
 {$IFDEF USE_FMOD}
   fmod in '../lib/FMOD/fmod.pas',
index f0fe29114071a4c6b9f5ce2f9b64ec678d387e77..81b3a03ab434389c7912d8a94afda118489c8a72 100644 (file)
@@ -74,7 +74,6 @@ function g_Weapon_Explode(X, Y: Integer; rad: Integer; SpawnerUID: Word): Boolea
 procedure g_Weapon_BFG9000(X, Y: Integer; SpawnerUID: Word);
 procedure g_Weapon_PreUpdate();
 procedure g_Weapon_Update();
-procedure g_Weapon_Draw();
 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
 procedure g_Weapon_DestroyShot(I: Integer; X, Y: Integer; Loud: Boolean = True);
 
@@ -2595,65 +2594,6 @@ begin
   end;
 end;
 
-procedure g_Weapon_Draw();
-var
-  i, fX, fY: Integer;
-  a: SmallInt;
-  p: TDFPoint;
-begin
-  if Shots = nil then
-    Exit;
-
-  for i := 0 to High(Shots) do
-    if Shots[i].ShotType <> 0 then
-      with Shots[i] do
-      begin
-        if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) or
-           (Shots[i].ShotType = WEAPON_BARON_FIRE) or
-           (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
-           (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
-          a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
-        else
-          a := 0;
-
-        Obj.lerp(gLerpFactor, fX, fY);
-        p.X := Obj.Rect.Width div 2;
-        p.Y := Obj.Rect.Height div 2;
-
-        if Shots[i].ShotType = WEAPON_BFG then
-        begin
-          DEC(fX, 6);
-          DEC(fY, 7);
-        end;
-
-        if Animation <> nil then
-          begin
-            if (Shots[i].ShotType = WEAPON_BARON_FIRE) or
-               (Shots[i].ShotType = WEAPON_MANCUB_FIRE) or
-               (Shots[i].ShotType = WEAPON_SKEL_FIRE) then
-              Animation.DrawEx(fX, fY, TMirrorType.None, p, a)
-            else
-              Animation.Draw(fX, fY, TMirrorType.None);
-          end
-        else if TextureID <> 0 then
-          begin
-            if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
-              e_DrawAdv(TextureID, fX, fY, 0, True, False, a, @p, TMirrorType.None)
-            else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
-              e_Draw(TextureID, fX, fY, 0, True, False);
-          end;
-
-          if g_debug_Frames 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;
-
 function g_Weapon_Danger(UID: Word; X, Y: Integer; Width, Height: Word; Time: Byte): Boolean;
 var
   a: Integer;
index b9ca74dc00b9924f561a706c5c35da8bac0fa7fb..d4e596cdbea6f059b84d1e9e310a40098da426b4 100644 (file)
@@ -32,7 +32,7 @@ implementation
     g_textures, e_input, e_sound,
     g_language, g_console, g_menu, g_triggers, g_player, g_options, g_monsters, g_map, g_panel, g_window,
     g_items, g_weapons, g_gfx, g_phys, g_net, g_gui, g_netmaster,
-    g_game, r_console, r_gfx, r_items, r_map, r_panel, r_monsters
+    g_game, r_console, r_gfx, r_items, r_map, r_panel, r_monsters, r_weapons
   ;
 
   var
@@ -1239,7 +1239,7 @@ begin
   drawPanelType('*back', PANEL_BACK, g_rlayer_back);
   drawPanelType('*step', PANEL_STEP, g_rlayer_step);
   drawOther('items', @r_Items_Draw);
-  drawOther('weapons', @g_Weapon_Draw);
+  drawOther('weapons', @r_Weapon_Draw);
   drawOther('shells', @g_Player_DrawShells);
   drawOther('drawall', @g_Player_DrawAll);
   drawOther('corpses', @g_Player_DrawCorpses);
diff --git a/src/game/opengl/r_weapons.pas b/src/game/opengl/r_weapons.pas
new file mode 100644 (file)
index 0000000..3b1f085
--- /dev/null
@@ -0,0 +1,79 @@
+(* 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_weapons;
+
+interface
+
+  procedure r_Weapon_Draw;
+
+implementation
+
+  uses
+    SysUtils, Classes, Math,
+    MAPDEF,
+    e_graphics,
+    g_basic, g_game,
+    g_weapons
+  ;
+
+  procedure r_Weapon_Draw;
+    var i, fX, fY, xx, yy: Integer; a: SmallInt; p: TDFPoint;
+  begin
+    if Shots = nil then
+      Exit;
+
+    for i := 0 to High(Shots) do
+    begin
+      if Shots[i].ShotType <> 0 then
+      begin
+        with Shots[i] do
+        begin
+          if Shots[i].ShotType in [WEAPON_ROCKETLAUNCHER, WEAPON_BARON_FIRE, WEAPON_MANCUB_FIRE, WEAPON_SKEL_FIRE] then
+            a := -GetAngle2(Obj.Vel.X, Obj.Vel.Y)
+          else
+            a := 0;
+
+          Obj.lerp(gLerpFactor, fX, fY);
+          p.X := Obj.Rect.Width div 2;
+          p.Y := Obj.Rect.Height div 2;
+
+          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)
+            else
+              Animation.Draw(fX, fY, TMirrorType.None);
+          end
+          else if TextureID <> 0 then
+          begin
+            if (Shots[i].ShotType = WEAPON_ROCKETLAUNCHER) then
+              e_DrawAdv(TextureID, fX, fY, 0, True, False, a, @p, TMirrorType.None)
+            else if (Shots[i].ShotType <> WEAPON_FLAMETHROWER) then
+              e_Draw(TextureID, fX, fY, 0, True, False);
+          end;
+
+          if g_debug_Frames then
+          begin
+            xx := Obj.X + Obj.Rect.X;
+            yy := Obj.Y + Obj.Rect.Y;
+            e_DrawQuad(xx, yy, xx + Obj.Rect.Width - 1, yy + Obj.Rect.Height - 1, 0, 255, 0);
+          end
+        end
+      end
+    end
+  end;
+
+end.