Add more draw functions, make less code use rectangles

Some code still used rectangles to draw things like lines and pixels,
so this commit adds more draw functions to support drawing lines and
pixels without directly using the renderer.

Aside from making generated minimaps draw points instead of 1x1
rectangles, this commit also batches the point drawing for an
additional speed increase.
This commit is contained in:
AllyTally
2023-05-22 14:24:36 -03:00
committed by Misa Elizabeth Kai
parent dc9c51dbf3
commit 5089bc373e
3 changed files with 233 additions and 49 deletions

View File

@@ -1697,15 +1697,10 @@ void customlevelclass::generatecustomminimap(void)
{
for (int i2 = 0; i2 < mapwidth; i2++)
{
int tm;
if (getroomprop(i2, j2)->tileset == 1)
{
tm = 96;
}
else
{
tm = 196;
}
std::vector<SDL_Point> dark_points;
std::vector<SDL_Point> light_points;
bool dark = getroomprop(i2, j2)->tileset == 1;
// Ok, now scan over each square
for (int j = 0; j < 9 * map.customzoom; j++)
@@ -1737,16 +1732,28 @@ void customlevelclass::generatecustomminimap(void)
if (tile >= 1)
{
// Fill in this pixel
graphics.fill_rect(
(i2 * 12 * map.customzoom) + i,
(j2 * 9 * map.customzoom) + j,
1, 1,
graphics.getRGB(tm, tm, tm)
);
// Add this pixel
SDL_Point point = { (i2 * 12 * map.customzoom) + i, (j2 * 9 * map.customzoom) + j };
if (dark)
{
dark_points.push_back(point);
}
else
{
light_points.push_back(point);
}
}
}
}
// Draw them all at once
if (!dark_points.empty())
{
graphics.draw_points(dark_points.data(), dark_points.size(), 96, 96, 96);
}
if (!light_points.empty())
{
graphics.draw_points(light_points.data(), light_points.size(), 196, 196, 196);
}
}
}