DEADSOFTWARE

render: separate item logic and drawing
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Mon, 7 Jun 2021 17:52:39 +0000 (20:52 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 9 Jun 2023 07:41:07 +0000 (10:41 +0300)
src/game/Doom2DF.lpr
src/game/g_items.pas
src/game/opengl/r_game.pas
src/game/opengl/r_items.pas [new file with mode: 0644]

index adbf20556266cf7651dc6d74d098e89e863269b3..a23adf686d22769219fadce121ba1fc98b72c234 100644 (file)
@@ -156,6 +156,7 @@ uses
   r_console in 'opengl/r_console.pas',
   r_game in 'opengl/r_game.pas',
   r_gfx in 'opengl/r_gfx.pas',
+  r_items in 'opengl/r_items.pas',
 
 {$IFDEF USE_FMOD}
   fmod in '../lib/FMOD/fmod.pas',
index a69ceaaf811bd9f84f5b07ec41b0e6e2fcf11537..23c10df8aadc7d3a1e45197991f8f0317a5bb1a2 100644 (file)
@@ -47,6 +47,7 @@ Type
     procedure getMapBox (out x, y, w, h: Integer); inline;
     procedure moveBy (dx, dy: Integer); inline;
 
+    property used: Boolean read slotIsUsed;
     property myid: Integer read arrIdx;
   end;
 
@@ -59,8 +60,6 @@ function g_Items_Create(X, Y: Integer; ItemType: Byte;
 procedure g_Items_SetDrop (ID: DWORD);
 procedure g_Items_PreUpdate();
 procedure g_Items_Update();
-procedure g_Items_Draw();
-procedure g_Items_DrawDrop();
 procedure g_Items_Pick(ID: DWORD);
 procedure g_Items_Remove(ID: DWORD);
 procedure g_Items_SaveState (st: TStream);
@@ -88,20 +87,18 @@ var
   gItemsTexturesID: Array [1..ITEM_MAX] of DWORD;
   gMaxDist: Integer = 1; // for sounds
 
+  var (* private state *)
+    ggItems: Array of TItem = nil;
+
 implementation
 
 uses
   Math,
-  g_basic, e_graphics, g_sound, g_main, g_gfx, g_map,
+  g_basic, g_sound, g_main, g_gfx, g_map,
   g_game, g_triggers, g_console, g_player, g_net, g_netmsg,
   e_log,
   g_grid, binheap, idpool, utils, xstreams;
 
-
-var
-  ggItems: Array of TItem = nil;
-
-
 // ////////////////////////////////////////////////////////////////////////// //
 var
   freeIds: TIdPool = nil;
@@ -669,60 +666,6 @@ begin
   end;
 end;
 
-
-procedure itemsDrawInternal (dropflag: Boolean);
-var
-  i, fX, fY: Integer;
-  it: PItem;
-begin
-  if (ggItems = nil) then exit;
-
-  for i := 0 to High(ggItems) do
-  begin
-    it := @ggItems[i];
-    if (not it.slotIsUsed) or (it.ItemType = ITEM_NONE) then continue; // just in case
-    if not it.alive then continue;
-    if (it.dropped <> dropflag) then continue;
-
-    with it^ do
-    begin
-      if g_Collide(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height, sX, sY, sWidth, sHeight) then
-      begin
-        Obj.lerp(gLerpFactor, fX, fY);
-        if (Animation = nil) then
-        begin
-          e_Draw(gItemsTexturesID[ItemType], fX, fY, 0, true, false);
-        end
-        else
-        begin
-          Animation.Draw(fX, fY, TMirrorType.None);
-        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;
-  end;
-end;
-
-
-procedure g_Items_Draw ();
-begin
-  itemsDrawInternal(false);
-end;
-
-procedure g_Items_DrawDrop ();
-begin
-  itemsDrawInternal(true);
-end;
-
-
 procedure g_Items_SetDrop (ID: DWORD);
 begin
   if (ID < Length(ggItems)) then
index 974731147b2cb0911748877183820fcd92be8e4f..79d4b2ece9fa7f22848eaaf06c81d1751c7d10d8 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
+    g_game, r_console, r_gfx, r_items
   ;
 
   var
@@ -1238,14 +1238,14 @@ begin
 
   drawPanelType('*back', PANEL_BACK, g_rlayer_back);
   drawPanelType('*step', PANEL_STEP, g_rlayer_step);
-  drawOther('items', @g_Items_Draw);
+  drawOther('items', @r_Items_Draw);
   drawOther('weapons', @g_Weapon_Draw);
   drawOther('shells', @g_Player_DrawShells);
   drawOther('drawall', @g_Player_DrawAll);
   drawOther('corpses', @g_Player_DrawCorpses);
   drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
   drawOther('monsters', @g_Monsters_Draw);
-  drawOther('itemdrop', @g_Items_DrawDrop);
+  drawOther('itemdrop', @r_Items_DrawDrop);
   drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
   drawOther('gfx', @r_GFX_Draw);
   drawOther('flags', @g_Map_DrawFlags);
diff --git a/src/game/opengl/r_items.pas b/src/game/opengl/r_items.pas
new file mode 100644 (file)
index 0000000..a738b4d
--- /dev/null
@@ -0,0 +1,84 @@
+(* 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_items;
+
+interface
+
+  procedure r_Items_Draw;
+  procedure r_Items_DrawDrop;
+
+implementation
+
+  uses
+    SysUtils, Classes, Math,
+    e_graphics,
+    MAPDEF,
+    g_basic, g_game,
+    g_items
+  ;
+
+procedure itemsDrawInternal (dropflag: Boolean);
+var
+  i, fX, fY: Integer;
+  it: PItem;
+begin
+  if (ggItems = nil) then exit;
+
+  for i := 0 to High(ggItems) do
+  begin
+    it := @ggItems[i];
+    if (not it.used) or (it.ItemType = ITEM_NONE) then continue; // just in case
+    if not it.alive then continue;
+    if (it.dropped <> dropflag) then continue;
+
+    with it^ do
+    begin
+      if g_Collide(Obj.X, Obj.Y, Obj.Rect.Width, Obj.Rect.Height, sX, sY, sWidth, sHeight) then
+      begin
+        Obj.lerp(gLerpFactor, fX, fY);
+        if (Animation = nil) then
+        begin
+          e_Draw(gItemsTexturesID[ItemType], fX, fY, 0, true, false);
+        end
+        else
+        begin
+          Animation.Draw(fX, fY, TMirrorType.None);
+        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;
+  end;
+end;
+
+procedure r_Items_Draw;
+begin
+  itemsDrawInternal(false);
+end;
+
+procedure r_Items_DrawDrop;
+begin
+  itemsDrawInternal(true);
+end;
+
+end.