Changeset - r24849:01243a72f255
[Not reviewed]
master
0 11 0
Patric Stout - 3 years ago 2021-02-19 10:01:49
truebrain@openttd.org
Codechange: move all input-handling of video-drivers into InputLoop
11 files changed with 193 insertions and 159 deletions:
0 comments (0 inline, 0 general)
src/video/allegro_v.cpp
Show inline comments
 
@@ -444,12 +444,42 @@ const char *VideoDriver_Allegro::Start(c
 

	
 
void VideoDriver_Allegro::Stop()
 
{
 
	if (--_allegro_instance_count == 0) allegro_exit();
 
}
 

	
 
void VideoDriver_Allegro::InputLoop()
 
{
 
	bool old_ctrl_pressed = _ctrl_pressed;
 

	
 
	_ctrl_pressed  = !!(key_shifts & KB_CTRL_FLAG);
 
	_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG);
 

	
 
#if defined(_DEBUG)
 
	if (_shift_pressed)
 
#else
 
	/* Speedup when pressing tab, except when using ALT+TAB
 
	 * to switch to another application. */
 
	if (key[KEY_TAB] && (key_shifts & KB_ALT_FLAG) == 0)
 
#endif
 
	{
 
		if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
 
	} else if (_fast_forward & 2) {
 
		_fast_forward = 0;
 
	}
 

	
 
	/* Determine which directional keys are down. */
 
	_dirkeys =
 
		(key[KEY_LEFT]  ? 1 : 0) |
 
		(key[KEY_UP]    ? 2 : 0) |
 
		(key[KEY_RIGHT] ? 4 : 0) |
 
		(key[KEY_DOWN]  ? 8 : 0);
 

	
 
	if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 
}
 

	
 
void VideoDriver_Allegro::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;
 
@@ -459,25 +489,12 @@ void VideoDriver_Allegro::MainLoop()
 
	for (;;) {
 
		InteractiveRandom(); // randomness
 

	
 
		PollEvent();
 
		if (_exit_game) return;
 

	
 
#if defined(_DEBUG)
 
		if (_shift_pressed)
 
#else
 
		/* Speedup when pressing tab, except when using ALT+TAB
 
		 * to switch to another application */
 
		if (key[KEY_TAB] && (key_shifts & KB_ALT_FLAG) == 0)
 
#endif
 
		{
 
			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();
 
@@ -499,27 +516,14 @@ void VideoDriver_Allegro::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  = !!(key_shifts & KB_CTRL_FLAG);
 
			_shift_pressed = !!(key_shifts & KB_SHIFT_FLAG);
 

	
 
			/* determine which directional keys are down */
 
			_dirkeys =
 
				(key[KEY_LEFT]  ? 1 : 0) |
 
				(key[KEY_UP]    ? 2 : 0) |
 
				(key[KEY_RIGHT] ? 4 : 0) |
 
				(key[KEY_DOWN]  ? 8 : 0);
 

	
 
			if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 

	
 
			InputLoop();
 
			this->InputLoop();
 
			::InputLoop();
 
			UpdateWindows();
 
			CheckPaletteAnim();
 

	
 
			DrawSurfaceToScreen();
 
		}
 

	
src/video/allegro_v.h
Show inline comments
 
@@ -29,12 +29,15 @@ public:
 

	
 
	bool AfterBlitterChange() override;
 

	
 
	bool ClaimMousePointer() override;
 

	
 
	const char *GetName() const override { return "allegro"; }
 

	
 
protected:
 
	void InputLoop() override;
 
};
 

	
 
/** Factory for the allegro video driver. */
 
class FVideoDriver_Allegro : public DriverFactoryBase {
 
public:
 
	FVideoDriver_Allegro() : DriverFactoryBase(Driver::DT_VIDEO, 4, "allegro", "Allegro Video Driver") {}
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -71,12 +71,13 @@ public:
 

	
 
	void AllocateBackingStore();
 

	
 
protected:
 
	Dimension GetScreenSize() const override;
 
	float GetDPIScale() override;
 
	void InputLoop() override;
 

	
 
private:
 
	bool PollEvent();
 

	
 
	bool IsFullscreen();
 
	void GameSizeChanged();
src/video/cocoa/cocoa_v.mm
Show inline comments
 
@@ -629,12 +629,34 @@ bool VideoDriver_Cocoa::PollEvent()
 

	
 
	[ NSApp sendEvent:event ];
 

	
 
	return true;
 
}
 

	
 
void VideoDriver_Cocoa::InputLoop()
 
{
 
	NSUInteger cur_mods = [ NSEvent modifierFlags ];
 

	
 
	bool old_ctrl_pressed = _ctrl_pressed;
 

	
 
	_ctrl_pressed = (cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask)) != 0;
 
	_shift_pressed = (cur_mods & NSShiftKeyMask) != 0;
 

	
 
#if defined(_DEBUG)
 
	if (_shift_pressed) {
 
#else
 
	if (_tab_is_down) {
 
#endif
 
		if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
 
	} else if (_fast_forward & 2) {
 
		_fast_forward = 0;
 
	}
 

	
 
	if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 
}
 

	
 
/** Main game loop. */
 
void VideoDriver_Cocoa::GameLoop()
 
{
 
	auto cur_ticks = std::chrono::steady_clock::now();
 
	auto last_realtime_tick = cur_ticks;
 
	auto next_game_tick = cur_ticks;
 
@@ -650,23 +672,12 @@ void VideoDriver_Cocoa::GameLoop()
 
			if (_exit_game) {
 
				/* Restore saved resolution if in fullscreen mode. */
 
				if (this->IsFullscreen()) _cur_resolution = this->orig_res;
 
				break;
 
			}
 

	
 
			NSUInteger cur_mods = [ NSEvent modifierFlags ];
 

	
 
#if defined(_DEBUG)
 
			if (cur_mods & NSShiftKeyMask) {
 
#else
 
			if (_tab_is_down) {
 
#endif
 
				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);
 
@@ -689,20 +700,14 @@ void VideoDriver_Cocoa::GameLoop()
 
			/* 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 = (cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask)) != 0;
 
				_shift_pressed = (cur_mods & NSShiftKeyMask) != 0;
 

	
 
				if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 

	
 
				InputLoop();
 
				this->InputLoop();
 
				::InputLoop();
 
				UpdateWindows();
 
				this->CheckPaletteAnim();
 

	
 
				this->Draw();
 
			}
 

	
src/video/sdl2_v.cpp
Show inline comments
 
@@ -726,17 +726,47 @@ 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();
 
	const Uint8 *keys = SDL_GetKeyboardState(NULL);
 

	
 
	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 (keys[SDL_SCANCODE_TAB] && (mod & KMOD_ALT) == 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 =
 
		(keys[SDL_SCANCODE_LEFT]  ? 1 : 0) |
 
		(keys[SDL_SCANCODE_UP]    ? 2 : 0) |
 
		(keys[SDL_SCANCODE_RIGHT] ? 4 : 0) |
 
		(keys[SDL_SCANCODE_DOWN]  ? 8 : 0);
 

	
 
	if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 
}
 

	
 
void VideoDriver_SDL::LoopOnce()
 
{
 
	uint32 mod;
 
	int numkeys;
 
	const Uint8 *keys;
 
	InteractiveRandom(); // randomness
 

	
 
	while (PollEvent() == -1) {}
 
	if (_exit_game) {
 
#ifdef __EMSCRIPTEN__
 
		/* Emscripten is event-driven, and as such the main loop is inside
 
@@ -748,28 +778,12 @@ void VideoDriver_SDL::LoopOnce()
 
		emscripten_cancel_main_loop();
 
		MainLoopCleanup();
 
#endif
 
		return;
 
	}
 

	
 
	mod = SDL_GetModState();
 
	keys = SDL_GetKeyboardState(&numkeys);
 

	
 
#if defined(_DEBUG)
 
	if (_shift_pressed)
 
#else
 
	/* Speedup when pressing tab, except when using ALT+TAB
 
	 * to switch to another application */
 
	if (keys[SDL_SCANCODE_TAB] && (mod & KMOD_ALT) == 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();
 
@@ -795,26 +809,14 @@ void VideoDriver_SDL::LoopOnce()
 
	/* 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 =
 
			(keys[SDL_SCANCODE_LEFT]  ? 1 : 0) |
 
			(keys[SDL_SCANCODE_UP]    ? 2 : 0) |
 
			(keys[SDL_SCANCODE_RIGHT] ? 4 : 0) |
 
			(keys[SDL_SCANCODE_DOWN]  ? 8 : 0);
 
		if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 

	
 
		InputLoop();
 
		this->InputLoop();
 
		::InputLoop();
 
		UpdateWindows();
 
		this->CheckPaletteAnim();
 

	
 
		if (_draw_mutex != nullptr && !HasModalProgress()) {
 
			_draw_signal->notify_one();
 
		} else {
src/video/sdl2_v.h
Show inline comments
 
@@ -40,12 +40,13 @@ public:
 
	void EditBoxLostFocus() override;
 

	
 
	const char *GetName() const override { return "sdl"; }
 

	
 
protected:
 
	Dimension GetScreenSize() const override;
 
	void InputLoop() override;
 

	
 
private:
 
	int PollEvent();
 
	void LoopOnce();
 
	void MainLoopCleanup();
 
	bool CreateMainSurface(uint w, uint h, bool resize);
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 {
src/video/sdl_v.h
Show inline comments
 
@@ -33,12 +33,16 @@ public:
 

	
 
	void ReleaseBlitterLock() override;
 

	
 
	bool ClaimMousePointer() override;
 

	
 
	const char *GetName() const override { return "sdl"; }
 

	
 
protected:
 
	void InputLoop() override;
 

	
 
private:
 
	int PollEvent();
 
	bool CreateMainSurface(uint w, uint h);
 
	void SetupKeyboard();
 
};
 

	
src/video/video_driver.hpp
Show inline comments
 
@@ -153,12 +153,17 @@ protected:
 
			Dimension res = this->GetScreenSize();
 
			_cur_resolution.width  = ClampU(res.width  * 3 / 4, DEFAULT_WINDOW_WIDTH, UINT16_MAX / 2);
 
			_cur_resolution.height = ClampU(res.height * 3 / 4, DEFAULT_WINDOW_HEIGHT, UINT16_MAX / 2);
 
		}
 
	}
 

	
 
	/**
 
	 * Handle input logic, is CTRL pressed, should we fast-forward, etc.
 
	 */
 
	virtual void InputLoop() {}
 

	
 
	std::chrono::steady_clock::duration GetGameInterval()
 
	{
 
		return std::chrono::milliseconds(MILLISECONDS_PER_TICK);
 
	}
 

	
 
	std::chrono::steady_clock::duration GetDrawInterval()
src/video/win32_v.cpp
Show inline comments
 
@@ -1115,12 +1115,46 @@ void VideoDriver_Win32::CheckPaletteAnim
 
	if (_cur_palette.count_dirty == 0) return;
 

	
 
	_local_palette = _cur_palette;
 
	this->MakeDirty(0, 0, _screen.width, _screen.height);
 
}
 

	
 
void VideoDriver_Win32::InputLoop()
 
{
 
	bool old_ctrl_pressed = _ctrl_pressed;
 

	
 
	_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL) < 0;
 
	_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0;
 

	
 
#if defined(_DEBUG)
 
	if (_shift_pressed)
 
#else
 
	/* Speedup when pressing tab, except when using ALT+TAB
 
	 * to switch to another application. */
 
	if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0)
 
#endif
 
	{
 
		if (!_networking && _game_mode != GM_MENU) _fast_forward |= 2;
 
	} else if (_fast_forward & 2) {
 
		_fast_forward = 0;
 
	}
 

	
 
	/* Determine which directional keys are down. */
 
	if (_wnd.has_focus) {
 
		_dirkeys =
 
			(GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
 
			(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
 
			(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
 
			(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
 
	} else {
 
		_dirkeys = 0;
 
	}
 

	
 
	if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 
}
 

	
 
void VideoDriver_Win32::MainLoop()
 
{
 
	MSG mesg;
 
	auto cur_ticks = std::chrono::steady_clock::now();
 
	auto last_realtime_tick = cur_ticks;
 
	auto next_game_tick = cur_ticks;
 
@@ -1171,24 +1205,12 @@ void VideoDriver_Win32::MainLoop()
 
			/* Convert key messages to char messages if we want text input. */
 
			if (EditBoxInGlobalFocus()) TranslateMessage(&mesg);
 
			DispatchMessage(&mesg);
 
		}
 
		if (_exit_game) break;
 

	
 
#if defined(_DEBUG)
 
		if (_wnd.has_focus && GetAsyncKeyState(VK_SHIFT) < 0)
 
#else
 
		/* Speed up using TAB, but disable for ALT+TAB of course */
 
		if (_wnd.has_focus && GetAsyncKeyState(VK_TAB) < 0 && GetAsyncKeyState(VK_MENU) >= 0)
 
#endif
 
		{
 
			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();
 
@@ -1217,36 +1239,19 @@ void VideoDriver_Win32::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 = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
 
			_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0;
 

	
 
			/* determine which directional keys are down */
 
			if (_wnd.has_focus) {
 
				_dirkeys =
 
					(GetAsyncKeyState(VK_LEFT) < 0 ? 1 : 0) +
 
					(GetAsyncKeyState(VK_UP) < 0 ? 2 : 0) +
 
					(GetAsyncKeyState(VK_RIGHT) < 0 ? 4 : 0) +
 
					(GetAsyncKeyState(VK_DOWN) < 0 ? 8 : 0);
 
			} else {
 
				_dirkeys = 0;
 
			}
 

	
 
			if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
 

	
 
			if (_force_full_redraw) MarkWholeScreenDirty();
 

	
 
			/* Flush GDI buffer to ensure we don't conflict with the drawing thread. */
 
			GdiFlush();
 

	
 
			InputLoop();
 
			this->InputLoop();
 
			::InputLoop();
 
			UpdateWindows();
 
			CheckPaletteAnim();
 

	
 
			if (_draw_mutex != nullptr && !HasModalProgress()) {
 
				_draw_signal->notify_one();
 
			} else {
src/video/win32_v.h
Show inline comments
 
@@ -40,14 +40,14 @@ public:
 
	const char *GetName() const override { return "win32"; }
 

	
 
	bool MakeWindow(bool full_screen);
 

	
 
protected:
 
	Dimension GetScreenSize() const override;
 

	
 
	float GetDPIScale() override;
 
	void InputLoop() override;
 

	
 
private:
 
	void CheckPaletteAnim();
 
};
 

	
 
/** The factory for Windows' video driver. */
0 comments (0 inline, 0 general)