From 4ddb8fb9574fdab67736236020e90e2d33765cf2 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 7 Jun 2021 20:52:39 +0300 Subject: [PATCH] render: separate item logic and drawing --- src/game/Doom2DF.lpr | 1 + src/game/g_items.pas | 67 +++-------------------------- src/game/opengl/r_game.pas | 6 +-- src/game/opengl/r_items.pas | 84 +++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 65 deletions(-) create mode 100644 src/game/opengl/r_items.pas diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index adbf205..a23adf6 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -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', diff --git a/src/game/g_items.pas b/src/game/g_items.pas index a69ceaa..23c10df 100644 --- a/src/game/g_items.pas +++ b/src/game/g_items.pas @@ -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 diff --git a/src/game/opengl/r_game.pas b/src/game/opengl/r_game.pas index 9747311..79d4b2e 100644 --- a/src/game/opengl/r_game.pas +++ b/src/game/opengl/r_game.pas @@ -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 index 0000000..a738b4d --- /dev/null +++ b/src/game/opengl/r_items.pas @@ -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 . + *) +{$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. -- 2.29.2