feat: added basic culling to cell renderer

This commit is contained in:
Sara Gerretsen 2025-09-23 14:25:26 +02:00
parent 658b96b201
commit 5484039e3e

View file

@ -271,8 +271,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
viewOffset.x += input::scrollMotion.x;
viewOffset.y += input::scrollMotion.y;
}
int w;
SDL_GetCurrentRenderOutputSize(renderer, &w, nullptr);
int w, h;
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
float const cellWidth = static_cast<float>(w) * cellSizePercent;
SDL_FRect cellRect{
0, 0, cellWidth, cellWidth
@ -281,6 +281,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
for (Cell const &cell : living) {
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
if (cellRect.x < -cellRect.w || cellRect.y < -cellRect.h || cellRect.x > w || cellRect.y > h)
continue;
SDL_RenderFillRect(renderer, &cellRect);
}
if (!drawDebugInfo) {
@ -293,6 +295,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
for (Cell const &cell : wl->changes) {
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
if (cellRect.x < -cellRect.w || cellRect.y < -cellRect.h || cellRect.x > w || cellRect.y > h)
continue;
SDL_RenderRect(renderer, &cellRect);
}
}
@ -302,6 +306,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
for (Cell const &cell : wl->changes) {
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
if (cellRect.x < -cellRect.w || cellRect.y < -cellRect.h || cellRect.x > w || cellRect.y > h)
continue;
SDL_RenderRect(renderer, &cellRect);
}
}
@ -311,6 +317,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
for (Cell const &cell : wl->changes) {
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
if (cellRect.x < -cellRect.w || cellRect.y < -cellRect.h || cellRect.x > w || cellRect.y > h)
continue;
SDL_RenderRect(renderer, &cellRect);
}
}