summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--editor/app.hpp13
-rw-r--r--editor/ctor.cpp2
-rw-r--r--editor/events.cpp2
-rw-r--r--editor/imgui.cpp4
-rw-r--r--editor/inspect-draw.cpp12
-rw-r--r--editor/inspectors.cpp36
6 files changed, 51 insertions, 18 deletions
diff --git a/editor/app.hpp b/editor/app.hpp
index 662313bc..b869f2b4 100644
--- a/editor/app.hpp
+++ b/editor/app.hpp
@@ -8,8 +8,8 @@
#include "editor-enums.hpp"
#include "tests.hpp"
#include <memory>
-#include <array>
-#include <vector> // todo try removing?
+#include <Corrade/Containers/Array.h>
+#include <Corrade/Containers/StaticArray.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/Optional.h>
#include <Magnum/Math/Vector2.h>
@@ -171,14 +171,19 @@ private:
void tests_reset_mode();
tests_data& tests();
+ void reserve_inspector_array();
+ void add_inspector(popup_target p);
+ void erase_inspector(size_t index, ptrdiff_t count = 1);
+ void kill_inspectors();
+
Pointer<floormat_main> M;
Pointer<ImGuiIntegration::Context> _imgui;
Pointer<floormat::wireframe::meshes> _wireframe;
Pointer<tests_data_> _tests;
Pointer<editor> _editor;
Pointer<key_set> keys_;
- std::array<int, key_COUNT> key_modifiers = {};
- std::vector<popup_target> inspectors;
+ StaticArray<key_COUNT, int> key_modifiers{ValueInit};
+ Array<popup_target> inspectors;
object_id _character_id = 0;
struct cursor_state cursor;
popup_target _popup_target;
diff --git a/editor/ctor.cpp b/editor/ctor.cpp
index 0d912ded..ccda3060 100644
--- a/editor/ctor.cpp
+++ b/editor/ctor.cpp
@@ -21,7 +21,7 @@ app::app(fm_settings&& opts) :
maybe_initialize_chunk_(coord, w[coord]);
reset_camera_offset();
M->set_render_vobjs(_render_vobjs);
- inspectors.reserve(16);
+ reserve_inspector_array();
}
app::~app()
diff --git a/editor/events.cpp b/editor/events.cpp
index 8eb99677..77d9db11 100644
--- a/editor/events.cpp
+++ b/editor/events.cpp
@@ -49,7 +49,7 @@ void app::clear_keys(key min_inclusive, key max_exclusive)
void app::clear_keys()
{
keys_->reset();
- key_modifiers = {};
+ key_modifiers = StaticArray<key_COUNT, int>{ValueInit};
}
void app::on_mouse_move(const mouse_move_event& event) noexcept
diff --git a/editor/imgui.cpp b/editor/imgui.cpp
index 2b768948..3465f27a 100644
--- a/editor/imgui.cpp
+++ b/editor/imgui.cpp
@@ -366,7 +366,7 @@ void app::do_popup_menu()
ImGui::MenuItem("Inspect", nullptr, exists))
{
if (!exists)
- inspectors.push_back(std::exchange(_popup_target, {}));
+ add_inspector(std::exchange(_popup_target, {}));
else
{
char buf[32];
@@ -407,7 +407,7 @@ void app::kill_popups(bool hard)
ImGui::CloseCurrentPopup();
if (hard)
- inspectors.clear();
+ kill_inspectors();
if (_imgui)
ImGui::FocusWindow(nullptr);
diff --git a/editor/inspect-draw.cpp b/editor/inspect-draw.cpp
index bc3237a5..34c096ea 100644
--- a/editor/inspect-draw.cpp
+++ b/editor/inspect-draw.cpp
@@ -17,14 +17,6 @@ void app::draw_inspector()
{
auto b = push_id("inspector");
- constexpr auto max_inspectors = 10;
- if (auto size = inspectors.size(); size > max_inspectors)
- {
- auto end = inspectors.begin() + (ptrdiff_t)size - max_inspectors;
- inspectors.erase(inspectors.begin(), end);
- fm_assert(inspectors.size() <= max_inspectors);
- }
-
const auto dpi = M->dpi_scale();
auto& w = M->world();
@@ -34,7 +26,7 @@ void app::draw_inspector()
auto e_ = w.find_object(id);
if (!e_)
{
- inspectors.erase(inspectors.begin() + ptrdiff_t(i));
+ erase_inspector(i);
continue;
}
auto& e = *e_;
@@ -61,7 +53,7 @@ auto z = e.coord.z();
(void)ret;
}
if (!is_open)
- inspectors.erase(inspectors.begin() + (ptrdiff_t)i);
+ erase_inspector(i);
}
}
diff --git a/editor/inspectors.cpp b/editor/inspectors.cpp
new file mode 100644
index 00000000..d91bc70f
--- /dev/null
+++ b/editor/inspectors.cpp
@@ -0,0 +1,36 @@
+#include "app.hpp"
+#include <Corrade/Containers/GrowableArray.h>
+
+namespace floormat {
+
+namespace {
+constexpr inline size_t max_inspectors = 2;
+} // namespace
+
+void app::reserve_inspector_array()
+{
+ arrayReserve(inspectors, max_inspectors);
+}
+
+void app::add_inspector(popup_target p)
+{
+ if (inspectors.size() >= max_inspectors)
+ arrayRemove(inspectors, 1 + inspectors.size() - max_inspectors);
+
+ arrayAppend(inspectors, p);
+}
+
+void app::erase_inspector(size_t index, ptrdiff_t count)
+{
+ fm_assert(count >= 0);
+ fm_assert(index < inspectors.size());
+ fm_assert(index + (size_t)count <= inspectors.size());
+ arrayRemove(inspectors, index, (size_t)count);
+}
+
+void app::kill_inspectors()
+{
+ arrayResize(inspectors, 0);
+}
+
+} // namespace floormat