From 9882a97f9526e64b5a9c1940ca0cd9994fdd6da9 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 25 Apr 2024 07:49:27 +0200 Subject: [PATCH] added configurable keys for fast and slow playing speed --- src/conf_gfx.c | 2 + src/events.c | 28 ++++++++++++ src/files.c | 15 +++++++ src/game_bd/bd_gameplay.c | 2 +- src/libgame/system.h | 6 +++ src/main.h | 1 + src/screens.c | 93 +++++++++++++++++++++++++-------------- 7 files changed, 113 insertions(+), 34 deletions(-) diff --git a/src/conf_gfx.c b/src/conf_gfx.c index b758cec9..01350173 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -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" }, diff --git a/src/events.c b/src/events.c index 2e3c7ca9..04f69108 100644 --- a/src/events.c +++ b/src/events.c @@ -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 diff --git a/src/files.c b/src/files.c index 5ae706b9..587e71b9 100644 --- a/src/files.c +++ b/src/files.c @@ -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; diff --git a/src/game_bd/bd_gameplay.c b/src/game_bd/bd_gameplay.c index 7a4d889c..12eb53bc 100644 --- a/src/game_bd/bd_gameplay.c +++ b/src/game_bd/bd_gameplay.c @@ -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) diff --git a/src/libgame/system.h b/src/libgame/system.h index d8ca9a29..162ca489 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -197,6 +197,8 @@ #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; diff --git a/src/main.h b/src/main.h index 7f70cea7..8ae91599 100644 --- a/src/main.h +++ b/src/main.h @@ -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, diff --git a/src/screens.c b/src/screens.c index c7a69c30..14a2adf4 100644 --- a/src/screens.c +++ b/src/screens.c @@ -58,42 +58,43 @@ #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); -- 2.34.1