added configurable keys for fast and slow playing speed
authorHolger Schemel <info@artsoft.org>
Thu, 25 Apr 2024 05:49:27 +0000 (07:49 +0200)
committerHolger Schemel <info@artsoft.org>
Thu, 25 Apr 2024 05:49:49 +0000 (07:49 +0200)
src/conf_gfx.c
src/events.c
src/files.c
src/game_bd/bd_gameplay.c
src/libgame/system.h
src/main.h
src/screens.c

index b758cec997ac702286d653ce6586173c0138abd8..01350173d5cdd19027a675dbf7ee84b6208ad362 100644 (file)
@@ -9126,6 +9126,8 @@ struct ConfigInfo image_config[] =
   { "menu.draw_yoffset.SETUP[SHORTCUTS_4]",            "0"                             },
   { "menu.draw_xoffset.SETUP[SHORTCUTS_5]",            "0"                             },
   { "menu.draw_yoffset.SETUP[SHORTCUTS_5]",            "0"                             },
+  { "menu.draw_xoffset.SETUP[SHORTCUTS_6]",            "0"                             },
+  { "menu.draw_yoffset.SETUP[SHORTCUTS_6]",            "0"                             },
   { "menu.draw_xoffset.SETUP[CHOOSE_ARTWORK]",         "0"                             },
   { "menu.draw_yoffset.SETUP[CHOOSE_ARTWORK]",         "0"                             },
   { "menu.draw_xoffset.SETUP[CHOOSE_OTHER]",           "0"                             },
index 2e3c7ca9bbd232639c4d62e34153f2cd1ed2b0ea..04f69108527feaca46f5eca02ce2fc30b82f3ad9 100644 (file)
@@ -1986,6 +1986,31 @@ static void HandleKeysSpecial(Key key)
   }
 }
 
+static boolean HandleKeysSpeed(Key key, int key_status)
+{
+  if (game_status == GAME_MODE_PLAYING)
+  {
+    if (key == setup.shortcut.speed_fast ||
+       key == setup.shortcut.speed_slow)
+    {
+      int speed_factor = 4;
+
+      GameFrameDelay = (key_status != KEY_PRESSED ? setup.game_frame_delay :
+                       key == setup.shortcut.speed_fast ? setup.game_frame_delay / speed_factor :
+                       key == setup.shortcut.speed_slow ? setup.game_frame_delay * speed_factor :
+                       setup.game_frame_delay);
+
+      GameFrameDelay = MIN(MAX(1, GameFrameDelay), 1000);
+
+      SetVideoFrameDelay(GameFrameDelay);
+
+      return TRUE;
+    }
+  }
+
+  return FALSE;
+}
+
 boolean HandleKeysDebug(Key key, int key_status)
 {
 #ifdef DEBUG
@@ -2073,6 +2098,9 @@ void HandleKey(Key key, int key_status)
   int joy = 0;
   int i;
 
+  if (HandleKeysSpeed(key, key_status))
+    return;            // do not handle already processed keys again
+
   if (HandleKeysDebug(key, key_status))
     return;            // do not handle already processed keys again
 
index 5ae706b91353694ea68aede8dd31128c2cd38974..587e71b956c02b45bd64682399db1464b1c2477f 100644 (file)
@@ -11191,6 +11191,14 @@ static struct TokenInfo shortcut_setup_tokens[] =
     TYPE_KEY_X11,
     &setup.shortcut.snap_down,                 "shortcut.snap_down"
   },
+  {
+    TYPE_KEY_X11,
+    &setup.shortcut.speed_fast,                        "shortcut.speed_fast"
+  },
+  {
+    TYPE_KEY_X11,
+    &setup.shortcut.speed_slow,                        "shortcut.speed_slow"
+  },
 };
 
 static struct SetupInputInfo setup_input;
@@ -11432,6 +11440,10 @@ static struct TokenInfo internal_setup_tokens[] =
     TYPE_BOOLEAN,
     &setup.internal.menu_shortcuts_snap,       "menu_shortcuts_snap"
   },
+  {
+    TYPE_BOOLEAN,
+    &setup.internal.menu_shortcuts_speed,      "menu_shortcuts_speed"
+  },
   {
     TYPE_BOOLEAN,
     &setup.internal.info_title,                        "info_title"
@@ -11789,6 +11801,9 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->shortcut.snap_up         = DEFAULT_KEY_SNAP_UP;
   si->shortcut.snap_down       = DEFAULT_KEY_SNAP_DOWN;
 
+  si->shortcut.speed_fast      = DEFAULT_KEY_SPEED_FAST;
+  si->shortcut.speed_slow      = DEFAULT_KEY_SPEED_SLOW;
+
   for (i = 0; i < MAX_PLAYERS; i++)
   {
     si->input[i].use_joystick = FALSE;
index 7a4d889c051d49dcc237bef31f3181496f00f2d8..12eb53bcca2ba1c7e8699e3af954f96907e75c33 100644 (file)
@@ -599,7 +599,7 @@ void play_game_func(GdGame *game, int action)
     game->player_fire = fire;
 
   // tell the interrupt "20ms has passed"
-  state = gd_game_main_int(game, !game->out_of_window, gd_keystate[SDL_SCANCODE_F]);
+  state = gd_game_main_int(game, !game->out_of_window, FALSE);
 
   // state of game, returned by gd_game_main_int
   switch (state)
index d8ca9a29a1e7f4191b32e22d5c4b9a5e213f6ef3..162ca4890c55ee68ad604c1751262d4da6f24b62 100644 (file)
 #define DEFAULT_KEY_SNAP_RIGHT         KSYM_UNDEFINED
 #define DEFAULT_KEY_SNAP_UP            KSYM_UNDEFINED
 #define DEFAULT_KEY_SNAP_DOWN          KSYM_UNDEFINED
+#define DEFAULT_KEY_SPEED_FAST         KSYM_f
+#define DEFAULT_KEY_SPEED_SLOW         KSYM_s
 
 // default debug setup keys and values
 #define DEFAULT_FRAME_DELAY_0          20              // 100 % speed
@@ -1384,6 +1386,9 @@ struct SetupShortcutInfo
   Key snap_right;
   Key snap_up;
   Key snap_down;
+
+  Key speed_fast;
+  Key speed_slow;
 };
 
 struct SetupSystemInfo
@@ -1441,6 +1446,7 @@ struct SetupInternalInfo
   boolean menu_shortcuts_tape;
   boolean menu_shortcuts_sound;
   boolean menu_shortcuts_snap;
+  boolean menu_shortcuts_speed;
 
   boolean info_title;
   boolean info_elements;
index 7f70cea7ca544c23d7157c1f32068f5a594e3ea5..8ae91599a57a75c6d0802113e5373ddf1896d123 100644 (file)
@@ -2745,6 +2745,7 @@ enum
   GFX_SPECIAL_ARG_SETUP_SHORTCUTS_3,
   GFX_SPECIAL_ARG_SETUP_SHORTCUTS_4,
   GFX_SPECIAL_ARG_SETUP_SHORTCUTS_5,
+  GFX_SPECIAL_ARG_SETUP_SHORTCUTS_6,
   GFX_SPECIAL_ARG_SETUP_CHOOSE_ARTWORK,
   GFX_SPECIAL_ARG_SETUP_CHOOSE_OTHER,
 
index c7a69c3005eeec67c497204bd6d06647e73de02a..14a2adf4b3d68be9726f6e78f3d51f3ae7b99661 100644 (file)
 #define SETUP_MODE_SHORTCUTS_3                 12
 #define SETUP_MODE_SHORTCUTS_4                 13
 #define SETUP_MODE_SHORTCUTS_5                 14
+#define SETUP_MODE_SHORTCUTS_6                 15
 
 // sub-screens on the setup screen (generic)
-#define SETUP_MODE_CHOOSE_ARTWORK              15
-#define SETUP_MODE_CHOOSE_OTHER                        16
+#define SETUP_MODE_CHOOSE_ARTWORK              16
+#define SETUP_MODE_CHOOSE_OTHER                        17
 
 // sub-screens on the setup screen (specific)
-#define SETUP_MODE_CHOOSE_SCORES_TYPE          17
-#define SETUP_MODE_CHOOSE_GAME_SPEED           18
-#define SETUP_MODE_CHOOSE_SCROLL_DELAY         19
-#define SETUP_MODE_CHOOSE_SNAPSHOT_MODE                20
-#define SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE     21
-#define SETUP_MODE_CHOOSE_BD_PALETTE_C64       22
-#define SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV    23
-#define SETUP_MODE_CHOOSE_BD_PALETTE_ATARI     24
-#define SETUP_MODE_CHOOSE_BD_COLOR_TYPE                25
-#define SETUP_MODE_CHOOSE_WINDOW_SIZE          26
-#define SETUP_MODE_CHOOSE_SCALING_TYPE         27
-#define SETUP_MODE_CHOOSE_RENDERING            28
-#define SETUP_MODE_CHOOSE_VSYNC                        29
-#define SETUP_MODE_CHOOSE_GRAPHICS             30
-#define SETUP_MODE_CHOOSE_SOUNDS               31
-#define SETUP_MODE_CHOOSE_MUSIC                        32
-#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE                33
-#define SETUP_MODE_CHOOSE_VOLUME_LOOPS         34
-#define SETUP_MODE_CHOOSE_VOLUME_MUSIC         35
-#define SETUP_MODE_CHOOSE_TOUCH_CONTROL                36
-#define SETUP_MODE_CHOOSE_MOVE_DISTANCE                37
-#define SETUP_MODE_CHOOSE_DROP_DISTANCE                38
-#define SETUP_MODE_CHOOSE_TRANSPARENCY         39
-#define SETUP_MODE_CHOOSE_GRID_XSIZE_0         40
-#define SETUP_MODE_CHOOSE_GRID_YSIZE_0         41
-#define SETUP_MODE_CHOOSE_GRID_XSIZE_1         42
-#define SETUP_MODE_CHOOSE_GRID_YSIZE_1         43
-#define SETUP_MODE_CONFIG_VIRT_BUTTONS         44
-
-#define MAX_SETUP_MODES                                45
+#define SETUP_MODE_CHOOSE_SCORES_TYPE          18
+#define SETUP_MODE_CHOOSE_GAME_SPEED           19
+#define SETUP_MODE_CHOOSE_SCROLL_DELAY         20
+#define SETUP_MODE_CHOOSE_SNAPSHOT_MODE                21
+#define SETUP_MODE_CHOOSE_GAME_ENGINE_TYPE     22
+#define SETUP_MODE_CHOOSE_BD_PALETTE_C64       23
+#define SETUP_MODE_CHOOSE_BD_PALETTE_C64DTV    24
+#define SETUP_MODE_CHOOSE_BD_PALETTE_ATARI     25
+#define SETUP_MODE_CHOOSE_BD_COLOR_TYPE                26
+#define SETUP_MODE_CHOOSE_WINDOW_SIZE          27
+#define SETUP_MODE_CHOOSE_SCALING_TYPE         28
+#define SETUP_MODE_CHOOSE_RENDERING            29
+#define SETUP_MODE_CHOOSE_VSYNC                        30
+#define SETUP_MODE_CHOOSE_GRAPHICS             31
+#define SETUP_MODE_CHOOSE_SOUNDS               32
+#define SETUP_MODE_CHOOSE_MUSIC                        33
+#define SETUP_MODE_CHOOSE_VOLUME_SIMPLE                34
+#define SETUP_MODE_CHOOSE_VOLUME_LOOPS         35
+#define SETUP_MODE_CHOOSE_VOLUME_MUSIC         36
+#define SETUP_MODE_CHOOSE_TOUCH_CONTROL                37
+#define SETUP_MODE_CHOOSE_MOVE_DISTANCE                38
+#define SETUP_MODE_CHOOSE_DROP_DISTANCE                39
+#define SETUP_MODE_CHOOSE_TRANSPARENCY         40
+#define SETUP_MODE_CHOOSE_GRID_XSIZE_0         41
+#define SETUP_MODE_CHOOSE_GRID_YSIZE_0         42
+#define SETUP_MODE_CHOOSE_GRID_XSIZE_1         43
+#define SETUP_MODE_CHOOSE_GRID_YSIZE_1         44
+#define SETUP_MODE_CONFIG_VIRT_BUTTONS         45
+
+#define MAX_SETUP_MODES                                46
 
 #define MAX_MENU_MODES                         MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
 
@@ -723,7 +724,7 @@ static int align_yoffset = 0;
                                 INFO_MODE_MAIN)
 
 #define DRAW_MODE_SETUP(i)     ((i) >= SETUP_MODE_MAIN &&                      \
-                                (i) <= SETUP_MODE_SHORTCUTS_5 ? (i) :          \
+                                (i) <= SETUP_MODE_SHORTCUTS_6 ? (i) :          \
                                 (i) >= SETUP_MODE_CHOOSE_GRAPHICS &&           \
                                 (i) <= SETUP_MODE_CHOOSE_MUSIC ?               \
                                 SETUP_MODE_CHOOSE_ARTWORK :                    \
@@ -7625,6 +7626,13 @@ static void execSetupShortcuts5(void)
   DrawSetupScreen();
 }
 
+static void execSetupShortcuts6(void)
+{
+  setup_mode = SETUP_MODE_SHORTCUTS_6;
+
+  DrawSetupScreen();
+}
+
 static void execExitSetup(void)
 {
   SetGameStatus(GAME_MODE_MAIN);
@@ -7880,6 +7888,7 @@ static struct
   { &setup.internal.menu_shortcuts_tape,       execSetupShortcuts3             },
   { &setup.internal.menu_shortcuts_sound,      execSetupShortcuts4             },
   { &setup.internal.menu_shortcuts_snap,       execSetupShortcuts5             },
+  { &setup.internal.menu_shortcuts_speed,      execSetupShortcuts6             },
 
   { &setup.internal.info_title,                        execInfoTitleScreen             },
   { &setup.internal.info_elements,             execInfoElements                },
@@ -8208,6 +8217,7 @@ static struct TokenInfo setup_info_shortcuts[] =
   { TYPE_ENTER_MENU,   execSetupShortcuts3,            "Tape Buttons"                  },
   { TYPE_ENTER_MENU,   execSetupShortcuts4,            "Sound & Music"                 },
   { TYPE_ENTER_MENU,   execSetupShortcuts5,            "TAS Snap Keys"                 },
+  { TYPE_ENTER_MENU,   execSetupShortcuts6,            "Speed Keys"                    },
   { TYPE_EMPTY,                NULL,                           ""                              },
   { TYPE_LEAVE_MENU,   execSetupMain,                  "Back"                          },
 
@@ -8303,6 +8313,18 @@ static struct TokenInfo setup_info_shortcuts_5[] =
   { 0,                 NULL,                           NULL                            }
 };
 
+static struct TokenInfo setup_info_shortcuts_6[] =
+{
+  { TYPE_KEYTEXT,      NULL,                           "Fast Playing Speed:"           },
+  { TYPE_KEY,          &setup.shortcut.speed_fast,     ""                              },
+  { TYPE_KEYTEXT,      NULL,                           "Slow Playing Speed:"           },
+  { TYPE_KEY,          &setup.shortcut.speed_slow,     ""                              },
+  { TYPE_EMPTY,                NULL,                           ""                              },
+  { TYPE_LEAVE_MENU,   execSetupShortcuts,             "Back"                          },
+
+  { 0,                 NULL,                           NULL                            }
+};
+
 static Key getSetupKey(void)
 {
   Key key = KSYM_UNDEFINED;
@@ -8691,6 +8713,11 @@ static void DrawSetupScreen_Generic(void)
     setup_info = setup_info_shortcuts_5;
     title_string = STR_SETUP_SHORTCUTS;
   }
+  else if (setup_mode == SETUP_MODE_SHORTCUTS_6)
+  {
+    setup_info = setup_info_shortcuts_6;
+    title_string = STR_SETUP_SHORTCUTS;
+  }
 
   // use modified setup info without setup entries marked as hidden
   setup_info = getSetupInfoFinal(setup_info);