From 7c1791841c13db2f3b92a3b5a790daf2a816cc35 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 25 Feb 2024 05:01:14 +0100 Subject: rename astar -> search-astar --- bench/dijkstra.cpp | 2 +- editor/tests/path-test.cpp | 2 +- main/ctor.cpp | 2 +- main/main-impl.cpp | 2 +- src/astar.hpp | 75 ---------------------------------------------- src/dijkstra.cpp | 2 +- src/search-astar.hpp | 75 ++++++++++++++++++++++++++++++++++++++++++++++ src/search.cpp | 2 +- test/dijkstra.cpp | 2 +- 9 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 src/astar.hpp create mode 100644 src/search-astar.hpp diff --git a/bench/dijkstra.cpp b/bench/dijkstra.cpp index c525fdbb..925b5c31 100644 --- a/bench/dijkstra.cpp +++ b/bench/dijkstra.cpp @@ -1,4 +1,4 @@ -#include "src/astar.hpp" +#include "src/search-astar.hpp" #include "src/search-result.hpp" #include "src/world.hpp" #include "loader/loader.hpp" diff --git a/editor/tests/path-test.cpp b/editor/tests/path-test.cpp index 93da7a33..8589829b 100644 --- a/editor/tests/path-test.cpp +++ b/editor/tests/path-test.cpp @@ -3,7 +3,7 @@ #include "compat/shared-ptr-wrapper.hpp" #include "compat/vector-wrapper.hpp" #include "floormat/main.hpp" -#include "src/astar.hpp" +#include "src/search-astar.hpp" #include "src/critter.hpp" #include "shaders/shader.hpp" #include "../imgui-raii.hpp" diff --git a/main/ctor.cpp b/main/ctor.cpp index e40eb5a3..09976016 100644 --- a/main/ctor.cpp +++ b/main/ctor.cpp @@ -1,6 +1,6 @@ #include "main-impl.hpp" #include "compat/fpu.hpp" -#include "src/astar.hpp" +#include "src/search-astar.hpp" #include namespace floormat { diff --git a/main/main-impl.cpp b/main/main-impl.cpp index 689c249b..74ee87ce 100644 --- a/main/main-impl.cpp +++ b/main/main-impl.cpp @@ -1,5 +1,5 @@ #include "main-impl.hpp" -#include "src/astar.hpp" +#include "src/search-astar.hpp" #include #include diff --git a/src/astar.hpp b/src/astar.hpp deleted file mode 100644 index 7c48c5db..00000000 --- a/src/astar.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once -#include "search.hpp" -#include "point.hpp" -#include -#include - -namespace floormat::Search { - -struct cache; -struct chunk_cache; - -struct cache -{ - Vector2ui size; - Vector2i start{(int)((1u << 31) - 1)}; - Array array; - - cache(); - fm_DECLARE_DELETED_COPY_ASSIGNMENT(cache); - - size_t get_chunk_index(Vector2i chunk) const; - static size_t get_chunk_index(Vector2i start, Vector2ui size, Vector2i coord); - static size_t get_tile_index(Vector2i pos, Vector2b offset); - static Vector2ui get_size_to_allocate(uint32_t max_dist); - - void allocate(point from, uint32_t max_dist); - void add_index(size_t chunk_index, size_t tile_index, uint32_t index); - void add_index(point pt, uint32_t index); - uint32_t lookup_index(size_t chunk_index, size_t tile_index); - chunk* try_get_chunk(world& w, chunk_coords_ ch); - - std::array get_neighbors(world& w, chunk_coords_ ch0); -}; - -} // namespace floormat::Search - -namespace floormat { - -class astar -{ -public: - struct visited - { - uint32_t dist = (uint32_t)-1; - uint32_t prev = (uint32_t)-1; - point pt; - }; - - using pred = Search::pred; - - fm_DECLARE_DELETED_COPY_ASSIGNMENT(astar); - - astar(); - void reserve(size_t capacity); - void clear(); - - // todo add simple bresenham short-circuit - path_search_result Dijkstra(world& w, point from, point to, - object_id own_id, uint32_t max_dist, Vector2ub own_size, - int debug = 0, const pred& p = Search::never_continue()); - -private: - static constexpr auto initial_capacity = TILE_COUNT * 16 * Search::div_factor*Search::div_factor; - - struct chunk_cache; - - void add_to_heap(uint32_t id); - uint32_t pop_from_heap(); - - struct Search::cache cache; - Array nodes; - Array Q; -}; - -} // namespace floormat diff --git a/src/dijkstra.cpp b/src/dijkstra.cpp index 1f353e30..15232f90 100644 --- a/src/dijkstra.cpp +++ b/src/dijkstra.cpp @@ -1,4 +1,4 @@ -#include "astar.hpp" +#include "search-astar.hpp" #include "search-bbox.hpp" #include "compat/format.hpp" #include "compat/vector-wrapper.hpp" diff --git a/src/search-astar.hpp b/src/search-astar.hpp new file mode 100644 index 00000000..7c48c5db --- /dev/null +++ b/src/search-astar.hpp @@ -0,0 +1,75 @@ +#pragma once +#include "search.hpp" +#include "point.hpp" +#include +#include + +namespace floormat::Search { + +struct cache; +struct chunk_cache; + +struct cache +{ + Vector2ui size; + Vector2i start{(int)((1u << 31) - 1)}; + Array array; + + cache(); + fm_DECLARE_DELETED_COPY_ASSIGNMENT(cache); + + size_t get_chunk_index(Vector2i chunk) const; + static size_t get_chunk_index(Vector2i start, Vector2ui size, Vector2i coord); + static size_t get_tile_index(Vector2i pos, Vector2b offset); + static Vector2ui get_size_to_allocate(uint32_t max_dist); + + void allocate(point from, uint32_t max_dist); + void add_index(size_t chunk_index, size_t tile_index, uint32_t index); + void add_index(point pt, uint32_t index); + uint32_t lookup_index(size_t chunk_index, size_t tile_index); + chunk* try_get_chunk(world& w, chunk_coords_ ch); + + std::array get_neighbors(world& w, chunk_coords_ ch0); +}; + +} // namespace floormat::Search + +namespace floormat { + +class astar +{ +public: + struct visited + { + uint32_t dist = (uint32_t)-1; + uint32_t prev = (uint32_t)-1; + point pt; + }; + + using pred = Search::pred; + + fm_DECLARE_DELETED_COPY_ASSIGNMENT(astar); + + astar(); + void reserve(size_t capacity); + void clear(); + + // todo add simple bresenham short-circuit + path_search_result Dijkstra(world& w, point from, point to, + object_id own_id, uint32_t max_dist, Vector2ub own_size, + int debug = 0, const pred& p = Search::never_continue()); + +private: + static constexpr auto initial_capacity = TILE_COUNT * 16 * Search::div_factor*Search::div_factor; + + struct chunk_cache; + + void add_to_heap(uint32_t id); + uint32_t pop_from_heap(); + + struct Search::cache cache; + Array nodes; + Array Q; +}; + +} // namespace floormat diff --git a/src/search.cpp b/src/search.cpp index 9f497134..f879260b 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -1,6 +1,6 @@ #include "search.hpp" #include "search-bbox.hpp" -#include "astar.hpp" +#include "search-astar.hpp" #include "global-coords.hpp" #include "world.hpp" #include "pass-mode.hpp" diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp index 14015ade..fe73a468 100644 --- a/test/dijkstra.cpp +++ b/test/dijkstra.cpp @@ -1,5 +1,5 @@ #include "app.hpp" -#include "src/astar.hpp" +#include "src/search-astar.hpp" #include "src/world.hpp" #include "loader/loader.hpp" #include "loader/wall-cell.hpp" -- cgit v1.2.3