diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-23 17:22:32 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-02-23 17:22:32 +0100 |
commit | ecacc4e197eb8da6c311dad6e37330bcbbfef86e (patch) | |
tree | 4e9d6f70b93d2e53aa948eac6cd0aceff11f1fc5 | |
parent | 25e36ab269096f11ebb2a1c9f6cc3ab93f830b44 (diff) |
wip
-rw-r--r-- | cmake/msvc.cmake | 1 | ||||
-rw-r--r-- | editor/app.hpp | 1 | ||||
-rw-r--r-- | editor/imgui.cpp | 19 | ||||
-rw-r--r-- | editor/inspect-types.cpp (renamed from entity/chunk.cpp) | 11 | ||||
-rw-r--r-- | editor/inspect.cpp | 22 | ||||
-rw-r--r-- | editor/inspect.hpp | 8 | ||||
-rw-r--r-- | entity/accessor.hpp | 6 | ||||
-rw-r--r-- | entity/types.hpp | 24 |
8 files changed, 53 insertions, 39 deletions
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<tile_atlas>& 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 <Magnum/Math/Color.h> 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/entity/chunk.cpp b/editor/inspect-types.cpp index f7b9aadc..27d61f97 100644 --- a/entity/chunk.cpp +++ b/editor/inspect-types.cpp @@ -3,6 +3,8 @@ #include "src/scenery.hpp" #include "src/anim-atlas.hpp" #include "src/tile-defs.hpp" +#include "entity/types.hpp" +#include "inspect.hpp" namespace floormat::entities { @@ -32,4 +34,13 @@ template<> struct entity_accessors<scenery_ref> { } }; +template<> +void inspect_type<scenery_ref>(scenery_ref& x) +{ + visit_tuple([&](const auto& field) { + using type = typename std::decay_t<decltype(field)>::FieldType; + inspect_field<type>(&x, field.erased()); + }, entity_metadata<scenery_ref>::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 <Magnum/Math/Vector4.h> #include <algorithm> -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<typename T, std::size_t N> constexpr bool eqv(const Math::Vector<N, T>& template<typename T> void do_inspect_field(void* datum, const erased_accessor& accessor, field_repr repr) { - fm_assert(accessor.check_field_name<T>()); + fm_assert(accessor.check_field_type<T>()); + bool should_disable; switch (accessor.is_enabled(datum)) @@ -64,7 +65,9 @@ template<typename T> 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<T>) + if constexpr(std::is_same_v<T, bool>) + ret = ImGui::Checkbox(label.data(), &value); + else if constexpr (!is_magnum_vector<T>) { auto [min, max] = accessor.get_range(datum).convert<T>(); constexpr auto igdt = IGDT<T>; @@ -105,13 +108,15 @@ template<typename T> void do_inspect_field(void* datum, const erased_accessor& a } // namespace -#define MAKE_SPEC(type, repr) \ - template<> void inspect_field<type>(void* datum, const erased_accessor& accessor) { \ +#define MAKE_SPEC(type, repr) \ + template<> \ + void inspect_field<type>(void* datum, const erased_accessor& accessor) { \ do_inspect_field<type>(datum, accessor, (repr)); \ } #define MAKE_SPEC2(type, repr) \ - template<> void inspect_field<field_repr_<type, field_repr, repr>>(void* datum, const erased_accessor& accessor) { \ + template<> \ + void inspect_field<field_repr_<type, field_repr, repr>>(void* datum, const erased_accessor& accessor) { \ do_inspect_field<type>(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<typename T, typename Enum, Enum As> struct field_repr_ final { @@ -26,5 +25,6 @@ template<typename T> using field_repr_slider = field_repr_<T, field_repr, field_ template<typename T> using field_repr_drag = field_repr_<T, field_repr, field_repr::drag>; template<typename T> void inspect_field(void* datum, const entities::erased_accessor& accessor); +template<typename T> 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<typename FieldType> - [[nodiscard]] constexpr bool check_field_name() const noexcept; + [[nodiscard]] constexpr bool check_field_type() const noexcept; template<typename Obj> constexpr void do_asserts() const; @@ -114,10 +114,10 @@ constexpr bool erased_accessor::check_name() const noexcept } template<typename FieldType> -constexpr bool erased_accessor::check_field_name() const noexcept +constexpr bool erased_accessor::check_field_type() const noexcept { constexpr auto name = name_of<FieldType>; - return field_name == name; + return field_type == name; } template<typename Obj, typename FieldType> 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<erased_field_type> struct type_of_erased_field; -template<typename T> struct erased_field_type_v_ : std::integral_constant<erased_field_type, erased_field_type::DYNAMIC> {}; - -#define FM_ERASED_FIELD_TYPE(TYPE, ENUM) \ - template<> struct erased_field_type_v_<TYPE> : std::integral_constant<erased_field_type, erased_field_type::ENUM> {}; \ - template<> struct type_of_erased_field<erased_field_type::ENUM> { 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 |