summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-03-18 17:48:34 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-03-18 17:48:34 +0100
commitb426d61f903fa4dd635fb525eb4c28ca1c1d1929 (patch)
treeb941499890be0698f3138866c94677a86fcd59e6
parenta418f0571231a429b8e0adfea7e09c2f81856a57 (diff)
src: fix scenery mesh modified marking
-rw-r--r--editor/scenery-editor.cpp3
-rw-r--r--editor/update.cpp8
-rw-r--r--serialize/world-reader.cpp2
-rw-r--r--src/chunk.cpp19
-rw-r--r--src/chunk.hpp2
-rw-r--r--src/entity.cpp9
-rw-r--r--src/world.cpp3
7 files changed, 23 insertions, 23 deletions
diff --git a/editor/scenery-editor.cpp b/editor/scenery-editor.cpp
index 22a7fd16..45dd0288 100644
--- a/editor/scenery-editor.cpp
+++ b/editor/scenery-editor.cpp
@@ -96,11 +96,8 @@ void scenery_editor::place_tile(world& w, global_coords pos, const scenery_& s)
}
}
else
- {
// todo check collision at pos
w.make_entity<scenery>(w.make_id(), pos, s.proto);
- }
- c.mark_scenery_modified();
}
} // namespace floormat
diff --git a/editor/update.cpp b/editor/update.cpp
index 7c084a85..e9570208 100644
--- a/editor/update.cpp
+++ b/editor/update.cpp
@@ -108,11 +108,7 @@ void app::do_rotate(bool backward)
{
auto& e = *cl->e;
auto r = backward ? e.atlas->prev_rotation_from(e.r) : e.atlas->next_rotation_from(e.r);
- if (r != e.r)
- {
- e.rotate(e.index(), r);
- e.chunk().mark_scenery_modified();
- }
+ e.rotate(e.index(), r);
}
}
}
@@ -211,7 +207,7 @@ void app::set_cursor()
{
if (!cursor.in_imgui)
{
- if (auto* cl = find_clickable_scenery(cursor.pixel))
+ if ([[maybe_unused]] auto* cl = find_clickable_scenery(cursor.pixel))
M->set_cursor(std::uint32_t(Cursor::Hand));
else
M->set_cursor(std::uint32_t(Cursor::Arrow));
diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp
index 4b050bc2..1b32204f 100644
--- a/serialize/world-reader.cpp
+++ b/serialize/world-reader.cpp
@@ -234,7 +234,7 @@ void reader_state::read_chunks(reader_t& s)
if (!(id & meta_short_scenery_bit))
read_offsets(s, proto);
SET_CHUNK_SIZE();
- auto e = _world->make_entity<character>(oid, {ch, local}, proto);
+ auto e = _world->make_entity<character, false>(oid, {ch, local}, proto);
(void)e;
break;
}
diff --git a/src/chunk.cpp b/src/chunk.cpp
index e0a09012..3adce5de 100644
--- a/src/chunk.cpp
+++ b/src/chunk.cpp
@@ -63,13 +63,11 @@ void chunk::mark_walls_modified() noexcept
mark_passability_modified();
}
-void chunk::mark_scenery_modified(bool collision_too) noexcept // todo remove bool
+void chunk::mark_scenery_modified() noexcept
{
if (!_scenery_modified && !is_log_quiet())
fm_debug("scenery reload %zu", ++_reload_no_);
_scenery_modified = true;
- if (collision_too)
- mark_passability_modified();
}
void chunk::mark_passability_modified() noexcept
@@ -86,7 +84,7 @@ void chunk::mark_modified() noexcept
{
mark_ground_modified();
mark_walls_modified();
- mark_scenery_modified(false);
+ mark_scenery_modified();
mark_passability_modified();
}
@@ -110,7 +108,7 @@ void chunk::add_entity_unsorted(const std::shared_ptr<entity>& e)
{
_entities_sorted = false;
if (!e->is_dynamic())
- mark_scenery_modified(false);
+ mark_scenery_modified();
if (bbox bb; _bbox_for_scenery(*e, bb))
_add_bbox(bb);
_entities.push_back(e);
@@ -118,8 +116,11 @@ void chunk::add_entity_unsorted(const std::shared_ptr<entity>& e)
void chunk::sort_entities()
{
+ if (_entities_sorted)
+ return;
+
_entities_sorted = true;
- mark_scenery_modified(false);
+ mark_scenery_modified();
std::sort(_entities.begin(), _entities.end(), [](const auto& a, const auto& b) {
return a->ordinal() < b->ordinal();
@@ -129,8 +130,8 @@ void chunk::sort_entities()
void chunk::add_entity(const std::shared_ptr<entity>& e)
{
fm_assert(_entities_sorted);
- if (e->atlas->info().fps == 0)
- mark_scenery_modified(false);
+ if (!e->is_dynamic())
+ mark_scenery_modified();
if (bbox bb; _bbox_for_scenery(*e, bb))
_add_bbox(bb);
@@ -147,7 +148,7 @@ void chunk::remove_entity(std::size_t i)
fm_debug_assert(i < _entities.size());
const auto& e = _entities[i];
if (!e->is_dynamic())
- mark_scenery_modified(false);
+ mark_scenery_modified();
if (bbox bb; _bbox_for_scenery(*e, bb))
_remove_bbox(bb);
diff --git a/src/chunk.hpp b/src/chunk.hpp
index e51c55ac..d22ce7fe 100644
--- a/src/chunk.hpp
+++ b/src/chunk.hpp
@@ -59,7 +59,7 @@ struct chunk final
void mark_ground_modified() noexcept;
void mark_walls_modified() noexcept;
- void mark_scenery_modified(bool collision_too = true) noexcept;
+ void mark_scenery_modified() noexcept;
void mark_passability_modified() noexcept;
void mark_modified() noexcept;
diff --git a/src/entity.cpp b/src/entity.cpp
index d06cf52a..efa4655f 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -91,6 +91,8 @@ void entity::rotate(std::size_t, rotation new_r)
{
fm_assert(atlas->check_rotation(new_r));
set_bbox(offset, rotate_point(bbox_offset, r, new_r), rotate_size(bbox_size, r, new_r), pass);
+ if (r != new_r && !is_dynamic())
+ c->mark_scenery_modified();
const_cast<rotation&>(r) = new_r;
}
@@ -152,7 +154,7 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r)
return i;
if (!e.is_dynamic())
- c->mark_scenery_modified(false);
+ c->mark_scenery_modified();
chunk::bbox bb0, bb1;
const auto bb_offset = rotate_point(bbox_offset, r, new_r);
@@ -185,7 +187,7 @@ std::size_t entity::move(std::size_t i, Vector2i delta, rotation new_r)
//fm_debug("change-chunk (%hd;%hd|%hhd;%hhd)", coord_.chunk().x, coord_.chunk().y, coord_.local().x, coord_.local().y);
auto& c2 = w[coord_.chunk()];
if (!e.is_dynamic())
- c2.mark_scenery_modified(false);
+ c2.mark_scenery_modified();
c2._add_bbox(bb1);
c->remove_entity(i);
auto& es = c2._entities;
@@ -225,6 +227,9 @@ entity::operator entity_proto() const
void entity::set_bbox(Vector2b offset_, Vector2b bbox_offset_, Vector2ub bbox_size_, pass_mode pass)
{
+ if (offset != offset_ && !is_dynamic())
+ c->mark_scenery_modified();
+
chunk::bbox bb0, bb;
const bool b0 = c->_bbox_for_scenery(*this, bb0);
set_bbox_(offset_, bbox_offset_, bbox_size_, pass);
diff --git a/src/world.cpp b/src/world.cpp
index f519a91f..d6099302 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -39,7 +39,8 @@ world::~world() noexcept
for (auto& [k, v] : _chunks)
{
v._teardown = true;
- v.mark_scenery_modified(true);
+ v.mark_scenery_modified();
+ v.mark_passability_modified();
_last_chunk = {};
v._entities.clear();
}