From 3f43071711c968a2c31d6f1398df453b80c9d899 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 87b41f8..bec1c21 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 7331242..02c8b5f 100644 --- a/src/game/g_items.pas +++ b/src/game/g_items.pas @@ -44,6 +44,7 @@ Type procedure positionChanged (); //WARNING! call this after monster position was changed, or coldet will not work right! + property used: Boolean read slotIsUsed; property myid: Integer read arrIdx; end; @@ -56,8 +57,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); @@ -85,20 +84,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; @@ -645,60 +642,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 d2ead67..aa13e6b 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