diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-20 04:20:51 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-20 04:20:51 +0200 |
commit | 9099eec2a638bcf61bf46e86740458d933197577 (patch) | |
tree | dca1ae5c0f8fc89ebf55624b2988733d094af3bc /editor | |
parent | e8a7d188eb186204dc8d8e25aa732e14fac96594 (diff) |
wip tests
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.cpp | 9 | ||||
-rw-r--r-- | editor/app.hpp | 14 | ||||
-rw-r--r-- | editor/camera.cpp | 6 | ||||
-rw-r--r-- | editor/events.cpp | 16 | ||||
-rw-r--r-- | editor/imgui-misc.cpp | 1 | ||||
-rw-r--r-- | editor/imgui.cpp | 6 | ||||
-rw-r--r-- | editor/tests-private.hpp | 36 | ||||
-rw-r--r-- | editor/tests.cpp | 90 | ||||
-rw-r--r-- | editor/tests.hpp | 19 | ||||
-rw-r--r-- | editor/update.cpp | 3 |
10 files changed, 187 insertions, 13 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index 4c81ffda..a2ffc9f4 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -18,7 +18,8 @@ namespace floormat { app::app(fm_settings&& opts) : - M{floormat_main::create(*this, Utility::move(opts))} + M{floormat_main::create(*this, Utility::move(opts))}, + _tests{tests_data_::make()} { reset_world(); auto& w = M->world(); @@ -29,7 +30,10 @@ app::app(fm_settings&& opts) : inspectors.reserve(16); } -app::~app() = default; +app::~app() +{ + +} void app::reset_world() { @@ -79,6 +83,7 @@ void app::reset_world(struct world&& w_) _editor.clear_selection(); kill_popups(true); tested_light_chunk = {}; + tests_reset_mode(); clear_keys(); const auto pixel = cursor.pixel; diff --git a/editor/app.hpp b/editor/app.hpp index 0d99a01f..8a898e4f 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -11,6 +11,7 @@ #include "floormat/app.hpp" #include "keys.hpp" #include "src/object-id.hpp" +#include "tests.hpp" #include <memory> #include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Optional.h> @@ -148,7 +149,18 @@ private: void clear_non_global_keys(); void clear_non_repeated_keys(); - Containers::Pointer<floormat_main> M; + [[nodiscard]] bool tests_handle_key(const key_event& e); + [[nodiscard]] bool tests_handle_mouse_click(const mouse_button_event& e); + [[nodiscard]] bool tests_handle_mouse_move(const mouse_move_event& e); + void tests_pre_update(); + void tests_post_update(); + void draw_tests_pane(float main_menu_height); + void draw_tests_overlay(); + void tests_reset_mode(); + tests_data& tests(); + + Pointer<floormat_main> M; + Pointer<tests_data_> _tests; ImGuiIntegration::Context _imgui{NoCreate}; GL::Texture2D _wireframe_texture = wireframe::make_constant_texture(); wireframe_mesh<wireframe::quad_floor> _wireframe_quad {_wireframe_texture}; diff --git a/editor/camera.cpp b/editor/camera.cpp index 6dcaaa7d..42b81c82 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -142,9 +142,9 @@ void app::update_cursor_tile(const Optional<Vector2i>& pixel) const auto tile_ = Vector2(M->pixel_to_tile_(Vector2d(*pixel))); const auto curchunk = Vector2(tile.chunk()); - const auto subpixel_ = Vector2(std::fmod(tile_[0], 1.f), std::fmod(tile_[1], 1.f)); - auto subpixel = TILE_SIZE2 * Vector2(curchunk.x() < 0 ? 1 + subpixel_[0] : subpixel_[0], - curchunk.y() < 0 ? 1 + subpixel_[1] : subpixel_[1]); + const auto subpixel_ = Vector2(std::fmod(tile_.x(), 1.f), std::fmod(tile_.y(), 1.f)); + auto subpixel = TILE_SIZE2 * Vector2(curchunk.x() < 0 ? 1 + subpixel_.x() : subpixel_.x(), + curchunk.y() < 0 ? 1 + subpixel_.y() : subpixel_.y()); constexpr auto half_tile = Vector2(iTILE_SIZE2/2); subpixel -= half_tile; subpixel.x() = Math::clamp(std::round(subpixel.x()), -half_tile.x(), half_tile.x()-1); diff --git a/editor/events.cpp b/editor/events.cpp index 0863e6ec..64f544e4 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -58,7 +58,10 @@ void app::on_mouse_move(const mouse_move_event& event) noexcept accessor(Vector2i, position) } e = {event.position}; - cursor.in_imgui = _imgui.handleMouseMoveEvent(e); + if ((cursor.in_imgui = _imgui.handleMouseMoveEvent(e))) + void(); + else if (_editor.mode() == editor_mode::tests && tests_handle_mouse_move(event)) + void(); update_cursor_tile(event.position); do_mouse_move(fixup_mods(event.mods)); } @@ -82,7 +85,11 @@ void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexce accessor(Button, button) } e = {event.position, Button_(button)}; - if (!(cursor.in_imgui = is_down ? _imgui.handleMousePressEvent(e) : _imgui.handleMouseReleaseEvent(e))) + if ((cursor.in_imgui = is_down ? _imgui.handleMousePressEvent(e) : _imgui.handleMouseReleaseEvent(e))) + void(); + else if (_editor.mode() == editor_mode::tests && tests_handle_mouse_click(event)) + void(); + else do_mouse_up_down(button, is_down, fixup_mods(event.mods)); } @@ -182,9 +189,8 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept auto [x, mods] = resolve_keybinding(event.key, event.mods); static_assert(key_GLOBAL >= key_NO_REPEAT); - if (x == key_COUNT) - is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e); - else if (x < key_GLOBAL && is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e)) + if (x == key_COUNT && (is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e)) || + x == key_COUNT && _editor.mode() == editor_mode::tests && tests_handle_key(event)) clear_non_global_keys(); else if (x >= key_NO_REPEAT) is_down && !event.is_repeated ? do_key(x, mods) : void(); diff --git a/editor/imgui-misc.cpp b/editor/imgui-misc.cpp index 22fe3d2f..6ee177f8 100644 --- a/editor/imgui-misc.cpp +++ b/editor/imgui-misc.cpp @@ -6,7 +6,6 @@ namespace floormat { using namespace floormat::imgui; - void app::draw_fps() { const auto dpi = M->dpi_scale(); diff --git a/editor/imgui.cpp b/editor/imgui.cpp index f7c970e3..b2623800 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -114,6 +114,8 @@ void app::draw_ui() draw_clickables(); if (_render_vobjs) draw_light_info(); + if (_editor.mode() == editor_mode::tests) + draw_tests_overlay(); const float main_menu_height = draw_main_menu(); [[maybe_unused]] auto font = font_saver{ctx.FontSize*dpi}; @@ -122,11 +124,15 @@ void app::draw_ui() if (_editor.current_tile_editor() || _editor.current_scenery_editor() || _editor.current_vobj_editor()) draw_editor_pane(main_menu_height); + else if (_editor.mode() == editor_mode::tests) + draw_tests_pane(main_menu_height); draw_fps(); draw_tile_under_cursor(); if (_editor.mode() == editor_mode::none) draw_inspector(); + if (_editor.mode() == editor_mode::tests) + draw_tests_pane(main_menu_height); draw_z_level(); do_popup_menu(); ImGui::EndFrame(); diff --git a/editor/tests-private.hpp b/editor/tests-private.hpp new file mode 100644 index 00000000..777daba5 --- /dev/null +++ b/editor/tests-private.hpp @@ -0,0 +1,36 @@ +#pragma once +#include "compat/defs.hpp" +#include "tests.hpp" +#include "src/point.hpp" +#include <vector> +#include <variant> + +namespace floormat::tests { + +template<typename... Ts> struct overloaded : Ts... { using Ts::operator()...; }; +template<typename... Ts> overloaded(Ts...) -> overloaded<Ts...>; + +struct path_test +{ + point from; + std::vector<point> path; + bool active = false; +}; + +using variant = std::variant<std::monostate, tests::path_test>; + +} // namespace floormat::tests + +namespace floormat { + +struct tests_data final : tests_data_ +{ + fm_DECLARE_DELETED_COPY_ASSIGNMENT(tests_data); + tests_data(); + ~tests_data() noexcept override; + //tests::variant& operator*(); + //tests::variant* operator->(); + tests::variant data{std::monostate{}}; +}; + +} // namespace floormat diff --git a/editor/tests.cpp b/editor/tests.cpp new file mode 100644 index 00000000..52b52aa0 --- /dev/null +++ b/editor/tests.cpp @@ -0,0 +1,90 @@ +#include "tests-private.hpp" +#include "app.hpp" +#include "floormat/events.hpp" +#include "imgui-raii.hpp" + +namespace floormat { + +using namespace floormat::tests; +using namespace floormat::imgui; + +tests_data_::~tests_data_() noexcept = default; +tests_data_::tests_data_() = default; + +tests_data::~tests_data() noexcept = default; +tests_data::tests_data() = default; + +Pointer<tests_data_> tests_data_::make() +{ + return Pointer<tests_data>{InPlaceInit}; +} + +void app::tests_pre_update() +{ +} + +void app::tests_post_update() +{ +} + +bool app::tests_handle_mouse_click(const mouse_button_event& e) +{ + update_cursor_tile(cursor.pixel); + auto& var = tests(); + + if (e.button == mouse_button_left) + { + std::visit(overloaded { + [](std::monostate) {}, + [&](path_test& t) { + // todo + } + }, var.data); + + return true; + } + else if (e.button == mouse_button_right) + { + bool ret = false; + std::visit(overloaded { + [](std::monostate) {}, + [&](path_test& t) { + ret = t.active; + t = {}; + }, + }, var.data); + return ret; + } + return false; +} + +bool app::tests_handle_key(const key_event& e) +{ + return false; +} + +bool app::tests_handle_mouse_move(const mouse_move_event& e) +{ + return false; +} + +tests_data& app::tests() +{ + return static_cast<tests_data&>(*_tests); +} + +void app::tests_reset_mode() +{ + if (!std::holds_alternative<std::monostate>(tests().data)) + tests().data = std::monostate{}; +} + +void app::draw_tests_pane(float main_menu_height) +{ +} + +void app::draw_tests_overlay() +{ +} + +} // namespace floormat diff --git a/editor/tests.hpp b/editor/tests.hpp new file mode 100644 index 00000000..06762127 --- /dev/null +++ b/editor/tests.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "compat/defs.hpp" + +namespace floormat { + +struct tests_data; + +struct tests_data_ +{ + fm_DECLARE_DELETED_COPY_ASSIGNMENT(tests_data_); + + virtual ~tests_data_() noexcept; + static Pointer<tests_data_> make(); + +protected: + tests_data_(); +}; + +} // namespace floormat diff --git a/editor/update.cpp b/editor/update.cpp index 73e5cb00..33c5243c 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -263,13 +263,14 @@ auto app::get_z_bounds() -> z_bounds void app::update(float dt) { update_cursor_tile(cursor.pixel); + tests_pre_update(); apply_commands(keys); update_character(dt); update_world(dt); do_camera(dt, keys, get_key_modifiers()); clear_non_repeated_keys(); set_cursor(); - + tests_post_update(); M->world().maybe_collect(); } |