summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-02-20 11:15:15 +0100
committerPatric Stout <github@truebrain.nl>2021-02-20 17:08:44 +0100
commitec1dd0bf618f2c4fe17c62db9eec3b5e056574a0 (patch)
tree07ccc0fcb66cc6f73b01fc9e0cf1b29f6b82e7cb /src/video
parent790fa7102ec934544b427dd5fa9fc4f7099fd4da (diff)
downloadopenttd-ec1dd0bf618f2c4fe17c62db9eec3b5e056574a0.tar.xz
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.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/allegro_v.cpp6
-rw-r--r--src/video/allegro_v.h1
-rw-r--r--src/video/cocoa/cocoa_v.h2
-rw-r--r--src/video/sdl2_v.cpp2
-rw-r--r--src/video/sdl2_v.h2
-rw-r--r--src/video/sdl_v.cpp10
-rw-r--r--src/video/sdl_v.h1
-rw-r--r--src/video/video_driver.hpp5
-rw-r--r--src/video/win32_v.cpp1
-rw-r--r--src/video/win32_v.h3
10 files changed, 16 insertions, 17 deletions
diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp
index 9b5b2e1d9..883e1f72e 100644
--- a/src/video/allegro_v.cpp
+++ b/src/video/allegro_v.cpp
@@ -95,7 +95,7 @@ static void InitPalette()
UpdatePalette(0, 256);
}
-static void CheckPaletteAnim()
+void VideoDriver_Allegro::CheckPaletteAnim()
{
if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
@@ -484,8 +484,6 @@ void VideoDriver_Allegro::MainLoop()
auto next_game_tick = cur_ticks;
auto next_draw_tick = cur_ticks;
- CheckPaletteAnim();
-
for (;;) {
InteractiveRandom(); // randomness
@@ -522,7 +520,7 @@ void VideoDriver_Allegro::MainLoop()
this->InputLoop();
::InputLoop();
UpdateWindows();
- CheckPaletteAnim();
+ this->CheckPaletteAnim();
this->Paint();
}
diff --git a/src/video/allegro_v.h b/src/video/allegro_v.h
index 3c55a6691..2ab74fa30 100644
--- a/src/video/allegro_v.h
+++ b/src/video/allegro_v.h
@@ -36,6 +36,7 @@ public:
protected:
void InputLoop() override;
void Paint() override;
+ void CheckPaletteAnim() override;
};
/** Factory for the allegro video driver. */
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h
index 09668ed8b..7e4d8c9fd 100644
--- a/src/video/cocoa/cocoa_v.h
+++ b/src/video/cocoa/cocoa_v.h
@@ -76,6 +76,7 @@ protected:
float GetDPIScale() override;
void InputLoop() override;
void Paint() override;
+ void CheckPaletteAnim() override;
private:
bool PollEvent();
@@ -88,7 +89,6 @@ private:
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);
};
diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp
index 1cc6c5598..7c406b677 100644
--- a/src/video/sdl2_v.cpp
+++ b/src/video/sdl2_v.cpp
@@ -853,8 +853,6 @@ void VideoDriver_SDL::MainLoop()
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. */
diff --git a/src/video/sdl2_v.h b/src/video/sdl2_v.h
index 91f4b2c7f..4f1f286c9 100644
--- a/src/video/sdl2_v.h
+++ b/src/video/sdl2_v.h
@@ -48,6 +48,7 @@ protected:
void UnlockVideoBuffer() override;
void Paint() override;
void PaintThread() override;
+ void CheckPaletteAnim();
private:
int PollEvent();
@@ -55,7 +56,6 @@ private:
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. */
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index 0aa216df2..ab91cb56a 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -123,8 +123,10 @@ static void InitPalette()
UpdatePalette(true);
}
-static void CheckPaletteAnim()
+void VideoDriver_SDL::CheckPaletteAnim()
{
+ _local_palette = _cur_palette;
+
if (_cur_palette.count_dirty != 0) {
Blitter *blitter = BlitterFactory::GetCurrentBlitter();
@@ -183,7 +185,6 @@ void VideoDriver_SDL::PaintThread()
_draw_signal->wait(*_draw_mutex);
while (_draw_continue) {
- CheckPaletteAnim();
/* Then just draw and wait till we stop */
this->Paint();
_draw_signal->wait(lock);
@@ -708,8 +709,6 @@ void VideoDriver_SDL::MainLoop()
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*
@@ -781,12 +780,11 @@ void VideoDriver_SDL::MainLoop()
this->InputLoop();
::InputLoop();
UpdateWindows();
- _local_palette = _cur_palette;
+ this->CheckPaletteAnim();
if (_draw_mutex != nullptr && !HasModalProgress()) {
_draw_signal->notify_one();
} else {
- CheckPaletteAnim();
this->Paint();
}
}
diff --git a/src/video/sdl_v.h b/src/video/sdl_v.h
index a51062d85..be6010aca 100644
--- a/src/video/sdl_v.h
+++ b/src/video/sdl_v.h
@@ -43,6 +43,7 @@ protected:
void UnlockVideoBuffer() override;
void Paint() override;
void PaintThread() override;
+ void CheckPaletteAnim();
private:
std::unique_lock<std::recursive_mutex> draw_lock;
diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp
index b8acb2bb8..768b2fe6c 100644
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -184,6 +184,11 @@ protected:
*/
virtual void PaintThread() {}
+ /**
+ * Process any pending palette animation.
+ */
+ virtual void CheckPaletteAnim() {}
+
std::chrono::steady_clock::duration GetGameInterval()
{
return std::chrono::milliseconds(MILLISECONDS_PER_TICK);
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 8e887f0aa..2024aec18 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -1201,7 +1201,6 @@ void VideoDriver_Win32::MainLoop()
_wnd.running = true;
- CheckPaletteAnim();
for (;;) {
InteractiveRandom(); // randomness
diff --git a/src/video/win32_v.h b/src/video/win32_v.h
index d51594418..695477085 100644
--- a/src/video/win32_v.h
+++ b/src/video/win32_v.h
@@ -49,12 +49,11 @@ protected:
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);
};