2021-09-29 02:36:08 -04:00
// Copyright Epic Games, Inc. All Rights Reserved.
2021-09-29 09:10:30 -04:00
# include "MassEntitySubsystem.h"
2022-11-03 14:18:47 -04:00
# include "HAL/IConsoleManager.h"
2022-08-12 07:56:27 -04:00
2022-09-28 01:06:15 -04:00
# include UE_INLINE_GENERATED_CPP_BY_NAME(MassEntitySubsystem)
2024-08-02 16:47:31 -04:00
namespace UE : : Mass : : Private
{
static bool bEnableMassConcurrentReserveRuntime = true ;
static int32 ConcurrentReserveMaxEntityCount = 1 < < 27 ;
static int32 ConcurrentReserveMaxEntitiesPerPage = 1 < < 16 ;
2022-09-28 01:06:15 -04:00
2024-08-02 16:47:31 -04:00
namespace
{
FAutoConsoleVariableRef CVars [ ] = {
{
TEXT ( " Mass.ConcurrentReserve.Enable " ) ,
bEnableMassConcurrentReserveRuntime ,
TEXT ( " Enable Mass's concurrent reserve feature in runtime " ) ,
ECVF_Default
} ,
{
TEXT ( " Mass.ConcurrentReserve.MaxEntityCount " ) ,
ConcurrentReserveMaxEntityCount ,
TEXT ( " Set maximum number of permissible entities. Must be power of 2. " ) ,
ECVF_Default
} ,
{
TEXT ( " Mass.ConcurrentReserve.EntitiesPerPage " ) ,
ConcurrentReserveMaxEntitiesPerPage ,
TEXT ( " Set number of entities per page. Must be power of 2. Larger reduces fixed memory overhead of FEntityData page lookup but requires bigger contiguous memory blocks per page " ) ,
ECVF_Default
}
} ;
}
}
2022-08-12 07:56:27 -04:00
//////////////////////////////////////////////////////////////////////
// UMassEntitySubsystem
UMassEntitySubsystem : : UMassEntitySubsystem ( )
: EntityManager ( MakeShareable ( new FMassEntityManager ( this ) ) )
{
}
void UMassEntitySubsystem : : GetResourceSizeEx ( FResourceSizeEx & CumulativeResourceSize )
{
Super : : GetResourceSizeEx ( CumulativeResourceSize ) ;
EntityManager - > GetResourceSizeEx ( CumulativeResourceSize ) ;
}
void UMassEntitySubsystem : : Initialize ( FSubsystemCollectionBase & Collection )
{
2023-11-14 03:36:11 -05:00
Super : : Initialize ( Collection ) ;
2024-08-02 16:47:31 -04:00
FMassEntityManagerStorageInitParams InitializationParams ;
if ( UE : : Mass : : Private : : bEnableMassConcurrentReserveRuntime )
{
InitializationParams . Emplace < FMassEntityManager_InitParams_Concurrent > (
FMassEntityManager_InitParams_Concurrent
{
. MaxEntityCount = static_cast < uint32 > ( UE : : Mass : : Private : : ConcurrentReserveMaxEntityCount ) ,
. MaxEntitiesPerPage = static_cast < uint32 > ( UE : : Mass : : Private : : ConcurrentReserveMaxEntitiesPerPage )
} ) ;
}
else
{
InitializationParams . Emplace < FMassEntityManager_InitParams_SingleThreaded > ( ) ;
}
EntityManager - > Initialize ( InitializationParams ) ;
2023-11-14 03:36:11 -05:00
HandleLateCreation ( ) ;
2022-08-12 07:56:27 -04:00
}
void UMassEntitySubsystem : : PostInitialize ( )
{
2023-11-14 03:36:11 -05:00
Super : : PostInitialize ( ) ;
2022-08-12 07:56:27 -04:00
// this needs to be done after all the subsystems have been initialized since some processors might want to access
// them during processors' initialization
EntityManager - > PostInitialize ( ) ;
}
void UMassEntitySubsystem : : Deinitialize ( )
{
EntityManager - > Deinitialize ( ) ;
2022-08-29 11:12:18 -04:00
EntityManager . Reset ( ) ;
2023-11-14 03:36:11 -05:00
Super : : Deinitialize ( ) ;
2022-08-12 07:56:27 -04:00
}
2022-08-12 10:47:11 -04:00
# if WITH_MASSENTITY_DEBUG
//////////////////////////////////////////////////////////////////////
// Debug commands
FAutoConsoleCommandWithWorldArgsAndOutputDevice GPrintArchetypesCmd (
TEXT ( " EntityManager.PrintArchetypes " ) ,
TEXT ( " Prints information about all archetypes in the current world " ) ,
FConsoleCommandWithWorldArgsAndOutputDeviceDelegate : : CreateStatic (
[ ] ( const TArray < FString > & Params , UWorld * World , FOutputDevice & Ar )
{
if ( const UMassEntitySubsystem * EntitySubsystem = World ? World - > GetSubsystem < UMassEntitySubsystem > ( ) : nullptr )
{
EntitySubsystem - > GetEntityManager ( ) . DebugPrintArchetypes ( Ar ) ;
}
else
{
Ar . Logf ( ELogVerbosity : : Error , TEXT ( " Failed to find Entity Subsystem for world %s " ) , * GetPathNameSafe ( World ) ) ;
}
} ) ) ;
# endif // WITH_MASSENTITY_DEBUG