From 046d1eae9707a210a52633d9c7bd9405894ad864 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sun, 16 Jan 2022 22:28:16 +0300 Subject: [PATCH] render: player punch TAnimation -> TAnimationState --- src/game/g_game.pas | 12 ------------ src/game/g_player.pas | 34 +++++++++++--------------------- src/game/opengl/r_player.pas | 38 +++++++++++++++++++++++++++++------- src/game/opengl/r_render.pas | 4 +++- 4 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/game/g_game.pas b/src/game/g_game.pas index b786671..5f7efda 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -2516,12 +2516,6 @@ begin end; end; - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False); g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT'); g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT'); g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET'); @@ -2658,12 +2652,6 @@ begin g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D'); g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE'); g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA'); - g_Frames_DeleteByName('FRAMES_PUNCH'); - g_Frames_DeleteByName('FRAMES_PUNCH_UP'); - g_Frames_DeleteByName('FRAMES_PUNCH_DN'); - g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK'); - g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP'); - g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN'); g_Sound_Delete('SOUND_GAME_TELEPORT'); g_Sound_Delete('SOUND_GAME_NOTELEPORT'); g_Sound_Delete('SOUND_GAME_SECRET'); diff --git a/src/game/g_player.pas b/src/game/g_player.pas index 5a0d7d7..603718d 100644 --- a/src/game/g_player.pas +++ b/src/game/g_player.pas @@ -194,7 +194,7 @@ type FSavedStateNum: Integer; FModel: TPlayerModel; - FPunchAnim: TAnimation; + FPunchAnim: TAnimationState; FActionPrior: Byte; FActionAnim: Byte; FActionForce: Boolean; @@ -422,7 +422,7 @@ type property Berserk: Integer read FBerserk; property Pain: Integer read FPain; property Pickup: Integer read FPickup; - property PunchAnim: TAnimation read FPunchAnim write FPunchAnim; + property PunchAnim: TAnimationState read FPunchAnim write FPunchAnim; property SpawnInvul: Integer read FSpawnInvul; property Ghost: Boolean read FGhost; @@ -2145,6 +2145,8 @@ begin FNetTime := 0; FWaitForFirstSpawn := false; + FPunchAnim := TAnimationState.Create(False, 1, 4); + FPunchAnim.Disable; resetWeaponQueue(); end; @@ -2296,31 +2298,15 @@ begin FJetSoundOn.Free(); FJetSoundOff.Free(); FModel.Free(); - if FPunchAnim <> nil then - FPunchAnim.Free(); + FPunchAnim.Free(); inherited; end; procedure TPlayer.DoPunch(); -var - id: DWORD; - st: String; begin - if FPunchAnim <> nil then begin - FPunchAnim.reset(); - FPunchAnim.Free; - FPunchAnim := nil; - end; - st := 'FRAMES_PUNCH'; - if R_BERSERK in FRulez then - st := st + '_BERSERK'; - if FKeys[KEY_UP].Pressed then - st := st + '_UP' - else if FKeys[KEY_DOWN].Pressed then - st := st + '_DN'; - g_Frames_Get(id, st); - FPunchAnim := TAnimation.Create(id, False, 1); + FPunchAnim.Reset; + FPunchAnim.Enable; end; procedure TPlayer.Fire(); @@ -4374,8 +4360,10 @@ begin FLoss := 0; end; - if FAlive and (FPunchAnim <> nil) then - FPunchAnim.Update(); + if FAlive then + FPunchAnim.Update; + if FPunchAnim.played then + FPunchAnim.Disable; if FAlive and (gFly or FJetpack) then FlySmoke(); diff --git a/src/game/opengl/r_player.pas b/src/game/opengl/r_player.pas index 6306e17..6addd06 100644 --- a/src/game/opengl/r_player.pas +++ b/src/game/opengl/r_player.pas @@ -19,6 +19,9 @@ interface uses g_player, g_base; // TPlayer, TRGB + procedure r_Player_Load; + procedure r_Player_Free; + procedure r_Player_DrawAll; procedure r_Player_DrawDebug (p: TPlayer); procedure r_Player_DrawHealth; @@ -49,6 +52,29 @@ implementation r_playermodel, r_graphics, r_animations, r_textures, r_items ; + var + PunchFrames: array [Boolean, 0..2] of DWORD; + + procedure r_Player_Load; + begin + g_Frames_CreateWAD(@PunchFrames[False, 0], 'FRAMES_PUNCH', GameWAD + ':WEAPONS\PUNCH', 64, 64, 4, False); + g_Frames_CreateWAD(@PunchFrames[False, 1], 'FRAMES_PUNCH_UP', GameWAD + ':WEAPONS\PUNCH_UP', 64, 64, 4, False); + g_Frames_CreateWAD(@PunchFrames[False, 2], 'FRAMES_PUNCH_DN', GameWAD + ':WEAPONS\PUNCH_DN', 64, 64, 4, False); + g_Frames_CreateWAD(@PunchFrames[True, 0], 'FRAMES_PUNCH_BERSERK', GameWAD + ':WEAPONS\PUNCHB', 64, 64, 4, False); + g_Frames_CreateWAD(@PunchFrames[True, 1], 'FRAMES_PUNCH_BERSERK_UP', GameWAD + ':WEAPONS\PUNCHB_UP', 64, 64, 4, False); + g_Frames_CreateWAD(@PunchFrames[True, 2], 'FRAMES_PUNCH_BERSERK_DN', GameWAD + ':WEAPONS\PUNCHB_DN', 64, 64, 4, False); + end; + + procedure r_Player_Free; + begin + g_Frames_DeleteByName('FRAMES_PUNCH'); + g_Frames_DeleteByName('FRAMES_PUNCH_UP'); + g_Frames_DeleteByName('FRAMES_PUNCH_DN'); + g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK'); + g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP'); + g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN'); + end; + procedure r_Player_DrawAll; var i: Integer; begin @@ -305,14 +331,12 @@ begin else Mirror := TMirrorType.Horizontal; - if p.PunchAnim <> nil then + if p.PunchAnim.enabled then begin - 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; - p.PunchAnim := nil; - end; + if p.FKeys[KEY_DOWN].Pressed then ID := PunchFrames[R_BERSERK in p.FRulez, 2] + else if p.FKeys[KEY_UP].Pressed then ID := PunchFrames[R_BERSERK in p.FRulez, 1] + else ID := PunchFrames[R_BERSERK in p.FRulez, 0]; + r_AnimationState_Draw(ID, 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); end; if (p.FMegaRulez[MR_INVUL] > gTime) and ((gPlayerDrawn <> p) or (p.SpawnInvul >= gTime)) then diff --git a/src/game/opengl/r_render.pas b/src/game/opengl/r_render.pas index 50e5892..b6bb016 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_map + r_weapons, r_items, r_gfx, r_monsters, r_map, r_player ; var @@ -78,6 +78,7 @@ implementation procedure r_Render_Load; begin + r_Player_Load; r_Map_Load; r_PlayerModel_Load; r_Monsters_Load; @@ -94,6 +95,7 @@ implementation r_Monsters_Free; r_PlayerModel_Free; r_Map_Free; + r_Player_Free; end; procedure r_Render_Initialize; -- 2.29.2