2020-08-11 01:36:57 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "EntitySystem/EntityAllocationIterator.h"
|
|
|
|
|
#include "EntitySystem/MovieSceneEntitySystemTypes.h"
|
|
|
|
|
#include "EntitySystem/MovieSceneEntityManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace UE
|
|
|
|
|
{
|
|
|
|
|
namespace MovieScene
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
FEntityAllocationIterator::FEntityAllocationIterator(const FEntityManager* InManager)
|
|
|
|
|
: Filter(nullptr)
|
|
|
|
|
, Manager(InManager)
|
|
|
|
|
, AllocationIndex(Manager->EntityAllocationMasks.GetMaxIndex())
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
FEntityAllocationIterator::FEntityAllocationIterator(const FEntityManager* InManager, const FEntityComponentFilter* InFilter)
|
|
|
|
|
: Filter(InFilter)
|
|
|
|
|
, Manager(InManager)
|
|
|
|
|
{
|
|
|
|
|
Manager->EnterIteration();
|
|
|
|
|
AllocationIndex = FindMatchingAllocationStartingAt(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FEntityAllocationIterator::FEntityAllocationIterator(FEntityAllocationIterator&& RHS)
|
|
|
|
|
{
|
|
|
|
|
*this = MoveTemp(RHS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FEntityAllocationIterator& FEntityAllocationIterator::operator=(FEntityAllocationIterator&& RHS)
|
|
|
|
|
{
|
|
|
|
|
Manager = RHS.Manager;
|
|
|
|
|
Filter = RHS.Filter;
|
|
|
|
|
AllocationIndex = RHS.AllocationIndex;
|
|
|
|
|
|
|
|
|
|
// Wipe out the filter so it doesn't decrement the iteration count on destruction
|
|
|
|
|
RHS.Filter= nullptr;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FEntityAllocationIterator::~FEntityAllocationIterator()
|
|
|
|
|
{
|
|
|
|
|
if (Filter)
|
|
|
|
|
{
|
|
|
|
|
Manager->ExitIteration();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FEntityAllocationIterator::operator!=(const FEntityAllocationIterator& Other) const
|
|
|
|
|
{
|
|
|
|
|
return AllocationIndex != Other.AllocationIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FEntityAllocationIterator& FEntityAllocationIterator::operator++()
|
|
|
|
|
{
|
|
|
|
|
AllocationIndex = FindMatchingAllocationStartingAt(AllocationIndex + 1);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-11-24 18:42:39 -04:00
|
|
|
FEntityAllocationIteratorItem FEntityAllocationIterator::operator*() const
|
2020-08-11 01:36:57 -04:00
|
|
|
{
|
2020-11-24 18:42:39 -04:00
|
|
|
return FEntityAllocationIteratorItem(Manager, AllocationIndex);
|
2020-08-11 01:36:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int32 FEntityAllocationIterator::FindMatchingAllocationStartingAt(int32 Index) const
|
|
|
|
|
{
|
2021-05-25 02:43:26 -04:00
|
|
|
const FEntityComponentFilter& GlobalIterationFilter = Manager->GetGlobalIterationFilter();
|
|
|
|
|
const bool bHasGlobalFilter = GlobalIterationFilter.IsValid();
|
|
|
|
|
for ( ; Index < Manager->EntityAllocationMasks.GetMaxIndex(); ++Index)
|
2020-08-11 01:36:57 -04:00
|
|
|
{
|
2021-05-25 02:43:26 -04:00
|
|
|
if (!Manager->EntityAllocationMasks.IsAllocated(Index))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bHasGlobalFilter == true)
|
|
|
|
|
{
|
|
|
|
|
if (!GlobalIterationFilter.Match(Manager->EntityAllocationMasks[Index]))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Filter->Match(Manager->EntityAllocationMasks[Index]) && Manager->EntityAllocations[Index]->Num() > 0)
|
2020-08-11 01:36:57 -04:00
|
|
|
{
|
|
|
|
|
return Index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace MovieScene
|
2021-11-07 23:43:01 -05:00
|
|
|
} // namespace UE
|