From 9ca79baec88669ec171e3ffa3ef555408d7e1d51 Mon Sep 17 00:00:00 2001 From: John McCardle Date: Fri, 10 Apr 2026 01:07:08 -0400 Subject: [PATCH] Fix grid layers with z_index=0 rendering on top of entities, closes #257 Layers with z_index <= 0 now render below entities (ground level), and only layers with z_index > 0 render above entities. Previously z_index=0 was treated as "above entities" which was unintuitive -- entities stand on ground level (z=0) with their feet, so z=0 layers should be beneath. Changed in both UIGrid.cpp and UIGridView.cpp render methods: - "z_index >= 0" to "z_index > 0" for break condition - "z_index < 0" to "z_index <= 0" for skip condition Co-Authored-By: Claude Opus 4.6 --- src/GridLayers.h | 2 +- src/UIGrid.cpp | 8 ++++---- src/UIGridView.cpp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/GridLayers.h b/src/GridLayers.h index 9597a30..94ebe43 100644 --- a/src/GridLayers.h +++ b/src/GridLayers.h @@ -30,7 +30,7 @@ public: GridLayerType type; std::string name; // #150 - Layer name for GridPoint property access - int z_index; // Negative = below entities, >= 0 = above entities + int z_index; // <= 0 = below entities (ground level), > 0 = above entities int grid_x, grid_y; // Dimensions GridData* parent_grid; // Parent grid reference (#252: GridData, not UIGrid) bool visible; // Visibility flag diff --git a/src/UIGrid.cpp b/src/UIGrid.cpp index 1004a2a..6dea9f1 100644 --- a/src/UIGrid.cpp +++ b/src/UIGrid.cpp @@ -182,10 +182,10 @@ void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target) if (y_limit > grid_h) y_limit = grid_h; // #150 - Layers are now the sole source of grid rendering (base layer removed) - // Render layers with z_index < 0 (below entities) + // Render layers with z_index <= 0 (below entities) sortLayers(); for (auto& layer : layers) { - if (layer->z_index >= 0) break; // Stop at layers that go above entities + if (layer->z_index > 0) break; // Stop at layers that go above entities (#257) layer->render(*activeTexture, left_spritepixels, top_spritepixels, left_edge, top_edge, x_limit, y_limit, zoom, cell_width, cell_height); } @@ -222,9 +222,9 @@ void UIGrid::render(sf::Vector2f offset, sf::RenderTarget& target) Resources::game->metrics.totalEntities += totalEntities; } - // #147 - Render dynamic layers with z_index >= 0 (above entities) + // #147 - Render dynamic layers with z_index > 0 (above entities) for (auto& layer : layers) { - if (layer->z_index < 0) continue; // Skip layers below entities + if (layer->z_index <= 0) continue; // Skip layers at or below entities (#257) layer->render(*activeTexture, left_spritepixels, top_spritepixels, left_edge, top_edge, x_limit, y_limit, zoom, cell_width, cell_height); } diff --git a/src/UIGridView.cpp b/src/UIGridView.cpp index d1ee84c..4e928b6 100644 --- a/src/UIGridView.cpp +++ b/src/UIGridView.cpp @@ -167,10 +167,10 @@ void UIGridView::render(sf::Vector2f offset, sf::RenderTarget& target) int y_limit = top_edge + height_sq + 2; if (y_limit > grid_data->grid_h) y_limit = grid_data->grid_h; - // Render layers below entities (z_index < 0) + // Render layers below entities (z_index <= 0) grid_data->sortLayers(); for (auto& layer : grid_data->layers) { - if (layer->z_index >= 0) break; + if (layer->z_index > 0) break; // #257: z_index=0 is ground level (below entities) layer->render(*activeTexture, left_spritepixels, top_spritepixels, left_edge, top_edge, x_limit, y_limit, zoom, cell_width, cell_height); } @@ -191,9 +191,9 @@ void UIGridView::render(sf::Vector2f offset, sf::RenderTarget& target) } } - // Render layers above entities (z_index >= 0) + // Render layers above entities (z_index > 0) for (auto& layer : grid_data->layers) { - if (layer->z_index < 0) continue; + if (layer->z_index <= 0) continue; // #257: skip ground-level and below layer->render(*activeTexture, left_spritepixels, top_spritepixels, left_edge, top_edge, x_limit, y_limit, zoom, cell_width, cell_height); }