diff options
-rw-r--r-- | compat/enum-bitset-fwd.hpp | 9 | ||||
-rw-r--r-- | compat/enum-bitset.hpp | 3 | ||||
-rw-r--r-- | editor/app.cpp | 31 | ||||
-rw-r--r-- | editor/app.hpp | 7 | ||||
-rw-r--r-- | editor/camera.cpp | 1 | ||||
-rw-r--r-- | editor/ctor.cpp | 37 | ||||
-rw-r--r-- | editor/events.cpp | 8 | ||||
-rw-r--r-- | editor/update.cpp | 6 |
8 files changed, 63 insertions, 39 deletions
diff --git a/compat/enum-bitset-fwd.hpp b/compat/enum-bitset-fwd.hpp new file mode 100644 index 00000000..ad75b3aa --- /dev/null +++ b/compat/enum-bitset-fwd.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace floormat { + +template<typename Enum, Enum COUNT_ = Enum::COUNT> +requires (std::is_enum_v<Enum> && std::is_same_v<size_t, std::common_type_t<size_t, std::underlying_type_t<Enum>>>) +struct enum_bitset; + +} // namespace floormat diff --git a/compat/enum-bitset.hpp b/compat/enum-bitset.hpp index ebbd9982..f1c23808 100644 --- a/compat/enum-bitset.hpp +++ b/compat/enum-bitset.hpp @@ -1,9 +1,10 @@ #pragma once +#include "enum-bitset-fwd.hpp" #include <bitset> namespace floormat { -template<typename Enum, Enum COUNT_ = Enum::COUNT> +template<typename Enum, Enum COUNT_> requires (std::is_enum_v<Enum> && std::is_same_v<size_t, std::common_type_t<size_t, std::underlying_type_t<Enum>>>) struct enum_bitset : std::bitset<size_t(COUNT_)> { using enum_type = Enum; diff --git a/editor/app.cpp b/editor/app.cpp index 94e78576..44df5c5e 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -1,22 +1,18 @@ #include "app.hpp" #include "compat/assert.hpp" #include "compat/sysexits.hpp" -#include "src/world.hpp" +#include "editor.hpp" #include "src/anim-atlas.hpp" #include "src/critter.hpp" +#include "src/world.hpp" #include "floormat/main.hpp" #include "floormat/settings.hpp" #include "loader/loader.hpp" -#include "draw/wireframe-meshes.hpp" -#include "editor.hpp" - #include <cstdlib> #include <cstring> -#include <algorithm> #include <Corrade/Containers/StringIterable.h> #include <Corrade/Utility/Arguments.h> #include <Corrade/Utility/Move.h> -#include <Magnum/ImGuiIntegration/Context.h> namespace floormat { @@ -31,29 +27,6 @@ Optional<struct point> cursor_state::point() const floormat_main& app::main() { return *M; } const cursor_state& app::cursor_state() { return cursor; } -app::app(fm_settings&& opts) : - M{floormat_main::create(*this, Utility::move(opts))}, - _wireframe{InPlaceInit}, - _tests{tests_data_::make()}, - _editor{InPlaceInit, this} -{ - reset_world(); - auto& w = M->world(); - constexpr chunk_coords_ coord{0, 0, 0}; - maybe_initialize_chunk_(coord, w[coord]); - reset_camera_offset(); - M->set_render_vobjs(_render_vobjs); - inspectors.reserve(16); -} - -app::~app() -{ -} - -void app::reset_world() -{ - reset_world(world{}); -} std::shared_ptr<critter> app::ensure_player_character(world& w) { diff --git a/editor/app.hpp b/editor/app.hpp index 5aefe4f5..662313bc 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -1,6 +1,6 @@ #pragma once #include "compat/defs.hpp" -#include "compat/enum-bitset.hpp" +#include "compat/enum-bitset-fwd.hpp" #include "floormat/app.hpp" #include "keys.hpp" #include "src/global-coords.hpp" @@ -176,9 +176,8 @@ private: Pointer<floormat::wireframe::meshes> _wireframe; Pointer<tests_data_> _tests; Pointer<editor> _editor; - - key_set keys; - std::array<int, key_set::COUNT> key_modifiers = {}; + Pointer<key_set> keys_; + std::array<int, key_COUNT> key_modifiers = {}; std::vector<popup_target> inspectors; object_id _character_id = 0; struct cursor_state cursor; diff --git a/editor/camera.cpp b/editor/camera.cpp index 9e673ae9..3ec532eb 100644 --- a/editor/camera.cpp +++ b/editor/camera.cpp @@ -6,6 +6,7 @@ #include "src/object.hpp" #include "src/world.hpp" #include "src/camera-offset.hpp" +#include "compat/enum-bitset.hpp" #include <bit> #include <algorithm> diff --git a/editor/ctor.cpp b/editor/ctor.cpp new file mode 100644 index 00000000..0d912ded --- /dev/null +++ b/editor/ctor.cpp @@ -0,0 +1,37 @@ +#include "app.hpp" +#include "compat/enum-bitset.hpp" +#include "src/world.hpp" +#include "editor.hpp" +#include "draw/wireframe-meshes.hpp" +#include "floormat/main.hpp" +#include <Magnum/ImGuiIntegration/Context.h> + +namespace floormat { + +app::app(fm_settings&& opts) : + M{floormat_main::create(*this, Utility::move(opts))}, + _wireframe{InPlaceInit}, + _tests{tests_data_::make()}, + _editor{InPlaceInit, this}, + keys_{InPlaceInit, 0} +{ + reset_world(); + auto& w = M->world(); + constexpr chunk_coords_ coord{0, 0, 0}; + maybe_initialize_chunk_(coord, w[coord]); + reset_camera_offset(); + M->set_render_vobjs(_render_vobjs); + inspectors.reserve(16); +} + +app::~app() +{ +} + +void app::reset_world() +{ + reset_world(world{}); +} + + +} // namespace floormat diff --git a/editor/events.cpp b/editor/events.cpp index 1ec52172..8eb99677 100644 --- a/editor/events.cpp +++ b/editor/events.cpp @@ -5,6 +5,7 @@ #include "src/world.hpp" #include "keys.hpp" #include "editor.hpp" +#include "compat/enum-bitset.hpp" #include <tuple> #include <Magnum/Platform/Sdl2Application.h> #include <Magnum/ImGuiIntegration/Context.hpp> @@ -35,7 +36,8 @@ static constexpr int fixup_mods(int mods) void app::clear_keys(key min_inclusive, key max_exclusive) { - using key_type = decltype(keys)::value_type; + auto& keys = *keys_; + using key_type = std::decay_t<decltype(keys)>::value_type; for (key_type i = key_type(min_inclusive); i < key_type(max_exclusive); i++) { const auto idx = key(i); @@ -46,7 +48,7 @@ void app::clear_keys(key min_inclusive, key max_exclusive) void app::clear_keys() { - keys.reset(); + keys_->reset(); key_modifiers = {}; } @@ -194,7 +196,7 @@ void app::on_key_up_down(const key_event& event, bool is_down) noexcept is_down && !event.is_repeated ? do_key(x, mods) : void(); else { - keys[x] = is_down; + (*keys_)[x] = is_down; key_modifiers[size_t(x)] = mods; } } diff --git a/editor/update.cpp b/editor/update.cpp index 5d4c75cb..be686567 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -10,6 +10,7 @@ #include "src/tile-iterator.hpp" #include "keys.hpp" #include "loader/loader.hpp" +#include "compat/enum-bitset.hpp" #include <cmath> namespace floormat { @@ -211,6 +212,7 @@ void app::update_world(float dt) void app::update_character([[maybe_unused]] float dt) { + auto& keys = *keys_; if (_character_id) { auto& w = M->world(); @@ -242,10 +244,10 @@ void app::update(float dt) { update_cursor_tile(cursor.pixel); tests_pre_update(); - apply_commands(keys); + apply_commands(*keys_); update_character(dt); update_world(dt); - do_camera(dt, keys, get_key_modifiers()); + do_camera(dt, *keys_, get_key_modifiers()); clear_non_repeated_keys(); set_cursor(); tests_post_update(); |