diff --git a/src/UIGrid.cpp b/src/UIGrid.cpp index 0756dc9..d589185 100644 --- a/src/UIGrid.cpp +++ b/src/UIGrid.cpp @@ -138,7 +138,13 @@ void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target) // middle layer - entities // disabling entity rendering until I can render their UISprite inside the rendertexture (not directly to window) 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->sprite; //drawent.setScale(zoom, zoom);