From ecacc4e197eb8da6c311dad6e37330bcbbfef86e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 23 Feb 2023 17:22:32 +0100 Subject: wip --- cmake/msvc.cmake | 1 + editor/app.hpp | 1 + editor/imgui.cpp | 19 +++++++++++++++++++ editor/inspect-types.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ editor/inspect.cpp | 22 ++++++++++++++-------- editor/inspect.hpp | 8 ++++---- entity/accessor.hpp | 6 +++--- entity/chunk.cpp | 35 ----------------------------------- entity/types.hpp | 24 ------------------------ 9 files changed, 88 insertions(+), 74 deletions(-) create mode 100644 editor/inspect-types.cpp delete mode 100644 entity/chunk.cpp diff --git a/cmake/msvc.cmake b/cmake/msvc.cmake index 59dde4fe..2e8e47ac 100644 --- a/cmake/msvc.cmake +++ b/cmake/msvc.cmake @@ -38,6 +38,7 @@ SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) #add_definitions(-D_ITERATOR_DEBUG_LEVEL=0) #add_compile_options(-Qvec-report:2) #add_compile_options(-d2cgsummary -Bt) +add_compile_options(-QIntel-jcc-erratum) add_definitions(-D_HAS_EXCEPTIONS=0) if(DEFINED CMAKE_TOOLCHAIN_FILE) diff --git a/editor/app.hpp b/editor/app.hpp index 9385c2a9..f6a2e842 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -94,6 +94,7 @@ private: void draw_collision_boxes(); void draw_editor_pane(float main_menu_height); + void draw_inspector(); void draw_editor_tile_pane_atlas(tile_editor& ed, StringView name, const std::shared_ptr& atlas); void draw_editor_scenery_pane(scenery_editor& ed); void set_cursor_from_imgui(); diff --git a/editor/imgui.cpp b/editor/imgui.cpp index 69037861..c26e9987 100644 --- a/editor/imgui.cpp +++ b/editor/imgui.cpp @@ -2,6 +2,9 @@ #include "floormat/main.hpp" #include "compat/format.hpp" #include "imgui-raii.hpp" +#include "world.hpp" +#include "scenery.hpp" +#include "inspect.hpp" #include namespace floormat { @@ -109,6 +112,7 @@ void app::draw_ui() draw_editor_pane(main_menu_height); draw_fps(); draw_tile_under_cursor(); + draw_inspector(); ImGui::EndFrame(); } @@ -144,6 +148,21 @@ void app::draw_tile_under_cursor() {window_size[0]*.5f - size.x/2, 3*dpi[1]}, (unsigned)-1, buf); } +void app::draw_inspector() +{ + auto& w = M->world(); + if (cursor.tile) + { + auto [c, t] = w[*cursor.tile]; + if (auto s = t.scenery()) + { + ImGui::SetNextWindowSize({400, 0}); + auto b = begin_window("inspector"_s); + entities::inspect_type(s); + } + } +} + void app::draw_editor_pane(float main_menu_height) { auto* ed = _editor.current_tile_editor(); diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp new file mode 100644 index 00000000..27d61f97 --- /dev/null +++ b/editor/inspect-types.cpp @@ -0,0 +1,46 @@ +#include "entity/metadata.hpp" +#include "entity/accessor.hpp" +#include "src/scenery.hpp" +#include "src/anim-atlas.hpp" +#include "src/tile-defs.hpp" +#include "entity/types.hpp" +#include "inspect.hpp" + +namespace floormat::entities { + +template<> struct entity_accessors { + static constexpr auto accessors() + { + using entity = Entity; + using frame_t = scenery::frame_t; + constexpr auto tuple = std::make_tuple( + entity::type::field{"frame"_s, + [](const scenery_ref& x) { return x.frame.frame; }, + [](scenery_ref& x, frame_t value) { x.frame.frame = value; }, + [](const scenery_ref& x) { return constraints::range{0, !x.atlas ? frame_t(0) : frame_t(x.atlas->info().nframes)}; } + }, + entity::type::field{"offset"_s, + [](const scenery_ref& x) { return x.frame.offset; }, + [](scenery_ref& x, Vector2b value) { x.frame.offset = value; }, + constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)}) + }, + // todo pass_mode enum + entity::type::field{"interactive"_s, + [](const scenery_ref& x) { return x.frame.interactive; }, + [](scenery_ref& x, bool value) { x.frame.interactive = value; } + } + ); + return tuple; + } +}; + +template<> +void inspect_type(scenery_ref& x) +{ + visit_tuple([&](const auto& field) { + using type = typename std::decay_t::FieldType; + inspect_field(&x, field.erased()); + }, entity_metadata::accessors); +} + +} // namespace floormat::entities diff --git a/editor/inspect.cpp b/editor/inspect.cpp index 48e4c708..ef06671a 100644 --- a/editor/inspect.cpp +++ b/editor/inspect.cpp @@ -11,11 +11,11 @@ #include #include -namespace floormat { +namespace floormat::entities { namespace { -using entities::erased_constraints::is_magnum_vector; +using erased_constraints::is_magnum_vector; String label_left(StringView label) { @@ -46,7 +46,8 @@ template constexpr bool eqv(const Math::Vector& template void do_inspect_field(void* datum, const erased_accessor& accessor, field_repr repr) { - fm_assert(accessor.check_field_name()); + fm_assert(accessor.check_field_type()); + bool should_disable; switch (accessor.is_enabled(datum)) @@ -64,7 +65,9 @@ template void do_inspect_field(void* datum, const erased_accessor& a accessor.read_fun(datum, accessor.reader, &value); auto orig = value; - if constexpr (!is_magnum_vector) + if constexpr(std::is_same_v) + ret = ImGui::Checkbox(label.data(), &value); + else if constexpr (!is_magnum_vector) { auto [min, max] = accessor.get_range(datum).convert(); constexpr auto igdt = IGDT; @@ -105,13 +108,15 @@ template void do_inspect_field(void* datum, const erased_accessor& a } // namespace -#define MAKE_SPEC(type, repr) \ - template<> void inspect_field(void* datum, const erased_accessor& accessor) { \ +#define MAKE_SPEC(type, repr) \ + template<> \ + void inspect_field(void* datum, const erased_accessor& accessor) { \ do_inspect_field(datum, accessor, (repr)); \ } #define MAKE_SPEC2(type, repr) \ - template<> void inspect_field>(void* datum, const erased_accessor& accessor) { \ + template<> \ + void inspect_field>(void* datum, const erased_accessor& accessor) { \ do_inspect_field(datum, accessor, (repr)); \ } @@ -134,5 +139,6 @@ MAKE_SPEC_REPRS2(std::int16_t) MAKE_SPEC_REPRS2(std::uint32_t) MAKE_SPEC_REPRS2(std::int32_t) MAKE_SPEC_REPRS2(float) +MAKE_SPEC(bool, field_repr::input) -} // namespace floormat +} // namespace floormat::entities diff --git a/editor/inspect.hpp b/editor/inspect.hpp index d2824f2c..5cb71303 100644 --- a/editor/inspect.hpp +++ b/editor/inspect.hpp @@ -1,8 +1,7 @@ #pragma once -//#include "entity/accessor.hpp" -namespace floormat::entities { struct erased_accessor; } +namespace floormat::entities { -namespace floormat { +struct erased_accessor; template struct field_repr_ final { @@ -26,5 +25,6 @@ template using field_repr_slider = field_repr_ using field_repr_drag = field_repr_; template void inspect_field(void* datum, const entities::erased_accessor& accessor); +template void inspect_type(T& x); -} // namespace floormat +} // namespace floormat::entities diff --git a/entity/accessor.hpp b/entity/accessor.hpp index 84c599c2..cc777e5d 100644 --- a/entity/accessor.hpp +++ b/entity/accessor.hpp @@ -69,7 +69,7 @@ struct erased_accessor final { [[nodiscard]] constexpr bool check_name() const noexcept; template - [[nodiscard]] constexpr bool check_field_name() const noexcept; + [[nodiscard]] constexpr bool check_field_type() const noexcept; template constexpr void do_asserts() const; @@ -114,10 +114,10 @@ constexpr bool erased_accessor::check_name() const noexcept } template -constexpr bool erased_accessor::check_field_name() const noexcept +constexpr bool erased_accessor::check_field_type() const noexcept { constexpr auto name = name_of; - return field_name == name; + return field_type == name; } template diff --git a/entity/chunk.cpp b/entity/chunk.cpp deleted file mode 100644 index f7b9aadc..00000000 --- a/entity/chunk.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "entity/metadata.hpp" -#include "entity/accessor.hpp" -#include "src/scenery.hpp" -#include "src/anim-atlas.hpp" -#include "src/tile-defs.hpp" - -namespace floormat::entities { - -template<> struct entity_accessors { - static constexpr auto accessors() - { - using entity = Entity; - using frame_t = scenery::frame_t; - constexpr auto tuple = std::make_tuple( - entity::type::field{"frame"_s, - [](const scenery_ref& x) { return x.frame.frame; }, - [](scenery_ref& x, frame_t value) { x.frame.frame = value; }, - [](const scenery_ref& x) { return constraints::range{0, !x.atlas ? frame_t(0) : frame_t(x.atlas->info().nframes)}; } - }, - entity::type::field{"offset"_s, - [](const scenery_ref& x) { return x.frame.offset; }, - [](scenery_ref& x, Vector2b value) { x.frame.offset = value; }, - constantly(constraints::range{Vector2b(iTILE_SIZE2/-2), Vector2b(iTILE_SIZE2/2)}) - }, - // todo pass_mode enum - entity::type::field{"interactive"_s, - [](const scenery_ref& x) { return x.frame.interactive; }, - [](scenery_ref& x, bool value) { x.frame.interactive = value; } - } - ); - return tuple; - } -}; - -} // namespace floormat::entities diff --git a/entity/types.hpp b/entity/types.hpp index 2987f2e8..d2cf5542 100644 --- a/entity/types.hpp +++ b/entity/types.hpp @@ -4,30 +4,6 @@ namespace floormat::entities { -enum class erased_field_type : unsigned { - none, - string, - u8, u16, u32, u64, s8, s16, s32, s64, - user_type_start, - MAX = (1u << 31) - 1u, - DYNAMIC = (std::uint32_t)-1, -}; -template struct type_of_erased_field; -template struct erased_field_type_v_ : std::integral_constant {}; - -#define FM_ERASED_FIELD_TYPE(TYPE, ENUM) \ - template<> struct erased_field_type_v_ : std::integral_constant {}; \ - template<> struct type_of_erased_field { using type = TYPE; } -FM_ERASED_FIELD_TYPE(std::uint8_t, u8); -FM_ERASED_FIELD_TYPE(std::uint16_t, u16); -FM_ERASED_FIELD_TYPE(std::uint32_t, u32); -FM_ERASED_FIELD_TYPE(std::uint64_t, u64); -FM_ERASED_FIELD_TYPE(std::int8_t, s8); -FM_ERASED_FIELD_TYPE(std::int16_t, s16); -FM_ERASED_FIELD_TYPE(std::int32_t, s32); -FM_ERASED_FIELD_TYPE(std::int64_t, s64); -FM_ERASED_FIELD_TYPE(StringView, string); -#undef FM_ERASED_FIELD_TYPE } // namespace floormat::entities -- cgit v1.2.3