From d5d513b459869550bc0623d910eb97c706fab07d Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 20 Jun 2021 13:17:40 +0300 Subject: [PATCH] render: separate animation drawing from game code --- src/game/Doom2DF.lpr | 3 ++- src/game/g_gfx.pas | 2 +- src/game/g_textures.pas | 38 +++++++++------------------- src/game/opengl/r_animations.pas | 41 +++++++++++++++++++++++++++++++ src/game/opengl/r_gfx.pas | 4 +-- src/game/opengl/r_items.pas | 4 +-- src/game/opengl/r_map.pas | 4 +-- src/game/opengl/r_monsters.pas | 7 +++--- src/game/opengl/r_panel.pas | 4 +-- src/game/opengl/r_player.pas | 8 +++--- src/game/opengl/r_playermodel.pas | 12 ++++----- src/game/opengl/r_weapons.pas | 6 ++--- 12 files changed, 80 insertions(+), 53 deletions(-) create mode 100644 src/game/opengl/r_animations.pas diff --git a/src/game/Doom2DF.lpr b/src/game/Doom2DF.lpr index cf27ff7..13d80a6 100644 --- a/src/game/Doom2DF.lpr +++ b/src/game/Doom2DF.lpr @@ -152,6 +152,7 @@ uses g_touch in 'sdl2/g_touch.pas', {$ENDIF} + r_animations in 'opengl/r_animations.pas', r_console in 'opengl/r_console.pas', r_game in 'opengl/r_game.pas', r_gfx in 'opengl/r_gfx.pas', @@ -163,10 +164,10 @@ uses r_panel in 'opengl/r_panel.pas', r_player in 'opengl/r_player.pas', r_playermodel in 'opengl/r_playermodel.pas', + r_render in 'opengl/r_render.pas', r_texture in 'opengl/r_texture.pas', r_weapons in 'opengl/r_weapons.pas', r_window in 'opengl/r_window.pas', - r_render in 'opengl/r_render.pas', {$IFDEF USE_FMOD} fmod in '../lib/FMOD/fmod.pas', diff --git a/src/game/g_gfx.pas b/src/game/g_gfx.pas index 2a77c03..9c58759 100644 --- a/src/game/g_gfx.pas +++ b/src/game/g_gfx.pas @@ -135,7 +135,7 @@ function awmIsSetHolmes (x, y: Integer): Boolean; inline; implementation uses - g_map, g_panel, g_basic, Math, + g_map, g_panel, g_basic, Math, r_animations, g_options, g_console, SysUtils, g_triggers, MAPDEF, g_game, g_language, g_net, utils, xprofiler; diff --git a/src/game/g_textures.pas b/src/game/g_textures.pas index 773260f..e95fc6d 100644 --- a/src/game/g_textures.pas +++ b/src/game/g_textures.pas @@ -53,9 +53,6 @@ type constructor Create (aframesID: LongWord; aloop: Boolean; aspeed: Byte); destructor Destroy (); override; - procedure draw (x, y: Integer; mirror: TMirrorType); - procedure drawEx (x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt); - procedure reset (); procedure update (); procedure enable (); @@ -82,6 +79,8 @@ type property framesId: LongWord read mId; property width: Word read mWidth; property height: Word read mHeight; + + property id: LongWord read mId; end; @@ -112,6 +111,16 @@ procedure g_Frames_DeleteAll (); procedure DumpTextureNames (); + type (* private state *) + TFrames = record + texturesID: array of LongWord; + name: AnsiString; + frameWidth, frameHeight: Word; + used: Boolean; + end; + + var (* private state *) + framesArray: array of TFrames = nil; implementation @@ -127,16 +136,8 @@ type used: Boolean; end; - TFrames = record - texturesID: array of LongWord; - name: AnsiString; - frameWidth, frameHeight: Word; - used: Boolean; - end; - var texturesArray: array of _TTexture = nil; - framesArray: array of TFrames = nil; const @@ -760,14 +761,6 @@ begin end; -procedure TAnimation.draw (x, y: Integer; mirror: TMirrorType); -begin - if (not mEnabled) then exit; - e_DrawAdv(framesArray[mId].TexturesID[mCurrentFrame], x, y, mAlpha, true, mBlending, 0, nil, mirror); - //e_DrawQuad(X, Y, X+FramesArray[ID].FrameWidth-1, Y+FramesArray[ID].FrameHeight-1, 0, 255, 0); -end; - - procedure TAnimation.update (); begin if (not mEnabled) then exit; @@ -833,13 +826,6 @@ procedure TAnimation.disable (); begin mEnabled := false; end; procedure TAnimation.enable (); begin mEnabled := true; end; -procedure TAnimation.drawEx (x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt); -begin - if (not mEnabled) then exit; - e_DrawAdv(framesArray[mId].TexturesID[mCurrentFrame], x, y, mAlpha, true, mBlending, angle, @rpoint, mirror); -end; - - function TAnimation.totalFrames (): Integer; inline; begin result := Length(framesArray[mId].TexturesID); end; diff --git a/src/game/opengl/r_animations.pas b/src/game/opengl/r_animations.pas new file mode 100644 index 0000000..71d752a --- /dev/null +++ b/src/game/opengl/r_animations.pas @@ -0,0 +1,41 @@ +(* 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_animations; + +interface + + uses g_base, g_textures, MAPDEF; // TMirrorType, TAnimation, TDFPoint + + procedure r_Animation_Draw (t: TAnimation; x, y: Integer; mirror: TMirrorType); + procedure r_Animation_DrawEx (t: TAnimation; x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt); + +implementation + + uses r_graphics; + + procedure r_Animation_Draw (t: TAnimation; x, y: Integer; mirror: TMirrorType); + begin + if t.enabled then + e_DrawAdv(framesArray[t.id].TexturesID[t.currentFrame], x, y, t.alpha, true, t.blending, 0, nil, mirror) + end; + + procedure r_Animation_DrawEx (t: TAnimation; x, y: Integer; mirror: TMirrorType; rpoint: TDFPoint; angle: SmallInt); + begin + if t.enabled then + e_DrawAdv(framesArray[t.id].TexturesID[t.currentFrame], x, y, t.alpha, true, t.blending, angle, @rpoint, mirror) + end; + +end. diff --git a/src/game/opengl/r_gfx.pas b/src/game/opengl/r_gfx.pas index 293e3aa..0bd271a 100644 --- a/src/game/opengl/r_gfx.pas +++ b/src/game/opengl/r_gfx.pas @@ -25,7 +25,7 @@ implementation {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, Math, utils, - g_base, r_graphics, g_options, + g_base, r_graphics, g_options, r_animations, g_game, g_gfx ; @@ -81,7 +81,7 @@ begin begin fx := nlerp(oldx, x, gLerpFactor); fy := nlerp(oldy, y, gLerpFactor); - Animation.Draw(x, y, TMirrorType.None); + r_Animation_Draw(Animation, x, y, TMirrorType.None); end; end; end; diff --git a/src/game/opengl/r_items.pas b/src/game/opengl/r_items.pas index 6e3dfee..a317d85 100644 --- a/src/game/opengl/r_items.pas +++ b/src/game/opengl/r_items.pas @@ -24,7 +24,7 @@ implementation uses SysUtils, Classes, Math, - r_graphics, + r_graphics, r_animations, MAPDEF, g_base, g_basic, g_game, g_items @@ -55,7 +55,7 @@ begin end else begin - Animation.Draw(fX, fY, TMirrorType.None); + r_Animation_Draw(Animation, fX, fY, TMirrorType.None); end; if g_debug_Frames then diff --git a/src/game/opengl/r_map.pas b/src/game/opengl/r_map.pas index ef75c14..525bf35 100644 --- a/src/game/opengl/r_map.pas +++ b/src/game/opengl/r_map.pas @@ -30,7 +30,7 @@ implementation uses {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, Math, - r_graphics, + r_graphics, r_animations, g_base, g_basic, g_game, g_options, g_panel, g_map, r_panel @@ -129,7 +129,7 @@ begin dx := 1; end; - Animation.Draw(Obj.X+dx, Obj.Y+1, Mirror); + r_Animation_Draw(Animation, Obj.X + dx, Obj.Y + 1, Mirror); if g_debug_Frames then begin diff --git a/src/game/opengl/r_monsters.pas b/src/game/opengl/r_monsters.pas index 9a74745..c55e143 100644 --- a/src/game/opengl/r_monsters.pas +++ b/src/game/opengl/r_monsters.pas @@ -24,7 +24,7 @@ implementation uses SysUtils, Classes, Math, - r_graphics, g_options, + r_graphics, g_options, r_animations, MAPDEF, g_base, g_basic, g_game, g_phys, g_monsters @@ -44,7 +44,7 @@ implementation if MonsterType = MONSTER_VILE then if MonsterState = MONSTATE_SHOOT then if GetPos(MonsterTargetUID, @o) then - VileFireAnim.Draw(o.X + o.Rect.X + (o.Rect.Width div 2) - 32, o.Y + o.Rect.Y + o.Rect.Height - 128, TMirrorType.None); + r_Animation_Draw(VileFireAnim, o.X + o.Rect.X + (o.Rect.Width div 2) - 32, o.Y + o.Rect.Y + o.Rect.Height - 128, TMirrorType.None); // Не в области рисования не ресуем: //FIXME! @@ -93,8 +93,7 @@ implementation dy := MONSTER_ANIMTABLE[MonsterType].AnimDeltaRight[MonsterAnim].Y; end; - // Рисуем: - DirAnim[MonsterAnim, GameDirection].Draw(fX + dx, fY + dy, m); + r_Animation_Draw(DirAnim[MonsterAnim, GameDirection], fX + dx, fY + dy, m); end; if g_debug_Frames then diff --git a/src/game/opengl/r_panel.pas b/src/game/opengl/r_panel.pas index 5160510..c9de77c 100644 --- a/src/game/opengl/r_panel.pas +++ b/src/game/opengl/r_panel.pas @@ -27,7 +27,7 @@ implementation uses {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, Math, - r_graphics, g_options, + r_graphics, g_options, r_animations, g_base, g_basic, g_textures ; @@ -46,7 +46,7 @@ implementation Exit; for xx := 0 to Width div TextureWidth - 1 do for yy := 0 to Height div TextureHeight - 1 do - TextureIDs[FCurTexture].AnTex.Draw(X + xx * TextureWidth, Y + yy * TextureHeight, TMirrorType.None); + r_Animation_Draw(TextureIDs[FCurTexture].AnTex, X + xx * TextureWidth, Y + yy * TextureHeight, TMirrorType.None); end else begin diff --git a/src/game/opengl/r_player.pas b/src/game/opengl/r_player.pas index bb25f29..32e7ca8 100644 --- a/src/game/opengl/r_player.pas +++ b/src/game/opengl/r_player.pas @@ -46,7 +46,7 @@ implementation {$IFDEF ENABLE_HOLMES} g_holmes, {$ENDIF} - r_playermodel, r_graphics + r_playermodel, r_graphics, r_animations ; procedure r_Player_DrawAll; @@ -331,7 +331,7 @@ begin if p.PunchAnim <> nil then begin - p.PunchAnim.Draw(fX + IfThen(p.Direction = TDirection.D_LEFT, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15), fY + fSlope + p.Obj.Rect.Y - 11, Mirror); + r_Animation_Draw(p.PunchAnim, fX + IfThen(p.Direction = TDirection.D_LEFT, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15), fY + fSlope + p.Obj.Rect.Y - 11, Mirror); if p.PunchAnim.played then begin p.PunchAnim.Free; @@ -795,12 +795,12 @@ begin p.Obj.lerp(gLerpFactor, fX, fY); if p.Animation <> nil then - p.Animation.Draw(fX, fY, TMirrorType.None); + r_Animation_Draw(p.Animation, fX, fY, TMirrorType.None); if p.AnimationMask <> nil then begin e_Colors := p.Color; - p.AnimationMask.Draw(fX, fY, TMirrorType.None); + r_Animation_Draw(p.AnimationMask, fX, fY, TMirrorType.None); e_Colors.R := 255; e_Colors.G := 255; e_Colors.B := 255; diff --git a/src/game/opengl/r_playermodel.pas b/src/game/opengl/r_playermodel.pas index 2f40e9f..fc15760 100644 --- a/src/game/opengl/r_playermodel.pas +++ b/src/game/opengl/r_playermodel.pas @@ -28,7 +28,7 @@ implementation uses SysUtils, Classes, Math, MAPDEF, - r_graphics, g_options, + r_graphics, g_options, r_animations, g_base, g_basic, g_map, g_weapons, g_textures ; @@ -79,7 +79,7 @@ begin p.X := IfThen(pm.Direction = TDirection.D_LEFT, FLAG_BASEPOINT.X, 64 - FLAG_BASEPOINT.X); p.Y := FLAG_BASEPOINT.Y; - pm.FlagAnim.DrawEx(X+IfThen(pm.Direction = TDirection.D_LEFT, pm.FlagPoint.X-1, 2*FLAG_BASEPOINT.X-pm.FlagPoint.X+1)-FLAG_BASEPOINT.X, + r_Animation_DrawEx(pm.FlagAnim, X+IfThen(pm.Direction = TDirection.D_LEFT, pm.FlagPoint.X-1, 2*FLAG_BASEPOINT.X-pm.FlagPoint.X+1)-FLAG_BASEPOINT.X, Y+pm.FlagPoint.Y-FLAG_BASEPOINT.Y+1, Mirror, p, IfThen(pm.Direction = TDirection.D_RIGHT, pm.FlagAngle, -pm.FlagAngle)); end; @@ -118,12 +118,12 @@ begin if (pm.Direction = TDirection.D_LEFT) and (pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation] <> nil) then begin pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation].Alpha := Alpha; - pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation].Draw(X, Y, TMirrorType.None); + r_Animation_Draw(pm.Anim[TDirection.D_LEFT][pm.CurrentAnimation], X, Y, TMirrorType.None); end else begin pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation].Alpha := Alpha; - pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation].Draw(X, Y, Mirror); + r_Animation_Draw(pm.Anim[TDirection.D_RIGHT][pm.CurrentAnimation], X, Y, Mirror); end; // Маска модели: @@ -132,12 +132,12 @@ begin if (pm.Direction = TDirection.D_LEFT) and (pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation] <> nil) then begin pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation].Alpha := Alpha; - pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation].Draw(X, Y, TMirrorType.None); + r_Animation_Draw(pm.MaskAnim[TDirection.D_LEFT][pm.CurrentAnimation], X, Y, TMirrorType.None); end else begin pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation].Alpha := Alpha; - pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation].Draw(X, Y, Mirror); + r_Animation_Draw(pm.MaskAnim[TDirection.D_RIGHT][pm.CurrentAnimation], X, Y, Mirror); end; e_Colors.R := 255; diff --git a/src/game/opengl/r_weapons.pas b/src/game/opengl/r_weapons.pas index 38882f1..94d1d4a 100644 --- a/src/game/opengl/r_weapons.pas +++ b/src/game/opengl/r_weapons.pas @@ -24,7 +24,7 @@ implementation uses SysUtils, Classes, Math, MAPDEF, - r_graphics, + r_graphics, r_animations, g_base, g_basic, g_game, g_weapons ; @@ -53,9 +53,9 @@ implementation 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) + r_Animation_DrawEx(Animation, fX, fY, TMirrorType.None, p, a) else - Animation.Draw(fX, fY, TMirrorType.None); + r_Animation_Draw(Animation, fX, fY, TMirrorType.None); end else if TextureID <> 0 then begin -- 2.29.2