perf: Skip out-of-bounds entities during Grid rendering closes #52

- Add visibility bounds check in entity render loop
- Skip entities outside view with 1 cell margin
- Improves performance for large grids with many entities
- Bounds check considers zoom and pan settings
This commit is contained in:
John McCardle 2025-07-06 00:42:15 -04:00
parent c0270c9b32
commit 61a05dd6ba
1 changed files with 7 additions and 1 deletions

View File

@ -138,7 +138,13 @@ void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target)
// middle layer - entities // middle layer - entities
// disabling entity rendering until I can render their UISprite inside the rendertexture (not directly to window) // disabling entity rendering until I can render their UISprite inside the rendertexture (not directly to window)
for (auto e : *entities) { for (auto e : *entities) {
// TODO skip out-of-bounds entities (grid square not visible at all, check for partially on visible grid squares / floating point grid position) // Skip out-of-bounds entities for performance
// Check if entity is within visible bounds (with 1 cell margin for partially visible entities)
if (e->position.x < left_edge - 1 || e->position.x >= left_edge + width_sq + 1 ||
e->position.y < top_edge - 1 || e->position.y >= top_edge + height_sq + 1) {
continue; // Skip this entity as it's not visible
}
//auto drawent = e->cGrid->indexsprite.drawable(); //auto drawent = e->cGrid->indexsprite.drawable();
auto& drawent = e->sprite; auto& drawent = e->sprite;
//drawent.setScale(zoom, zoom); //drawent.setScale(zoom, zoom);