diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -647,15 +647,61 @@ void VideoDriver_SDL::Stop() } } +void VideoDriver_SDL::InputLoop() +{ + uint32 mod = SDL_GetModState(); +#if SDL_VERSION_ATLEAST(1, 3, 0) + Uint8 *keys = SDL_GetKeyboardState(&numkeys); +#else + int numkeys; + Uint8 *keys = SDL_GetKeyState(&numkeys); +#endif + + bool old_ctrl_pressed = _ctrl_pressed; + + _ctrl_pressed = !!(mod & KMOD_CTRL); + _shift_pressed = !!(mod & KMOD_SHIFT); + +#if defined(_DEBUG) + if (_shift_pressed) +#else + /* Speedup when pressing tab, except when using ALT+TAB + * to switch to another application. */ +#if SDL_VERSION_ATLEAST(1, 3, 0) + if (keys[SDL_SCANCODE_TAB] && (mod & KMOD_ALT) == 0) +#else + if (keys[SDLK_TAB] && (mod & KMOD_ALT) == 0) +#endif /* SDL_VERSION_ATLEAST(1, 3, 0) */ +#endif /* defined(_DEBUG) */ + { + if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; + } else if (_fast_forward & 2) { + _fast_forward = 0; + } + + /* Determine which directional keys are down. */ + _dirkeys = +#if SDL_VERSION_ATLEAST(1, 3, 0) + (keys[SDL_SCANCODE_LEFT] ? 1 : 0) | + (keys[SDL_SCANCODE_UP] ? 2 : 0) | + (keys[SDL_SCANCODE_RIGHT] ? 4 : 0) | + (keys[SDL_SCANCODE_DOWN] ? 8 : 0); +#else + (keys[SDLK_LEFT] ? 1 : 0) | + (keys[SDLK_UP] ? 2 : 0) | + (keys[SDLK_RIGHT] ? 4 : 0) | + (keys[SDLK_DOWN] ? 8 : 0); +#endif + + if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged(); +} + void VideoDriver_SDL::MainLoop() { auto cur_ticks = std::chrono::steady_clock::now(); auto last_realtime_tick = cur_ticks; auto next_game_tick = cur_ticks; auto next_draw_tick = cur_ticks; - uint32 mod; - int numkeys; - Uint8 *keys; CheckPaletteAnim(); @@ -697,29 +743,6 @@ void VideoDriver_SDL::MainLoop() while (PollEvent() == -1) {} if (_exit_game) break; - mod = SDL_GetModState(); -#if SDL_VERSION_ATLEAST(1, 3, 0) - keys = SDL_GetKeyboardState(&numkeys); -#else - keys = SDL_GetKeyState(&numkeys); -#endif -#if defined(_DEBUG) - if (_shift_pressed) -#else - /* Speedup when pressing tab, except when using ALT+TAB - * to switch to another application */ -#if SDL_VERSION_ATLEAST(1, 3, 0) - if (keys[SDL_SCANCODE_TAB] && (mod & KMOD_ALT) == 0) -#else - if (keys[SDLK_TAB] && (mod & KMOD_ALT) == 0) -#endif /* SDL_VERSION_ATLEAST(1, 3, 0) */ -#endif /* defined(_DEBUG) */ - { - if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2; - } else if (_fast_forward & 2) { - _fast_forward = 0; - } - cur_ticks = std::chrono::steady_clock::now(); /* If more than a millisecond has passed, increase the _realtime_tick. */ @@ -751,27 +774,8 @@ void VideoDriver_SDL::MainLoop() /* Avoid next_draw_tick getting behind more and more if it cannot keep up. */ if (next_draw_tick < cur_ticks - ALLOWED_DRIFT * this->GetDrawInterval()) next_draw_tick = cur_ticks; - bool old_ctrl_pressed = _ctrl_pressed; - - _ctrl_pressed = !!(mod & KMOD_CTRL); - _shift_pressed = !!(mod & KMOD_SHIFT); - - /* determine which directional keys are down */ - _dirkeys = -#if SDL_VERSION_ATLEAST(1, 3, 0) - (keys[SDL_SCANCODE_LEFT] ? 1 : 0) | - (keys[SDL_SCANCODE_UP] ? 2 : 0) | - (keys[SDL_SCANCODE_RIGHT] ? 4 : 0) | - (keys[SDL_SCANCODE_DOWN] ? 8 : 0); -#else - (keys[SDLK_LEFT] ? 1 : 0) | - (keys[SDLK_UP] ? 2 : 0) | - (keys[SDLK_RIGHT] ? 4 : 0) | - (keys[SDLK_DOWN] ? 8 : 0); -#endif - if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged(); - - InputLoop(); + this->InputLoop(); + ::InputLoop(); UpdateWindows(); _local_palette = _cur_palette;