feat: added basic culling to cell renderer
This commit is contained in:
parent
658b96b201
commit
5484039e3e
|
|
@ -271,8 +271,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
|
||||||
viewOffset.x += input::scrollMotion.x;
|
viewOffset.x += input::scrollMotion.x;
|
||||||
viewOffset.y += input::scrollMotion.y;
|
viewOffset.y += input::scrollMotion.y;
|
||||||
}
|
}
|
||||||
int w;
|
int w, h;
|
||||||
SDL_GetCurrentRenderOutputSize(renderer, &w, nullptr);
|
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
|
||||||
float const cellWidth = static_cast<float>(w) * cellSizePercent;
|
float const cellWidth = static_cast<float>(w) * cellSizePercent;
|
||||||
SDL_FRect cellRect{
|
SDL_FRect cellRect{
|
||||||
0, 0, cellWidth, cellWidth
|
0, 0, cellWidth, cellWidth
|
||||||
|
|
@ -281,6 +281,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
|
||||||
for (Cell const &cell : living) {
|
for (Cell const &cell : living) {
|
||||||
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
||||||
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
|
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);
|
SDL_RenderFillRect(renderer, &cellRect);
|
||||||
}
|
}
|
||||||
if (!drawDebugInfo) {
|
if (!drawDebugInfo) {
|
||||||
|
|
@ -293,6 +295,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
|
||||||
for (Cell const &cell : wl->changes) {
|
for (Cell const &cell : wl->changes) {
|
||||||
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
||||||
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
|
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);
|
SDL_RenderRect(renderer, &cellRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -302,6 +306,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
|
||||||
for (Cell const &cell : wl->changes) {
|
for (Cell const &cell : wl->changes) {
|
||||||
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
||||||
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
|
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);
|
SDL_RenderRect(renderer, &cellRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -311,6 +317,8 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
|
||||||
for (Cell const &cell : wl->changes) {
|
for (Cell const &cell : wl->changes) {
|
||||||
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
cellRect.x = (viewOffset.x + cell.x) * cellRect.w;
|
||||||
cellRect.y = (viewOffset.y + cell.y) * cellRect.h;
|
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);
|
SDL_RenderRect(renderer, &cellRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue