From: Holger Schemel Date: Mon, 13 Jun 2016 22:27:58 +0000 (+0200) Subject: added configurable debug key shortcuts for changing game/menu frame rate X-Git-Tag: 4.0.0.0-rc3~12 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=12d5d704d201d4df017290bfee65145e51cdf97a;p=rocksndiamonds.git added configurable debug key shortcuts for changing game/menu frame rate --- diff --git a/src/events.c b/src/events.c index ab6dc8ca..3997764e 100644 --- a/src/events.c +++ b/src/events.c @@ -309,7 +309,7 @@ void EventLoop(void) BackToFront(); /* reset video frame delay to default (may change again while playing) */ - SetVideoFrameDelay(GAME_FRAME_DELAY); + SetVideoFrameDelay(MenuFrameDelay); if (game_status == GAME_MODE_QUIT) return; @@ -1523,10 +1523,6 @@ void HandleKey(Key key, int key_status) break; #ifdef DEBUG - case KSYM_0: - GameFrameDelay = (GameFrameDelay == 500 ? GAME_FRAME_DELAY : 500); - break; - case KSYM_b: setup.sp_show_border_elements = !setup.sp_show_border_elements; printf("Supaplex border elements %s\n", @@ -1553,20 +1549,6 @@ void HandleKey(Key key, int key_status) break; #ifdef DEBUG - case KSYM_0: - if (key == KSYM_0) - { - if (GameFrameDelay == 500) - GameFrameDelay = GAME_FRAME_DELAY; - else - GameFrameDelay = 500; - } - else - GameFrameDelay = (key - KSYM_0) * 10; - printf("Game speed == %d%% (%d ms delay between two frames)\n", - GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay); - break; - case KSYM_d: if (options.debug) { @@ -1602,6 +1584,41 @@ void HandleKey(Key key, int key_status) return; } } + +#ifdef DEBUG + if (game_status == GAME_MODE_PLAYING || !setup.debug.frame_delay_game_only) + { + boolean mod_key_pressed = ((GetKeyModState() & KMOD_Control) || + (GetKeyModState() & KMOD_Alt) || + (GetKeyModState() & KMOD_Meta)); + + for (i = 0; i < NUM_DEBUG_FRAME_DELAY_KEYS; i++) + { + if (key == setup.debug.frame_delay_key[i] && + (mod_key_pressed || !setup.debug.frame_delay_use_mod_key)) + { + GameFrameDelay = (GameFrameDelay != setup.debug.frame_delay[i] ? + setup.debug.frame_delay[i] : GAME_FRAME_DELAY); + + if (!setup.debug.frame_delay_game_only) + MenuFrameDelay = GameFrameDelay; + + SetVideoFrameDelay(GameFrameDelay); + + if (GameFrameDelay > ONE_SECOND_DELAY) + Error(ERR_DEBUG, "frame delay == %d ms", GameFrameDelay); + else if (GameFrameDelay != 0) + Error(ERR_DEBUG, "frame delay == %d ms (max. %d fps / %d %%)", + GameFrameDelay, ONE_SECOND_DELAY / GameFrameDelay, + GAME_FRAME_DELAY * 100 / GameFrameDelay); + else + Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)"); + + break; + } + } + } +#endif } void HandleNoEvent() diff --git a/src/files.c b/src/files.c index 97934c17..ed527469 100644 --- a/src/files.c +++ b/src/files.c @@ -8050,6 +8050,32 @@ void SaveScore(int nr) #define NUM_INTERNAL_SETUP_TOKENS 17 +/* debug setup */ +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_0 0 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_1 1 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_2 2 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_3 3 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_4 4 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_5 5 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_6 6 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_7 7 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_8 8 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_9 9 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_0 10 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_1 11 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_2 12 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_3 13 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_4 14 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_5 15 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_6 16 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_7 17 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_8 18 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_KEY_9 19 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_USE_MOD_KEY 20 +#define SETUP_TOKEN_DEBUG_FRAME_DELAY_GAME_ONLY 21 + +#define NUM_DEBUG_SETUP_TOKENS 22 + /* options setup */ #define SETUP_TOKEN_OPTIONS_VERBOSE 0 @@ -8063,6 +8089,7 @@ static struct SetupShortcutInfo ssi; static struct SetupInputInfo sii; static struct SetupSystemInfo syi; static struct SetupInternalInfo sxi; +static struct SetupDebugInfo sdi; static struct OptionInfo soi; static struct TokenInfo global_setup_tokens[] = @@ -8225,6 +8252,32 @@ static struct TokenInfo internal_setup_tokens[] = { TYPE_INTEGER,&sxi.default_window_height, "default_window_height" }, }; +static struct TokenInfo debug_setup_tokens[] = +{ + { TYPE_INTEGER, &sdi.frame_delay[0], "debug.frame_delay_0" }, + { TYPE_INTEGER, &sdi.frame_delay[1], "debug.frame_delay_1" }, + { TYPE_INTEGER, &sdi.frame_delay[2], "debug.frame_delay_2" }, + { TYPE_INTEGER, &sdi.frame_delay[3], "debug.frame_delay_3" }, + { TYPE_INTEGER, &sdi.frame_delay[4], "debug.frame_delay_4" }, + { TYPE_INTEGER, &sdi.frame_delay[5], "debug.frame_delay_5" }, + { TYPE_INTEGER, &sdi.frame_delay[6], "debug.frame_delay_6" }, + { TYPE_INTEGER, &sdi.frame_delay[7], "debug.frame_delay_7" }, + { TYPE_INTEGER, &sdi.frame_delay[8], "debug.frame_delay_8" }, + { TYPE_INTEGER, &sdi.frame_delay[9], "debug.frame_delay_9" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[0], "debug.key.frame_delay_0" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[1], "debug.key.frame_delay_1" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[2], "debug.key.frame_delay_2" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[3], "debug.key.frame_delay_3" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[4], "debug.key.frame_delay_4" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[5], "debug.key.frame_delay_5" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[6], "debug.key.frame_delay_6" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[7], "debug.key.frame_delay_7" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[8], "debug.key.frame_delay_8" }, + { TYPE_KEY_X11, &sdi.frame_delay_key[9], "debug.key.frame_delay_9" }, + { TYPE_BOOLEAN, &sdi.frame_delay_use_mod_key,"debug.frame_delay.use_mod_key"}, + { TYPE_BOOLEAN, &sdi.frame_delay_game_only, "debug.frame_delay.game_only" }, +}; + static struct TokenInfo options_setup_tokens[] = { { TYPE_BOOLEAN, &soi.verbose, "options.verbose" }, @@ -8389,6 +8442,31 @@ static void setSetupInfoToDefaults(struct SetupInfo *si) si->internal.default_window_width = WIN_XSIZE_DEFAULT; si->internal.default_window_height = WIN_YSIZE_DEFAULT; + si->debug.frame_delay[0] = DEFAULT_FRAME_DELAY_0; + si->debug.frame_delay[1] = DEFAULT_FRAME_DELAY_1; + si->debug.frame_delay[2] = DEFAULT_FRAME_DELAY_2; + si->debug.frame_delay[3] = DEFAULT_FRAME_DELAY_3; + si->debug.frame_delay[4] = DEFAULT_FRAME_DELAY_4; + si->debug.frame_delay[5] = DEFAULT_FRAME_DELAY_5; + si->debug.frame_delay[6] = DEFAULT_FRAME_DELAY_6; + si->debug.frame_delay[7] = DEFAULT_FRAME_DELAY_7; + si->debug.frame_delay[8] = DEFAULT_FRAME_DELAY_8; + si->debug.frame_delay[9] = DEFAULT_FRAME_DELAY_9; + + si->debug.frame_delay_key[0] = DEFAULT_KEY_FRAME_DELAY_0; + si->debug.frame_delay_key[1] = DEFAULT_KEY_FRAME_DELAY_1; + si->debug.frame_delay_key[2] = DEFAULT_KEY_FRAME_DELAY_2; + si->debug.frame_delay_key[3] = DEFAULT_KEY_FRAME_DELAY_3; + si->debug.frame_delay_key[4] = DEFAULT_KEY_FRAME_DELAY_4; + si->debug.frame_delay_key[5] = DEFAULT_KEY_FRAME_DELAY_5; + si->debug.frame_delay_key[6] = DEFAULT_KEY_FRAME_DELAY_6; + si->debug.frame_delay_key[7] = DEFAULT_KEY_FRAME_DELAY_7; + si->debug.frame_delay_key[8] = DEFAULT_KEY_FRAME_DELAY_8; + si->debug.frame_delay_key[9] = DEFAULT_KEY_FRAME_DELAY_9; + + si->debug.frame_delay_use_mod_key = DEFAULT_FRAME_DELAY_USE_MOD_KEY; + si->debug.frame_delay_game_only = DEFAULT_FRAME_DELAY_GAME_ONLY; + si->options.verbose = FALSE; #if defined(PLATFORM_ANDROID) @@ -8477,6 +8555,13 @@ static void decodeSetupFileHash(SetupFileHash *setup_file_hash) getHashEntry(setup_file_hash, internal_setup_tokens[i].text)); setup.internal = sxi; + /* debug setup */ + sdi = setup.debug; + for (i = 0; i < NUM_DEBUG_SETUP_TOKENS; i++) + setSetupInfo(debug_setup_tokens, i, + getHashEntry(setup_file_hash, debug_setup_tokens[i].text)); + setup.debug = sdi; + /* options setup */ soi = setup.options; for (i = 0; i < NUM_OPTIONS_SETUP_TOKENS; i++) @@ -8643,6 +8728,12 @@ void SaveSetup() /* internal setup */ /* (internal setup values not saved to user setup file) */ + /* debug setup */ + sdi = setup.debug; + fprintf(file, "\n"); + for (i = 0; i < NUM_DEBUG_SETUP_TOKENS; i++) + fprintf(file, "%s\n", getSetupLine(debug_setup_tokens, "", i)); + /* options setup */ soi = setup.options; fprintf(file, "\n"); diff --git a/src/libgame/system.h b/src/libgame/system.h index 4710ea17..0bd948bd 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -130,6 +130,34 @@ #define DEFAULT_KEY_SNAP_UP KSYM_UNDEFINED #define DEFAULT_KEY_SNAP_DOWN KSYM_UNDEFINED +/* default debug setup keys and values */ +#define DEFAULT_FRAME_DELAY_0 20 // 100 % speed +#define DEFAULT_FRAME_DELAY_1 500 // 4 % speed +#define DEFAULT_FRAME_DELAY_2 250 // 8 % speed +#define DEFAULT_FRAME_DELAY_3 125 // 16 % speed +#define DEFAULT_FRAME_DELAY_4 60 // 33 % speed +#define DEFAULT_FRAME_DELAY_5 40 // 50 % speed +#define DEFAULT_FRAME_DELAY_6 30 // 66 % speed +#define DEFAULT_FRAME_DELAY_7 10 // 200 % speed +#define DEFAULT_FRAME_DELAY_8 5 // 400 % speed +#define DEFAULT_FRAME_DELAY_9 0 // maximum speed + +#define DEFAULT_KEY_FRAME_DELAY_0 KSYM_0 +#define DEFAULT_KEY_FRAME_DELAY_1 KSYM_1 +#define DEFAULT_KEY_FRAME_DELAY_2 KSYM_2 +#define DEFAULT_KEY_FRAME_DELAY_3 KSYM_3 +#define DEFAULT_KEY_FRAME_DELAY_4 KSYM_4 +#define DEFAULT_KEY_FRAME_DELAY_5 KSYM_5 +#define DEFAULT_KEY_FRAME_DELAY_6 KSYM_6 +#define DEFAULT_KEY_FRAME_DELAY_7 KSYM_7 +#define DEFAULT_KEY_FRAME_DELAY_8 KSYM_8 +#define DEFAULT_KEY_FRAME_DELAY_9 KSYM_9 + +#define NUM_DEBUG_FRAME_DELAY_KEYS 10 + +#define DEFAULT_FRAME_DELAY_USE_MOD_KEY FALSE +#define DEFAULT_FRAME_DELAY_GAME_ONLY TRUE + /* values for key_status */ #define KEY_NOT_PRESSED FALSE #define KEY_RELEASED FALSE @@ -371,6 +399,7 @@ /* fundamental game speed values */ #define ONE_SECOND_DELAY 1000 /* delay value for one second */ +#define MENU_FRAME_DELAY 20 /* frame delay in milliseconds */ #define GAME_FRAME_DELAY 20 /* frame delay in milliseconds */ #define FFWD_FRAME_DELAY 10 /* 200% speed for fast forward */ #define FRAMES_PER_SECOND (ONE_SECOND_DELAY / GAME_FRAME_DELAY) @@ -1010,6 +1039,14 @@ struct SetupInternalInfo boolean choose_from_top_leveldir; }; +struct SetupDebugInfo +{ + int frame_delay[10]; + Key frame_delay_key[10]; + boolean frame_delay_use_mod_key; + boolean frame_delay_game_only; +}; + struct SetupInfo { char *player_name; @@ -1063,6 +1100,8 @@ struct SetupInfo struct SetupTouchInfo touch; struct SetupSystemInfo system; struct SetupInternalInfo internal; + struct SetupDebugInfo debug; + struct OptionInfo options; }; diff --git a/src/main.c b/src/main.c index 047c1cb2..d29a341a 100644 --- a/src/main.c +++ b/src/main.c @@ -118,6 +118,7 @@ int ScrollStepSize; int ScreenMovDir = MV_NONE, ScreenMovPos = 0; int ScreenGfxPos = 0; int BorderElement = EL_STEELWALL; +int MenuFrameDelay = MENU_FRAME_DELAY; int GameFrameDelay = GAME_FRAME_DELAY; int FfwdFrameDelay = FFWD_FRAME_DELAY; int BX1, BY1; diff --git a/src/main.h b/src/main.h index 2da45584..c3a0ab04 100644 --- a/src/main.h +++ b/src/main.h @@ -3058,6 +3058,7 @@ extern int FX, FY; extern int ScrollStepSize; extern int ScreenMovDir, ScreenMovPos, ScreenGfxPos; extern int BorderElement; +extern int MenuFrameDelay; extern int GameFrameDelay; extern int FfwdFrameDelay; extern int BX1, BY1;