From 7cec20e4f295ea2f92613b0231a765d710c2411a Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 13 Jan 2024 04:48:59 +0100 Subject: dw --- draw/wireframe-meshes.cpp | 10 +++++----- draw/wireframe-meshes.hpp | 10 +++++----- editor/app.hpp | 2 +- editor/draw.cpp | 16 ++++++++-------- editor/events.cpp | 12 ++++++------ editor/imgui.cpp | 12 ++++++------ editor/inspect-types.cpp | 3 +-- loader/vobj.cpp | 14 ++++++++++++-- 8 files changed, 44 insertions(+), 35 deletions(-) diff --git a/draw/wireframe-meshes.cpp b/draw/wireframe-meshes.cpp index 7baeddf7..f81f6822 100644 --- a/draw/wireframe-meshes.cpp +++ b/draw/wireframe-meshes.cpp @@ -4,11 +4,11 @@ namespace floormat::wireframe { meshes::meshes() : _wireframe_texture{make_constant_texture()}, - _wireframe_quad {_wireframe_texture}, - _wireframe_wall_n {_wireframe_texture}, - _wireframe_wall_w {_wireframe_texture}, - _wireframe_box {_wireframe_texture}, - _wireframe_rect {_wireframe_texture} + quad {_wireframe_texture}, + wall_n {_wireframe_texture}, + wall_w {_wireframe_texture}, + box {_wireframe_texture}, + rect {_wireframe_texture} { } diff --git a/draw/wireframe-meshes.hpp b/draw/wireframe-meshes.hpp index be9b6b79..ca514ff5 100644 --- a/draw/wireframe-meshes.hpp +++ b/draw/wireframe-meshes.hpp @@ -19,11 +19,11 @@ struct meshes final meshes(); GL::Texture2D _wireframe_texture; - wireframe_mesh _wireframe_quad {_wireframe_texture}; - wireframe_mesh _wireframe_wall_n {_wireframe_texture}; - wireframe_mesh _wireframe_wall_w {_wireframe_texture}; - wireframe_mesh _wireframe_box {_wireframe_texture}; - wireframe_mesh _wireframe_rect {_wireframe_texture}; + wireframe_mesh quad; + wireframe_mesh wall_n; + wireframe_mesh wall_w; + wireframe_mesh box; + wireframe_mesh rect; }; } // namespace floormat::wireframe diff --git a/editor/app.hpp b/editor/app.hpp index e0dc36e0..9eb61d86 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -166,8 +166,8 @@ private: tests_data& tests(); Pointer M; - Pointer _wireframe; Pointer _imgui; + Pointer _wireframe; Pointer _tests; editor _editor{this}; diff --git a/editor/draw.cpp b/editor/draw.cpp index 84ceef00..47655647 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -5,10 +5,10 @@ #include "main/clickable.hpp" #include "src/anim-atlas.hpp" #include "draw/anim.hpp" +#include "draw/wireframe-meshes.hpp" #include "src/camera-offset.hpp" #include "src/world.hpp" #include "src/critter.hpp" - #include "src/rotation.inl" #include "src/RTree-search.hpp" @@ -46,7 +46,7 @@ void app::draw_cursor() { if (!ed->is_anything_selected()) shader.set_tint(inactive_color); - draw(_wireframe_quad, TILE_SIZE2); + draw(_wireframe->quad, TILE_SIZE2); } else if (const auto* ed = _editor.current_wall_editor()) { @@ -54,8 +54,8 @@ void app::draw_cursor() shader.set_tint(inactive_color); switch (ed->rotation()) { - case rotation::N: draw(_wireframe_wall_n, TILE_SIZE); break; - case rotation::W: draw(_wireframe_wall_w, TILE_SIZE); break; + case rotation::N: draw(_wireframe->wall_n, TILE_SIZE); break; + case rotation::W: draw(_wireframe->wall_w, TILE_SIZE); break; default: std::unreachable(); } } @@ -64,7 +64,7 @@ void app::draw_cursor() if (!ed->is_anything_selected()) shader.set_tint(inactive_color); const auto& sel = ed->get_selected().proto; - draw(_wireframe_quad, TILE_SIZE2); + draw(_wireframe->quad, TILE_SIZE2); if (ed->is_anything_selected()) { shader.set_tint({1, 1, 1, 0.75f}); @@ -84,7 +84,7 @@ void app::draw_cursor() if (vo->is_anything_selected()) { const auto& atlas = vo->get_selected()->factory->atlas(); - draw(_wireframe_quad, TILE_SIZE2); + draw(_wireframe->quad, TILE_SIZE2); shader.set_tint({1, 1, 1, 0.75f}); auto [_g, _w, anim_mesh] = M->meshes(); const auto pos = Vector3i(tile)*iTILE_SIZE; @@ -138,7 +138,7 @@ void app::draw_collision_boxes() auto size = (end - start); auto center = Vector3(start + size*.5f, 0.f); shader.set_tint(x.pass == (uint64_t)pass_mode::pass ? pass_tint : tint); - _wireframe_rect.draw(shader, { center, size, 3 }); + _wireframe->rect.draw(shader, { center, size, 3 }); return true; }); } @@ -187,7 +187,7 @@ void app::draw_collision_boxes() Vector2 start(rect.m_min[0], rect.m_min[1]), end(rect.m_max[0], rect.m_max[1]); auto size = end - start; auto center = Vector3(start + size*.5f, 0.f); - _wireframe_rect.draw(shader, { center, size, 3 }); + _wireframe->rect.draw(shader, { center, size, 3 }); return true; }); } diff --git a/editor/events.cpp b/editor/events.cpp index 59507ccf..8823e7be 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -58,7 +58,7 @@ void app::on_mouse_move(const mouse_move_event& event) noexcept accessor(Vector2i, position) } e = {event.position}; - if ((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(); @@ -81,7 +81,7 @@ void app::on_mouse_up_down(const mouse_button_event& event, bool is_down) noexce accessor(Button, button) } e = {event.position, ev::Button(event.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, is_down)) void(); @@ -99,7 +99,7 @@ void app::on_mouse_scroll(const mouse_scroll_event& event) noexcept accessor(Vector2i, position) } e = {event.offset, event.position}; - if (!(cursor.in_imgui = _imgui.handleMouseScrollEvent(e))) + if (!(cursor.in_imgui = _imgui->handleMouseScrollEvent(e))) do_mouse_scroll((int)e.offset()[1]); } @@ -186,7 +186,7 @@ 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)) || + if (x == key_COUNT && (is_down ? _imgui->handleKeyPressEvent(e) : _imgui->handleKeyReleaseEvent(e)) || (x == key_COUNT || x == key_escape) && _editor.mode() == editor_mode::tests && tests_handle_key(event, is_down)) clear_non_global_keys(); else if (x >= key_NO_REPEAT) @@ -203,7 +203,7 @@ void app::on_text_input_event(const text_input_event& event) noexcept struct { accessor(Containers::StringView, text) } e = {event.text}; - if (_imgui.handleTextInputEvent(e)) + if (_imgui->handleTextInputEvent(e)) clear_non_global_keys(); } @@ -235,7 +235,7 @@ int app::get_key_modifiers() void app::set_cursor_from_imgui() { - _imgui.updateApplicationCursor(M->application()); + _imgui->updateApplicationCursor(M->application()); } } // namespace floormat diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 1e9dfc89..0cc8274b 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -22,16 +22,16 @@ void app::init_imgui(Vector2i size) { if (!_imgui) [[unlikely]] { - _imgui = ImGuiIntegration::Context(Vector2{size}, size, size); - fm_assert(_imgui.context()); + _imgui = Pointer{InPlaceInit, Vector2{size}, size, size}; + fm_assert(_imgui->context()); } else - _imgui.relayout(Vector2{size}, size, size); + _imgui->relayout(Vector2{size}, size, size); } void app::render_menu() { - _imgui.drawFrame(); + _imgui->drawFrame(); } float app::draw_main_menu() @@ -114,7 +114,7 @@ void app::draw_ui() style.ScaleAllSizes(dpi); ImGui::GetIO().IniFilename = nullptr; - _imgui.newFrame(); + _imgui->newFrame(); if (_render_clickables) draw_clickables(); @@ -387,7 +387,7 @@ void app::do_popup_menu() void app::kill_popups(bool hard) { - const bool imgui = _imgui.context() != nullptr; + const bool imgui = _imgui->context() != nullptr; _pending_popup = false; _popup_target = {}; diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index a6c30ed4..c500b050 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -7,9 +7,8 @@ #include "loader/loader.hpp" #include "src/chunk.hpp" #include "src/critter.hpp" - #include "src/light.hpp" -#include +#include #include namespace floormat::entities { diff --git a/loader/vobj.cpp b/loader/vobj.cpp index db277410..ca6a2e63 100644 --- a/loader/vobj.cpp +++ b/loader/vobj.cpp @@ -16,9 +16,17 @@ struct vobj { }; } // namespace floormat::loader_detail +namespace nlohmann { + using floormat::loader_detail::vobj; -void nlohmann::adl_serializer::to_json(json& j, const vobj& val) +template<> +struct adl_serializer { + static void to_json(json& j, const vobj& val); + static void from_json(const json& j, vobj& val); +}; + +void adl_serializer::to_json(json& j, const vobj& val) { j["name"] = val.name; if (val.descr) @@ -26,7 +34,7 @@ void nlohmann::adl_serializer::to_json(json& j, const vobj& val) j["image"] = val.image_filename; } -void nlohmann::adl_serializer::from_json(const json& j, vobj& val) +void adl_serializer::from_json(const json& j, vobj& val) { val.name = j["name"]; if (j.contains("description")) @@ -36,6 +44,8 @@ void nlohmann::adl_serializer::from_json(const json& j, vobj& val) val.image_filename = j["image"]; } +} // namespace nlohmann + namespace floormat::loader_detail { std::shared_ptr loader_impl::make_vobj_anim_atlas(StringView name, StringView image_filename) -- cgit v1.2.3