mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [Video] make the prototype of PollEvent() the same for all drivers
Additionally, call it from the draw-tick.pull/8743/head
parent
70e4845915
commit
c409f45ddd
|
@ -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()) {
|
||||
|
|
|
@ -37,6 +37,7 @@ protected:
|
|||
void InputLoop() override;
|
||||
void Paint() override;
|
||||
void CheckPaletteAnim() override;
|
||||
bool PollEvent() override;
|
||||
};
|
||||
|
||||
/** Factory for the allegro video driver. */
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -249,6 +249,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.
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -60,6 +60,7 @@ protected:
|
|||
bool LockVideoBuffer() override;
|
||||
void UnlockVideoBuffer() override;
|
||||
void CheckPaletteAnim() override;
|
||||
bool PollEvent() override;
|
||||
|
||||
void Initialize();
|
||||
bool MakeWindow(bool full_screen);
|
||||
|
|
Loading…
Reference in New Issue