summaryrefslogtreecommitdiffhomepage
path: root/editor
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-01 17:23:27 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-01 17:23:27 +0100
commit257c2420545eb632a53c0fe3cd317be613dcb272 (patch)
tree95dfb97898f84ea60b293e60453bef1c57088fa4 /editor
parentf6aed5a3ae2e6b2b2eb822deee0a579ca66cd13f (diff)
editor: update bboxes from a central place
Diffstat (limited to 'editor')
-rw-r--r--editor/imgui-inspect.cpp3
-rw-r--r--editor/inspect-types.cpp25
-rw-r--r--editor/update.cpp12
3 files changed, 23 insertions, 17 deletions
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 <Corrade/Containers/ArrayViewStl.h>
//#define TEST_STR
@@ -46,16 +47,32 @@ struct entity_accessors<scenery_ref> {
},
entity::type<pass_mode>::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<Vector2b>::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<Vector2ub>::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<bool>::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()