diff options
-rw-r--r-- | compat/assert.hpp | 7 | ||||
-rw-r--r-- | src/path-search-dijkstra.cpp | 3 | ||||
-rw-r--r-- | test/app.cpp (renamed from test/main.cpp) | 2 | ||||
-rw-r--r-- | test/app.hpp | 2 | ||||
-rw-r--r-- | test/bench.hpp | 27 | ||||
-rw-r--r-- | test/coords.cpp | 23 | ||||
-rw-r--r-- | test/dijkstra.cpp | 36 |
7 files changed, 60 insertions, 40 deletions
diff --git a/compat/assert.hpp b/compat/assert.hpp index 6e7ef5c0..d4c6d49d 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -92,8 +92,11 @@ { \ if (a != b) [[unlikely]] \ { \ - DBG_nospace << "fatal: " << a << " != " << b \ - << " in " << __FILE__ << ":" << __LINE__; \ + DBG_nospace << "assertion failed: " \ + << #__VA_ARGS__ << " in " \ + << __FILE__ << ":" << __LINE__; \ + DBG_nospace << " expected: " << a; \ + DBG_nospace << " actual: " << b; \ fm_EMIT_ABORT(); \ } \ })(__VA_ARGS__) diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp index e0f09a65..fa04d33b 100644 --- a/src/path-search-dijkstra.cpp +++ b/src/path-search-dijkstra.cpp @@ -238,6 +238,9 @@ path_search_result astar::Dijkstra(world& w, point from_, point to_, object_id o n_offset = n.offset; n_pt = {n_coord, n_offset}; n_dist = n.dist; +#if FM_ASTAR_NO_EDGE_CACHE + (void)n_pt; +#endif } if (auto d = distance({n_coord, n_offset}, {to, to_offset}); d < closest) diff --git a/test/main.cpp b/test/app.cpp index af64dfec..3e1f7f82 100644 --- a/test/main.cpp +++ b/test/app.cpp @@ -21,6 +21,7 @@ test_app::~test_app() int test_app::exec() { + test_coords(); test_json(); test_tile_iter(); test_magnum_math(); @@ -33,7 +34,6 @@ int test_app::exec() test_math(); test_hash(); test_path_search_node_pool(); - test_coords(); test_dijkstra(); diff --git a/test/app.hpp b/test/app.hpp index 3544ed1b..0822e68f 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -31,6 +31,7 @@ struct test_app final : private FM_APPLICATION int exec() override; + static void test_coords(); static void test_json(); static void test_tile_iter(); static void test_magnum_math(); @@ -44,7 +45,6 @@ struct test_app final : private FM_APPLICATION static void test_hash(); static void test_path_search_node_pool(); static void test_dijkstra(); - static void test_coords(); static void zzz_test_misc(); }; } // namespace floormat diff --git a/test/bench.hpp b/test/bench.hpp new file mode 100644 index 00000000..7101e49f --- /dev/null +++ b/test/bench.hpp @@ -0,0 +1,27 @@ +#pragma once +#include <chrono> +#include <Corrade/Containers/StringView.h> + +namespace floormat { + +template<typename F> +requires requires (F& fun) { fun(); } +void bench_run(StringView name, F&& fun) +{ + using namespace std::chrono; + using clock = high_resolution_clock; +#if 0 + for (int i = 0; i < 20; i++) + fun(); + const auto t0 = clock::now(); + for (int i = 0; i < 1000; i++) + fun(); +#else + const auto t0 = clock::now(); + fun(); +#endif + const auto tm = clock::now() - t0; + Debug{} << "test" << name << "took" << duration_cast<milliseconds>(tm).count() << "ms."; +} + +} // namespace floormat diff --git a/test/coords.cpp b/test/coords.cpp index 363d6f8a..7fbf8c34 100644 --- a/test/coords.cpp +++ b/test/coords.cpp @@ -1,10 +1,16 @@ #include "app.hpp" #include "src/object.hpp" +#include "bench.hpp" namespace floormat { namespace { +point norm(const point& pt, Vector2i delta) +{ + return object::normalize_coords(pt, delta); +}; + void test_normalize_point() { point a = { {{ 0, 0, 0}, { 0, 0}}, { 0, 0} }, @@ -12,16 +18,13 @@ void test_normalize_point() c = { {{ -1, 1, 1}, { 7, 9}}, { 1, 31} }, d = { {{16384,-16384,2}, {15, 0}}, { 1, 2} }; - { constexpr auto norm = [](const point& pt, Vector2i delta) { return object::normalize_coords(pt, delta); }; - - fm_assert_equal(norm(a, {}), point{{{ 0, 0, 0}, { 0, 0}}, { 0, 0} }); - fm_assert_equal(norm(b, {}), point{{{ -1, 1, 2}, { 0, 15}}, { 0, 0} }); - fm_assert_equal(norm(b, { 1, -1} ), point{{{ -1, 1 , 2}, { 0, 15}}, { 1, -1} }); - fm_assert_equal(norm(b, { -65, 65 }), point{{{ -2, 2, 2}, {15, 0}}, { -1, 1} }); - fm_assert_equal(norm(c, { 30, -62 }), point{{{ -1, 1, 1}, { 7, 9}}, { 31, -31} }); - fm_assert_equal(norm(c, {1024, 1024}), point{{{ 0, 2, 1}, { 7, 9}}, { 1, 31} }); - fm_assert_equal(norm(d, {2048, 1087}), point{{{16386,-16383,2}, {15, 1}}, { 1, 1} }); - } + fm_assert_equal(norm(a, {}), point{{{ 0, 0, 0}, { 0, 0}}, { 0, 0} }); + fm_assert_equal(norm(b, {}), point{{{ -1, 1, 2}, { 0, 15}}, { 0, 0} }); + fm_assert_equal(norm(b, { 1, -1} ), point{{{ -1, 1 , 2}, { 0, 15}}, { 1, -1} }); + fm_assert_equal(norm(b, { -65, 65 }), point{{{ -2, 2, 2}, {15, 0}}, { -1, 1} }); + fm_assert_equal(norm(c, { 30, -62 }), point{{{ -1, 1, 1}, { 7, 9}}, { 31, -31} }); + fm_assert_equal(norm(c, {1024, 1024}), point{{{ 0, 2, 1}, { 7, 9}}, { 1, 31} }); + fm_assert_equal(norm(d, {2048, 1087}), point{{{16386,-16383,2}, {15, 1}}, { 1, 1} }); } } // namespace diff --git a/test/dijkstra.cpp b/test/dijkstra.cpp index 8b56e505..8c35648d 100644 --- a/test/dijkstra.cpp +++ b/test/dijkstra.cpp @@ -1,36 +1,11 @@ #include "app.hpp" +#include "bench.hpp" #include "src/path-search.hpp" #include "loader/loader.hpp" #include <Magnum/Math/Functions.h> -#include <chrono> -#include <Corrade/Containers/StringView.h> namespace floormat { -namespace { - -template<typename F> -requires requires (F& fun) { fun(); } -void bench_run(StringView name, F&& fun) -{ - using namespace std::chrono; - using clock = high_resolution_clock; -#if 0 - for (int i = 0; i < 20; i++) - fun(); - const auto t0 = clock::now(); - for (int i = 0; i < 1000; i++) - fun(); -#else - const auto t0 = clock::now(); - fun(); -#endif - const auto tm = clock::now() - t0; - Debug{} << "test" << name << "took" << duration_cast<milliseconds>(tm).count() << "ms."; -} - -} // namespace - void test_app::test_dijkstra() { auto w = world(); @@ -58,6 +33,15 @@ void test_app::test_dijkstra() fm_assert(ch.is_passability_modified()); + auto do_bench = [&](int debug) { + a.Dijkstra(w, + {{0,0,0}, {11,9}}, // from + {wpos, {wox, woy}}, // to + 0, max_dist, {32,32}, // size + debug); + }; + + //do_bench(0); bench_run("Dijkstra", [&] { a.Dijkstra(w, {{0,0,0}, {11,9}}, // from |