fixup! Created World::Merge which will merge a world into another one
This commit is contained in:
@@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
// Merge another world into this one
|
// Merge another world into this one
|
||||||
// Returns a map that maps entities from the other world to their copies in this one
|
// Returns a map that maps entities from the other world to their copies in this one
|
||||||
std::unordered_map<EntityID, EntityID> Merge(World& other);
|
std::unordered_map<EntityID, EntityID> Merge(const World* other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EventBroker* m_EventBroker = nullptr;
|
EventBroker* m_EventBroker = nullptr;
|
||||||
|
|||||||
@@ -169,27 +169,29 @@ EntityWrapper World::GetFirstEntityByName(const std::string& name)
|
|||||||
return EntityWrapper::Invalid;
|
return EntityWrapper::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unordered_map<EntityID, EntityID> World::Merge(World& other)
|
std::unordered_map<EntityID, EntityID> World::Merge(const World* other)
|
||||||
{
|
{
|
||||||
std::unordered_map<EntityID, EntityID> oldToNew;
|
std::unordered_map<EntityID, EntityID> oldToNew;
|
||||||
|
|
||||||
// Create new entities
|
// Create new entities
|
||||||
for (auto& kv : other.m_EntityParents) {
|
for (auto& kv : other->m_EntityParents) {
|
||||||
EntityID entity = kv.first;
|
EntityID entity = kv.first;
|
||||||
|
|
||||||
EntityID newEntity = CreateEntity();
|
EntityID newEntity = CreateEntity();
|
||||||
SetName(newEntity, other.GetName(entity));
|
SetName(newEntity, other->GetName(entity));
|
||||||
oldToNew[entity] = newEntity;
|
oldToNew[entity] = newEntity;
|
||||||
}
|
}
|
||||||
// Fix relationships
|
// Fix relationships
|
||||||
for (auto& kv : other.m_EntityParents) {
|
for (auto& kv : other->m_EntityParents) {
|
||||||
EntityID entity = kv.first;
|
EntityID entity = kv.first;
|
||||||
EntityID parent = kv.second;
|
EntityID parent = kv.second;
|
||||||
SetParent(oldToNew.at(entity), oldToNew.at(parent));
|
if (parent != EntityID_Invalid) {
|
||||||
|
SetParent(oldToNew.at(entity), oldToNew.at(parent));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer components
|
// Transfer components
|
||||||
for (auto& kv : other.m_ComponentPools) {
|
for (auto& kv : other->m_ComponentPools) {
|
||||||
auto& componentType = kv.first;
|
auto& componentType = kv.first;
|
||||||
ComponentPool* pool = kv.second;
|
ComponentPool* pool = kv.second;
|
||||||
// Register pool if it's not present in world
|
// Register pool if it's not present in world
|
||||||
|
|||||||
Reference in New Issue
Block a user