Browse Source

♻️ Make SetPixel a method

pull/1888/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
710ddb9af6
  1. 32
      Source/automap.cpp
  2. 25
      Source/engine.h
  3. 12
      Source/engine/render/automap_render.cpp
  4. 6
      Source/qol/xpbar.cpp

32
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) {

25
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

12
Source/engine/render/automap_render.cpp

@ -17,26 +17,26 @@ template <DirectionX DirX, DirectionY DirY>
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<int>(DirX);
SetPixel(out, from, colorIndex);
out.SetPixel(from, colorIndex);
from.x += static_cast<int>(DirX);
from.y += static_cast<int>(DirY);
}
SetPixel(out, from, colorIndex);
out.SetPixel(from, colorIndex);
}
template <DirectionX DirX, DirectionY DirY>
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<int>(DirY);
SetPixel(out, from, colorIndex);
out.SetPixel(from, colorIndex);
from.y += static_cast<int>(DirY);
from.x += static_cast<int>(DirX);
}
SetPixel(out, from, colorIndex);
out.SetPixel(from, colorIndex);
}
} // namespace

6
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

Loading…
Cancel
Save