diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dijkstra.cpp | 11 | ||||
-rw-r--r-- | src/path-search.cpp | 4 | ||||
-rw-r--r-- | src/path-search.hpp | 4 | ||||
-rw-r--r-- | src/world.cpp | 11 | ||||
-rw-r--r-- | src/world.hpp | 4 |
5 files changed, 13 insertions, 21 deletions
diff --git a/src/dijkstra.cpp b/src/dijkstra.cpp index d303960a..9fa348b3 100644 --- a/src/dijkstra.cpp +++ b/src/dijkstra.cpp @@ -487,15 +487,12 @@ chunk* cache::try_get_chunk(world& w, floormat::chunk_coords_ ch) return page.chunk; } -std::array<world::neighbor_pair, 8> cache::get_neighbors(world& w, chunk_coords_ ch0) +std::array<chunk*, 8> cache::get_neighbors(world& w, chunk_coords_ ch0) { fm_debug_assert(!size.isZero()); - std::array<world::neighbor_pair, 8> neighbors; - for (auto i = 0uz; const auto& x : world::neighbor_offsets) - { - auto ch = ch0 + x; - neighbors[i++] = { try_get_chunk(w, ch), ch0 }; - } + std::array<chunk*, 8> neighbors; + for (auto i = 0u; i < 8; i++) + neighbors[i] = try_get_chunk(w, ch0 + world::neighbor_offsets[i]); return neighbors; } diff --git a/src/path-search.cpp b/src/path-search.cpp index f5a36feb..2b93ad14 100644 --- a/src/path-search.cpp +++ b/src/path-search.cpp @@ -46,7 +46,7 @@ bool path_search::is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id ow return is_passable; } -bool path_search::is_passable_(chunk* c0, const std::array<world::neighbor_pair, 8>& neighbors, +bool path_search::is_passable_(chunk* c0, const std::array<chunk*, 8>& neighbors, Vector2 min, Vector2 max, object_id own_id, const pred& p) { fm_debug_assert(max >= min); @@ -60,7 +60,7 @@ bool path_search::is_passable_(chunk* c0, const std::array<world::neighbor_pair, for (auto i = 0uz; i < 8; i++) { auto nb = world::neighbor_offsets[i]; - auto* c2 = neighbors[i].c; + auto* c2 = neighbors[i]; if (c2) { diff --git a/src/path-search.hpp b/src/path-search.hpp index b448afe8..210d1a73 100644 --- a/src/path-search.hpp +++ b/src/path-search.hpp @@ -50,7 +50,7 @@ struct cache uint32_t lookup_index(size_t chunk_index, size_t tile_index); chunk* try_get_chunk(world& w, chunk_coords_ ch); - std::array<world::neighbor_pair, 8> get_neighbors(world& w, chunk_coords_ ch0); + std::array<chunk*, 8> get_neighbors(world& w, chunk_coords_ ch0); }; } // namespace detail_astar struct path_search_result; @@ -83,7 +83,7 @@ public: static const pred& always_continue() noexcept; static bool is_passable_1(chunk& c, Vector2 min, Vector2 max, object_id own_id, const pred& p = never_continue()); - static bool is_passable_(chunk* c0, const std::array<world::neighbor_pair, 8>& neighbors, + static bool is_passable_(chunk* c0, const std::array<chunk*, 8>& neighbors, Vector2 min, Vector2 max, object_id own_id, const pred& p = never_continue()); static bool is_passable(world& w, global_coords coord, Vector2b offset, Vector2ui size, object_id own_id, const pred& p = never_continue()); static bool is_passable(world& w, struct detail_astar::cache& cache, global_coords coord, Vector2b offset, Vector2ui size, object_id own_id, const pred& p = never_continue()); diff --git a/src/world.cpp b/src/world.cpp index 759b9060..a28db7d3 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -188,14 +188,11 @@ void world::throw_on_wrong_object_type(object_id id, object_type actual, object_ fm_throw("object '{}' has wrong object type '{}', should be '{}'"_cf, id, (size_t)actual, (size_t)expected); } -auto world::neighbors(chunk_coords_ coord) -> std::array<neighbor_pair, 8> +auto world::neighbors(chunk_coords_ coord) -> std::array<chunk*, 8> { - std::array<neighbor_pair, 8> ret; - for (auto i = 0uz; const auto& x : neighbor_offsets) - { - auto ch = coord + x; - ret[i++] = { at(ch), ch }; - } + std::array<chunk*, 8> ret; + for (auto i = 0u; i < 8; i++) + ret[i] = at(coord + neighbor_offsets[i]); return ret; } diff --git a/src/world.hpp b/src/world.hpp index 8e6b9815..20d9bd1d 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -96,9 +96,7 @@ public: [[nodiscard]] object_id make_id() { return ++_object_counter; } void set_object_counter(object_id value); - struct neighbor_pair final { chunk* c = nullptr; chunk_coords_ coord; }; - - std::array<neighbor_pair, 8> neighbors(chunk_coords_ coord); + std::array<chunk*, 8> neighbors(chunk_coords_ coord); static constexpr std::array<Vector2b, 8> neighbor_offsets = {{ {-1, -1}, {-1, 0}, { 0, -1}, { 1, 1}, { 1, 0}, { 0, 1}, { 1, -1}, {-1, 1}, |