From 9a231ffd8bd35108092d218c834544657bfb5986 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 15 Jan 2024 12:01:33 +0100 Subject: c --- compat/enum-bitset-fwd.hpp | 9 +++++++++ compat/enum-bitset.hpp | 3 ++- editor/app.cpp | 31 ++----------------------------- editor/app.hpp | 7 +++---- editor/camera.cpp | 1 + editor/ctor.cpp | 37 +++++++++++++++++++++++++++++++++++++ editor/events.cpp | 8 +++++--- editor/update.cpp | 6 ++++-- 8 files changed, 63 insertions(+), 39 deletions(-) create mode 100644 compat/enum-bitset-fwd.hpp create mode 100644 editor/ctor.cpp 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 +requires (std::is_enum_v && std::is_same_v>>) +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 namespace floormat { -template +template requires (std::is_enum_v && std::is_same_v>>) struct enum_bitset : std::bitset { 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 #include -#include #include #include #include -#include namespace floormat { @@ -31,29 +27,6 @@ Optional 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 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 _wireframe; Pointer _tests; Pointer _editor; - - key_set keys; - std::array key_modifiers = {}; + Pointer keys_; + std::array key_modifiers = {}; std::vector 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 #include 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 + +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 #include #include @@ -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::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 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(); -- cgit v1.2.3