Clean up behaviors properly when moving levels

Also adds support for foreach loops with the behavior iterator.
This commit is contained in:
Boondorl 2025-01-25 10:52:54 -05:00 committed by Ricardo Luís Vaz Silva
commit 1e05bb2a55
6 changed files with 55 additions and 2 deletions

View file

@ -716,6 +716,44 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, ClearBehaviors, ClearBehaviors)
return 0;
}
void AActor::UnlinkBehaviorsFromLevel()
{
TArray<FName> toRemove = {};
TMap<FName, DBehavior*>::Iterator it = { Behaviors };
TMap<FName, DBehavior*>::Pair* pair = nullptr;
while (it.NextPair(pair))
{
auto b = pair->Value;
if (b == nullptr || (b->ObjectFlags & OF_EuthanizeMe))
toRemove.Push(pair->Key);
else
b->Level->RemoveActorBehavior(*b);
}
for (auto& type : toRemove)
RemoveBehavior(*PClass::FindClass(type));
}
void AActor::LinkBehaviorsToLevel()
{
TArray<FName> toRemove = {};
TMap<FName, DBehavior*>::Iterator it = { Behaviors };
TMap<FName, DBehavior*>::Pair* pair = nullptr;
while (it.NextPair(pair))
{
auto b = pair->Value;
if (b == nullptr || (b->ObjectFlags & OF_EuthanizeMe))
toRemove.Push(pair->Key);
else
Level->AddActorBehavior(*b);
}
for (auto& type : toRemove)
RemoveBehavior(*PClass::FindClass(type));
}
//==========================================================================
//
// AActor::InStateSequence