1
0
Fork 0

Codechange: be consistent in naming the paint function Paint()

Also move this function to be a class member. This to allow
further deduplicating of code in a later commit.
pull/8709/head
Patric Stout 2021-02-20 11:08:20 +01:00 committed by Patric Stout
parent 761efbb457
commit 790fa7102e
11 changed files with 58 additions and 23 deletions

View File

@ -56,7 +56,7 @@ void VideoDriver_Allegro::MakeDirty(int left, int top, int width, int height)
_num_dirty_rects++; _num_dirty_rects++;
} }
static void DrawSurfaceToScreen() void VideoDriver_Allegro::Paint()
{ {
PerformanceMeasurer framerate(PFE_VIDEO); PerformanceMeasurer framerate(PFE_VIDEO);
@ -524,7 +524,7 @@ void VideoDriver_Allegro::MainLoop()
UpdateWindows(); UpdateWindows();
CheckPaletteAnim(); CheckPaletteAnim();
DrawSurfaceToScreen(); this->Paint();
} }
/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */ /* If we are not in fast-forward, create some time between calls to ease up CPU usage. */

View File

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

View File

@ -75,6 +75,7 @@ protected:
Dimension GetScreenSize() const override; Dimension GetScreenSize() const override;
float GetDPIScale() override; float GetDPIScale() override;
void InputLoop() override; void InputLoop() override;
void Paint() override;
private: private:
bool PollEvent(); bool PollEvent();
@ -89,7 +90,6 @@ private:
void UpdatePalette(uint first_color, uint num_colors); void UpdatePalette(uint first_color, uint num_colors);
void CheckPaletteAnim(); void CheckPaletteAnim();
void Draw(bool force_update = false);
void BlitIndexedToView32(int left, int top, int right, int bottom); void BlitIndexedToView32(int left, int top, int right, int bottom);
}; };

View File

@ -465,10 +465,10 @@ void VideoDriver_Cocoa::BlitIndexedToView32(int left, int top, int right, int bo
} }
/** /**
* Draw window. * Paint window.
* @param force_update Whether to redraw unconditionally * @param force_update Whether to redraw unconditionally
*/ */
void VideoDriver_Cocoa::Draw(bool force_update) void VideoDriver_Cocoa::Paint()
{ {
PerformanceMeasurer framerate(PFE_VIDEO); PerformanceMeasurer framerate(PFE_VIDEO);
@ -502,9 +502,8 @@ void VideoDriver_Cocoa::Draw(bool force_update)
dirtyrect.size.height = this->dirty_rects[i].bottom - this->dirty_rects[i].top; dirtyrect.size.height = this->dirty_rects[i].bottom - this->dirty_rects[i].top;
/* Normally drawRect will be automatically called by Mac OS X during next update cycle, /* Normally drawRect will be automatically called by Mac OS X during next update cycle,
* and then blitting will occur. If force_update is true, it will be done right now. */ * and then blitting will occur. */
[ this->cocoaview setNeedsDisplayInRect:[ this->cocoaview getVirtualRect:dirtyrect ] ]; [ this->cocoaview setNeedsDisplayInRect:[ this->cocoaview getVirtualRect:dirtyrect ] ];
if (force_update) [ this->cocoaview displayIfNeeded ];
} }
this->num_dirty_rects = 0; this->num_dirty_rects = 0;
@ -708,7 +707,7 @@ void VideoDriver_Cocoa::GameLoop()
UpdateWindows(); UpdateWindows();
this->CheckPaletteAnim(); this->CheckPaletteAnim();
this->Draw(); this->Paint();
} }
/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */ /* If we are not in fast-forward, create some time between calls to ease up CPU usage. */

View File

@ -124,7 +124,7 @@ void VideoDriver_SDL::CheckPaletteAnim()
this->MakeDirty(0, 0, _screen.width, _screen.height); this->MakeDirty(0, 0, _screen.width, _screen.height);
} }
static void Paint() void VideoDriver_SDL::Paint()
{ {
PerformanceMeasurer framerate(PFE_VIDEO); PerformanceMeasurer framerate(PFE_VIDEO);
@ -161,7 +161,7 @@ static void Paint()
MemSetT(&_dirty_rect, 0); MemSetT(&_dirty_rect, 0);
} }
static void PaintThread() void VideoDriver_SDL::PaintThread()
{ {
/* First tell the main thread we're started */ /* First tell the main thread we're started */
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex); std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
@ -172,11 +172,16 @@ static void PaintThread()
while (_draw_continue) { while (_draw_continue) {
/* Then just draw and wait till we stop */ /* Then just draw and wait till we stop */
Paint(); this->Paint();
_draw_signal->wait(lock); _draw_signal->wait(lock);
} }
} }
/* static */ void VideoDriver_SDL::PaintThreadThunk(VideoDriver_SDL *drv)
{
drv->PaintThread();
}
static const Dimension default_resolutions[] = { static const Dimension default_resolutions[] = {
{ 640, 480 }, { 640, 480 },
{ 800, 600 }, { 800, 600 },
@ -820,7 +825,7 @@ void VideoDriver_SDL::LoopOnce()
if (_draw_mutex != nullptr && !HasModalProgress()) { if (_draw_mutex != nullptr && !HasModalProgress()) {
_draw_signal->notify_one(); _draw_signal->notify_one();
} else { } else {
Paint(); this->Paint();
} }
} }
@ -861,7 +866,7 @@ void VideoDriver_SDL::MainLoop()
_draw_signal = new std::condition_variable_any(); _draw_signal = new std::condition_variable_any();
_draw_continue = true; _draw_continue = true;
_draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &PaintThread); _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &VideoDriver_SDL::PaintThreadThunk, this);
/* Free the mutex if we won't be able to use it. */ /* Free the mutex if we won't be able to use it. */
if (!_draw_threaded) { if (!_draw_threaded) {

View File

@ -46,6 +46,8 @@ protected:
void InputLoop() override; void InputLoop() override;
bool LockVideoBuffer() override; bool LockVideoBuffer() override;
void UnlockVideoBuffer() override; void UnlockVideoBuffer() override;
void Paint() override;
void PaintThread() override;
private: private:
int PollEvent(); int PollEvent();
@ -73,6 +75,8 @@ private:
int startup_display; int startup_display;
std::thread draw_thread; std::thread draw_thread;
std::unique_lock<std::recursive_mutex> draw_lock; std::unique_lock<std::recursive_mutex> draw_lock;
static void PaintThreadThunk(VideoDriver_SDL *drv);
}; };
/** Factory for the SDL video driver. */ /** Factory for the SDL video driver. */

View File

@ -147,7 +147,7 @@ static void CheckPaletteAnim()
} }
} }
static void DrawSurfaceToScreen() void VideoDriver_SDL::Paint()
{ {
PerformanceMeasurer framerate(PFE_VIDEO); PerformanceMeasurer framerate(PFE_VIDEO);
@ -173,7 +173,7 @@ static void DrawSurfaceToScreen()
} }
} }
static void DrawSurfaceToScreenThread() void VideoDriver_SDL::PaintThread()
{ {
/* First tell the main thread we're started */ /* First tell the main thread we're started */
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex); std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
@ -185,11 +185,16 @@ static void DrawSurfaceToScreenThread()
while (_draw_continue) { while (_draw_continue) {
CheckPaletteAnim(); CheckPaletteAnim();
/* Then just draw and wait till we stop */ /* Then just draw and wait till we stop */
DrawSurfaceToScreen(); this->Paint();
_draw_signal->wait(lock); _draw_signal->wait(lock);
} }
} }
/* static */ void VideoDriver_SDL::PaintThreadThunk(VideoDriver_SDL *drv)
{
drv->PaintThread();
}
static const Dimension _default_resolutions[] = { static const Dimension _default_resolutions[] = {
{ 640, 480}, { 640, 480},
{ 800, 600}, { 800, 600},
@ -717,7 +722,7 @@ void VideoDriver_SDL::MainLoop()
_draw_signal = new std::condition_variable_any(); _draw_signal = new std::condition_variable_any();
_draw_continue = true; _draw_continue = true;
_draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &DrawSurfaceToScreenThread); _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-sdl", &VideoDriver_SDL::PaintThreadThunk, this);
/* Free the mutex if we won't be able to use it. */ /* Free the mutex if we won't be able to use it. */
if (!_draw_threaded) { if (!_draw_threaded) {
@ -782,7 +787,7 @@ void VideoDriver_SDL::MainLoop()
_draw_signal->notify_one(); _draw_signal->notify_one();
} else { } else {
CheckPaletteAnim(); CheckPaletteAnim();
DrawSurfaceToScreen(); this->Paint();
} }
} }

View File

@ -41,6 +41,8 @@ protected:
void InputLoop() override; void InputLoop() override;
bool LockVideoBuffer() override; bool LockVideoBuffer() override;
void UnlockVideoBuffer() override; void UnlockVideoBuffer() override;
void Paint() override;
void PaintThread() override;
private: private:
std::unique_lock<std::recursive_mutex> draw_lock; std::unique_lock<std::recursive_mutex> draw_lock;
@ -48,6 +50,8 @@ private:
int PollEvent(); int PollEvent();
bool CreateMainSurface(uint w, uint h); bool CreateMainSurface(uint w, uint h);
void SetupKeyboard(); void SetupKeyboard();
static void PaintThreadThunk(VideoDriver_SDL *drv);
}; };
/** Factory for the SDL video driver. */ /** Factory for the SDL video driver. */

View File

@ -174,6 +174,16 @@ protected:
*/ */
virtual void UnlockVideoBuffer() {} virtual void UnlockVideoBuffer() {}
/**
* Paint the window.
*/
virtual void Paint() {}
/**
* Thread function for threaded drawing.
*/
virtual void PaintThread() {}
std::chrono::steady_clock::duration GetGameInterval() std::chrono::steady_clock::duration GetGameInterval()
{ {
return std::chrono::milliseconds(MILLISECONDS_PER_TICK); return std::chrono::milliseconds(MILLISECONDS_PER_TICK);

View File

@ -332,7 +332,7 @@ bool VideoDriver_Win32::MakeWindow(bool full_screen)
} }
/** Do palette animation and blit to the window. */ /** Do palette animation and blit to the window. */
static void PaintWindow() void VideoDriver_Win32::Paint()
{ {
PerformanceMeasurer framerate(PFE_VIDEO); PerformanceMeasurer framerate(PFE_VIDEO);
@ -385,7 +385,7 @@ static void PaintWindow()
MemSetT(&_dirty_rect, 0); MemSetT(&_dirty_rect, 0);
} }
static void PaintWindowThread() void VideoDriver_Win32::PaintThread()
{ {
/* First tell the main thread we're started */ /* First tell the main thread we're started */
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex); std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
@ -395,7 +395,7 @@ static void PaintWindowThread()
_draw_signal->wait(*_draw_mutex); _draw_signal->wait(*_draw_mutex);
while (_draw_continue) { while (_draw_continue) {
PaintWindow(); this->Paint();
/* Flush GDI buffer to ensure drawing here doesn't conflict with any GDI usage in the main WndProc. */ /* Flush GDI buffer to ensure drawing here doesn't conflict with any GDI usage in the main WndProc. */
GdiFlush(); GdiFlush();
@ -404,6 +404,11 @@ static void PaintWindowThread()
} }
} }
/* static */ void VideoDriver_Win32::PaintThreadThunk(VideoDriver_Win32 *drv)
{
drv->PaintThread();
}
/** Forward key presses to the window system. */ /** Forward key presses to the window system. */
static LRESULT HandleCharMsg(uint keycode, WChar charcode) static LRESULT HandleCharMsg(uint keycode, WChar charcode)
{ {
@ -1176,7 +1181,7 @@ void VideoDriver_Win32::MainLoop()
this->draw_lock = std::unique_lock<std::recursive_mutex>(*_draw_mutex); this->draw_lock = std::unique_lock<std::recursive_mutex>(*_draw_mutex);
_draw_continue = true; _draw_continue = true;
_draw_threaded = StartNewThread(&draw_thread, "ottd:draw-win32", &PaintWindowThread); _draw_threaded = StartNewThread(&draw_thread, "ottd:draw-win32", &VideoDriver_Win32::PaintThreadThunk, this);
/* Free the mutex if we won't be able to use it. */ /* Free the mutex if we won't be able to use it. */
if (!_draw_threaded) { if (!_draw_threaded) {
@ -1254,7 +1259,7 @@ void VideoDriver_Win32::MainLoop()
if (_draw_mutex != nullptr && !HasModalProgress()) { if (_draw_mutex != nullptr && !HasModalProgress()) {
_draw_signal->notify_one(); _draw_signal->notify_one();
} else { } else {
PaintWindow(); this->Paint();
} }
} }

View File

@ -47,6 +47,8 @@ protected:
void InputLoop() override; void InputLoop() override;
bool LockVideoBuffer() override; bool LockVideoBuffer() override;
void UnlockVideoBuffer() override; void UnlockVideoBuffer() override;
void Paint() override;
void PaintThread() override;
private: private:
std::unique_lock<std::recursive_mutex> draw_lock; std::unique_lock<std::recursive_mutex> draw_lock;