diff --git a/src/GridChunk.cpp b/src/GridChunk.cpp index f1ff7f2..d98339b 100644 --- a/src/GridChunk.cpp +++ b/src/GridChunk.cpp @@ -33,13 +33,6 @@ void GridChunk::markDirty() { // #150 - Removed ensureTexture/renderToTexture - base layer rendering removed // 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, float right_edge, float bottom_edge) const { // 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); } -void ChunkManager::markAllDirty() { - for (auto& chunk : chunks) { - chunk->markDirty(); - } -} - -std::vector ChunkManager::getVisibleChunks(float left_edge, float top_edge, - float right_edge, float bottom_edge) { - std::vector 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) { // For now, simple rebuild - could be optimized to preserve data grid_x = new_grid_x; diff --git a/src/GridChunk.h b/src/GridChunk.h index 1360355..133b786 100644 --- a/src/GridChunk.h +++ b/src/GridChunk.h @@ -50,9 +50,6 @@ public: // Mark chunk as dirty 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 bool isVisible(float left_edge, float top_edge, float right_edge, float bottom_edge) const; @@ -90,13 +87,6 @@ public: UIGridPoint& at(int x, int y); 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 getVisibleChunks(float left_edge, float top_edge, - float right_edge, float bottom_edge); - // Resize grid (rebuilds chunks) void resize(int new_grid_x, int new_grid_y); diff --git a/src/GridLayers.cpp b/src/GridLayers.cpp index 16f02c4..f6c6f85 100644 --- a/src/GridLayers.cpp +++ b/src/GridLayers.cpp @@ -57,11 +57,6 @@ int GridLayer::getChunkIndex(int cell_x, int cell_y) const { 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 { start_x = chunk_x * CHUNK_SIZE; start_y = chunk_y * CHUNK_SIZE; diff --git a/src/GridLayers.h b/src/GridLayers.h index 290162d..aeccdf5 100644 --- a/src/GridLayers.h +++ b/src/GridLayers.h @@ -56,9 +56,6 @@ public: // Get chunk index for a cell 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 void getChunkBounds(int chunk_x, int chunk_y, int& start_x, int& start_y, int& end_x, int& end_y) const; diff --git a/src/SpatialHash.cpp b/src/SpatialHash.cpp index 9902d94..0ca4b81 100644 --- a/src/SpatialHash.cpp +++ b/src/SpatialHash.cpp @@ -92,24 +92,6 @@ std::vector> SpatialHash::getBucketsInRadius(float x, float return result; } -std::vector> SpatialHash::getBucketsInRect(float x, float y, float width, float height) const -{ - std::vector> result; - - int min_bx = static_cast(std::floor(x / bucket_size)); - int max_bx = static_cast(std::floor((x + width) / bucket_size)); - int min_by = static_cast(std::floor(y / bucket_size)); - int max_by = static_cast(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> SpatialHash::queryRadius(float x, float y, float radius) const { std::vector> result; @@ -137,57 +119,7 @@ std::vector> SpatialHash::queryRadius(float x, float y return result; } -std::vector> SpatialHash::queryRect(float x, float y, float width, float height) const -{ - std::vector> 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() { 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>& bucket) -{ - bucket.erase( - std::remove_if(bucket.begin(), bucket.end(), - [](const std::weak_ptr& wp) { - return wp.expired(); - }), - bucket.end() - ); -} diff --git a/src/SpatialHash.h b/src/SpatialHash.h index 8bc9828..c902cf6 100644 --- a/src/SpatialHash.h +++ b/src/SpatialHash.h @@ -37,15 +37,11 @@ public: // Returns entities whose positions are within the circular radius std::vector> queryRadius(float x, float y, float radius) const; - // Query all entities within a rectangular region - std::vector> queryRect(float x, float y, float width, float height) const; - // Clear all entities from the hash void clear(); // Get statistics for debugging size_t bucketCount() const { return buckets.size(); } - size_t totalEntities() const; private: int bucket_size; @@ -72,10 +68,4 @@ private: // Get all bucket coordinates that overlap with a radius query std::vector> getBucketsInRadius(float x, float y, float radius) const; - - // Get all bucket coordinates that overlap with a rectangle - std::vector> getBucketsInRect(float x, float y, float width, float height) const; - - // Clean expired weak_ptrs from a bucket - void cleanBucket(std::vector>& bucket); };