From 83bca7d6861a701e8ba383a93076f346db393a33 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 24 Feb 2023 08:59:46 +0100 Subject: a --- editor/events.cpp | 2 +- editor/inspect-types.cpp | 14 +++++++++++++- editor/inspect.cpp | 4 ---- entity/constraints.hpp | 5 +++++ entity/metadata.hpp | 12 ++++++------ 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/editor/events.cpp b/editor/events.cpp index cc1c0d7a..d0a57d8b 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -152,7 +152,7 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept static_assert(key_GLOBAL >= key_NO_REPEAT); if (x == key_COUNT) - void(); + is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e); else if (x < key_GLOBAL && is_down ? _imgui.handleKeyPressEvent(e) : _imgui.handleKeyReleaseEvent(e)) clear_non_global_keys(); else if (x >= key_NO_REPEAT) diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 235ee72e..d4feb1c3 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -6,9 +6,16 @@ #include "entity/types.hpp" #include "inspect.hpp" #include +#include + +//#define TEST_STR namespace floormat::entities { +#ifdef TEST_STR +static String my_str; +#endif + template<> struct entity_accessors { static constexpr auto accessors() { @@ -29,11 +36,16 @@ template<> struct entity_accessors { [](const scenery_ref& x) { return x.frame.passability; }, [](scenery_ref& x, pass_mode value) { x.frame.passability = value; } }, - // 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; } } +#ifdef TEST_STR + , entity::type::field{"string"_s, + [](const scenery_ref&) { return my_str; }, + [](scenery_ref&, String value) { my_str = std::move(value); } + } +#endif ); return tuple; } diff --git a/editor/inspect.cpp b/editor/inspect.cpp index cd2904fc..aa17029a 100644 --- a/editor/inspect.cpp +++ b/editor/inspect.cpp @@ -53,11 +53,7 @@ int corrade_string_resize_callback(ImGuiInputTextCallbackData* data) { auto* my_str = reinterpret_cast(data->UserData); fm_assert(my_str->begin() == data->Buf); - String tmp = std::move(*my_str); *my_str = String{ValueInit, (std::size_t)data->BufSize}; - auto len = std::min(tmp.size(), my_str->size()); - for (std::size_t i = 0; i < len; i++) - (*my_str)[i] = tmp[i]; data->Buf = my_str->begin(); } return 0; diff --git a/entity/constraints.hpp b/entity/constraints.hpp index cfe33bfe..b4989353 100644 --- a/entity/constraints.hpp +++ b/entity/constraints.hpp @@ -35,6 +35,11 @@ constexpr range::operator erased_constraints::range() const noexcept template constexpr range::operator std::pair() const noexcept { return { min, max }; } +template<> struct range +{ + constexpr operator erased_constraints::range() const noexcept { return {}; } +}; + using max_length = erased_constraints::max_length; using group = erased_constraints::group; diff --git a/entity/metadata.hpp b/entity/metadata.hpp index b373a927..e2d9eb67 100644 --- a/entity/metadata.hpp +++ b/entity/metadata.hpp @@ -123,9 +123,9 @@ public: fm_DECLARE_DEFAULT_MOVE_COPY_ASSIGNMENTS(entity_field); static constexpr decltype(auto) read(const R& reader, const Obj& x) { return detail::read_field::read(x, reader); } - static constexpr void write(const W& writer, Obj& x, move_qualified v); + static constexpr void write(const W& writer, Obj& x, Type v); constexpr decltype(auto) read(const Obj& x) const { return read(reader, x); } - constexpr void write(Obj& x, move_qualified value) const { write(writer, x, value); } + constexpr void write(Obj& x, Type value) const { write(writer, x, std::move(value)); } static constexpr bool can_write = !std::is_same_v::writer)>; static constexpr field_status is_enabled(const Predicate & p, const Obj& x); @@ -149,9 +149,9 @@ public: }; template R, FieldWriter W, typename... Ts> -constexpr void entity_field::write(const W& writer, Obj& x, move_qualified v) +constexpr void entity_field::write(const W& writer, Obj& x, Type v) { - static_assert(can_write); detail::write_field::write(x, writer, v); + static_assert(can_write); detail::write_field::write(x, writer, std::move(v)); } template R, FieldWriter W, typename... Ts> @@ -174,8 +174,8 @@ constexpr erased_accessor entity_field::erased() const constexpr auto writer_fn = [](void* obj, const writer_t* writer, void* value) { auto& obj_ = *reinterpret_cast(obj); const auto& writer_ = *reinterpret_cast(writer); - move_qualified value_ = std::move(*reinterpret_cast(value)); - write(writer_, obj_, value_); + Type value_ = std::move(*reinterpret_cast(value)); + write(writer_, obj_, std::move(value_)); }; constexpr auto predicate_fn = [](const void* obj, const predicate_t* predicate) { const auto& obj_ = *reinterpret_cast(obj); -- cgit v1.2.3