From 38f37ffd695612d219b1dbd7bf3165880a012502 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Mon, 13 Jun 2022 20:38:38 +0300 Subject: [PATCH] gl: handle shot animations by render --- src/game/g_weapons.pas | 85 +++++++------------------------ src/game/renders/opengl/r_map.pas | 78 ++++++++++++++-------------- 2 files changed, 54 insertions(+), 109 deletions(-) diff --git a/src/game/g_weapons.pas b/src/game/g_weapons.pas index 2b38de3..8fdde86 100644 --- a/src/game/g_weapons.pas +++ b/src/game/g_weapons.pas @@ -20,7 +20,7 @@ interface uses SysUtils, Classes, mempool, - g_animations, g_basic, g_phys, xprofiler; + g_basic, g_phys, xprofiler; type @@ -30,7 +30,7 @@ type SpawnerUID: Word; Triggers: DWArray; Obj: TObj; - Animation: TAnimState; + time: LongWord; Timeout: DWORD; Stopped: Byte; @@ -589,6 +589,8 @@ begin SetLength(Shots, find_id + 64) end; + shots[find_id].time := gTime; + case ShotType of WEAPON_ROCKETLAUNCHER: begin @@ -601,7 +603,6 @@ begin Triggers := nil; ShotType := WEAPON_ROCKETLAUNCHER; - Animation.Invalidate; end; end; @@ -616,7 +617,6 @@ begin Triggers := nil; ShotType := WEAPON_PLASMA; - Animation := TAnimState.Create(True, 5, 2); // !!! put values into table end; end; @@ -631,7 +631,6 @@ begin Triggers := nil; ShotType := WEAPON_BFG; - Animation := TAnimState.Create(True, 6, 2); // !!! put values into table end; end; @@ -646,8 +645,6 @@ begin Triggers := nil; ShotType := WEAPON_FLAMETHROWER; - Animation.Invalidate; - // Animation := TAnimState.Create(True, 6, 0); // drawed as gfx end; end; @@ -662,7 +659,6 @@ begin Triggers := nil; ShotType := WEAPON_IMP_FIRE; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table end; end; @@ -677,7 +673,6 @@ begin Triggers := nil; ShotType := WEAPON_CACO_FIRE; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table end; end; @@ -692,7 +687,6 @@ begin Triggers := nil; ShotType := WEAPON_MANCUB_FIRE; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table end; end; @@ -707,7 +701,6 @@ begin Triggers := nil; ShotType := WEAPON_BARON_FIRE; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table end; end; @@ -722,7 +715,6 @@ begin Triggers := nil; ShotType := WEAPON_BSP_FIRE; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table end; end; @@ -738,7 +730,6 @@ begin Triggers := nil; ShotType := WEAPON_SKEL_FIRE; target := TargetUID; - Animation := TAnimState.Create(True, 5, 2); // !!! put values into table end; end; end; @@ -1654,8 +1645,8 @@ begin ShotType := WEAPON_ROCKETLAUNCHER; throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 12); - Animation.Invalidate; triggers := nil; + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1694,7 +1685,7 @@ begin triggers := nil; target := TargetUID; - Animation := TAnimState.Create(True, 5, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1735,7 +1726,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - Animation := TAnimState.Create(True, 5, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1776,7 +1767,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - Animation.Invalidate; + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1817,7 +1808,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1858,7 +1849,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1899,7 +1890,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1940,8 +1931,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -1982,8 +1972,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - - Animation := TAnimState.Create(True, 4, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -2024,7 +2013,7 @@ begin throw(find_id, x+dx, y+dy, xd+dx, yd+dy, 16); triggers := nil; - Animation := TAnimState.Create(True, 6, 2); // !!! put values into table + time := gTime; end; Shots[find_id].SpawnerUID := SpawnerUID; @@ -2183,10 +2172,6 @@ begin end; end; - // Àíèìàöèÿ ñíàðÿäà: - if Animation.IsValid() then - Animation.Update(); - // Äâèæåíèå: spl := (ShotType <> WEAPON_PLASMA) and (ShotType <> WEAPON_BFG) and @@ -2208,7 +2193,7 @@ begin begin // Íà êëèåíòå ñêîðåå âñåãî è òàê óæå âûïàë. ShotType := 0; - Animation.Invalidate(); + time := 0; Continue; end; @@ -2482,7 +2467,7 @@ begin begin if gGameSettings.GameType = GT_SERVER then MH_SEND_DeleteShot(i, Obj.X, Obj.Y, Loud); - Animation.Invalidate; + time := 0; end else if (ShotType <> WEAPON_FLAMETHROWER) and ((oldvx <> Obj.Vel.X) or (oldvy <> Obj.Vel.Y)) then if gGameSettings.GameType = GT_SERVER then @@ -2588,42 +2573,7 @@ begin // Êîñòûëèíà åáàíàÿ Shots[i].Stopped := utils.readByte(st); - // Óñòàíîâêà òåêñòóðû èëè àíèìàöèè - Shots[i].Animation.Invalidate; - - case Shots[i].ShotType of - WEAPON_ROCKETLAUNCHER, WEAPON_SKEL_FIRE: - begin - end; - WEAPON_PLASMA: - begin - Shots[i].Animation := TAnimState.Create(True, 5, 2); // !!! put values into table - end; - WEAPON_BFG: - begin - Shots[i].Animation := TAnimState.Create(True, 6, 2); // !!! put values into table - end; - WEAPON_IMP_FIRE: - begin - Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table - end; - WEAPON_BSP_FIRE: - begin - Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table - end; - WEAPON_CACO_FIRE: - begin - Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table - end; - WEAPON_BARON_FIRE: - begin - Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table - end; - WEAPON_MANCUB_FIRE: - begin - Shots[i].Animation := TAnimState.Create(True, 4, 2); // !!! put values into table - end; - end; + Shots[i].time := gTime; // TODO save time? end; end; @@ -2708,7 +2658,6 @@ begin end; // case ShotType of... ShotType := 0; - Animation.Invalidate; end; end; diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index 4ffd6e1..0702872 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -177,35 +177,35 @@ implementation ShotAnim: array [0..WEAPON_LAST] of record name: AnsiString; w, h: Integer; - count: Integer; + anim: TAnimInfo; end = ( - (name: ''; w: 0; h: 0; count: 0), // 0 KASTET - (name: ''; w: 0; h: 0; count: 0), // 1 SAW - (name: ''; w: 0; h: 0; count: 0), // 2 PISTOL - (name: ''; w: 0; h: 0; count: 0), // 3 SHOTGUN1 - (name: ''; w: 0; h: 0; count: 0), // 4 SHOTGUN2 - (name: ''; w: 0; h: 0; count: 0), // 5 CHAINGUN - (name: 'BROCKET'; w: 64; h: 32; count: 1), // 6 ROCKETLAUNCHER - (name: 'BPLASMA'; w: 16; h: 16; count: 2), // 7 PLASMA - (name: 'BBFG'; w: 64; h: 64; count: 2), // 8 BFG - (name: ''; w: 0; h: 0; count: 0), // 9 SUPERPULEMET - (name: 'FLAME'; w: 32; h: 32; count: 0{11}), // 10 FLAMETHROWER - (name: ''; w: 0; h: 0; count: 0), // 11 - (name: ''; w: 0; h: 0; count: 0), // 12 - (name: ''; w: 0; h: 0; count: 0), // 13 - (name: ''; w: 0; h: 0; count: 0), // 14 - (name: ''; w: 0; h: 0; count: 0), // 15 - (name: ''; w: 0; h: 0; count: 0), // 16 - (name: ''; w: 0; h: 0; count: 0), // 17 - (name: ''; w: 0; h: 0; count: 0), // 18 - (name: ''; w: 0; h: 0; count: 0), // 19 - (name: ''; w: 0; h: 0; count: 0), // 20 ZOMPY_PISTOL - (name: 'BIMPFIRE'; w: 16; h: 16; count: 2), // 21 IMP_FIRE - (name: 'BBSPFIRE'; w: 16; h: 16; count: 2), // 22 BSP_FIRE - (name: 'BCACOFIRE'; w: 16; h: 16; count: 2), // 23 CACO_FIRE - (name: 'BBARONFIRE'; w: 64; h: 16; count: 2), // 24 BARON_FIRE - (name: 'BMANCUBFIRE'; w: 64; h: 32; count: 2), // 25 MANCUB_FIRE - (name: 'BSKELFIRE'; w: 64; h: 64; count: 2) // 26 SKEL_FIRE + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 0 KASTET + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 1 SAW + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 2 PISTOL + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 3 SHOTGUN1 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 4 SHOTGUN2 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 5 CHAINGUN + (name: 'BROCKET'; w: 64; h: 32; anim: (loop: true; delay: 1; frames: 1; back: false)), // 6 ROCKETLAUNCHER + (name: 'BPLASMA'; w: 16; h: 16; anim: (loop: true; delay: 5; frames: 2; back: false)), // 7 PLASMA + (name: 'BBFG'; w: 64; h: 64; anim: (loop: true; delay: 6; frames: 2; back: false)), // 8 BFG + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 9 SUPERPULEMET + (name: 'FLAME'; w: 32; h: 32; anim: (loop: true; delay: 6; frames: 0{11}; back: false)), // 10 FLAMETHROWER + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 11 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 12 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 13 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 14 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 15 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 16 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 17 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 18 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 19 + (name: ''; w: 0; h: 0; anim: (loop: true; delay: 0; frames: 0; back: false)), // 20 ZOMPY_PISTOL + (name: 'BIMPFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 21 IMP_FIRE + (name: 'BBSPFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 22 BSP_FIRE + (name: 'BCACOFIRE'; w: 16; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 23 CACO_FIRE + (name: 'BBARONFIRE'; w: 64; h: 16; anim: (loop: true; delay: 4; frames: 2; back: false)), // 24 BARON_FIRE + (name: 'BMANCUBFIRE'; w: 64; h: 32; anim: (loop: true; delay: 4; frames: 2; back: false)), // 25 MANCUB_FIRE + (name: 'BSKELFIRE'; w: 64; h: 64; anim: (loop: true; delay: 5; frames: 2; back: false)) // 26 SKEL_FIRE ); {$IFDEF ENABLE_SHELLS} @@ -260,9 +260,6 @@ implementation {$ENDIF} end; - StubShotAnim: TAnimState; // TODO remove this hack - FlagFrame: LongInt; - {$IFDEF ENABLE_SHELLS} ShellTextures: array [0..SHELL_LAST] of TGLTexture; {$ENDIF} @@ -278,6 +275,7 @@ implementation end = nil; {$ENDIF} + FlagFrame: LongInt; plist: TBinHeapPanelDraw = nil; class function TBinHeapPanelDrawCmp.less (const a, b: TPanel): Boolean; inline; @@ -289,7 +287,6 @@ implementation procedure r_Map_Initialize; begin - StubShotAnim := TAnimState.Create(true, 1, 1); FlagFrame := 0; plist := TBinHeapPanelDraw.Create(); end; @@ -298,7 +295,6 @@ implementation begin plist.Free; FlagFrame := 0; - StubShotAnim.Invalidate; end; procedure r_Map_FreeModel (i: Integer); @@ -447,8 +443,8 @@ implementation {$ENDIF} // --------- shots --------- // for i := 0 to WEAPON_LAST do - if ShotAnim[i].count > 0 then - ShotTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].count, false); + if ShotAnim[i].anim.frames > 0 then + ShotTextures[i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/' + ShotAnim[i].name, ShotAnim[i].w, ShotAnim[i].h, ShotAnim[i].anim.frames, ShotAnim[i].anim.back); // --------- flags --------- // FlagTextures[FLAG_NONE] := nil; FlagTextures[FLAG_RED] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':TEXTURES/FLAGRED', 64, 64, 5, false); @@ -1075,7 +1071,7 @@ implementation {$ENDIF} procedure r_Map_DrawShots (x, y, w, h: Integer); - var i, a, fX, fY, pX, pY, typ: Integer; tex: TGLMultiTexture; anim: ^TAnimState; + var i, a, fX, fY, pX, pY, typ: Integer; count, frame: LongInt; t: TGLMultiTexture; tex: TGLTexture; begin if Shots <> nil then begin @@ -1084,8 +1080,8 @@ implementation typ := Shots[i].ShotType; if typ <> 0 then begin - tex := ShotTextures[typ]; - if tex <> nil then + t := ShotTextures[typ]; + if t <> nil then begin a := 0; case typ of @@ -1095,9 +1091,9 @@ implementation Shots[i].Obj.Lerp(gLerpFactor, fX, fY); pX := Shots[i].Obj.Rect.Width div 2; pY := Shots[i].Obj.Rect.Height div 2; - // TODO fix this hack - if Shots[i].Animation.IsValid() then anim := @Shots[i].Animation else anim := @StubShotAnim; - r_Draw_MultiTextureRepeatRotate(tex, anim^, fX, fY, tex.width, tex.height, false, 255, 255, 255, 255, false, pX, pY, a); + g_Anim_GetFrameByTime(ShotAnim[typ].anim, (gTime - Shots[i].time) DIV GAME_TICK, count, frame); + tex := t.GetTexture(frame); + r_Draw_TextureRepeatRotate(tex, fX, fY, tex.width, tex.height, false, 255, 255, 255, 255, false, pX, pY, a); end; end; end; -- 2.29.2