Files
UnrealEngineUWP/Engine/Source/Runtime/MovieScene/Private/EntitySystem/EntityAllocationIterator.cpp
aurel cordonnier fc542f6cfd Merge from Release-Engine-Staging @ 18081189 to Release-Engine-Test
This represents UE4/Main @18073326, Release-5.0 @18081140 and Dev-PerfTest @18045971

[CL 18081471 by aurel cordonnier in ue5-release-engine-test branch]
2021-11-07 23:43:01 -05:00

100 lines
2.4 KiB
C++

// 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;
}
FEntityAllocationIteratorItem FEntityAllocationIterator::operator*() const
{
return FEntityAllocationIteratorItem(Manager, AllocationIndex);
}
int32 FEntityAllocationIterator::FindMatchingAllocationStartingAt(int32 Index) const
{
const FEntityComponentFilter& GlobalIterationFilter = Manager->GetGlobalIterationFilter();
const bool bHasGlobalFilter = GlobalIterationFilter.IsValid();
for ( ; Index < Manager->EntityAllocationMasks.GetMaxIndex(); ++Index)
{
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)
{
return Index;
}
}
return Index;
}
} // namespace MovieScene
} // namespace UE