1
0
Fork 0

Codechange: [Video] make the prototype of PollEvent() the same for all drivers

Additionally, call it from the draw-tick.
pull/8743/head
Patric Stout 2021-02-24 14:45:10 +01:00 committed by Patric Stout
parent 70e4845915
commit c409f45ddd
12 changed files with 36 additions and 23 deletions

View File

@ -329,7 +329,7 @@ static uint32 ConvertAllegroKeyIntoMy(WChar *character)
static const uint LEFT_BUTTON = 0; static const uint LEFT_BUTTON = 0;
static const uint RIGHT_BUTTON = 1; static const uint RIGHT_BUTTON = 1;
static void PollEvent() bool VideoDriver_Allegro::PollEvent()
{ {
poll_mouse(); poll_mouse();
@ -403,6 +403,8 @@ static void PollEvent()
uint keycode = ConvertAllegroKeyIntoMy(&character); uint keycode = ConvertAllegroKeyIntoMy(&character);
HandleKeypress(keycode, character); HandleKeypress(keycode, character);
} }
return false;
} }
/** /**
@ -482,7 +484,6 @@ void VideoDriver_Allegro::MainLoop()
for (;;) { for (;;) {
InteractiveRandom(); // randomness InteractiveRandom(); // randomness
PollEvent();
if (_exit_game) return; if (_exit_game) return;
if (this->Tick()) { if (this->Tick()) {

View File

@ -37,6 +37,7 @@ protected:
void InputLoop() override; void InputLoop() override;
void Paint() override; void Paint() override;
void CheckPaletteAnim() override; void CheckPaletteAnim() override;
bool PollEvent() override;
}; };
/** Factory for the allegro video driver. */ /** Factory for the allegro video driver. */

View File

@ -62,6 +62,7 @@ protected:
void InputLoop() override; void InputLoop() override;
bool LockVideoBuffer() override; bool LockVideoBuffer() override;
void UnlockVideoBuffer() override; void UnlockVideoBuffer() override;
bool PollEvent() override;
void GameSizeChanged(); void GameSizeChanged();
@ -79,8 +80,6 @@ protected:
virtual void ReleaseVideoPointer() {} virtual void ReleaseVideoPointer() {}
private: private:
bool PollEvent();
bool IsFullscreen(); bool IsFullscreen();
}; };

View File

@ -440,8 +440,6 @@ void VideoDriver_Cocoa::GameLoop()
InteractiveRandom(); // randomness InteractiveRandom(); // randomness
while (this->PollEvent()) {}
if (_exit_game) { if (_exit_game) {
/* Restore saved resolution if in fullscreen mode. */ /* Restore saved resolution if in fullscreen mode. */
if (this->IsFullscreen()) _cur_resolution = this->orig_res; if (this->IsFullscreen()) _cur_resolution = this->orig_res;

View File

@ -370,11 +370,11 @@ static uint ConvertSdlKeycodeIntoMy(SDL_Keycode kc)
return key; return key;
} }
int VideoDriver_SDL_Base::PollEvent() bool VideoDriver_SDL_Base::PollEvent()
{ {
SDL_Event ev; SDL_Event ev;
if (!SDL_PollEvent(&ev)) return -2; if (!SDL_PollEvent(&ev)) return false;
switch (ev.type) { switch (ev.type) {
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
@ -516,7 +516,8 @@ int VideoDriver_SDL_Base::PollEvent()
break; break;
} }
} }
return -1;
return true;
} }
static const char *InitializeSDL() static const char *InitializeSDL()
@ -629,7 +630,6 @@ void VideoDriver_SDL_Base::LoopOnce()
{ {
InteractiveRandom(); // randomness InteractiveRandom(); // randomness
while (PollEvent() == -1) {}
if (_exit_game) { if (_exit_game) {
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
/* Emscripten is event-driven, and as such the main loop is inside /* Emscripten is event-driven, and as such the main loop is inside

View File

@ -60,6 +60,7 @@ protected:
bool LockVideoBuffer() override; bool LockVideoBuffer() override;
void UnlockVideoBuffer() override; void UnlockVideoBuffer() override;
void CheckPaletteAnim() override; void CheckPaletteAnim() override;
bool PollEvent() override;
/** Indicate to the driver the client-side might have changed. */ /** Indicate to the driver the client-side might have changed. */
void ClientSizeChanged(int w, int h, bool force); void ClientSizeChanged(int w, int h, bool force);
@ -74,7 +75,6 @@ protected:
virtual bool CreateMainWindow(uint w, uint h, uint flags = 0); virtual bool CreateMainWindow(uint w, uint h, uint flags = 0);
private: private:
int PollEvent();
void LoopOnce(); void LoopOnce();
void MainLoopCleanup(); void MainLoopCleanup();
bool CreateMainSurface(uint w, uint h, bool resize); bool CreateMainSurface(uint w, uint h, bool resize);

View File

@ -507,11 +507,11 @@ static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, WChar *character)
return key; return key;
} }
int VideoDriver_SDL::PollEvent() bool VideoDriver_SDL::PollEvent()
{ {
SDL_Event ev; SDL_Event ev;
if (!SDL_PollEvent(&ev)) return -2; if (!SDL_PollEvent(&ev)) return false;
switch (ev.type) { switch (ev.type) {
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
@ -598,7 +598,8 @@ int VideoDriver_SDL::PollEvent()
break; break;
} }
} }
return -1;
return true;
} }
const char *VideoDriver_SDL::Start(const StringList &parm) const char *VideoDriver_SDL::Start(const StringList &parm)
@ -719,7 +720,6 @@ void VideoDriver_SDL::MainLoop()
for (;;) { for (;;) {
InteractiveRandom(); // randomness InteractiveRandom(); // randomness
while (PollEvent() == -1) {}
if (_exit_game) break; if (_exit_game) break;
if (this->Tick()) { if (this->Tick()) {

View File

@ -43,12 +43,12 @@ protected:
void UnlockVideoBuffer() override; void UnlockVideoBuffer() override;
void Paint() override; void Paint() override;
void PaintThread() override; void PaintThread() override;
void CheckPaletteAnim(); void CheckPaletteAnim() override;
bool PollEvent() override;
private: private:
std::unique_lock<std::recursive_mutex> draw_lock; std::unique_lock<std::recursive_mutex> draw_lock;
int PollEvent();
bool CreateMainSurface(uint w, uint h); bool CreateMainSurface(uint w, uint h);
void SetupKeyboard(); void SetupKeyboard();

View File

@ -55,6 +55,7 @@ bool VideoDriver::Tick()
/* Avoid next_draw_tick getting behind more and more if it cannot keep up. */ /* 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; if (this->next_draw_tick < cur_ticks - ALLOWED_DRIFT * this->GetDrawInterval()) this->next_draw_tick = cur_ticks;
while (this->PollEvent()) {}
this->InputLoop(); this->InputLoop();
::InputLoop(); ::InputLoop();
UpdateWindows(); UpdateWindows();

View File

@ -249,6 +249,12 @@ protected:
*/ */
virtual void CheckPaletteAnim() {} 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. * Run the game for a single tick, processing boththe game-tick and draw-tick.
* @returns True if the driver should redraw the screen. * @returns True if the driver should redraw the screen.

View File

@ -857,10 +857,21 @@ void VideoDriver_Win32Base::InputLoop()
if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged(); if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
} }
void VideoDriver_Win32Base::MainLoop() bool VideoDriver_Win32Base::PollEvent()
{ {
MSG mesg; 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; std::thread draw_thread;
if (this->draw_threaded) { if (this->draw_threaded) {
@ -898,11 +909,6 @@ void VideoDriver_Win32Base::MainLoop()
for (;;) { for (;;) {
InteractiveRandom(); // randomness 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; if (_exit_game) break;
/* Flush GDI buffer to ensure we don't conflict with the drawing thread. */ /* Flush GDI buffer to ensure we don't conflict with the drawing thread. */

View File

@ -60,6 +60,7 @@ protected:
bool LockVideoBuffer() override; bool LockVideoBuffer() override;
void UnlockVideoBuffer() override; void UnlockVideoBuffer() override;
void CheckPaletteAnim() override; void CheckPaletteAnim() override;
bool PollEvent() override;
void Initialize(); void Initialize();
bool MakeWindow(bool full_screen); bool MakeWindow(bool full_screen);