DEADSOFTWARE

render: player punch TAnimation -> TAnimationState
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 16 Jan 2022 19:28:16 +0000 (22:28 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Fri, 9 Jun 2023 07:52:44 +0000 (10:52 +0300)
src/game/g_game.pas
src/game/g_player.pas
src/game/opengl/r_player.pas
src/game/opengl/r_render.pas

index b78667168645fcef361ce6ca231569c3a4f911b3..5f7efda1bd62421ae0f36cef45e00593361d7c77 100644 (file)
@@ -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');
index 5a0d7d7cb525a27b2cd189e55c1ba8226efc592b..603718d80fd350afbcc6c08e3bb5ce0ab4ffc77c 100644 (file)
@@ -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();
index 6306e171713a69eff076b9e77bddfa3908abcc8c..6addd06278b06603b29f6e15d3866f2eb41faa53 100644 (file)
@@ -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
index 50e5892e9ee0366ce0f9359cafd67f66e4b408be..b6bb016f74410f1cf5dd53fa0e57c355ccd35720 100644 (file)
@@ -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;