Changeset - r24852:00c1bd78d033
[Not reviewed]
master
0 10 0
Patric Stout - 3 years ago 2021-02-20 10:15:15
truebrain@openttd.org
Codechange: be consistent in what CheckPaletteAnim() does and when it is called

Additionally, make sure this is a class method. Later commits
will make use of this.
10 files changed with 16 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/video/allegro_v.cpp
Show inline comments
 
@@ -92,13 +92,13 @@ static void UpdatePalette(uint start, ui
 

	
 
static void InitPalette()
 
{
 
	UpdatePalette(0, 256);
 
}
 

	
 
static void CheckPaletteAnim()
 
void VideoDriver_Allegro::CheckPaletteAnim()
 
{
 
	if (_cur_palette.count_dirty != 0) {
 
		Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 

	
 
		switch (blitter->UsePaletteAnimation()) {
 
			case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
 
@@ -481,14 +481,12 @@ 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;
 

	
 
	CheckPaletteAnim();
 

	
 
	for (;;) {
 
		InteractiveRandom(); // randomness
 

	
 
		PollEvent();
 
		if (_exit_game) return;
 

	
 
@@ -519,13 +517,13 @@ void VideoDriver_Allegro::MainLoop()
 
			/* 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;
 

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

	
 
			this->Paint();
 
		}
 

	
 
		/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
 
		if (!_fast_forward || _pause_mode) {
src/video/allegro_v.h
Show inline comments
 
@@ -33,12 +33,13 @@ public:
 

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

	
 
protected:
 
	void InputLoop() override;
 
	void Paint() override;
 
	void CheckPaletteAnim() 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
 
@@ -73,25 +73,25 @@ public:
 

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

	
 
private:
 
	bool PollEvent();
 

	
 
	bool IsFullscreen();
 
	void GameSizeChanged();
 

	
 
	void UpdateVideoModes();
 

	
 
	bool MakeWindow(int width, int height);
 

	
 
	void UpdatePalette(uint first_color, uint num_colors);
 
	void CheckPaletteAnim();
 

	
 
	void BlitIndexedToView32(int left, int top, int right, int bottom);
 
};
 

	
 
class FVideoDriver_Cocoa : public DriverFactoryBase {
 
public:
src/video/sdl2_v.cpp
Show inline comments
 
@@ -850,14 +850,12 @@ void VideoDriver_SDL::LoopOnce()
 
void VideoDriver_SDL::MainLoop()
 
{
 
	cur_ticks = std::chrono::steady_clock::now();
 
	last_realtime_tick = cur_ticks;
 
	next_game_tick = cur_ticks;
 

	
 
	this->CheckPaletteAnim();
 

	
 
	if (_draw_threaded) {
 
		/* Initialise the mutex first, because that's the thing we *need*
 
		 * directly in the newly created thread. */
 
		_draw_mutex = new std::recursive_mutex();
 
		if (_draw_mutex == nullptr) {
 
			_draw_threaded = false;
src/video/sdl2_v.h
Show inline comments
 
@@ -45,20 +45,20 @@ protected:
 
	Dimension GetScreenSize() const override;
 
	void InputLoop() override;
 
	bool LockVideoBuffer() override;
 
	void UnlockVideoBuffer() override;
 
	void Paint() override;
 
	void PaintThread() override;
 
	void CheckPaletteAnim();
 

	
 
private:
 
	int PollEvent();
 
	void LoopOnce();
 
	void MainLoopCleanup();
 
	bool CreateMainSurface(uint w, uint h, bool resize);
 
	bool CreateMainWindow(uint w, uint h);
 
	void CheckPaletteAnim();
 

	
 
#ifdef __EMSCRIPTEN__
 
	/* Convert a constant pointer back to a non-constant pointer to a member function. */
 
	static void EmscriptenLoop(void *self) { ((VideoDriver_SDL *)self)->LoopOnce(); }
 
#endif
 

	
src/video/sdl_v.cpp
Show inline comments
 
@@ -120,14 +120,16 @@ static void InitPalette()
 
	_local_palette = _cur_palette;
 
	_local_palette.first_dirty = 0;
 
	_local_palette.count_dirty = 256;
 
	UpdatePalette(true);
 
}
 

	
 
static void CheckPaletteAnim()
 
void VideoDriver_SDL::CheckPaletteAnim()
 
{
 
	_local_palette = _cur_palette;
 

	
 
	if (_cur_palette.count_dirty != 0) {
 
		Blitter *blitter = BlitterFactory::GetCurrentBlitter();
 

	
 
		switch (blitter->UsePaletteAnimation()) {
 
			case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
 
				UpdatePalette();
 
@@ -180,13 +182,12 @@ void VideoDriver_SDL::PaintThread()
 
	_draw_signal->notify_one();
 

	
 
	/* Now wait for the first thing to draw! */
 
	_draw_signal->wait(*_draw_mutex);
 

	
 
	while (_draw_continue) {
 
		CheckPaletteAnim();
 
		/* Then just draw and wait till we stop */
 
		this->Paint();
 
		_draw_signal->wait(lock);
 
	}
 
}
 

	
 
@@ -705,14 +706,12 @@ 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;
 

	
 
	CheckPaletteAnim();
 

	
 
	std::thread draw_thread;
 
	if (_draw_threaded) {
 
		/* Initialise the mutex first, because that's the thing we *need*
 
		 * directly in the newly created thread. */
 
		_draw_mutex = new std::recursive_mutex();
 
		if (_draw_mutex == nullptr) {
 
@@ -778,18 +777,17 @@ void VideoDriver_SDL::MainLoop()
 
			/* 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;
 

	
 
			this->InputLoop();
 
			::InputLoop();
 
			UpdateWindows();
 
			_local_palette = _cur_palette;
 
			this->CheckPaletteAnim();
 

	
 
			if (_draw_mutex != nullptr && !HasModalProgress()) {
 
				_draw_signal->notify_one();
 
			} else {
 
				CheckPaletteAnim();
 
				this->Paint();
 
			}
 
		}
 

	
 
		/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
 
		if (!_fast_forward || _pause_mode) {
src/video/sdl_v.h
Show inline comments
 
@@ -40,12 +40,13 @@ public:
 
protected:
 
	void InputLoop() override;
 
	bool LockVideoBuffer() override;
 
	void UnlockVideoBuffer() override;
 
	void Paint() override;
 
	void PaintThread() override;
 
	void CheckPaletteAnim();
 

	
 
private:
 
	std::unique_lock<std::recursive_mutex> draw_lock;
 

	
 
	int PollEvent();
 
	bool CreateMainSurface(uint w, uint h);
src/video/video_driver.hpp
Show inline comments
 
@@ -181,12 +181,17 @@ protected:
 

	
 
	/**
 
	 * Thread function for threaded drawing.
 
	 */
 
	virtual void PaintThread() {}
 

	
 
	/**
 
	 * Process any pending palette animation.
 
	 */
 
	virtual void CheckPaletteAnim() {}
 

	
 
	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
 
@@ -1198,13 +1198,12 @@ void VideoDriver_Win32::MainLoop()
 
			}
 
		}
 
	}
 

	
 
	_wnd.running = true;
 

	
 
	CheckPaletteAnim();
 
	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);
src/video/win32_v.h
Show inline comments
 
@@ -46,18 +46,17 @@ protected:
 
	float GetDPIScale() override;
 
	void InputLoop() override;
 
	bool LockVideoBuffer() override;
 
	void UnlockVideoBuffer() override;
 
	void Paint() override;
 
	void PaintThread() override;
 
	void CheckPaletteAnim() override;
 

	
 
private:
 
	std::unique_lock<std::recursive_mutex> draw_lock;
 

	
 
	void CheckPaletteAnim();
 

	
 
	static void PaintThreadThunk(VideoDriver_Win32 *drv);
 
};
 

	
 
/** The factory for Windows' video driver. */
 
class FVideoDriver_Win32 : public DriverFactoryBase {
 
public:
0 comments (0 inline, 0 general)