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>
Sun, 16 Jan 2022 19:28:16 +0000 (22:28 +0300)
src/game/g_game.pas
src/game/g_player.pas
src/game/opengl/r_player.pas
src/game/opengl/r_render.pas

index 48b713c6a645f0a2fd997e839636f9bfcbf933ba..539cf2c25f46a691ce730a68d9ffa80edd4f7a6b 100644 (file)
@@ -2472,12 +2472,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');
@@ -2614,12 +2608,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 7c73eb7e5754a68adf1831829d273a22c7b04fba..5478180bf23ed93ddf84d425087edbd16e20f605 100644 (file)
@@ -191,7 +191,7 @@ type
     FSavedStateNum:   Integer;
 
     FModel:     TPlayerModel;
-    FPunchAnim: TAnimation;
+    FPunchAnim: TAnimationState;
     FActionPrior:    Byte;
     FActionAnim:     Byte;
     FActionForce:    Boolean;
@@ -403,7 +403,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;
 
@@ -2123,6 +2123,8 @@ begin
   FNetTime := 0;
 
   FWaitForFirstSpawn := false;
+  FPunchAnim := TAnimationState.Create(False, 1, 4);
+  FPunchAnim.Disable;
 
   resetWeaponQueue();
 end;
@@ -2269,31 +2271,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();
@@ -4295,8 +4281,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 28eaf3d8af3810ce0d6961110b4fe87d2e9aae6c..8b25eb491187301e6dd06a2972bb58a39b0cb9bc 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;