mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-04-05 17:32:40 +00:00
Improve Behavior Tick() behavior
Collect all objects first to account for the map being modified mid-iteration.
This commit is contained in:
parent
bd60fd7546
commit
f301e6cc0f
2 changed files with 9 additions and 3 deletions
|
@ -1441,7 +1441,7 @@ public:
|
|||
auto b = Behaviors.CheckKey(type.TypeName);
|
||||
return b != nullptr && *b != nullptr && !((*b)->ObjectFlags & OF_EuthanizeMe) ? *b : nullptr;
|
||||
}
|
||||
DObject* AddBehavior(const PClass& type);
|
||||
DObject* AddBehavior(PClass& type);
|
||||
bool RemoveBehavior(const PClass& type);
|
||||
void TickBehaviors();
|
||||
void MoveBehaviors(AActor& from);
|
||||
|
|
|
@ -497,7 +497,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, RemoveBehavior, RemoveBehavior)
|
|||
ACTION_RETURN_BOOL(self->RemoveBehavior(*type));
|
||||
}
|
||||
|
||||
DObject* AActor::AddBehavior(const PClass& type)
|
||||
DObject* AActor::AddBehavior(PClass& type)
|
||||
{
|
||||
if (type.bAbstract || !type.IsDescendantOf(NAME_Behavior))
|
||||
return nullptr;
|
||||
|
@ -505,7 +505,7 @@ DObject* AActor::AddBehavior(const PClass& type)
|
|||
auto b = FindBehavior(type);
|
||||
if (b == nullptr)
|
||||
{
|
||||
b = Create<DObject>();
|
||||
b = type.CreateNew();
|
||||
if (b == nullptr)
|
||||
return nullptr;
|
||||
|
||||
|
@ -558,6 +558,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, AddBehavior, AddBehavior)
|
|||
void AActor::TickBehaviors()
|
||||
{
|
||||
TArray<FName> toRemove = {};
|
||||
TArray<DObject*> toTick = {};
|
||||
|
||||
TMap<FName, DObject*>::Iterator it = { Behaviors };
|
||||
TMap<FName, DObject*>::Pair* pair = nullptr;
|
||||
|
@ -570,6 +571,11 @@ void AActor::TickBehaviors()
|
|||
continue;
|
||||
}
|
||||
|
||||
toTick.Push(b);
|
||||
}
|
||||
|
||||
for (auto& b : toTick)
|
||||
{
|
||||
auto& owner = b->PointerVar<AActor>(NAME_Owner);
|
||||
if (owner != this)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue