Merge pull request #1898 from aws-lumberyard-dev/hultonha/gitflow_210706_o3de

stabilization2106 -> development merge (210706)
This commit is contained in:
hultonha
2021-07-07 16:08:06 +01:00
committed by GitHub
385 changed files with 6749 additions and 9320 deletions
@@ -46,10 +46,11 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
}
}
template<typename EntityPtr>
void OrganizeEntitiesForSorting(
AzFramework::Spawnable::EntityList& entities,
AZStd::vector<EntityPtr>& entities,
AZStd::unordered_set<AZ::EntityId>& existingEntityIds,
AZStd::unordered_map<AZ::EntityId, AzFramework::Spawnable::EntityList>& parentIdToChildren,
AZStd::unordered_map<AZ::EntityId, AZStd::vector<EntityPtr>>& parentIdToChildren,
AZStd::vector<AZ::EntityId>& candidateIds,
size_t& removedEntitiesCount)
{
@@ -90,7 +91,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
// entities with no transform component will be treated like entities with no parent.
AZ::EntityId parentId;
if (AZ::TransformInterface* transformInterface =
AZ::EntityUtils::FindFirstDerivedComponent<AZ::TransformInterface>(entity.get()))
AZ::EntityUtils::FindFirstDerivedComponent<AZ::TransformInterface>(&(*entity)))
{
parentId = transformInterface->GetParentId();
if (parentId == entityId)
@@ -104,8 +105,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
}
auto& children = parentIdToChildren[parentId];
children.emplace_back(nullptr);
children.back().swap(entity);
children.emplace_back(AZStd::move(entity));
}
// clear 'entities', we'll refill it in sorted order.
@@ -125,9 +125,10 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
}
template<typename EntityPtr>
void TraceParentingLoop(
const AZ::EntityId& parentFromLoopId,
const AZStd::unordered_map<AZ::EntityId, AzFramework::Spawnable::EntityList>& parentIdToChildren)
const AZStd::unordered_map<AZ::EntityId, AZStd::vector<EntityPtr>>& parentIdToChildren)
{
// Find name to use in warning message
@@ -153,16 +154,22 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
parentFromLoopId.ToString().c_str());
}
void SortEntitiesByTransformHierarchy(AzFramework::Spawnable& spawnable)
{
auto& entities = spawnable.GetEntities();
SortEntitiesByTransformHierarchy(spawnable.GetEntities());
}
template<typename EntityPtr>
void SortEntitiesByTransformHierarchy(AZStd::vector<EntityPtr>& entities)
{
const size_t originalEntityCount = entities.size();
// IDs of those present in 'entities'. Does not include parent ID if parent not found in 'entities'
AZStd::unordered_set<AZ::EntityId> existingEntityIds;
// map children by their parent ID (even if parent not found in 'entities')
AZStd::unordered_map<AZ::EntityId, AzFramework::Spawnable::EntityList> parentIdToChildren;
AZStd::unordered_map<AZ::EntityId, AZStd::vector<EntityPtr>> parentIdToChildren;
// use 'candidateIds' to track the parent IDs we're going to process next.
AZStd::vector<AZ::EntityId> candidateIds;
@@ -199,8 +206,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
for (auto& child : foundChildren->second)
{
candidateIds.push_back(child->GetId());
entities.emplace_back(nullptr);
entities.back().swap(child);
entities.emplace_back(AZStd::move(child));
}
parentIdToChildren.erase(foundChildren);
@@ -217,4 +223,7 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
}
// Explicit specializations of SortEntitiesByTransformHierarchy (have to be in cpp due to clang errors)
template void SortEntitiesByTransformHierarchy(AZStd::vector<AZ::Entity*>& entities);
template void SortEntitiesByTransformHierarchy(AZStd::vector<AZStd::unique_ptr<AZ::Entity>>& entities);
} // namespace AzToolsFramework::Prefab::SpawnableUtils
@@ -16,4 +16,8 @@ namespace AzToolsFramework::Prefab::SpawnableUtils
bool CreateSpawnable(AzFramework::Spawnable& spawnable, const PrefabDom& prefabDom, AZStd::vector<AZ::Data::Asset<AZ::Data::AssetData>>& referencedAssets);
void SortEntitiesByTransformHierarchy(AzFramework::Spawnable& spawnable);
template <typename EntityPtr>
void SortEntitiesByTransformHierarchy(AZStd::vector<EntityPtr>& entities);
} // namespace AzToolsFramework::Prefab::SpawnableUtils