summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video/allegro_v.cpp5
-rw-r--r--src/video/allegro_v.h1
-rw-r--r--src/video/cocoa/cocoa_v.h3
-rw-r--r--src/video/cocoa/cocoa_v.mm2
-rw-r--r--src/video/sdl2_v.cpp8
-rw-r--r--src/video/sdl2_v.h2
-rw-r--r--src/video/sdl_v.cpp8
-rw-r--r--src/video/sdl_v.h4
-rw-r--r--src/video/video_driver.cpp1
-rw-r--r--src/video/video_driver.hpp6
-rw-r--r--src/video/win32_v.cpp18
-rw-r--r--src/video/win32_v.h1
12 files changed, 36 insertions, 23 deletions
diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp
index aa4c3c9a4..60a05d3fd 100644
--- a/src/video/allegro_v.cpp
+++ b/src/video/allegro_v.cpp
@@ -329,7 +329,7 @@ static uint32 ConvertAllegroKeyIntoMy(WChar *character)
static const uint LEFT_BUTTON = 0;
static const uint RIGHT_BUTTON = 1;
-static void PollEvent()
+bool VideoDriver_Allegro::PollEvent()
{
poll_mouse();
@@ -403,6 +403,8 @@ static void PollEvent()
uint keycode = ConvertAllegroKeyIntoMy(&character);
HandleKeypress(keycode, character);
}
+
+ return false;
}
/**
@@ -482,7 +484,6 @@ void VideoDriver_Allegro::MainLoop()
for (;;) {
InteractiveRandom(); // randomness
- PollEvent();
if (_exit_game) return;
if (this->Tick()) {
diff --git a/src/video/allegro_v.h b/src/video/allegro_v.h
index 2ab74fa30..d67778b7f 100644
--- a/src/video/allegro_v.h
+++ b/src/video/allegro_v.h
@@ -37,6 +37,7 @@ protected:
void InputLoop() override;
void Paint() override;
void CheckPaletteAnim() override;
+ bool PollEvent() override;
};
/** Factory for the allegro video driver. */
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h
index c1a645245..d95d7bf98 100644
--- a/src/video/cocoa/cocoa_v.h
+++ b/src/video/cocoa/cocoa_v.h
@@ -62,6 +62,7 @@ protected:
void InputLoop() override;
bool LockVideoBuffer() override;
void UnlockVideoBuffer() override;
+ bool PollEvent() override;
void GameSizeChanged();
@@ -79,8 +80,6 @@ protected:
virtual void ReleaseVideoPointer() {}
private:
- bool PollEvent();
-
bool IsFullscreen();
};
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index bd8340ec1..febeae2d5 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -440,8 +440,6 @@ void VideoDriver_Cocoa::GameLoop()
InteractiveRandom(); // randomness
- while (this->PollEvent()) {}
-
if (_exit_game) {
/* Restore saved resolution if in fullscreen mode. */
if (this->IsFullscreen()) _cur_resolution = this->orig_res;
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp
index 818389b80..724689725 100644
--- a/src/video/sdl2_v.cpp
+++ b/src/video/sdl2_v.cpp
@@ -370,11 +370,11 @@ static uint ConvertSdlKeycodeIntoMy(SDL_Keycode kc)
return key;
}
-int VideoDriver_SDL_Base::PollEvent()
+bool VideoDriver_SDL_Base::PollEvent()
{
SDL_Event ev;
- if (!SDL_PollEvent(&ev)) return -2;
+ if (!SDL_PollEvent(&ev)) return false;
switch (ev.type) {
case SDL_MOUSEMOTION:
@@ -516,7 +516,8 @@ int VideoDriver_SDL_Base::PollEvent()
break;
}
}
- return -1;
+
+ return true;
}
static const char *InitializeSDL()
@@ -629,7 +630,6 @@ void VideoDriver_SDL_Base::LoopOnce()
{
InteractiveRandom(); // randomness
- while (PollEvent() == -1) {}
if (_exit_game) {
#ifdef __EMSCRIPTEN__
/* Emscripten is event-driven, and as such the main loop is inside
diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h
index 7042bf270..48515251a 100644
--- a/src/video/sdl2_v.h
+++ b/src/video/sdl2_v.h
@@ -60,6 +60,7 @@ protected:
bool LockVideoBuffer() override;
void UnlockVideoBuffer() override;
void CheckPaletteAnim() override;
+ bool PollEvent() override;
/** Indicate to the driver the client-side might have changed. */
void ClientSizeChanged(int w, int h, bool force);
@@ -74,7 +75,6 @@ protected:
virtual bool CreateMainWindow(uint w, uint h, uint flags = 0);
private:
- int PollEvent();
void LoopOnce();
void MainLoopCleanup();
bool CreateMainSurface(uint w, uint h, bool resize);
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 12a663e3b..f21b1e9fd 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -507,11 +507,11 @@ static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, WChar *character)
return key;
}
-int VideoDriver_SDL::PollEvent()
+bool VideoDriver_SDL::PollEvent()
{
SDL_Event ev;
- if (!SDL_PollEvent(&ev)) return -2;
+ if (!SDL_PollEvent(&ev)) return false;
switch (ev.type) {
case SDL_MOUSEMOTION:
@@ -598,7 +598,8 @@ int VideoDriver_SDL::PollEvent()
break;
}
}
- return -1;
+
+ return true;
}
const char *VideoDriver_SDL::Start(const StringList &parm)
@@ -719,7 +720,6 @@ void VideoDriver_SDL::MainLoop()
for (;;) {
InteractiveRandom(); // randomness
- while (PollEvent() == -1) {}
if (_exit_game) break;
if (this->Tick()) {
diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h
index be6010aca..7df29a2ea 100644
--- a/src/video/sdl_v.h
+++ b/src/video/sdl_v.h
@@ -43,12 +43,12 @@ protected:
void UnlockVideoBuffer() override;
void Paint() override;
void PaintThread() override;
- void CheckPaletteAnim();
+ void CheckPaletteAnim() override;
+ bool PollEvent() override;
private:
std::unique_lock<std::recursive_mutex> draw_lock;
- int PollEvent();
bool CreateMainSurface(uint w, uint h);
void SetupKeyboard();
diff --git a/src/video/video_driver.cpp b/src/video/video_driver.cpp
index 3f4fba6dd..d20879be9 100644
--- a/src/video/video_driver.cpp
+++ b/src/video/video_driver.cpp
@@ -55,6 +55,7 @@ bool VideoDriver::Tick()
/* Avoid next_draw_tick getting behind more and more if it cannot keep up. */
if (this->next_draw_tick < cur_ticks - ALLOWED_DRIFT * this->GetDrawInterval()) this->next_draw_tick = cur_ticks;
+ while (this->PollEvent()) {}
this->InputLoop();
::InputLoop();
UpdateWindows();
diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp
index 0b5c6f6fd..67c8064bc 100644
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -250,6 +250,12 @@ protected:
virtual void CheckPaletteAnim() {}
/**
+ * Process a single system event.
+ * @returns False if there are no more events to process.
+ */
+ virtual bool PollEvent() { return false; };
+
+ /**
* Run the game for a single tick, processing boththe game-tick and draw-tick.
* @returns True if the driver should redraw the screen.
*/
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 3ea93dd1c..ab59b8325 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -857,10 +857,21 @@ void VideoDriver_Win32Base::InputLoop()
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
}
-void VideoDriver_Win32Base::MainLoop()
+bool VideoDriver_Win32Base::PollEvent()
{
MSG mesg;
+ if (!PeekMessage(&mesg, nullptr, 0, 0, PM_REMOVE)) return false;
+
+ /* Convert key messages to char messages if we want text input. */
+ if (EditBoxInGlobalFocus()) TranslateMessage(&mesg);
+ DispatchMessage(&mesg);
+
+ return true;
+}
+
+void VideoDriver_Win32Base::MainLoop()
+{
std::thread draw_thread;
if (this->draw_threaded) {
@@ -898,11 +909,6 @@ void VideoDriver_Win32Base::MainLoop()
for (;;) {
InteractiveRandom(); // randomness
- while (PeekMessage(&mesg, nullptr, 0, 0, PM_REMOVE)) {
- /* Convert key messages to char messages if we want text input. */
- if (EditBoxInGlobalFocus()) TranslateMessage(&mesg);
- DispatchMessage(&mesg);
- }
if (_exit_game) break;
/* Flush GDI buffer to ensure we don't conflict with the drawing thread. */
diff --git a/src/video/win32_v.h b/src/video/win32_v.h
index 1f4c0ffe6..017467118 100644
--- a/src/video/win32_v.h
+++ b/src/video/win32_v.h
@@ -60,6 +60,7 @@ protected:
bool LockVideoBuffer() override;
void UnlockVideoBuffer() override;
void CheckPaletteAnim() override;
+ bool PollEvent() override;
void Initialize();
bool MakeWindow(bool full_screen);