Changeset - r24939:f00f6879a003
[Not reviewed]
master
0 12 0
Patric Stout - 3 years ago 2021-02-24 13:45:10
truebrain@openttd.org
Codechange: [Video] make the prototype of PollEvent() the same for all drivers

Additionally, call it from the draw-tick.
12 files changed with 36 insertions and 23 deletions:
0 comments (0 inline, 0 general)
src/video/allegro_v.cpp
Show inline comments
 
@@ -329,7 +329,7 @@ static uint32 ConvertAllegroKeyIntoMy(WC
 
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()) {
src/video/allegro_v.h
Show inline comments
 
@@ -37,6 +37,7 @@ protected:
 
	void InputLoop() override;
 
	void Paint() override;
 
	void CheckPaletteAnim() override;
 
	bool PollEvent() override;
 
};
 

	
 
/** Factory for the allegro video driver. */
src/video/cocoa/cocoa_v.h
Show inline comments
 
@@ -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();
 
};
 

	
src/video/cocoa/cocoa_v.mm
Show inline comments
 
@@ -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;
src/video/sdl2_v.cpp
Show inline comments
 
@@ -370,11 +370,11 @@ static uint ConvertSdlKeycodeIntoMy(SDL_
 
	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
src/video/sdl2_v.h
Show inline comments
 
@@ -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);
src/video/sdl_v.cpp
Show inline comments
 
@@ -507,11 +507,11 @@ static uint ConvertSdlKeyIntoMy(SDL_keys
 
	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()) {
src/video/sdl_v.h
Show inline comments
 
@@ -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();
 

	
src/video/video_driver.cpp
Show inline comments
 
@@ -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();
src/video/video_driver.hpp
Show inline comments
 
@@ -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.
 
	 */
src/video/win32_v.cpp
Show inline comments
 
@@ -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. */
src/video/win32_v.h
Show inline comments
 
@@ -60,6 +60,7 @@ protected:
 
	bool LockVideoBuffer() override;
 
	void UnlockVideoBuffer() override;
 
	void CheckPaletteAnim() override;
 
	bool PollEvent() override;
 

	
 
	void Initialize();
 
	bool MakeWindow(bool full_screen);
0 comments (0 inline, 0 general)