diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-29 00:39:41 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-02-29 00:39:41 +0100 |
commit | 0b09ee33c25e8ae8f1a7aa6b05e9453a82c65689 (patch) | |
tree | 3a9938551e923cb3e569db096a2be9c94fb29857 | |
parent | 3b03a82fb6db0a3fda4d711456fc89e7d21bfe26 (diff) |
always collect timing info on pathfinding/raycasting
-rw-r--r-- | editor/tests/raycast-test.cpp | 8 | ||||
-rw-r--r-- | editor/tests/region-test.cpp | 19 | ||||
-rw-r--r-- | src/chunk-region.cpp | 10 | ||||
-rw-r--r-- | src/chunk-region.hpp | 1 | ||||
-rw-r--r-- | src/raycast.cpp | 21 | ||||
-rw-r--r-- | src/raycast.hpp | 1 |
6 files changed, 28 insertions, 32 deletions
diff --git a/editor/tests/raycast-test.cpp b/editor/tests/raycast-test.cpp index 76fdde8b..13199244 100644 --- a/editor/tests/raycast-test.cpp +++ b/editor/tests/raycast-test.cpp @@ -10,7 +10,6 @@ #include <array> #include <vector> #include <mg/Color.h> -#include <mg/Timeline.h> namespace floormat::tests { @@ -57,7 +56,6 @@ struct raycast_test final : base_test raycast_result_s result; pending_s pending; raycast_diag_s diag; - float time = 0; ~raycast_test() noexcept override; @@ -70,7 +68,6 @@ struct raycast_test final : base_test { if (e.button == mouse_button_left && is_down) { - time = 0; auto& M = a.main(); auto& w = M.world(); if (auto pt_ = a.cursor_state().point()) @@ -250,7 +247,7 @@ struct raycast_test final : base_test text(buf); do_column("time"); - std::snprintf(buf, std::size(buf), "%.3f ms", (double)(1000 * time)); + std::snprintf(buf, std::size(buf), "%.3f ms", (double)(1000 * result.time)); text(buf); } } @@ -270,10 +267,7 @@ struct raycast_test final : base_test fm_warn("raycast: wrong Z value"); return; } - Timeline timeline; - timeline.start(); result = raycast_with_diag(diag, a.main().world(), pending.from, pending.to, pending.self); - time = timeline.currentFrameDuration(); } } }; diff --git a/editor/tests/region-test.cpp b/editor/tests/region-test.cpp index 895604fb..55602d98 100644 --- a/editor/tests/region-test.cpp +++ b/editor/tests/region-test.cpp @@ -8,7 +8,6 @@ #include "floormat/main.hpp" #include <bitset> #include <mg/Vector2.h> -#include <mg/Timeline.h> namespace floormat::tests { @@ -29,9 +28,8 @@ struct pending_s struct result_s { - std::bitset<chunk_bits> is_passable; + chunk::pass_region region; chunk_coords_ c; - float time = 0; bool exists : 1 = false; }; @@ -73,7 +71,7 @@ void region_test::draw_overlay(app& a) for (int i = 0; i < div_count.x(); i++) { auto index = (uint32_t)j * div_count.x() + (uint32_t)i; - if (result.is_passable[index]) + if (result.region.bits[index]) continue; auto pos = div_min + div_size * Vector2i{i, j}; auto pt = object::normalize_coords(start, pos); @@ -107,17 +105,17 @@ void region_test::draw_ui(app&, float) text(buf); do_column("passable"); - std::snprintf(buf, sizeof buf, "%zu", result.is_passable.count()); + std::snprintf(buf, sizeof buf, "%zu", result.region.bits.count()); //{ auto b = push_style_color(ImGuiCol_Text, 0x00ff00ff_rgbaf); text(buf); } text(buf); do_column("blocked"); - std::snprintf(buf, sizeof buf, "%zu", result.is_passable.size() - result.is_passable.count()); + std::snprintf(buf, sizeof buf, "%zu", result.region.bits.size() - result.region.bits.count()); //{ auto b = push_style_color(ImGuiCol_Text, 0xffff00ff_rgbaf); text(buf); } text(buf); do_column("time"); - std::snprintf(buf, sizeof buf, "%.1f ms", (double)(1000 * result.time)); + std::snprintf(buf, sizeof buf, "%.1f ms", (double)(1000 * result.region.time)); text(buf); } } @@ -157,16 +155,11 @@ void region_test::update_post(app& a) void region_test::do_region_extraction(world& w, chunk_coords_ coord) { if (auto* c = w.at(coord)) - { - Timeline timeline; - timeline.start(); result = { - .is_passable = c->make_pass_region(true).bits, + .region = c->make_pass_region(true), .c = coord, - .time = timeline.currentFrameDuration(), .exists = true, }; - } } } // namespace diff --git a/src/chunk-region.cpp b/src/chunk-region.cpp index 4bb2be7b..62fee2c4 100644 --- a/src/chunk-region.cpp +++ b/src/chunk-region.cpp @@ -139,8 +139,7 @@ auto chunk::make_pass_region(bool debug) -> pass_region auto chunk::make_pass_region(const pred& f, bool debug) -> pass_region { Timeline timeline; - if (debug) [[unlikely]] - timeline.start(); + timeline.start(); pass_region ret; auto& tmp = get_tmp(); @@ -184,11 +183,10 @@ auto chunk::make_pass_region(const pred& f, bool debug) -> pass_region do_pixel.operator()<D, false>(p); } + ret.time = timeline.currentFrameTime(); + if (debug) [[unlikely]] - { - const auto time = timeline.currentFrameTime(); - DBG_nospace << "region: generating for " << _coord << " took " << fraction(1e3f*time, 3) << " ms"; - } + DBG_nospace << "region: generating for " << _coord << " took " << fraction(1e3f*ret.time, 3) << " ms"; return ret; } diff --git a/src/chunk-region.hpp b/src/chunk-region.hpp index a7281c50..df2149bc 100644 --- a/src/chunk-region.hpp +++ b/src/chunk-region.hpp @@ -8,6 +8,7 @@ namespace floormat { struct chunk::pass_region { std::bitset<Search::div_count.product()> bits; + float time = 0; }; } // namespace floormat diff --git a/src/raycast.cpp b/src/raycast.cpp index 603b7606..bfc41296 100644 --- a/src/raycast.cpp +++ b/src/raycast.cpp @@ -6,10 +6,11 @@ #include "RTree-search.hpp" #include <cfloat> #include <bit> -#include <Corrade/Containers/StructuredBindings.h> -#include <Corrade/Containers/GrowableArray.h> -#include <Magnum/Math/Functions.h> -#include <Magnum/Math/Vector2.h> +#include <cr/StructuredBindings.h> +#include <cr/GrowableArray.h> +#include <mg/Math.h> +#include <mg/Vector2.h> +#include <mg/Timeline.h> namespace floormat::rc { @@ -310,12 +311,20 @@ raycast_result_s do_raycasting(std::conditional_t<EnableDiagnostics, raycast_dia raycast_result_s raycast(world& w, point from, point to, object_id self) { - return do_raycasting<false>(nullptr, w, from, to, self); + Timeline timeline; + timeline.start(); + auto ret = do_raycasting<false>(nullptr, w, from, to, self); + ret.time = timeline.currentFrameDuration(); + return ret; } raycast_result_s raycast_with_diag(raycast_diag_s& diag, world& w, point from, point to, object_id self) { - return do_raycasting<true>(diag, w, from, to, self); + Timeline timeline; + timeline.start(); + auto ret = do_raycasting<true>(diag, w, from, to, self); + ret.time = timeline.currentFrameDuration(); + return ret; } } // namespace floormat::rc diff --git a/src/raycast.hpp b/src/raycast.hpp index 3871c42f..6463a143 100644 --- a/src/raycast.hpp +++ b/src/raycast.hpp @@ -17,6 +17,7 @@ struct raycast_result_s { point from, to, collision; collision_data collider; + float time = 0; bool has_result : 1 = false, success : 1 = false; }; |