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>
Tue, 29 Jun 2021 09:51:11 +0000 (12:51 +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 dc006290469d28783770cbcfb3c27be03453751c..caa29550b00976720daa4d3c396c269dfc6ec300 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 32fc8f6c04a770ee0c0e34bfc5ab630b4958d20b..c94282d7b9c3ee1c71a89316b26324b1031f3370 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);
 
@@ -2544,59 +2543,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 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 090f6747993d012701e4f6dee7367afb12c43b11..c3577ccace0f47fd5332ab7839612e7aa90bfacb 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.