mirror of https://github.com/OpenTTD/OpenTTD
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
parent
761efbb457
commit
790fa7102e
|
@ -56,7 +56,7 @@ void VideoDriver_Allegro::MakeDirty(int left, int top, int width, int height)
|
|||
_num_dirty_rects++;
|
||||
}
|
||||
|
||||
static void DrawSurfaceToScreen()
|
||||
void VideoDriver_Allegro::Paint()
|
||||
{
|
||||
PerformanceMeasurer framerate(PFE_VIDEO);
|
||||
|
||||
|
@ -524,7 +524,7 @@ void VideoDriver_Allegro::MainLoop()
|
|||
UpdateWindows();
|
||||
CheckPaletteAnim();
|
||||
|
||||
DrawSurfaceToScreen();
|
||||
this->Paint();
|
||||
}
|
||||
|
||||
/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
|
||||
protected:
|
||||
void InputLoop() override;
|
||||
void Paint() override;
|
||||
};
|
||||
|
||||
/** Factory for the allegro video driver. */
|
||||
|
|
|
@ -75,6 +75,7 @@ protected:
|
|||
Dimension GetScreenSize() const override;
|
||||
float GetDPIScale() override;
|
||||
void InputLoop() override;
|
||||
void Paint() override;
|
||||
|
||||
private:
|
||||
bool PollEvent();
|
||||
|
@ -89,7 +90,6 @@ private:
|
|||
void UpdatePalette(uint first_color, uint num_colors);
|
||||
void CheckPaletteAnim();
|
||||
|
||||
void Draw(bool force_update = false);
|
||||
void BlitIndexedToView32(int left, int top, int right, int bottom);
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
void VideoDriver_Cocoa::Draw(bool force_update)
|
||||
void VideoDriver_Cocoa::Paint()
|
||||
{
|
||||
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;
|
||||
|
||||
/* 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 ] ];
|
||||
if (force_update) [ this->cocoaview displayIfNeeded ];
|
||||
}
|
||||
|
||||
this->num_dirty_rects = 0;
|
||||
|
@ -708,7 +707,7 @@ void VideoDriver_Cocoa::GameLoop()
|
|||
UpdateWindows();
|
||||
this->CheckPaletteAnim();
|
||||
|
||||
this->Draw();
|
||||
this->Paint();
|
||||
}
|
||||
|
||||
/* If we are not in fast-forward, create some time between calls to ease up CPU usage. */
|
||||
|
|
|
@ -124,7 +124,7 @@ void VideoDriver_SDL::CheckPaletteAnim()
|
|||
this->MakeDirty(0, 0, _screen.width, _screen.height);
|
||||
}
|
||||
|
||||
static void Paint()
|
||||
void VideoDriver_SDL::Paint()
|
||||
{
|
||||
PerformanceMeasurer framerate(PFE_VIDEO);
|
||||
|
||||
|
@ -161,7 +161,7 @@ static void Paint()
|
|||
MemSetT(&_dirty_rect, 0);
|
||||
}
|
||||
|
||||
static void PaintThread()
|
||||
void VideoDriver_SDL::PaintThread()
|
||||
{
|
||||
/* First tell the main thread we're started */
|
||||
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
|
||||
|
@ -172,11 +172,16 @@ static void PaintThread()
|
|||
|
||||
while (_draw_continue) {
|
||||
/* Then just draw and wait till we stop */
|
||||
Paint();
|
||||
this->Paint();
|
||||
_draw_signal->wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void VideoDriver_SDL::PaintThreadThunk(VideoDriver_SDL *drv)
|
||||
{
|
||||
drv->PaintThread();
|
||||
}
|
||||
|
||||
static const Dimension default_resolutions[] = {
|
||||
{ 640, 480 },
|
||||
{ 800, 600 },
|
||||
|
@ -820,7 +825,7 @@ void VideoDriver_SDL::LoopOnce()
|
|||
if (_draw_mutex != nullptr && !HasModalProgress()) {
|
||||
_draw_signal->notify_one();
|
||||
} else {
|
||||
Paint();
|
||||
this->Paint();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -861,7 +866,7 @@ void VideoDriver_SDL::MainLoop()
|
|||
_draw_signal = new std::condition_variable_any();
|
||||
_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. */
|
||||
if (!_draw_threaded) {
|
||||
|
|
|
@ -46,6 +46,8 @@ protected:
|
|||
void InputLoop() override;
|
||||
bool LockVideoBuffer() override;
|
||||
void UnlockVideoBuffer() override;
|
||||
void Paint() override;
|
||||
void PaintThread() override;
|
||||
|
||||
private:
|
||||
int PollEvent();
|
||||
|
@ -73,6 +75,8 @@ private:
|
|||
int startup_display;
|
||||
std::thread draw_thread;
|
||||
std::unique_lock<std::recursive_mutex> draw_lock;
|
||||
|
||||
static void PaintThreadThunk(VideoDriver_SDL *drv);
|
||||
};
|
||||
|
||||
/** Factory for the SDL video driver. */
|
||||
|
|
|
@ -147,7 +147,7 @@ static void CheckPaletteAnim()
|
|||
}
|
||||
}
|
||||
|
||||
static void DrawSurfaceToScreen()
|
||||
void VideoDriver_SDL::Paint()
|
||||
{
|
||||
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 */
|
||||
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
|
||||
|
@ -185,11 +185,16 @@ static void DrawSurfaceToScreenThread()
|
|||
while (_draw_continue) {
|
||||
CheckPaletteAnim();
|
||||
/* Then just draw and wait till we stop */
|
||||
DrawSurfaceToScreen();
|
||||
this->Paint();
|
||||
_draw_signal->wait(lock);
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void VideoDriver_SDL::PaintThreadThunk(VideoDriver_SDL *drv)
|
||||
{
|
||||
drv->PaintThread();
|
||||
}
|
||||
|
||||
static const Dimension _default_resolutions[] = {
|
||||
{ 640, 480},
|
||||
{ 800, 600},
|
||||
|
@ -717,7 +722,7 @@ void VideoDriver_SDL::MainLoop()
|
|||
_draw_signal = new std::condition_variable_any();
|
||||
_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. */
|
||||
if (!_draw_threaded) {
|
||||
|
@ -782,7 +787,7 @@ void VideoDriver_SDL::MainLoop()
|
|||
_draw_signal->notify_one();
|
||||
} else {
|
||||
CheckPaletteAnim();
|
||||
DrawSurfaceToScreen();
|
||||
this->Paint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,8 @@ protected:
|
|||
void InputLoop() override;
|
||||
bool LockVideoBuffer() override;
|
||||
void UnlockVideoBuffer() override;
|
||||
void Paint() override;
|
||||
void PaintThread() override;
|
||||
|
||||
private:
|
||||
std::unique_lock<std::recursive_mutex> draw_lock;
|
||||
|
@ -48,6 +50,8 @@ private:
|
|||
int PollEvent();
|
||||
bool CreateMainSurface(uint w, uint h);
|
||||
void SetupKeyboard();
|
||||
|
||||
static void PaintThreadThunk(VideoDriver_SDL *drv);
|
||||
};
|
||||
|
||||
/** Factory for the SDL video driver. */
|
||||
|
|
|
@ -174,6 +174,16 @@ protected:
|
|||
*/
|
||||
virtual void UnlockVideoBuffer() {}
|
||||
|
||||
/**
|
||||
* Paint the window.
|
||||
*/
|
||||
virtual void Paint() {}
|
||||
|
||||
/**
|
||||
* Thread function for threaded drawing.
|
||||
*/
|
||||
virtual void PaintThread() {}
|
||||
|
||||
std::chrono::steady_clock::duration GetGameInterval()
|
||||
{
|
||||
return std::chrono::milliseconds(MILLISECONDS_PER_TICK);
|
||||
|
|
|
@ -332,7 +332,7 @@ bool VideoDriver_Win32::MakeWindow(bool full_screen)
|
|||
}
|
||||
|
||||
/** Do palette animation and blit to the window. */
|
||||
static void PaintWindow()
|
||||
void VideoDriver_Win32::Paint()
|
||||
{
|
||||
PerformanceMeasurer framerate(PFE_VIDEO);
|
||||
|
||||
|
@ -385,7 +385,7 @@ static void PaintWindow()
|
|||
MemSetT(&_dirty_rect, 0);
|
||||
}
|
||||
|
||||
static void PaintWindowThread()
|
||||
void VideoDriver_Win32::PaintThread()
|
||||
{
|
||||
/* First tell the main thread we're started */
|
||||
std::unique_lock<std::recursive_mutex> lock(*_draw_mutex);
|
||||
|
@ -395,7 +395,7 @@ static void PaintWindowThread()
|
|||
_draw_signal->wait(*_draw_mutex);
|
||||
|
||||
while (_draw_continue) {
|
||||
PaintWindow();
|
||||
this->Paint();
|
||||
|
||||
/* Flush GDI buffer to ensure drawing here doesn't conflict with any GDI usage in the main WndProc. */
|
||||
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. */
|
||||
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);
|
||||
|
||||
_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. */
|
||||
if (!_draw_threaded) {
|
||||
|
@ -1254,7 +1259,7 @@ void VideoDriver_Win32::MainLoop()
|
|||
if (_draw_mutex != nullptr && !HasModalProgress()) {
|
||||
_draw_signal->notify_one();
|
||||
} else {
|
||||
PaintWindow();
|
||||
this->Paint();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ protected:
|
|||
void InputLoop() override;
|
||||
bool LockVideoBuffer() override;
|
||||
void UnlockVideoBuffer() override;
|
||||
void Paint() override;
|
||||
void PaintThread() override;
|
||||
|
||||
private:
|
||||
std::unique_lock<std::recursive_mutex> draw_lock;
|
||||
|
|
Loading…
Reference in New Issue