@ -198,7 +198,7 @@ namespace AZ
const EntityIdToEntityIdMap * remapFromIdToId /*=nullptr*/ ,
const EntityIdToEntityIdMap * remapFromIdToId /*=nullptr*/ ,
const DataFlagsTransformFunction & dataFlagsTransformFn /*=nullptr*/ )
const DataFlagsTransformFunction & dataFlagsTransformFn /*=nullptr*/ )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
for ( const auto & entityIdFlagsMapPair : from . m_entityToDataFlags )
for ( const auto & entityIdFlagsMapPair : from . m_entityToDataFlags )
{
{
@ -240,7 +240,7 @@ namespace AZ
//=========================================================================
//=========================================================================
DataPatch : : FlagsMap SliceComponent : : DataFlagsPerEntity : : GetDataFlagsForPatching ( const EntityIdToEntityIdMap * remapFromIdToId /*=nullptr*/ ) const
DataPatch : : FlagsMap SliceComponent : : DataFlagsPerEntity : : GetDataFlagsForPatching ( const EntityIdToEntityIdMap * remapFromIdToId /*=nullptr*/ ) const
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// Collect together data flags from all entities
// Collect together data flags from all entities
DataPatch : : FlagsMap dataFlagsForAllEntities ;
DataPatch : : FlagsMap dataFlagsForAllEntities ;
@ -423,7 +423,7 @@ namespace AZ
//=========================================================================
//=========================================================================
void SliceComponent : : DataFlagsPerEntity : : Cleanup ( const EntityList & validEntities )
void SliceComponent : : DataFlagsPerEntity : : Cleanup ( const EntityList & validEntities )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
EntityIdSet validEntityIds ;
EntityIdSet validEntityIds ;
for ( const Entity * entity : validEntities )
for ( const Entity * entity : validEntities )
@ -677,7 +677,7 @@ namespace AZ
//=========================================================================
//=========================================================================
SliceComponent : : SliceInstance * SliceComponent : : SliceReference : : PrepareCreateInstance ( const SliceInstanceId & sliceInstanceId , bool allowUninstantiated )
SliceComponent : : SliceInstance * SliceComponent : : SliceReference : : PrepareCreateInstance ( const SliceInstanceId & sliceInstanceId , bool allowUninstantiated )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// create an empty instance (just copy of the existing data)
// create an empty instance (just copy of the existing data)
SliceInstance * instance = CreateEmptyInstance ( sliceInstanceId ) ;
SliceInstance * instance = CreateEmptyInstance ( sliceInstanceId ) ;
@ -737,7 +737,7 @@ namespace AZ
AZ : : SerializeContext * serializeContext ,
AZ : : SerializeContext * serializeContext ,
const AZ : : IdUtils : : Remapper < AZ : : EntityId > : : IdMapper & customMapper )
const AZ : : IdUtils : : Remapper < AZ : : EntityId > : : IdMapper & customMapper )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
if ( ! remapContainer )
if ( ! remapContainer )
{
{
@ -808,7 +808,7 @@ namespace AZ
SliceComponent : : SliceInstance * SliceComponent : : SliceReference : : CreateInstance ( const AZ : : IdUtils : : Remapper < AZ : : EntityId > : : IdMapper & customMapper ,
SliceComponent : : SliceInstance * SliceComponent : : SliceReference : : CreateInstance ( const AZ : : IdUtils : : Remapper < AZ : : EntityId > : : IdMapper & customMapper ,
SliceInstanceId sliceInstanceId )
SliceInstanceId sliceInstanceId )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// Validate that we are able to create an instance at this time
// Validate that we are able to create an instance at this time
// If we are instantiated then this includes verifying that we have a valid component and asset
// If we are instantiated then this includes verifying that we have a valid component and asset
@ -842,7 +842,7 @@ namespace AZ
const EntityIdToEntityIdMap assetToLiveIdMap ,
const EntityIdToEntityIdMap assetToLiveIdMap ,
SliceInstanceId sliceInstanceId )
SliceInstanceId sliceInstanceId )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// Validate that we are able to create an instance at this time
// Validate that we are able to create an instance at this time
// This includes verifying that we are instantiated, and have a valid component and asset
// This includes verifying that we are instantiated, and have a valid component and asset
@ -883,7 +883,7 @@ namespace AZ
SliceComponent : : SliceInstance * SliceComponent : : SliceReference : : CloneInstance ( SliceComponent : : SliceInstance * instance ,
SliceComponent : : SliceInstance * SliceComponent : : SliceReference : : CloneInstance ( SliceComponent : : SliceInstance * instance ,
SliceComponent : : EntityIdToEntityIdMap & sourceToCloneEntityIdMap )
SliceComponent : : EntityIdToEntityIdMap & sourceToCloneEntityIdMap )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// check if source instance belongs to this slice reference
// check if source instance belongs to this slice reference
auto findIt = AZStd : : find_if ( m_instances . begin ( ) , m_instances . end ( ) , [ instance ] ( const SliceInstance & element ) - > bool { return & element = = instance ; } ) ;
auto findIt = AZStd : : find_if ( m_instances . begin ( ) , m_instances . end ( ) , [ instance ] ( const SliceInstance & element ) - > bool { return & element = = instance ; } ) ;
@ -1053,7 +1053,7 @@ namespace AZ
//=========================================================================
//=========================================================================
bool SliceComponent : : SliceReference : : Instantiate ( const AZ : : ObjectStream : : FilterDescriptor & filterDesc )
bool SliceComponent : : SliceReference : : Instantiate ( const AZ : : ObjectStream : : FilterDescriptor & filterDesc )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
if ( m_isInstantiated )
if ( m_isInstantiated )
{
{
@ -1145,7 +1145,7 @@ namespace AZ
//=========================================================================
//=========================================================================
void SliceComponent : : SliceReference : : InstantiateInstance ( SliceInstance & instance , const AZ : : ObjectStream : : FilterDescriptor & filterDesc )
void SliceComponent : : SliceReference : : InstantiateInstance ( SliceInstance & instance , const AZ : : ObjectStream : : FilterDescriptor & filterDesc )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// Could have set this during SliceInstance() constructor, but we wait until instantiation since it involves allocation.
// Could have set this during SliceInstance() constructor, but we wait until instantiation since it involves allocation.
instance . m_dataFlags . SetIsValidEntityFunction ( [ & instance ] ( EntityId entityId ) { return instance . IsValidEntity ( entityId ) ; } ) ;
instance . m_dataFlags . SetIsValidEntityFunction ( [ & instance ] ( EntityId entityId ) { return instance . IsValidEntity ( entityId ) ; } ) ;
@ -1167,7 +1167,7 @@ namespace AZ
// An empty map indicates its a fresh instance (i.e. has never be instantiated and then serialized).
// An empty map indicates its a fresh instance (i.e. has never be instantiated and then serialized).
if ( entityIdMap . empty ( ) )
if ( entityIdMap . empty ( ) )
{
{
AZ_PROFILE_SCOPE ( A Z: : Debug : : ProfileCategory : : A zCore, " SliceComponent::SliceReference::InstantiateInstance:FreshInstanceClone " ) ;
AZ_PROFILE_SCOPE ( A zCore, " SliceComponent::SliceReference::InstantiateInstance:FreshInstanceClone " ) ;
// Generate new Ids and populate the map.
// Generate new Ids and populate the map.
AZ_Assert ( ! dataPatch . IsValid ( ) , " Data patch is valid for slice instance, but entity Id map is not! " ) ;
AZ_Assert ( ! dataPatch . IsValid ( ) , " Data patch is valid for slice instance, but entity Id map is not! " ) ;
@ -1175,7 +1175,7 @@ namespace AZ
}
}
else
else
{
{
AZ_PROFILE_SCOPE ( A Z: : Debug : : ProfileCategory : : A zCore, " SliceComponent::SliceReference::InstantiateInstance:CloneAndApplyDataPatches " ) ;
AZ_PROFILE_SCOPE ( A zCore, " SliceComponent::SliceReference::InstantiateInstance:CloneAndApplyDataPatches " ) ;
// Clone entities while applying any data patches.
// Clone entities while applying any data patches.
AZ_Assert ( dataPatch . IsValid ( ) , " Data patch is not valid for existing slice instance! " ) ;
AZ_Assert ( dataPatch . IsValid ( ) , " Data patch is not valid for existing slice instance! " ) ;
@ -1261,7 +1261,7 @@ namespace AZ
// Broadcast OnSliceEntitiesLoaded for freshly instantiated entities.
// Broadcast OnSliceEntitiesLoaded for freshly instantiated entities.
if ( ! instance . m_instantiated - > m_entities . empty ( ) )
if ( ! instance . m_instantiated - > m_entities . empty ( ) )
{
{
AZ_PROFILE_SCOPE ( A Z: : Debug : : ProfileCategory : : A zCore, " SliceComponent::SliceReference::InstantiateInstance:OnSliceEntitiesLoaded " ) ;
AZ_PROFILE_SCOPE ( A zCore, " SliceComponent::SliceReference::InstantiateInstance:OnSliceEntitiesLoaded " ) ;
SliceAssetSerializationNotificationBus : : Broadcast ( & SliceAssetSerializationNotificationBus : : Events : : OnSliceEntitiesLoaded , instance . m_instantiated - > m_entities ) ;
SliceAssetSerializationNotificationBus : : Broadcast ( & SliceAssetSerializationNotificationBus : : Events : : OnSliceEntitiesLoaded , instance . m_instantiated - > m_entities ) ;
}
}
}
}
@ -1363,7 +1363,7 @@ namespace AZ
//=========================================================================
//=========================================================================
void SliceComponent : : SliceReference : : ComputeDataPatch ( )
void SliceComponent : : SliceReference : : ComputeDataPatch ( )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// Get source entities from the base asset (instantiate if needed)
// Get source entities from the base asset (instantiate if needed)
InstantiatedContainer source ( m_asset . Get ( ) - > GetComponent ( ) , false ) ;
InstantiatedContainer source ( m_asset . Get ( ) - > GetComponent ( ) , false ) ;
@ -1499,7 +1499,7 @@ namespace AZ
//=========================================================================
//=========================================================================
bool SliceComponent : : GetEntities ( EntityList & entities )
bool SliceComponent : : GetEntities ( EntityList & entities )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
bool result = true ;
bool result = true ;
@ -1532,7 +1532,7 @@ namespace AZ
//=========================================================================
//=========================================================================
bool SliceComponent : : GetEntityIds ( EntityIdSet & entities )
bool SliceComponent : : GetEntityIds ( EntityIdSet & entities )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
bool result = true ;
bool result = true ;
@ -1582,7 +1582,7 @@ namespace AZ
//=========================================================================
//=========================================================================
bool SliceComponent : : GetMetadataEntityIds ( EntityIdSet & metadataEntities )
bool SliceComponent : : GetMetadataEntityIds ( EntityIdSet & metadataEntities )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
bool result = true ;
bool result = true ;
@ -1654,7 +1654,7 @@ namespace AZ
//=========================================================================
//=========================================================================
SliceComponent : : InstantiateResult SliceComponent : : Instantiate ( )
SliceComponent : : InstantiateResult SliceComponent : : Instantiate ( )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
AZStd : : unique_lock < AZStd : : recursive_mutex > lock ( m_instantiateMutex ) ;
AZStd : : unique_lock < AZStd : : recursive_mutex > lock ( m_instantiateMutex ) ;
if ( m_slicesAreInstantiated )
if ( m_slicesAreInstantiated )
@ -1856,7 +1856,7 @@ namespace AZ
SliceComponent : : SliceInstanceAddress SliceComponent : : AddSliceUsingExistingEntities ( const Data : : Asset < SliceAsset > & sliceAsset , const AZ : : SliceComponent : : EntityIdToEntityIdMap & liveToAssetMap ,
SliceComponent : : SliceInstanceAddress SliceComponent : : AddSliceUsingExistingEntities ( const Data : : Asset < SliceAsset > & sliceAsset , const AZ : : SliceComponent : : EntityIdToEntityIdMap & liveToAssetMap ,
SliceInstanceId sliceInstanceId )
SliceInstanceId sliceInstanceId )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
if ( ! sliceAsset . Get ( ) - > GetComponent ( ) )
if ( ! sliceAsset . Get ( ) - > GetComponent ( ) )
{
{
@ -2337,7 +2337,7 @@ namespace AZ
//=========================================================================
//=========================================================================
bool SliceComponent : : RemoveSliceInstance ( SliceComponent : : SliceInstanceAddress sliceAddress )
bool SliceComponent : : RemoveSliceInstance ( SliceComponent : : SliceInstanceAddress sliceAddress )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
if ( ! sliceAddress . IsValid ( ) )
if ( ! sliceAddress . IsValid ( ) )
{
{
AZ_Error ( " Slices " , false , " Slice address is invalid. " ) ;
AZ_Error ( " Slices " , false , " Slice address is invalid. " ) ;
@ -2474,7 +2474,7 @@ namespace AZ
bool SliceComponent : : RemoveMetaDataEntity ( EntityId metaDataEntityId )
bool SliceComponent : : RemoveMetaDataEntity ( EntityId metaDataEntityId )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
GetEntityInfoMap ( ) ; // Ensure map is built
GetEntityInfoMap ( ) ; // Ensure map is built
@ -2567,7 +2567,7 @@ namespace AZ
void SliceComponent : : RemoveAllEntities ( bool deleteEntities , bool removeEmptyInstances )
void SliceComponent : : RemoveAllEntities ( bool deleteEntities , bool removeEmptyInstances )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
// If we are deleting the entities, we need to do that one by one
// If we are deleting the entities, we need to do that one by one
if ( deleteEntities )
if ( deleteEntities )
@ -2930,7 +2930,7 @@ namespace AZ
//=========================================================================
//=========================================================================
void SliceComponent : : OnAssetReloaded ( Data : : Asset < Data : : AssetData > /*asset*/ )
void SliceComponent : : OnAssetReloaded ( Data : : Asset < Data : : AssetData > /*asset*/ )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
if ( ! m_myAsset )
if ( ! m_myAsset )
{
{
@ -3073,7 +3073,7 @@ namespace AZ
/// Called right after we finish writing data to the instance pointed at by classPtr.
/// Called right after we finish writing data to the instance pointed at by classPtr.
void OnWriteEnd ( void * classPtr ) override
void OnWriteEnd ( void * classPtr ) override
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
SliceComponent * sliceComponent = reinterpret_cast < SliceComponent * > ( classPtr ) ;
SliceComponent * sliceComponent = reinterpret_cast < SliceComponent * > ( classPtr ) ;
EBUS_EVENT ( SliceAssetSerializationNotificationBus , OnWriteDataToSliceAssetEnd , * sliceComponent ) ;
EBUS_EVENT ( SliceAssetSerializationNotificationBus , OnWriteDataToSliceAssetEnd , * sliceComponent ) ;
@ -3082,7 +3082,7 @@ namespace AZ
// We can't broadcast this event for instanced entities yet, since they don't exist until instantiation.
// We can't broadcast this event for instanced entities yet, since they don't exist until instantiation.
if ( ! sliceComponent - > GetNewEntities ( ) . empty ( ) )
if ( ! sliceComponent - > GetNewEntities ( ) . empty ( ) )
{
{
AZ_PROFILE_SCOPE ( A Z: : Debug : : ProfileCategory : : A zCore, " SliceComponentSerializationEvents::OnWriteEnd:OnSliceEntitiesLoaded " ) ;
AZ_PROFILE_SCOPE ( A zCore, " SliceComponentSerializationEvents::OnWriteEnd:OnSliceEntitiesLoaded " ) ;
EBUS_EVENT ( SliceAssetSerializationNotificationBus , OnSliceEntitiesLoaded , sliceComponent - > GetNewEntities ( ) ) ;
EBUS_EVENT ( SliceAssetSerializationNotificationBus , OnSliceEntitiesLoaded , sliceComponent - > GetNewEntities ( ) ) ;
}
}
}
}
@ -3093,7 +3093,7 @@ namespace AZ
//=========================================================================
//=========================================================================
void SliceComponent : : PrepareSave ( )
void SliceComponent : : PrepareSave ( )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
if ( m_slicesAreInstantiated )
if ( m_slicesAreInstantiated )
{
{
@ -3262,7 +3262,7 @@ namespace AZ
//=========================================================================
//=========================================================================
void SliceComponent : : BuildEntityInfoMap ( )
void SliceComponent : : BuildEntityInfoMap ( )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
m_entityInfoMap . clear ( ) ;
m_entityInfoMap . clear ( ) ;
m_metaDataEntityInfoMap . clear ( ) ;
m_metaDataEntityInfoMap . clear ( ) ;
@ -3425,7 +3425,7 @@ namespace AZ
//=========================================================================
//=========================================================================
void SliceComponent : : BuildDataFlagsForInstances ( )
void SliceComponent : : BuildDataFlagsForInstances ( )
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
AZ_Assert ( IsInstantiated ( ) , " Slice must be instantiated before the ancestry of its data flags can be calculated. " ) ;
AZ_Assert ( IsInstantiated ( ) , " Slice must be instantiated before the ancestry of its data flags can be calculated. " ) ;
// Use lock since slice instantiation can occur from multiple threads
// Use lock since slice instantiation can occur from multiple threads
@ -3551,7 +3551,7 @@ namespace AZ
{
{
// if this function is a performance bottleneck, it could be optimized with caching
// if this function is a performance bottleneck, it could be optimized with caching
// be wary not to create the cache in-game if the information is only needed by tools
// be wary not to create the cache in-game if the information is only needed by tools
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
if ( ! IsInstantiated ( ) )
if ( ! IsInstantiated ( ) )
{
{
@ -3730,7 +3730,7 @@ namespace AZ
//=========================================================================
//=========================================================================
SliceComponent * SliceComponent : : Clone ( AZ : : SerializeContext & serializeContext , SliceInstanceToSliceInstanceMap * sourceToCloneSliceInstanceMap ) const
SliceComponent * SliceComponent : : Clone ( AZ : : SerializeContext & serializeContext , SliceInstanceToSliceInstanceMap * sourceToCloneSliceInstanceMap ) const
{
{
AZ_PROFILE_FUNCTION ( A Z: : Debug : : ProfileCategory : : A zCore) ;
AZ_PROFILE_FUNCTION ( A zCore) ;
SliceComponent * clonedComponent = serializeContext . CloneObject ( this ) ;
SliceComponent * clonedComponent = serializeContext . CloneObject ( this ) ;