From 710ddb9af6f00dd4f73fc19ddf7cf9ca8d5e06ee Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Thu, 6 May 2021 23:56:16 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20Make=20SetPixel=20a=20m?= =?UTF-8?q?ethod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/automap.cpp | 32 ++++++++++++------------- Source/engine.h | 25 +++++++++---------- Source/engine/render/automap_render.cpp | 12 +++++----- Source/qol/xpbar.cpp | 6 ++--- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/Source/automap.cpp b/Source/automap.cpp index edcc241f5..ba5e488b3 100644 --- a/Source/automap.cpp +++ b/Source/automap.cpp @@ -88,22 +88,22 @@ void DrawAutomapTile(const CelOutputBuffer &out, Point center, uint16_t automapT uint8_t flags = automapType >> 8; if ((flags & MapFlagsDirt) != 0) { - SetPixel(out, center, MapColorsDim); - SetPixel(out, { center.x - AmLine8, center.y - AmLine4 }, MapColorsDim); - SetPixel(out, { center.x - AmLine8, center.y + AmLine4 }, MapColorsDim); - SetPixel(out, { center.x + AmLine8, center.y - AmLine4 }, MapColorsDim); - SetPixel(out, { center.x + AmLine8, center.y + AmLine4 }, MapColorsDim); - SetPixel(out, { center.x - AmLine16, center.y }, MapColorsDim); - SetPixel(out, { center.x + AmLine16, center.y }, MapColorsDim); - SetPixel(out, { center.x, center.y - AmLine8 }, MapColorsDim); - SetPixel(out, { center.x, center.y + AmLine8 }, MapColorsDim); - SetPixel(out, { center.x + AmLine8 - AmLine32, center.y + AmLine4 }, MapColorsDim); - SetPixel(out, { center.x - AmLine8 + AmLine32, center.y + AmLine4 }, MapColorsDim); - SetPixel(out, { center.x - AmLine16, center.y + AmLine8 }, MapColorsDim); - SetPixel(out, { center.x + AmLine16, center.y + AmLine8 }, MapColorsDim); - SetPixel(out, { center.x - AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim); - SetPixel(out, { center.x + AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim); - SetPixel(out, { center.x, center.y + AmLine16 }, MapColorsDim); + out.SetPixel(center, MapColorsDim); + out.SetPixel({ center.x - AmLine8, center.y - AmLine4 }, MapColorsDim); + out.SetPixel({ center.x - AmLine8, center.y + AmLine4 }, MapColorsDim); + out.SetPixel({ center.x + AmLine8, center.y - AmLine4 }, MapColorsDim); + out.SetPixel({ center.x + AmLine8, center.y + AmLine4 }, MapColorsDim); + out.SetPixel({ center.x - AmLine16, center.y }, MapColorsDim); + out.SetPixel({ center.x + AmLine16, center.y }, MapColorsDim); + out.SetPixel({ center.x, center.y - AmLine8 }, MapColorsDim); + out.SetPixel({ center.x, center.y + AmLine8 }, MapColorsDim); + out.SetPixel({ center.x + AmLine8 - AmLine32, center.y + AmLine4 }, MapColorsDim); + out.SetPixel({ center.x - AmLine8 + AmLine32, center.y + AmLine4 }, MapColorsDim); + out.SetPixel({ center.x - AmLine16, center.y + AmLine8 }, MapColorsDim); + out.SetPixel({ center.x + AmLine16, center.y + AmLine8 }, MapColorsDim); + out.SetPixel({ center.x - AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim); + out.SetPixel({ center.x + AmLine8, center.y + AmLine16 - AmLine4 }, MapColorsDim); + out.SetPixel({ center.x, center.y + AmLine16 }, MapColorsDim); } if ((flags & MapFlagsStairs) != 0) { diff --git a/Source/engine.h b/Source/engine.h index 3e1b7af16..24fe64134 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -295,6 +295,17 @@ struct CelOutputBuffer { return at(0, region.h); } + /** + * @brief Set the value of a single pixel if it is in bounds. + * @param point Target buffer coordinate + * @param col Color index from current palette + */ + void SetPixel(Point position, std::uint8_t col) const + { + if (InBounds(position)) + (*this)[position] = col; + } + /** * @brief Line width of the raw underlying byte buffer. * May be wider than its logical width (for power-of-2 alignment). @@ -394,20 +405,6 @@ private: CelSprite LoadCel(const char *pszName, int width); CelSprite LoadCel(const char *pszName, const int *widths); -/** - * @brief Set the value of a single pixel in the back buffer, checks bounds - * @param out Target buffer - * @param point Target buffer coordinate - * @param col Color index from current palette - */ -inline void SetPixel(const CelOutputBuffer &out, Point position, std::uint8_t col) -{ - if (!out.InBounds(position)) - return; - - out[position] = col; -} - /** * @brief Draw a horizontal line segment in the target buffer (left to right) * @param out Target buffer diff --git a/Source/engine/render/automap_render.cpp b/Source/engine/render/automap_render.cpp index 3bea82e2b..3af491d5b 100644 --- a/Source/engine/render/automap_render.cpp +++ b/Source/engine/render/automap_render.cpp @@ -17,26 +17,26 @@ template void DrawMapLine(const CelOutputBuffer &out, Point from, int height, std::uint8_t colorIndex) { while (height-- > 0) { - SetPixel(out, from, colorIndex); + out.SetPixel(from, colorIndex); from.x += static_cast(DirX); - SetPixel(out, from, colorIndex); + out.SetPixel(from, colorIndex); from.x += static_cast(DirX); from.y += static_cast(DirY); } - SetPixel(out, from, colorIndex); + out.SetPixel(from, colorIndex); } template void DrawMapLineSteep(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex) { while (width-- > 0) { - SetPixel(out, from, colorIndex); + out.SetPixel(from, colorIndex); from.y += static_cast(DirY); - SetPixel(out, from, colorIndex); + out.SetPixel(from, colorIndex); from.y += static_cast(DirY); from.x += static_cast(DirX); } - SetPixel(out, from, colorIndex); + out.SetPixel(from, colorIndex); } } // namespace diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index d7756bdad..44c84f24c 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -36,9 +36,9 @@ void DrawBar(const CelOutputBuffer &out, int x, int y, int width, const ColorGra void DrawEndCap(const CelOutputBuffer &out, Point point, int idx, const ColorGradient &gradient) { - SetPixel(out, { point.x, point.y + 1 }, gradient[idx * 3 / 4]); - SetPixel(out, { point.x, point.y + 2 }, gradient[idx]); - SetPixel(out, { point.x, point.y + 3 }, gradient[idx / 2]); + out.SetPixel({ point.x, point.y + 1 }, gradient[idx * 3 / 4]); + out.SetPixel({ point.x, point.y + 2 }, gradient[idx]); + out.SetPixel({ point.x, point.y + 3 }, gradient[idx / 2]); } } // namespace