File diff r24848:4573f310a629 → r24849:01243a72f255
src/video/sdl_v.cpp
Show inline comments
 
@@ -644,21 +644,67 @@ void VideoDriver_SDL::Stop()
 
	SDL_QuitSubSystem(SDL_INIT_VIDEO);
 
	if (SDL_WasInit(SDL_INIT_EVERYTHING) == 0) {
 
		SDL_Quit(); // If there's nothing left, quit SDL
 
	}
 
}
 

	
 
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();
 

	
 
	std::thread draw_thread;
 
	std::unique_lock<std::recursive_mutex> draw_lock;
 
	if (_draw_threaded) {
 
@@ -694,35 +740,12 @@ void VideoDriver_SDL::MainLoop()
 
	for (;;) {
 
		InteractiveRandom(); // randomness
 

	
 
		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. */
 
		if (cur_ticks - last_realtime_tick > std::chrono::milliseconds(1)) {
 
			auto delta = std::chrono::duration_cast<std::chrono::milliseconds>(cur_ticks - last_realtime_tick);
 
			_realtime_tick += delta.count();
 
@@ -748,33 +771,14 @@ void VideoDriver_SDL::MainLoop()
 
		/* Prevent drawing when switching mode, as windows can be removed when they should still appear. */
 
		if (cur_ticks >= next_draw_tick && (_switch_mode == SM_NONE || HasModalProgress())) {
 
			next_draw_tick += this->GetDrawInterval();
 
			/* 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;
 

	
 
			if (_draw_mutex != nullptr && !HasModalProgress()) {
 
				_draw_signal->notify_one();
 
			} else {