From 257c2420545eb632a53c0fe3cd317be613dcb272 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 1 Mar 2023 17:23:27 +0100 Subject: editor: update bboxes from a central place --- editor/imgui-inspect.cpp | 3 +-- editor/inspect-types.cpp | 25 +++++++++++++++++++++---- editor/update.cpp | 12 +----------- 3 files changed, 23 insertions(+), 17 deletions(-) (limited to 'editor') diff --git a/editor/imgui-inspect.cpp b/editor/imgui-inspect.cpp index d776e032..529ef1a9 100644 --- a/editor/imgui-inspect.cpp +++ b/editor/imgui-inspect.cpp @@ -26,8 +26,7 @@ void app::draw_inspector() auto dpi = M->dpi_scale(); ImGui::SetNextWindowSize({300*dpi[0], 0}); auto b2 = begin_window("inspector"_s); - if (entities::inspect_type(s)) - c.mark_scenery_modified(); + c.with_scenery_bbox_update(s.index(), [&] { entities::inspect_type(s); }); } } } diff --git a/editor/inspect-types.cpp b/editor/inspect-types.cpp index 9a59118b..1168a88a 100644 --- a/editor/inspect-types.cpp +++ b/editor/inspect-types.cpp @@ -6,6 +6,7 @@ #include "entity/types.hpp" #include "inspect.hpp" #include "loader/loader.hpp" +#include "chunk.hpp" #include //#define TEST_STR @@ -46,16 +47,32 @@ struct entity_accessors { }, entity::type::field{"pass-mode"_s, [](const scenery_ref& x) { return x.frame.passability; }, - [](scenery_ref& x, pass_mode value) { x.frame.passability = value; } + [](scenery_ref& x, pass_mode value) { + x.chunk().with_scenery_bbox_update(x.index(), [&] { + x.frame.passability = value; + }); + }, }, entity::type::field{"bbox-offset"_s, [](const scenery_ref& x) { return x.frame.bbox_offset; }, - [](scenery_ref& x, Vector2b value) { x.frame.bbox_offset = value; }, - [](const scenery_ref& x) { return x.frame.passability == pass_mode::pass ? field_status::readonly : field_status::enabled; }, + [](scenery_ref& x, Vector2b value) { + x.chunk().with_scenery_bbox_update(x.index(), [&] { + x.frame.bbox_offset = value; + }); + }, + [](const scenery_ref& x) { + return x.frame.passability == pass_mode::pass + ? field_status::readonly + : field_status::enabled; + }, }, entity::type::field{"bbox-size"_s, [](const scenery_ref& x) { return x.frame.bbox_size; }, - [](scenery_ref& x, Vector2ub value) { x.frame.bbox_size = value; }, + [](scenery_ref& x, Vector2ub value) { + x.chunk().with_scenery_bbox_update(x.index(), [&] { + x.frame.bbox_size = value; + }); + }, [](const scenery_ref& x) { return x.frame.passability == pass_mode::pass ? field_status::readonly : field_status::enabled; }, }, entity::type::field{"interactive"_s, diff --git a/editor/update.cpp b/editor/update.cpp index f9afa6c9..a907117a 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -165,17 +165,7 @@ void app::update_world(float dt) for (std::int16_t x = minx; x <= maxx; x++) for (auto& c = world[chunk_coords{x, y}]; auto [x, k, pt] : c) if (auto sc = x.scenery()) - { - auto [atlas, s] = x.scenery(); - auto pass0 = s.passability; - auto offset0 = s.offset; - auto bb_offset0 = s.bbox_offset; - auto bb_size0 = s.bbox_size; - sc.update(dt); - if (pass0 != s.passability || offset0 != s.offset || - bb_offset0 != s.bbox_offset || bb_size0 != s.bbox_size) - c.mark_scenery_modified(); - } + c.with_scenery_bbox_update(sc.index(), [&] { sc.update(dt); }); } void app::set_cursor() -- cgit v1.2.3