From: Holger Schemel Date: Tue, 14 Jun 2016 21:38:19 +0000 (+0200) Subject: moved key event handling for debug keys to separate function X-Git-Tag: 4.0.0.0-rc3~5 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d7196292a6cc00acc4292f4920cd63fc16ef3068;p=rocksndiamonds.git moved key event handling for debug keys to separate function --- diff --git a/src/events.c b/src/events.c index 843fb197..c743a8b0 100644 --- a/src/events.c +++ b/src/events.c @@ -1202,6 +1202,62 @@ static void HandleKeysSpecial(Key key) } } +void HandleKeysDebug(Key key) +{ +#ifdef DEBUG + int i; + + 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; + } + } + } + + if (game_status == GAME_MODE_PLAYING) + { + if (key == KSYM_d) + { + options.debug = !options.debug; + + Error(ERR_DEBUG, "debug mode %s", + (options.debug ? "enabled" : "disabled")); + } + else if (key == KSYM_v) + { + Error(ERR_DEBUG, "currently using game engine version %d", + game.engine_version); + } + } +#endif +} + void HandleKey(Key key, int key_status) { boolean anyTextGadgetActiveOrJustFinished = anyTextGadgetActive(); @@ -1584,26 +1640,6 @@ void HandleKey(Key key, int key_status) RequestQuitGame(setup.ask_on_escape); break; -#ifdef DEBUG - case KSYM_d: - if (options.debug) - { - options.debug = FALSE; - printf("debug mode disabled\n"); - } - else - { - options.debug = TRUE; - printf("debug mode enabled\n"); - } - break; - - case KSYM_v: - printf("::: currently using game engine version %d\n", - game.engine_version); - break; -#endif - default: break; } @@ -1621,40 +1657,7 @@ void HandleKey(Key key, int key_status) } } -#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 + HandleKeysDebug(key); } void HandleNoEvent() diff --git a/src/events.h b/src/events.h index 0768f11f..a809665c 100644 --- a/src/events.h +++ b/src/events.h @@ -38,6 +38,7 @@ void HandleFingerEvent(FingerEvent *); void HandleTextEvent(TextEvent *); void HandlePauseResumeEvent(PauseResumeEvent *); #endif +void HandleKeysDebug(Key); void HandleKeyEvent(KeyEvent *); void HandleFocusEvent(FocusChangeEvent *); void HandleClientMessageEvent(ClientMessageEvent *);