File tree Expand file tree Collapse file tree 6 files changed +51
-18
lines changed Expand file tree Collapse file tree 6 files changed +51
-18
lines changed Original file line number Diff line number Diff line change 88#include " editor-enums.hpp"
99#include " tests.hpp"
1010#include < memory>
11- #include < array >
12- #include < vector > // todo try removing?
11+ #include < Corrade/Containers/Array.h >
12+ #include < Corrade/Containers/StaticArray.h >
1313#include < Corrade/Containers/Pointer.h>
1414#include < Corrade/Containers/Optional.h>
1515#include < Magnum/Math/Vector2.h>
@@ -171,14 +171,19 @@ struct app final : floormat_app
171171 void tests_reset_mode ();
172172 tests_data& tests ();
173173
174+ void reserve_inspector_array ();
175+ void add_inspector (popup_target p);
176+ void erase_inspector (size_t index, ptrdiff_t count = 1 );
177+ void kill_inspectors ();
178+
174179 Pointer<floormat_main> M;
175180 Pointer<ImGuiIntegration::Context> _imgui;
176181 Pointer<floormat::wireframe::meshes> _wireframe;
177182 Pointer<tests_data_> _tests;
178183 Pointer<editor> _editor;
179184 Pointer<key_set> keys_;
180- std::array< int , key_COUNT > key_modifiers = { };
181- std::vector <popup_target> inspectors;
185+ StaticArray<key_COUNT, int > key_modifiers{ValueInit };
186+ Array <popup_target> inspectors;
182187 object_id _character_id = 0 ;
183188 struct cursor_state cursor;
184189 popup_target _popup_target;
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ app::app(fm_settings&& opts) :
2121 maybe_initialize_chunk_ (coord, w[coord]);
2222 reset_camera_offset ();
2323 M->set_render_vobjs (_render_vobjs);
24- inspectors. reserve ( 16 );
24+ reserve_inspector_array ( );
2525}
2626
2727app::~app ()
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ void app::clear_keys(key min_inclusive, key max_exclusive)
4949void app::clear_keys ()
5050{
5151 keys_->reset ();
52- key_modifiers = { };
52+ key_modifiers = StaticArray<key_COUNT, int >{ValueInit };
5353}
5454
5555void app::on_mouse_move (const mouse_move_event& event) noexcept
Original file line number Diff line number Diff line change @@ -366,7 +366,7 @@ void app::do_popup_menu()
366366 ImGui::MenuItem (" Inspect" , nullptr , exists))
367367 {
368368 if (!exists)
369- inspectors. push_back (std::exchange (_popup_target, {}));
369+ add_inspector (std::exchange (_popup_target, {}));
370370 else
371371 {
372372 char buf[32 ];
@@ -407,7 +407,7 @@ void app::kill_popups(bool hard)
407407 ImGui::CloseCurrentPopup ();
408408
409409 if (hard)
410- inspectors. clear ();
410+ kill_inspectors ();
411411
412412 if (_imgui)
413413 ImGui::FocusWindow (nullptr );
Original file line number Diff line number Diff line change @@ -17,14 +17,6 @@ void app::draw_inspector()
1717{
1818 auto b = push_id (" inspector" );
1919
20- constexpr auto max_inspectors = 10 ;
21- if (auto size = inspectors.size (); size > max_inspectors)
22- {
23- auto end = inspectors.begin () + (ptrdiff_t )size - max_inspectors;
24- inspectors.erase (inspectors.begin (), end);
25- fm_assert (inspectors.size () <= max_inspectors);
26- }
27-
2820 const auto dpi = M->dpi_scale ();
2921 auto & w = M->world ();
3022
@@ -34,7 +26,7 @@ void app::draw_inspector()
3426 auto e_ = w.find_object (id);
3527 if (!e_)
3628 {
37- inspectors. erase (inspectors. begin () + ptrdiff_t (i) );
29+ erase_inspector (i );
3830 continue ;
3931 }
4032 auto & e = *e_;
@@ -61,7 +53,7 @@ auto z = e.coord.z();
6153 (void )ret;
6254 }
6355 if (!is_open)
64- inspectors. erase (inspectors. begin () + ( ptrdiff_t ) i);
56+ erase_inspector ( i);
6557 }
6658}
6759
Original file line number Diff line number Diff line change 1+ #include " app.hpp"
2+ #include < Corrade/Containers/GrowableArray.h>
3+
4+ namespace floormat {
5+
6+ namespace {
7+ constexpr inline size_t max_inspectors = 2 ;
8+ } // namespace
9+
10+ void app::reserve_inspector_array ()
11+ {
12+ arrayReserve (inspectors, max_inspectors);
13+ }
14+
15+ void app::add_inspector (popup_target p)
16+ {
17+ if (inspectors.size () >= max_inspectors)
18+ arrayRemove (inspectors, 1 + inspectors.size () - max_inspectors);
19+
20+ arrayAppend (inspectors, p);
21+ }
22+
23+ void app::erase_inspector (size_t index, ptrdiff_t count)
24+ {
25+ fm_assert (count >= 0 );
26+ fm_assert (index < inspectors.size ());
27+ fm_assert (index + (size_t )count <= inspectors.size ());
28+ arrayRemove (inspectors, index, (size_t )count);
29+ }
30+
31+ void app::kill_inspectors ()
32+ {
33+ arrayResize (inspectors, 0 );
34+ }
35+
36+ } // namespace floormat
You can’t perform that action at this time.
0 commit comments