From cabbb52cbb2cf44ba70df0748b07d882ebaab123 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 9 Oct 2024 12:03:16 +0200 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20Solventats=20els=20problemes=20de?= =?UTF-8?q?=20mem=C3=B2ria=20al=20eliminar=20un=20actor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/actor.cpp | 30 +++++++++++++++++++++++++++--- source/actor.h | 5 +++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/source/actor.cpp b/source/actor.cpp index ceb28de..ff28d2b 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -33,6 +33,7 @@ namespace actor int walk_channel = -1; bool push_sound_already_playing = false; + std::vector purgatory; void resetTag() { @@ -69,6 +70,7 @@ namespace actor act->surface = draw::getSurface(bmp.c_str()); act->bmp_rect = r; act->bmp_offset = o; + act->alive = true; return act; } @@ -89,6 +91,8 @@ namespace actor act->react_mask = act->react_push = 0; act->flags = FLAG_NONE; act->template_category = 0; + act->alive = true; + return act; } @@ -233,7 +237,7 @@ namespace actor newactor->prev = act->prev; newactor->next = act->next; act->prev = act->next = nullptr; - remove(act); + sendToPurgatory(act); return newactor; } @@ -1229,7 +1233,7 @@ namespace actor room::load(room::getExit(XP)); if (llevar_abad) { - actor::remove(actor::find("ABAD")); + actor::sendToPurgatory(actor::find("ABAD")); } act->pos.x = room::getMin().x - 3; act->pos.z = room::getDoor(XN) * 4; @@ -1427,7 +1431,7 @@ namespace actor { if (act->name[0] == '_') { - actor::remove(act); + actor::sendToPurgatory(act); return; } else @@ -1672,6 +1676,26 @@ namespace actor free(act); } + void sendToPurgatory(actor_t *act) + { + if (!act) return; + if (act->prev) act->prev->next = act->next; + if (act == first) first = act->next; + if (act == dirty) dirty = act->next; + if (act->next) act->next->prev = act->prev; + if (act == selected) selected = nullptr; + if (act->below) act->below->above = nullptr; + if (act->above) act->above->below = nullptr; + act->alive = false; + purgatory.push_back(act); + } + + void cleanPurgatory() + { + for (auto act : purgatory) remove(act); + purgatory.clear(); + } + void pick(actor_t *act) { if (!act) diff --git a/source/actor.h b/source/actor.h index 40a739f..b1b41e0 100644 --- a/source/actor.h +++ b/source/actor.h @@ -109,6 +109,7 @@ namespace actor int tag; int template_category; + bool alive; }; void resetTag(); @@ -169,6 +170,10 @@ namespace actor void remove(actor_t *act); + void sendToPurgatory(actor_t *act); + + void cleanPurgatory(); + void pick(actor_t *act); actor_t *getPicked();