2021-09-29 02:38:01 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "AITestsCommon.h"
|
2022-08-12 10:47:11 -04:00
|
|
|
#include "MassEntityManager.h"
|
2023-01-11 03:01:44 -05:00
|
|
|
#include "MassExecutionContext.h"
|
2021-09-30 14:28:31 -04:00
|
|
|
#include "MassProcessingTypes.h"
|
2021-09-29 02:38:01 -04:00
|
|
|
#include "MassEntityTestTypes.h"
|
|
|
|
|
#include "MassExecutor.h"
|
|
|
|
|
|
2021-10-01 13:35:13 -04:00
|
|
|
#define LOCTEXT_NAMESPACE "MassTest"
|
2021-09-29 02:38:01 -04:00
|
|
|
|
2023-01-20 10:29:35 -05:00
|
|
|
UE_DISABLE_OPTIMIZATION_SHIP
|
|
|
|
|
|
2021-09-30 10:07:42 -04:00
|
|
|
namespace FMassProcessorTest
|
2021-09-29 02:38:01 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
template<typename TProcessor>
|
2022-08-12 07:56:27 -04:00
|
|
|
int32 SimpleProcessorRun(FMassEntityManager& EntityManager)
|
2021-09-29 02:38:01 -04:00
|
|
|
{
|
|
|
|
|
int32 EntityProcessedCount = 0;
|
2022-08-12 07:56:27 -04:00
|
|
|
TProcessor* Processor = NewObject<TProcessor>();
|
2023-01-25 07:13:10 -05:00
|
|
|
Processor->ForEachEntityChunkExecutionFunction = [&EntityProcessedCount](FMassExecutionContext& Context)
|
|
|
|
|
{
|
|
|
|
|
EntityProcessedCount += Context.GetNumEntities();
|
2021-09-29 02:38:01 -04:00
|
|
|
};
|
|
|
|
|
|
2022-08-12 07:56:27 -04:00
|
|
|
FMassProcessingContext ProcessingContext(EntityManager, /*DeltaSeconds=*/0.f);
|
2021-10-01 13:35:13 -04:00
|
|
|
UE::Mass::Executor::Run(*Processor, ProcessingContext);
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
return EntityProcessedCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct FProcessorTest_NoEntities : FEntityTestBase
|
|
|
|
|
{
|
|
|
|
|
virtual bool InstantTest() override
|
|
|
|
|
{
|
2022-08-12 07:56:27 -04:00
|
|
|
CA_ASSUME(EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
|
2022-08-12 07:56:27 -04:00
|
|
|
int32 EntityProcessedCount = SimpleProcessorRun<UMassTestProcessor_Floats>(*EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
AITEST_EQUAL("No entities have been created yet so the processor shouldn't do any work.", EntityProcessedCount, 0);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-10-01 13:35:13 -04:00
|
|
|
IMPLEMENT_AI_INSTANT_TEST(FProcessorTest_NoEntities, "System.Mass.Processor.NoEntities");
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
struct FProcessorTest_NoMatchingEntities : FEntityTestBase
|
|
|
|
|
{
|
|
|
|
|
virtual bool InstantTest() override
|
|
|
|
|
{
|
2022-08-12 07:56:27 -04:00
|
|
|
CA_ASSUME(EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
|
2021-09-30 10:07:42 -04:00
|
|
|
TArray<FMassEntityHandle> EntitiesCreated;
|
2022-08-12 07:56:27 -04:00
|
|
|
EntityManager->BatchCreateEntities(IntsArchetype, 100, EntitiesCreated);
|
|
|
|
|
int32 EntityProcessedCount = SimpleProcessorRun<UMassTestProcessor_Floats>(*EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
AITEST_EQUAL("No matching entities have been created yet so the processor shouldn't do any work.", EntityProcessedCount, 0);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-10-01 13:35:13 -04:00
|
|
|
IMPLEMENT_AI_INSTANT_TEST(FProcessorTest_NoMatchingEntities, "System.Mass.Processor.NoMatchingEntities");
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
struct FProcessorTest_OneMatchingArchetype : FEntityTestBase
|
|
|
|
|
{
|
|
|
|
|
virtual bool InstantTest() override
|
|
|
|
|
{
|
2022-08-12 07:56:27 -04:00
|
|
|
CA_ASSUME(EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
const int32 EntitiesToCreate = 100;
|
2021-09-30 10:07:42 -04:00
|
|
|
TArray<FMassEntityHandle> EntitiesCreated;
|
2022-08-12 07:56:27 -04:00
|
|
|
EntityManager->BatchCreateEntities(FloatsArchetype, EntitiesToCreate, EntitiesCreated);
|
|
|
|
|
int32 EntityProcessedCount = SimpleProcessorRun<UMassTestProcessor_Floats>(*EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
AITEST_EQUAL("No matching entities have been created yet so the processor shouldn't do any work.", EntityProcessedCount, EntitiesToCreate);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-10-01 13:35:13 -04:00
|
|
|
IMPLEMENT_AI_INSTANT_TEST(FProcessorTest_OneMatchingArchetype, "System.Mass.Processor.OneMatchingArchetype");
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
struct FProcessorTest_MultipleMatchingArchetype : FEntityTestBase
|
|
|
|
|
{
|
|
|
|
|
virtual bool InstantTest() override
|
|
|
|
|
{
|
2022-08-12 07:56:27 -04:00
|
|
|
CA_ASSUME(EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
const int32 EntitiesToCreate = 100;
|
2021-09-30 10:07:42 -04:00
|
|
|
TArray<FMassEntityHandle> EntitiesCreated;
|
2022-08-12 07:56:27 -04:00
|
|
|
EntityManager->BatchCreateEntities(FloatsArchetype, EntitiesToCreate, EntitiesCreated);
|
|
|
|
|
EntityManager->BatchCreateEntities(FloatsIntsArchetype, EntitiesToCreate, EntitiesCreated);
|
|
|
|
|
EntityManager->BatchCreateEntities(IntsArchetype, EntitiesToCreate, EntitiesCreated);
|
2021-09-29 02:38:01 -04:00
|
|
|
// note that only two of these archetypes match
|
2022-08-12 07:56:27 -04:00
|
|
|
int32 EntityProcessedCount = SimpleProcessorRun<UMassTestProcessor_Floats>(*EntityManager);
|
2021-09-29 02:38:01 -04:00
|
|
|
AITEST_EQUAL("Two of given three archetypes should match.", EntityProcessedCount, EntitiesToCreate * 2);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-10-01 13:35:13 -04:00
|
|
|
IMPLEMENT_AI_INSTANT_TEST(FProcessorTest_MultipleMatchingArchetype, "System.Mass.Processor.MultipleMatchingArchetype");
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
struct FProcessorTest_Requirements : FEntityTestBase
|
|
|
|
|
{
|
|
|
|
|
virtual bool InstantTest() override
|
|
|
|
|
{
|
|
|
|
|
// add an array to the configurable ExecutionFunction an
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-10-01 13:35:13 -04:00
|
|
|
IMPLEMENT_AI_INSTANT_TEST(FProcessorTest_Requirements, "System.Mass.Processor.Requirements");
|
2021-09-29 02:38:01 -04:00
|
|
|
|
|
|
|
|
|
2021-09-30 10:07:42 -04:00
|
|
|
} // FMassProcessorTestTest
|
2021-09-29 02:38:01 -04:00
|
|
|
|
2023-01-20 10:29:35 -05:00
|
|
|
UE_ENABLE_OPTIMIZATION_SHIP
|
|
|
|
|
|
2021-09-29 02:38:01 -04:00
|
|
|
#undef LOCTEXT_NAMESPACE
|
|
|
|
|
|