fixed smoothing player movement with variable cave speed in BD engine
authorHolger Schemel <holger.schemel@virtion.de>
Mon, 16 Dec 2024 18:40:44 +0000 (19:40 +0100)
committerHolger Schemel <holger.schemel@virtion.de>
Mon, 16 Dec 2024 09:41:45 +0000 (10:41 +0100)
src/game_bd/bd_gameplay.c
src/game_bd/bd_gameplay.h
src/game_bd/main_bd.c

index 260d6d4a553f7c8febc8ce7152edc2c6de99a076..d134f0e8bb3ac933eeb63f3faae4e799637a577d 100644 (file)
@@ -150,8 +150,6 @@ static void load_cave(GdGame *game)
   game->milliseconds_anim = 0;
   game->milliseconds_game = 0;        // set game timer to zero, too
 
-  game->cycle_counter = 0;
-
   // create new element buffer
   game->element_buffer = gd_cave_map_new(game->cave, int);
 
@@ -462,19 +460,16 @@ static GdGameState gd_game_main_int(GdGame *game, boolean allow_iterate, boolean
       // store last maximum number of cycle frames (to force redraw if changed)
       game->itermax_last = game->itermax;
 
-      // store maximum number of cycle frames separately for even and odd cycles
-      game->itermax2[game->cycle_counter % 2] = game->itercycle;
-
-      // update maximum number of cycle frames per cave iteration
-      game->itermax = game->itermax2[!(game->cycle_counter % 2)];
+      // calculate expected maximum number of cycle frames for next cave iteration
+      // (assuming constant cave speed, which in fact might not always be the case)
+      game->itermax =
+        (cavespeed - game->milliseconds_game + millisecs_elapsed - 1) / millisecs_elapsed;
 
       // reset cycle frame counter for the next cave iteration
       game->itercycle = 0;
 
       iterate_cave(game, game->player_move, game->player_fire, game->player_suicide);
 
-      game->cycle_counter++;
-
       if (game->player_move == GD_MV_STILL)
       {
        game->player_move_stick = FALSE;
index adbb37a32585f20a516353fb0ca904f60d785975..fdacddef4e75f9b5fe7d2ec6a9acc9e1f7b7054c 100644 (file)
@@ -89,11 +89,9 @@ typedef struct _gd_game
   int itercycle;
   int itermax;
   int itermax_last;
-  int itermax2[2];
   int animcycle;
   int milliseconds_game;
   int milliseconds_anim;
-  int cycle_counter;
 
   int replay_no_more_movements;
   boolean show_story;           // to remember that story for a particular cave was already shown.
index 488837b85ad28aa580467dcd0dd1d60b5eb69474..a94dfde209ca727a0f2e6ff938dda4baf79fc7da 100644 (file)
@@ -334,8 +334,6 @@ void InitGameEngine_BD(void)
   game_bd.game->itercycle = 0;
   game_bd.game->itermax = 8;   // default; dynamically changed at runtime
   game_bd.game->itermax_last = game_bd.game->itermax;
-  game_bd.game->itermax2[0] = game_bd.game->itermax;
-  game_bd.game->itermax2[1] = game_bd.game->itermax;
 
   game_bd.game->use_old_engine = useOldEngine_BD();