diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-02 18:56:39 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-02 22:54:16 +0200 |
commit | 518efccab147cae5b670c14ea1fc7b477f696a09 (patch) | |
tree | 5b468654399e3ba449b29ade9f2f5622ef902653 | |
parent | 0af58edf619ca071210d2bab399ca780390c7100 (diff) |
actually, don't delete objects during update
-rw-r--r-- | editor/update.cpp | 22 | ||||
-rw-r--r-- | src/critter.cpp | 3 |
2 files changed, 12 insertions, 13 deletions
diff --git a/editor/update.cpp b/editor/update.cpp index 1e47d197..e461c9b4 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -235,7 +235,7 @@ void app::update_world(Ns dt) for (int16_t y = miny; y <= maxy; y++) for (int16_t x = minx; x <= maxx; x++) { - auto* cʹ = world.at({x, y, z}); + auto* const cʹ = world.at({x, y, z}); if (!cʹ) continue; auto& c = *cʹ; @@ -245,19 +245,15 @@ void app::update_world(Ns dt) { auto eʹ = es[i]; auto index = size_t{i}; + auto& e = *eʹ; + if (e.last_frame_no == frame_no) [[unlikely]] + continue; + e.last_frame_no = frame_no; + e.update(eʹ, index, dt); // objects can't delete themselves during update() + if (&e.chunk() != cʹ || index > i) [[unlikely]] { - auto& e = *eʹ; - if (e.last_frame_no == frame_no) [[unlikely]] - continue; - e.last_frame_no = frame_no; - } - { - eʹ->update(eʹ, index, dt); - if (&eʹ->chunk() != cʹ || index > i) [[unlikely]] - { - i--; - size = (uint32_t)es.size(); - } + i--; + size = (uint32_t)es.size(); } } } diff --git a/src/critter.cpp b/src/critter.cpp index 18f91797..b08c083c 100644 --- a/src/critter.cpp +++ b/src/critter.cpp @@ -369,8 +369,11 @@ void critter::update(const std::shared_ptr<object>& ptrʹ, size_t& i, const Ns& check_script_update_1(script.state()); script->on_update(std::static_pointer_cast<critter>(ptrʹ), i, dt); +#if 0 + // for now, objects can't delete themselves if (check_script_update_2(script.state())) [[unlikely]] return; +#endif if (playable) [[unlikely]] { |