From: DeaDDooMER Date: Mon, 13 Jun 2022 18:18:27 +0000 (+0300) Subject: gl: handle punch animation in render X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=b36923c380a9760c74967bc8c850517c386747db;p=d2df-sdl.git gl: handle punch animation in render --- diff --git a/src/game/g_player.pas b/src/game/g_player.pas index b3c8fec..75d1f40 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -21,7 +21,7 @@ interface uses SysUtils, Classes, {$IFDEF USE_MEMPOOL}mempool,{$ENDIF} - g_base, g_playermodel, g_basic, g_animations, + g_base, g_playermodel, g_basic, g_weapons, g_phys, g_sound, g_saveload, MAPDEF, g_panel; @@ -185,7 +185,7 @@ type FSavedStateNum: Integer; FModel: TPlayerModel; - FPunchAnim: TAnimState; + FPunchTime: LongWord; FActionPrior: Byte; FActionAnim: Byte; FActionForce: Boolean; @@ -414,7 +414,7 @@ type property Berserk: Integer read FBerserk; property Pain: Integer read FPain; property Pickup: Integer read FPickup; - property PunchAnim: TAnimState read FPunchAnim write FPunchAnim; + property PunchTime: LongWord read FPunchTime; property SpawnInvul: Integer read FSpawnInvul; property Ghost: Boolean read FGhost; @@ -1644,8 +1644,7 @@ begin FNetTime := 0; FWaitForFirstSpawn := false; - FPunchAnim := TAnimState.Create(False, 1, 4); - FPunchAnim.Disable; + FPunchTime := 0; resetWeaponQueue(); end; @@ -1799,15 +1798,14 @@ begin FJetSoundOn.Free(); FJetSoundOff.Free(); FModel.Free(); - FPunchAnim.Invalidate; + FPunchTime := 0; inherited; end; procedure TPlayer.DoPunch(); begin - FPunchAnim.Reset; - FPunchAnim.Enable; + FPunchTime := gTime; end; procedure TPlayer.Fire(); @@ -3869,11 +3867,6 @@ begin FLoss := 0; end; - if FAlive then - FPunchAnim.Update; - if FPunchAnim.played then - FPunchAnim.Disable; - if FAlive and (gFly or FJetpack) then FlySmoke(); diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index 0702872..f9ac5dc 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -45,7 +45,7 @@ interface implementation uses - Math, + Math, SysUtils, {$IFDEF USE_GLES1} GLES11, {$ELSE} @@ -67,7 +67,7 @@ implementation {$IFDEF ENABLE_GFX} g_gfx, {$ENDIF} - r_textures, r_draw + r_textures, r_draw, r_common ; const @@ -219,6 +219,7 @@ implementation ); {$ENDIF} + PunchAnim: TAnimInfo = (loop: false; delay: 1; frames: 4; back: false); FlagAnim: TAnimInfo = (loop: true; delay: 8; frames: 5; back: false); type @@ -459,7 +460,7 @@ implementation for b := false to true do begin for i := 0 to 2 do - PunchTextures[b, i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, 4, false); + PunchTextures[b, i] := r_Textures_LoadMultiFromFileAndInfo(GameWad + ':WEAPONS/' + PunchName[b] + WeapPos[i], 64, 64, PunchAnim.frames, PunchAnim.back); end; // --------- other --------- // InvulPenta := r_Textures_LoadFromFile(GameWad + ':TEXTURES/PENTA'); @@ -815,7 +816,7 @@ implementation end; procedure r_Map_DrawPlayer (p, drawed: TPlayer); - var fX, fY, fSlope, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; alpha: Byte; + var fX, fY, fSlope, ax, ay, w, h: Integer; b, flip: Boolean; t: TGLMultiTexture; tex: TGLTexture; alpha: Byte; count, frame: LongInt; begin if p.alive then begin @@ -825,21 +826,26 @@ implementation fSlope := nlerp(p.SlopeOld, p.obj.slopeUpLeft, gLerpFactor); (* punch effect *) - if p.PunchAnim.IsValid() and p.PunchAnim.enabled then + if p.PunchTime <= gTime then begin - b := R_BERSERK in p.FRulez; - if p.FKeys[KEY_DOWN].pressed then - t := PunchTextures[b, 2] - else if p.FKeys[KEY_UP].pressed then - t := PunchTextures[b, 1] - else - t := PunchTextures[b, 0]; - if t <> nil then + g_Anim_GetFrameByTime(PunchAnim, (gTime - p.PunchTime) DIV GAME_TICK, count, frame); + if count < 1 then begin - flip := p.Direction = TDirection.D_LEFT; - ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ??? - ay := p.Obj.Rect.Y - 11; - r_Draw_MultiTextureRepeat(t, p.PunchAnim, fx + ax, fy + fSlope + ay, t.width, t.height, flip, 255, 255, 255, 255, false) + b := R_BERSERK in p.FRulez; + if p.FKeys[KEY_DOWN].pressed then + t := PunchTextures[b, 2] + else if p.FKeys[KEY_UP].pressed then + t := PunchTextures[b, 1] + else + t := PunchTextures[b, 0]; + if t <> nil then + begin + flip := p.Direction = TDirection.D_LEFT; + ax := IfThen(flip, 15 - p.Obj.Rect.X, p.Obj.Rect.X - 15); // ??? + ay := p.Obj.Rect.Y - 11; + tex := t.GetTexture(frame); + r_Draw_TextureRepeat(tex, fx + ax, fy + fSlope + ay, tex.width, tex.height, flip, 255, 255, 255, 255, false) + end; end; end;