Remove YAGNI methods from performance systems

GridChunk: Remove getWorldBounds, markAllDirty, getVisibleChunks
- getWorldBounds: Chunk visibility handled by isVisible() instead
- markAllDirty: GridLayers uses per-cell markDirty() pattern
- getVisibleChunks: GridLayers computes visible range inline
- Keep dirtyChunks() for diagnostics

GridLayers: Remove getChunkCoords
- Trivial helper replaced by inline division throughout codebase

SpatialHash: Remove queryRect, totalEntities, cleanBucket
- queryRect: Exceeds #115 scope (only queryRadius required)
- totalEntities: Redundant with separate entity count tracking
- cleanBucket: Dead code - expired weak_ptrs cleaned during remove/update

All removals identified via cppcheck static analysis. Core functionality
of each system remains intact and actively used.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-01-09 15:40:13 -05:00
commit b6eb70748a
6 changed files with 0 additions and 123 deletions

View file

@ -33,13 +33,6 @@ void GridChunk::markDirty() {
// #150 - Removed ensureTexture/renderToTexture - base layer rendering removed // #150 - Removed ensureTexture/renderToTexture - base layer rendering removed
// GridChunk now only provides data storage for GridPoints // GridChunk now only provides data storage for GridPoints
sf::FloatRect GridChunk::getWorldBounds(int cell_width, int cell_height) const {
return sf::FloatRect(
sf::Vector2f(world_x * cell_width, world_y * cell_height),
sf::Vector2f(width * cell_width, height * cell_height)
);
}
bool GridChunk::isVisible(float left_edge, float top_edge, bool GridChunk::isVisible(float left_edge, float top_edge,
float right_edge, float bottom_edge) const { float right_edge, float bottom_edge) const {
// Check if chunk's cell range overlaps with viewport's cell range // Check if chunk's cell range overlaps with viewport's cell range
@ -147,26 +140,6 @@ const UIGridPoint& ChunkManager::at(int x, int y) const {
return chunk->at(local_x, local_y); return chunk->at(local_x, local_y);
} }
void ChunkManager::markAllDirty() {
for (auto& chunk : chunks) {
chunk->markDirty();
}
}
std::vector<GridChunk*> ChunkManager::getVisibleChunks(float left_edge, float top_edge,
float right_edge, float bottom_edge) {
std::vector<GridChunk*> visible;
visible.reserve(chunks.size()); // Pre-allocate for worst case
for (auto& chunk : chunks) {
if (chunk->isVisible(left_edge, top_edge, right_edge, bottom_edge)) {
visible.push_back(chunk.get());
}
}
return visible;
}
void ChunkManager::resize(int new_grid_x, int new_grid_y) { void ChunkManager::resize(int new_grid_x, int new_grid_y) {
// For now, simple rebuild - could be optimized to preserve data // For now, simple rebuild - could be optimized to preserve data
grid_x = new_grid_x; grid_x = new_grid_x;

View file

@ -50,9 +50,6 @@ public:
// Mark chunk as dirty // Mark chunk as dirty
void markDirty(); void markDirty();
// Get pixel bounds of this chunk in world coordinates
sf::FloatRect getWorldBounds(int cell_width, int cell_height) const;
// Check if chunk overlaps with viewport // Check if chunk overlaps with viewport
bool isVisible(float left_edge, float top_edge, bool isVisible(float left_edge, float top_edge,
float right_edge, float bottom_edge) const; float right_edge, float bottom_edge) const;
@ -90,13 +87,6 @@ public:
UIGridPoint& at(int x, int y); UIGridPoint& at(int x, int y);
const UIGridPoint& at(int x, int y) const; const UIGridPoint& at(int x, int y) const;
// Mark all chunks dirty (for full rebuild)
void markAllDirty();
// Get chunks that overlap with viewport
std::vector<GridChunk*> getVisibleChunks(float left_edge, float top_edge,
float right_edge, float bottom_edge);
// Resize grid (rebuilds chunks) // Resize grid (rebuilds chunks)
void resize(int new_grid_x, int new_grid_y); void resize(int new_grid_x, int new_grid_y);

View file

@ -57,11 +57,6 @@ int GridLayer::getChunkIndex(int cell_x, int cell_y) const {
return cy * chunks_x + cx; return cy * chunks_x + cx;
} }
void GridLayer::getChunkCoords(int cell_x, int cell_y, int& chunk_x, int& chunk_y) const {
chunk_x = cell_x / CHUNK_SIZE;
chunk_y = cell_y / CHUNK_SIZE;
}
void GridLayer::getChunkBounds(int chunk_x, int chunk_y, int& start_x, int& start_y, int& end_x, int& end_y) const { void GridLayer::getChunkBounds(int chunk_x, int chunk_y, int& start_x, int& start_y, int& end_x, int& end_y) const {
start_x = chunk_x * CHUNK_SIZE; start_x = chunk_x * CHUNK_SIZE;
start_y = chunk_y * CHUNK_SIZE; start_y = chunk_y * CHUNK_SIZE;

View file

@ -56,9 +56,6 @@ public:
// Get chunk index for a cell // Get chunk index for a cell
int getChunkIndex(int cell_x, int cell_y) const; int getChunkIndex(int cell_x, int cell_y) const;
// Get chunk coordinates for a cell
void getChunkCoords(int cell_x, int cell_y, int& chunk_x, int& chunk_y) const;
// Get cell bounds for a chunk // Get cell bounds for a chunk
void getChunkBounds(int chunk_x, int chunk_y, int& start_x, int& start_y, int& end_x, int& end_y) const; void getChunkBounds(int chunk_x, int chunk_y, int& start_x, int& start_y, int& end_x, int& end_y) const;

View file

@ -92,24 +92,6 @@ std::vector<std::pair<int, int>> SpatialHash::getBucketsInRadius(float x, float
return result; return result;
} }
std::vector<std::pair<int, int>> SpatialHash::getBucketsInRect(float x, float y, float width, float height) const
{
std::vector<std::pair<int, int>> result;
int min_bx = static_cast<int>(std::floor(x / bucket_size));
int max_bx = static_cast<int>(std::floor((x + width) / bucket_size));
int min_by = static_cast<int>(std::floor(y / bucket_size));
int max_by = static_cast<int>(std::floor((y + height) / bucket_size));
for (int bx = min_bx; bx <= max_bx; ++bx) {
for (int by = min_by; by <= max_by; ++by) {
result.emplace_back(bx, by);
}
}
return result;
}
std::vector<std::shared_ptr<UIEntity>> SpatialHash::queryRadius(float x, float y, float radius) const std::vector<std::shared_ptr<UIEntity>> SpatialHash::queryRadius(float x, float y, float radius) const
{ {
std::vector<std::shared_ptr<UIEntity>> result; std::vector<std::shared_ptr<UIEntity>> result;
@ -137,57 +119,7 @@ std::vector<std::shared_ptr<UIEntity>> SpatialHash::queryRadius(float x, float y
return result; return result;
} }
std::vector<std::shared_ptr<UIEntity>> SpatialHash::queryRect(float x, float y, float width, float height) const
{
std::vector<std::shared_ptr<UIEntity>> result;
auto bucket_coords = getBucketsInRect(x, y, width, height);
for (const auto& coord : bucket_coords) {
auto it = buckets.find(coord);
if (it == buckets.end()) continue;
for (const auto& wp : it->second) {
auto entity = wp.lock();
if (!entity) continue;
// Check if entity is within the rectangle
float ex = entity->position.x;
float ey = entity->position.y;
if (ex >= x && ex < x + width && ey >= y && ey < y + height) {
result.push_back(entity);
}
}
}
return result;
}
void SpatialHash::clear() void SpatialHash::clear()
{ {
buckets.clear(); buckets.clear();
} }
size_t SpatialHash::totalEntities() const
{
size_t count = 0;
for (const auto& [coord, bucket] : buckets) {
for (const auto& wp : bucket) {
if (wp.lock()) {
++count;
}
}
}
return count;
}
void SpatialHash::cleanBucket(std::vector<std::weak_ptr<UIEntity>>& bucket)
{
bucket.erase(
std::remove_if(bucket.begin(), bucket.end(),
[](const std::weak_ptr<UIEntity>& wp) {
return wp.expired();
}),
bucket.end()
);
}

View file

@ -37,15 +37,11 @@ public:
// Returns entities whose positions are within the circular radius // Returns entities whose positions are within the circular radius
std::vector<std::shared_ptr<UIEntity>> queryRadius(float x, float y, float radius) const; std::vector<std::shared_ptr<UIEntity>> queryRadius(float x, float y, float radius) const;
// Query all entities within a rectangular region
std::vector<std::shared_ptr<UIEntity>> queryRect(float x, float y, float width, float height) const;
// Clear all entities from the hash // Clear all entities from the hash
void clear(); void clear();
// Get statistics for debugging // Get statistics for debugging
size_t bucketCount() const { return buckets.size(); } size_t bucketCount() const { return buckets.size(); }
size_t totalEntities() const;
private: private:
int bucket_size; int bucket_size;
@ -72,10 +68,4 @@ private:
// Get all bucket coordinates that overlap with a radius query // Get all bucket coordinates that overlap with a radius query
std::vector<std::pair<int, int>> getBucketsInRadius(float x, float y, float radius) const; std::vector<std::pair<int, int>> getBucketsInRadius(float x, float y, float radius) const;
// Get all bucket coordinates that overlap with a rectangle
std::vector<std::pair<int, int>> getBucketsInRect(float x, float y, float width, float height) const;
// Clean expired weak_ptrs from a bucket
void cleanBucket(std::vector<std::weak_ptr<UIEntity>>& bucket);
}; };