Add multi-tile entity support with tile_width/tile_height, closes #236

Entities can now span multiple grid cells via tile_width and tile_height
properties (default 1x1). Frustum culling accounts for entity footprint,
and spatial hash queries return multi-tile entities for all covered cells.

API: entity.tile_size = (2, 2) or entity.tile_width = 2; entity.tile_height = 3

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-04-10 02:57:47 -04:00
commit a4e0b97ecb
5 changed files with 186 additions and 7 deletions

View file

@ -198,10 +198,12 @@ void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target)
int totalEntities = entities->size();
for (auto e : *entities) {
// Skip out-of-bounds entities for performance
// Check if entity is within visible bounds (with 2 cell margin for offset/oversized sprites)
if (e->position.x < left_edge - 2 || e->position.x >= left_edge + width_sq + 2 ||
e->position.y < top_edge - 2 || e->position.y >= top_edge + height_sq + 2) {
// #236: Account for multi-tile entity size in frustum culling
int margin = 2;
if (e->position.x + e->tile_width < left_edge - margin ||
e->position.x >= left_edge + width_sq + margin ||
e->position.y + e->tile_height < top_edge - margin ||
e->position.y >= top_edge + height_sq + margin) {
continue; // Skip this entity as it's not visible
}