Skip to content

Commit

Permalink
b
Browse files Browse the repository at this point in the history
  • Loading branch information
sthalik committed Jan 15, 2024
1 parent 9a231ff commit e850be4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
13 changes: 9 additions & 4 deletions editor/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -171,14 +171,19 @@ struct app final : floormat_app
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;
Expand Down
2 changes: 1 addition & 1 deletion editor/ctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion editor/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions editor/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -407,7 +407,7 @@ void app::kill_popups(bool hard)
ImGui::CloseCurrentPopup();

if (hard)
inspectors.clear();
kill_inspectors();

if (_imgui)
ImGui::FocusWindow(nullptr);
Expand Down
12 changes: 2 additions & 10 deletions editor/inspect-draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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_;
Expand All @@ -61,7 +53,7 @@ auto z = e.coord.z();
(void)ret;
}
if (!is_open)
inspectors.erase(inspectors.begin() + (ptrdiff_t)i);
erase_inspector(i);
}
}

Expand Down
36 changes: 36 additions & 0 deletions editor/inspectors.cpp
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e850be4

Please sign in to comment.