From fc0e0d029a0c24dd02b104f6d5f17351e79c60c4 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Mon, 3 Apr 2023 22:18:42 +0200 Subject: [PATCH] Use dpi ref in ui context and weather --- src/openrct2-ui/UiContext.cpp | 18 +++++++++--------- .../engines/opengl/OpenGLDrawingEngine.cpp | 14 +++++++------- src/openrct2/drawing/IDrawingEngine.h | 2 +- src/openrct2/drawing/Weather.cpp | 18 +++++++++--------- src/openrct2/drawing/Weather.h | 2 +- src/openrct2/drawing/X8DrawingEngine.cpp | 10 +++++----- src/openrct2/drawing/X8DrawingEngine.h | 2 +- src/openrct2/paint/Painter.cpp | 4 ++-- src/openrct2/title/TitleScreen.cpp | 6 +++--- src/openrct2/title/TitleScreen.h | 2 +- src/openrct2/ui/DummyUiContext.cpp | 4 ++-- src/openrct2/ui/UiContext.h | 6 +++--- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/openrct2-ui/UiContext.cpp b/src/openrct2-ui/UiContext.cpp index 1a37c58ed2..2cd1e99242 100644 --- a/src/openrct2-ui/UiContext.cpp +++ b/src/openrct2-ui/UiContext.cpp @@ -142,11 +142,11 @@ public: _inGameConsole.Update(); } - void Draw(DrawPixelInfo* dpi) override + void Draw(DrawPixelInfo& dpi) override { auto bgColour = ThemeGetColour(WindowClass::Chat, 0); - ChatDraw(*dpi, bgColour); - _inGameConsole.Draw(*dpi); + ChatDraw(dpi, bgColour); + _inGameConsole.Draw(dpi); } // Window @@ -291,12 +291,12 @@ public: return std::make_shared(); } - void DrawWeatherAnimation(IWeatherDrawer* weatherDrawer, DrawPixelInfo* dpi, DrawWeatherFunc drawFunc) override + void DrawWeatherAnimation(IWeatherDrawer* weatherDrawer, DrawPixelInfo& dpi, DrawWeatherFunc drawFunc) override { - int32_t left = dpi->x; - int32_t right = left + dpi->width; - int32_t top = dpi->y; - int32_t bottom = top + dpi->height; + int32_t left = dpi.x; + int32_t right = left + dpi.width; + int32_t top = dpi.y; + int32_t bottom = top + dpi.height; for (auto& w : g_window_list) { @@ -888,7 +888,7 @@ private: } static void DrawWeatherWindow( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, WindowBase* original_w, int16_t left, int16_t right, int16_t top, + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, WindowBase* original_w, int16_t left, int16_t right, int16_t top, int16_t bottom, DrawWeatherFunc drawFunc) { WindowBase* w{}; diff --git a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp index 02da93da61..2372e3dff9 100644 --- a/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp +++ b/src/openrct2-ui/drawing/engines/opengl/OpenGLDrawingEngine.cpp @@ -131,7 +131,7 @@ public: } virtual void Draw( - DrawPixelInfo* dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, + DrawPixelInfo& dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, const uint8_t* weatherpattern) override { const uint8_t* pattern = weatherpattern; @@ -141,7 +141,7 @@ public: uint8_t patternStartXOffset = xStart % patternXSpace; uint8_t patternStartYOffset = yStart % patternYSpace; - uint32_t pixelOffset = (dpi->pitch + dpi->width) * y + x; + uint32_t pixelOffset = (dpi.pitch + dpi.width) * y + x; uint8_t patternYPos = patternStartYOffset % patternYSpace; for (; height != 0; height--) @@ -157,14 +157,14 @@ public: auto patternPixel = pattern[patternYPos * 2 + 1]; for (; xPixelOffset < finalPixelOffset; xPixelOffset += patternXSpace) { - int32_t pixelX = xPixelOffset % dpi->width; - int32_t pixelY = (xPixelOffset / dpi->width) % dpi->height; + int32_t pixelX = xPixelOffset % dpi.width; + int32_t pixelY = (xPixelOffset / dpi.width) % dpi.height; - _drawingContext->DrawLine(dpi, patternPixel, { { pixelX, pixelY }, { pixelX + 1, pixelY + 1 } }); + _drawingContext->DrawLine(&dpi, patternPixel, { { pixelX, pixelY }, { pixelX + 1, pixelY + 1 } }); } } - pixelOffset += dpi->pitch + dpi->width; + pixelOffset += dpi.pitch + dpi.width; patternYPos++; patternYPos %= patternYSpace; } @@ -332,7 +332,7 @@ public: { _drawingContext->CalculcateClipping(&_bitsDPI); - DrawWeather(&_bitsDPI, &_weatherDrawer); + DrawWeather(_bitsDPI, &_weatherDrawer); } std::string Screenshot() override diff --git a/src/openrct2/drawing/IDrawingEngine.h b/src/openrct2/drawing/IDrawingEngine.h index 974819b226..7f0d24eb51 100644 --- a/src/openrct2/drawing/IDrawingEngine.h +++ b/src/openrct2/drawing/IDrawingEngine.h @@ -92,7 +92,7 @@ namespace OpenRCT2::Drawing { virtual ~IWeatherDrawer() = default; virtual void Draw( - DrawPixelInfo* dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, + DrawPixelInfo& dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, const uint8_t* weatherpattern) abstract; }; } // namespace OpenRCT2::Drawing diff --git a/src/openrct2/drawing/Weather.cpp b/src/openrct2/drawing/Weather.cpp index 3a5c30fd47..9c15fa91d8 100644 --- a/src/openrct2/drawing/Weather.cpp +++ b/src/openrct2/drawing/Weather.cpp @@ -23,13 +23,13 @@ using namespace OpenRCT2; using namespace OpenRCT2::Drawing; static void DrawLightRain( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); static void DrawHeavyRain( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); static void DrawLightSnow( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); static void DrawHeavySnow( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); /** * @@ -51,7 +51,7 @@ const DrawWeatherFunc DrawSnowFunctions[] = { * * rct2: 0x00684218 */ -void DrawWeather(DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer) +void DrawWeather(DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer) { if (gConfigGeneral.RenderWeatherEffects) { @@ -81,7 +81,7 @@ void DrawWeather(DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer) * rct2: 0x00684114 */ static void DrawLightRain( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) { int32_t x_start = -static_cast(gCurrentTicks) + 8; int32_t y_start = (gCurrentTicks * 3) + 7; @@ -103,7 +103,7 @@ static void DrawLightRain( * rct2: 0x0068416D */ static void DrawHeavyRain( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) { int32_t x_start = -static_cast(gCurrentTicks); int32_t y_start = gCurrentTicks * 5; @@ -135,7 +135,7 @@ static void DrawHeavyRain( } static void DrawLightSnow( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) { const uint32_t t = gCurrentTicks / 2; const int32_t negT = -static_cast(t); @@ -157,7 +157,7 @@ static void DrawLightSnow( } static void DrawHeavySnow( - DrawPixelInfo* dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) + DrawPixelInfo& dpi, IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height) { int32_t x_start = -static_cast(gCurrentTicks * 3) + 1; int32_t y_start = gCurrentTicks + 23; diff --git a/src/openrct2/drawing/Weather.h b/src/openrct2/drawing/Weather.h index 20d1acb032..5c98e2a00b 100644 --- a/src/openrct2/drawing/Weather.h +++ b/src/openrct2/drawing/Weather.h @@ -37,4 +37,4 @@ static constexpr const uint8_t SnowPattern[] = // clang-format on -void DrawWeather(DrawPixelInfo* dpi, OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer); +void DrawWeather(DrawPixelInfo& dpi, OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer); diff --git a/src/openrct2/drawing/X8DrawingEngine.cpp b/src/openrct2/drawing/X8DrawingEngine.cpp index a2cc5f7e7a..820a5e34f4 100644 --- a/src/openrct2/drawing/X8DrawingEngine.cpp +++ b/src/openrct2/drawing/X8DrawingEngine.cpp @@ -44,7 +44,7 @@ X8WeatherDrawer::~X8WeatherDrawer() } void X8WeatherDrawer::Draw( - DrawPixelInfo* dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, + DrawPixelInfo& dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, const uint8_t* weatherpattern) { const uint8_t* pattern = weatherpattern; @@ -54,10 +54,10 @@ void X8WeatherDrawer::Draw( uint8_t patternStartXOffset = xStart % patternXSpace; uint8_t patternStartYOffset = yStart % patternYSpace; - uint32_t pixelOffset = (dpi->pitch + dpi->width) * y + x; + uint32_t pixelOffset = (dpi.pitch + dpi.width) * y + x; uint8_t patternYPos = patternStartYOffset % patternYSpace; - uint8_t* screenBits = dpi->bits; + uint8_t* screenBits = dpi.bits; // Stores the colours of changed pixels WeatherPixel* newPixels = &_weatherPixels[_weatherPixelsCount]; @@ -86,7 +86,7 @@ void X8WeatherDrawer::Draw( } } - pixelOffset += dpi->pitch + dpi->width; + pixelOffset += dpi.pitch + dpi.width; patternYPos++; patternYPos %= patternYSpace; } @@ -214,7 +214,7 @@ void X8DrawingEngine::PaintWindows() void X8DrawingEngine::PaintWeather() { - DrawWeather(&_bitsDPI, &_weatherDrawer); + DrawWeather(_bitsDPI, &_weatherDrawer); } void X8DrawingEngine::CopyRect(int32_t x, int32_t y, int32_t width, int32_t height, int32_t dx, int32_t dy) diff --git a/src/openrct2/drawing/X8DrawingEngine.h b/src/openrct2/drawing/X8DrawingEngine.h index 7db0a27e34..15af40cc0a 100644 --- a/src/openrct2/drawing/X8DrawingEngine.h +++ b/src/openrct2/drawing/X8DrawingEngine.h @@ -56,7 +56,7 @@ namespace OpenRCT2 X8WeatherDrawer(); ~X8WeatherDrawer(); void Draw( - DrawPixelInfo* dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, + DrawPixelInfo& dpi, int32_t x, int32_t y, int32_t width, int32_t height, int32_t xStart, int32_t yStart, const uint8_t* weatherpattern) override; void Restore(DrawPixelInfo* dpi); }; diff --git a/src/openrct2/paint/Painter.cpp b/src/openrct2/paint/Painter.cpp index f9f64342ca..9867dae9ca 100644 --- a/src/openrct2/paint/Painter.cpp +++ b/src/openrct2/paint/Painter.cpp @@ -50,11 +50,11 @@ void Painter::Paint(IDrawingEngine& de) de.PaintWindows(); UpdatePaletteEffects(); - _uiContext->Draw(dpi); + _uiContext->Draw(*dpi); if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !TitleShouldHideVersionInfo()) { - DrawOpenRCT2(dpi, { 0, _uiContext->GetHeight() - 20 }); + DrawOpenRCT2(*dpi, { 0, _uiContext->GetHeight() - 20 }); } GfxDrawPickedUpPeep(dpi); diff --git a/src/openrct2/title/TitleScreen.cpp b/src/openrct2/title/TitleScreen.cpp index e8188b0943..1a3f72b6cc 100644 --- a/src/openrct2/title/TitleScreen.cpp +++ b/src/openrct2/title/TitleScreen.cpp @@ -440,7 +440,7 @@ bool TitleIsPreviewingSequence() return false; } -void DrawOpenRCT2(DrawPixelInfo* dpi, const ScreenCoordsXY& screenCoords) +void DrawOpenRCT2(DrawPixelInfo& dpi, const ScreenCoordsXY& screenCoords) { thread_local std::string buffer; buffer.clear(); @@ -448,7 +448,7 @@ void DrawOpenRCT2(DrawPixelInfo* dpi, const ScreenCoordsXY& screenCoords) // Write name and version information buffer += gVersionInfoFull; - GfxDrawString(*dpi, screenCoords + ScreenCoordsXY(5, 5 - 13), buffer.c_str(), { COLOUR_BLACK }); + GfxDrawString(dpi, screenCoords + ScreenCoordsXY(5, 5 - 13), buffer.c_str(), { COLOUR_BLACK }); // Invalidate screen area int16_t width = static_cast(GfxGetStringWidth(buffer, FontStyle::Medium)); @@ -461,5 +461,5 @@ void DrawOpenRCT2(DrawPixelInfo* dpi, const ScreenCoordsXY& screenCoords) buffer.append(" ("); buffer.append(OPENRCT2_ARCHITECTURE); buffer.append(")"); - GfxDrawString(*dpi, screenCoords + ScreenCoordsXY(5, 5), buffer.c_str(), { COLOUR_BLACK }); + GfxDrawString(dpi, screenCoords + ScreenCoordsXY(5, 5), buffer.c_str(), { COLOUR_BLACK }); } diff --git a/src/openrct2/title/TitleScreen.h b/src/openrct2/title/TitleScreen.h index 28e7cfe751..4cbe866f3c 100644 --- a/src/openrct2/title/TitleScreen.h +++ b/src/openrct2/title/TitleScreen.h @@ -65,4 +65,4 @@ size_t TitleGetCurrentSequence(); bool TitlePreviewSequence(size_t value); void TitleStopPreviewingSequence(); bool TitleIsPreviewingSequence(); -void DrawOpenRCT2(DrawPixelInfo* dpi, const ScreenCoordsXY& screenCoords); +void DrawOpenRCT2(DrawPixelInfo& dpi, const ScreenCoordsXY& screenCoords); diff --git a/src/openrct2/ui/DummyUiContext.cpp b/src/openrct2/ui/DummyUiContext.cpp index 17323a7378..ed0e7c4875 100644 --- a/src/openrct2/ui/DummyUiContext.cpp +++ b/src/openrct2/ui/DummyUiContext.cpp @@ -31,7 +31,7 @@ namespace OpenRCT2::Ui void Tick() override { } - void Draw(DrawPixelInfo* /*dpi*/) override + void Draw(DrawPixelInfo& /*dpi*/) override { } @@ -173,7 +173,7 @@ namespace OpenRCT2::Ui { return std::make_shared(); } - void DrawWeatherAnimation(IWeatherDrawer* weatherDrawer, DrawPixelInfo* dpi, DrawWeatherFunc drawFunc) override + void DrawWeatherAnimation(IWeatherDrawer* weatherDrawer, DrawPixelInfo& dpi, DrawWeatherFunc drawFunc) override { } diff --git a/src/openrct2/ui/UiContext.h b/src/openrct2/ui/UiContext.h index 52f4c13cde..da43eebe19 100644 --- a/src/openrct2/ui/UiContext.h +++ b/src/openrct2/ui/UiContext.h @@ -29,7 +29,7 @@ namespace OpenRCT2 struct IDrawingEngineFactory; struct IWeatherDrawer; using DrawWeatherFunc = void (*)( - DrawPixelInfo* dpi, OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, + DrawPixelInfo& dpi, OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, int32_t left, int32_t top, int32_t width, int32_t height); } // namespace Drawing @@ -101,7 +101,7 @@ namespace OpenRCT2 virtual void Initialise() abstract; virtual void Tick() abstract; - virtual void Draw(DrawPixelInfo* dpi) abstract; + virtual void Draw(DrawPixelInfo& dpi) abstract; // Window virtual void CreateWindow() abstract; @@ -149,7 +149,7 @@ namespace OpenRCT2 // Drawing [[nodiscard]] virtual std::shared_ptr GetDrawingEngineFactory() abstract; virtual void DrawWeatherAnimation( - OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, DrawPixelInfo* dpi, + OpenRCT2::Drawing::IWeatherDrawer* weatherDrawer, DrawPixelInfo& dpi, OpenRCT2::Drawing::DrawWeatherFunc drawFunc) abstract; // Text input