From 4756f15257c93cd6212b61efa7bd3bade826adcb Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Tue, 8 Jun 2021 05:44:59 +0300 Subject: [PATCH] render: separate weapon shots logic and drawing --- src/game/Doom2DF.lpr | 1 + src/game/g_weapons.pas | 60 -------------------------- src/game/opengl/r_game.pas | 4 +- src/game/opengl/r_weapons.pas | 79 +++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 62 deletions(-) create mode 100644 src/game/opengl/r_weapons.pas diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index 0d2c38a..179df4e 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -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', diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas index f0fe291..81b3a03 100644 --- a/src/game/g_weapons.pas +++ b/src/game/g_weapons.pas @@ -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; diff --git a/src/game/opengl/r_game.pas b/src/game/opengl/r_game.pas index b9ca74d..d4e596c 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, 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 index 0000000..3b1f085 --- /dev/null +++ b/src/game/opengl/r_weapons.pas @@ -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 . + *) +{$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. -- 2.29.2