From 46a80085210de073e82948959f872b0e93c22135 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 16 Jan 2022 21:49:28 +0300 Subject: [PATCH] render: draw flag animation using TAnimationState --- src/game/g_map.pas | 11 ---- src/game/opengl/r_map.pas | 101 +++++++++++++++++++++-------------- src/game/opengl/r_render.pas | 7 ++- 3 files changed, 67 insertions(+), 52 deletions(-) diff --git a/src/game/g_map.pas b/src/game/g_map.pas index d120dfc..92da4f4 100644 --- a/src/game/g_map.pas +++ b/src/game/g_map.pas @@ -52,7 +52,6 @@ type State: Byte; Count: Integer; CaptureTime: LongWord; - Animation: TAnimation; Direction: TDirection; NeedSend: Boolean; end; @@ -1079,7 +1078,6 @@ end; procedure CreateArea(Area: TDynRecord); var a: Integer; - id: DWORD = 0; begin case Area.AreaType of AREA_DMPOINT, AREA_PLAYERPOINT1, AREA_PLAYERPOINT2, @@ -1119,14 +1117,7 @@ begin with gFlags[a] do begin - case a of - FLAG_RED: g_Frames_Get(id, 'FRAMES_FLAG_RED'); - FLAG_BLUE: g_Frames_Get(id, 'FRAMES_FLAG_BLUE'); - end; - - Animation := TAnimation.Create(id, True, 8); Obj.Rect := FLAGRECT; - g_Map_ResetFlag(a); end; end; @@ -2205,8 +2196,6 @@ begin begin with gFlags[a] do begin - if gFlags[a].Animation <> nil then gFlags[a].Animation.Update(); - Obj.oldX := Obj.X; Obj.oldY := Obj.Y; diff --git a/src/game/opengl/r_map.pas b/src/game/opengl/r_map.pas index 0f508d7..d34100d 100644 --- a/src/game/opengl/r_map.pas +++ b/src/game/opengl/r_map.pas @@ -19,7 +19,16 @@ interface uses g_panel, MAPDEF; // TPanel, TDFColor + procedure r_Map_Initialize; + procedure r_Map_Finalize; + + procedure r_Map_Load; + procedure r_Map_Free; + procedure r_Map_LoadTextures; + // TODO procedure r_Map_FreeTextures + + procedure r_Map_Update; procedure r_Map_DrawBack (dx, dy: Integer); procedure r_Map_DrawPanels (PanelType: Word; hasAmbient: Boolean; constref ambColor: TDFColor); // unaccelerated @@ -35,7 +44,7 @@ implementation uses {$INCLUDE ../nogl/noGLuses.inc} SysUtils, Classes, Math, e_log, wadreader, CONFIG, utils, - r_graphics, r_animations, r_textures, + r_graphics, r_animations, r_textures, g_textures, g_base, g_basic, g_game, g_options, g_map ; @@ -46,6 +55,31 @@ implementation Width, Height: WORD; Anim: Boolean; end; + FlagFrames: array [FLAG_RED..FLAG_BLUE] of DWORD; + FlagAnim: TAnimationState; + + procedure r_Map_Initialize; + begin + FlagAnim := TAnimationState.Create(True, 8, 5); + end; + + procedure r_Map_Finalize; + begin + FlagAnim.Free; + FlagAnim := nil; + end; + + procedure r_Map_Load; + begin + g_Frames_CreateWAD(@FlagFrames[FLAG_RED], 'FRAMES_FLAG_RED', GameWAD + ':TEXTURES\FLAGRED', 64, 64, 5, False); + g_Frames_CreateWAD(@FlagFrames[FLAG_BLUE], 'FRAMES_FLAG_BLUE', GameWAD + ':TEXTURES\FLAGBLUE', 64, 64, 5, False); + end; + + procedure r_Map_Free; + begin + g_Frames_DeleteByName('FRAMES_FLAG_RED'); + g_Frames_DeleteByName('FRAMES_FLAG_BLUE'); + end; procedure r_Map_LoadTextures; const @@ -218,47 +252,29 @@ begin e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0); end; -procedure r_Map_DrawFlags(); -var - i, dx: Integer; - tx, ty: Integer; - Mirror: TMirrorType; -begin - if gGameSettings.GameMode <> GM_CTF then - Exit; - - for i := FLAG_RED to FLAG_BLUE do - with gFlags[i] do - if State <> FLAG_STATE_CAPTURED then + procedure r_Map_DrawFlags; + var i, dx, tx, ty: Integer; Mirror: TMirrorType; f: PFlag; + begin + if gGameSettings.GameMode = GM_CTF then + begin + for i := FLAG_RED to FLAG_BLUE do begin - if State = FLAG_STATE_NONE then - continue; - - Obj.lerp(gLerpFactor, tx, ty); - - if Direction = TDirection.D_LEFT then - begin - Mirror := TMirrorType.Horizontal; - dx := -1; - end - else - begin - Mirror := TMirrorType.None; - dx := 1; - end; - - r_Animation_Draw(Animation, tx + dx, ty + 1, Mirror); - - if g_debug_Frames then + f := @gFlags[i]; + if not (f.State in [FLAG_STATE_NONE, FLAG_STATE_CAPTURED]) 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; + f.Obj.lerp(gLerpFactor, tx, ty); + if f.Direction = TDirection.D_LEFT then + Mirror := TMirrorType.Horizontal + else + Mirror := TMirrorType.None; + dx := IfThen(f.Direction = TDirection.D_LEFT, -1, +1); + r_AnimationState_Draw(FlagFrames[i], FlagAnim, tx + dx, ty + 1, Mirror); + if g_debug_Frames then + e_DrawQuad(tx + f.Obj.Rect.X, ty + f.Obj.Rect.Y, tx + f.Obj.Rect.X + f.Obj.Rect.Width - 1, ty + f.Obj.Rect.Y + f.Obj.Rect.Height - 1, 0, 255, 0) + end + end + end + end; procedure Panel_Lerp (p: TPanel; t: Single; out tX, tY, tW, tH: Integer); begin @@ -384,4 +400,9 @@ end; end end; + procedure r_Map_Update; + begin + FlagAnim.Update + end; + end. diff --git a/src/game/opengl/r_render.pas b/src/game/opengl/r_render.pas index b26d0ec..50e5892 100644 --- a/src/game/opengl/r_render.pas +++ b/src/game/opengl/r_render.pas @@ -37,7 +37,7 @@ implementation e_log, g_system, g_game, g_options, g_console, r_window, r_graphics, r_console, r_playermodel, - r_weapons, r_items, r_gfx, r_monsters + r_weapons, r_items, r_gfx, r_monsters, r_map ; var @@ -78,6 +78,7 @@ implementation procedure r_Render_Load; begin + r_Map_Load; r_PlayerModel_Load; r_Monsters_Load; r_Weapon_Load; @@ -92,6 +93,7 @@ implementation r_Weapon_Free; r_Monsters_Free; r_PlayerModel_Free; + r_Map_Free; end; procedure r_Render_Initialize; @@ -102,10 +104,12 @@ implementation r_Window_Initialize; r_Console_Init; r_PlayerModel_Initialize; + r_Map_Initialize; end; procedure r_Render_Finalize; begin + r_Map_Finalize; r_PlayerModel_Finalize; FreeGL; e_ReleaseEngine @@ -113,6 +117,7 @@ implementation procedure r_Render_Update; begin + r_Map_Update; r_PlayerModel_Update; end; -- 2.29.2