diff --git a/Source/engine.cpp b/Source/engine.cpp index be77d79af..7a39d2c44 100644 --- a/Source/engine.cpp +++ b/Source/engine.cpp @@ -551,14 +551,6 @@ void CelBlitOutlineTo(const CelOutputBuffer &out, BYTE col, int sx, int sy, cons } } -void SetPixel(const CelOutputBuffer &out, Point position, BYTE col) -{ - if (!out.in_bounds(position)) - return; - - *out.at(position.x, position.y) = col; -} - void DrawHorizontalLine(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex) { if (from.y < 0 || from.y >= out.h() || from.x >= out.w() || width <= 0 || from.x + width <= 0) @@ -574,7 +566,7 @@ void DrawHorizontalLine(const CelOutputBuffer &out, Point from, int width, std:: void UnsafeDrawHorizontalLine(const CelOutputBuffer &out, Point from, int width, std::uint8_t colorIndex) { - std::memset(out.at(from.x, from.y), colorIndex, width); + std::memset(&out[from], colorIndex, width); } void DrawVerticalLine(const CelOutputBuffer &out, Point from, int height, std::uint8_t colorIndex) @@ -592,7 +584,7 @@ void DrawVerticalLine(const CelOutputBuffer &out, Point from, int height, std::u void UnsafeDrawVerticalLine(const CelOutputBuffer &out, Point from, int height, std::uint8_t colorIndex) { - auto *dst = out.at(from.x, from.y); + auto *dst = &out[from]; const auto pitch = out.pitch(); while (height-- > 0) { *dst = colorIndex; diff --git a/Source/engine.h b/Source/engine.h index a1fd53d7b..b2afeb06c 100644 --- a/Source/engine.h +++ b/Source/engine.h @@ -260,6 +260,11 @@ struct CelOutputBuffer { return region.h; } + std::uint8_t &operator[](Point p) const + { + return *at(p.x, p.y); + } + BYTE *at(int x, int y) const { return static_cast(surface->pixels) + region.x + x + surface->pitch * (region.y + y); @@ -283,7 +288,7 @@ struct CelOutputBuffer { return surface->pitch; } - bool in_bounds(Point position) const + bool InBounds(Point position) const { return position.x >= 0 && position.y >= 0 && position.x < region.w && position.y < region.h; } @@ -520,7 +525,13 @@ void CelBlitOutlineTo(const CelOutputBuffer &out, BYTE col, int sx, int sy, cons * @param point Target buffer coordinate * @param col Color index from current palette */ -void SetPixel(const CelOutputBuffer &out, Point position, BYTE col); +inline void SetPixel(const CelOutputBuffer &out, Point position, std::uint8_t col) +{ + if (!out.InBounds(position)) + return; + + out[position] = col; +} /** * @brief Blit CL2 sprite, to the back buffer at the given coordianates