Skip to content

Commit

Permalink
Worked on finding certain issues with conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Oct 1, 2023
1 parent a20c70e commit 8adc457
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 22 deletions.
21 changes: 18 additions & 3 deletions Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@ void ProjectUpgradeModal::DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt:
return;
}

entt::entity entityId = scene->GetRegistry().create(originalEntityId);
Volt::Entity newEntity = scene->CreateEntity("", originalEntityId);
const entt::entity entityId = newEntity.GetID();

if (entityId != originalEntityId)
{
Expand All @@ -443,7 +444,10 @@ void ProjectUpgradeModal::DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt:
{
case Volt::ValueType::Component:
{
Volt::ComponentRegistry::Helpers::AddComponentWithGUID(compGuid, scene->GetRegistry(), entityId);
if (!Volt::ComponentRegistry::Helpers::HasComponentWithGUID(compGuid, scene->GetRegistry(), entityId))
{
Volt::ComponentRegistry::Helpers::AddComponentWithGUID(compGuid, scene->GetRegistry(), entityId);
}
void* voidCompPtr = Volt::ComponentRegistry::Helpers::GetComponentWithGUID(compGuid, scene->GetRegistry(), entityId);
uint8_t* componentData = reinterpret_cast<uint8_t*>(voidCompPtr);

Expand All @@ -469,10 +473,16 @@ void ProjectUpgradeModal::DeserializePreV113Entity(Ref<Volt::Scene> scene, Volt:

if (prefabAsset && prefabAsset->IsValid())
{
prefabAsset->CopyPrefabEntity(Volt::Entity{ entityId, scene }, prefabComp.prefabEntity);
prefabAsset->CopyPrefabEntity(newEntity, prefabComp.prefabEntity);
}
}

if (scene->GetRegistry().any_of<Volt::PrefabComponent>(entityId))
{
auto& prefabComp = scene->GetRegistry().get<Volt::PrefabComponent>(entityId);
VT_CORE_INFO("ID: {0}", prefabComp.prefabEntity);
}

// Make sure entity has relationship component
if (!scene->GetRegistry().any_of<Volt::RelationshipComponent>(entityId))
{
Expand Down Expand Up @@ -504,6 +514,11 @@ void ProjectUpgradeModal::DeserializePreV113Component(uint8_t* componentData, co
return;
}

if (componentMember->name == "prefabEntity")
{
VT_CORE_INFO("Test");
}

const PreV113PropertyType oldType = static_cast<PreV113PropertyType>(streamReader.ReadKey("type", 0u));

if (oldType == PreV113PropertyType::Vector && componentMember->typeDesc != nullptr)
Expand Down
3 changes: 2 additions & 1 deletion Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace Volt
{
outTypes[std::type_index{ typeid(T) }] = [](YAMLStreamWriter& streamWriter, const uint8_t* data, const size_t offset)
{
streamWriter.SetKey("data", *reinterpret_cast<const T*>(&data[offset]));
const T& var = *reinterpret_cast<const T*>(&data[offset]);
streamWriter.SetKey("data", var);
};
}

Expand Down
12 changes: 5 additions & 7 deletions Volt/Volt/src/Volt/Asset/Prefab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ namespace Volt
return;
}

auto dstTransform = dstEntity.GetComponent<TransformComponent>();

Entity::Copy(prefabEntity, dstEntity);

dstEntity.GetComponent<TransformComponent>() = dstTransform;
Entity::Copy(prefabEntity, dstEntity, EntityCopyFlags::SkipPrefab | EntityCopyFlags::SkipRelationships | EntityCopyFlags::SkipTransform | EntityCopyFlags::SkipCommonData);
}

const bool Prefab::IsEntityValidInPrefab(Entity entity) const
Expand All @@ -124,7 +120,9 @@ namespace Volt
return false;
}

Entity prefabEntity{ entity.GetComponent<PrefabComponent>().prefabEntity, m_prefabScene };
const entt::entity prefabEntityId = entity.GetComponent<PrefabComponent>().prefabEntity;

Entity prefabEntity{ prefabEntityId, m_prefabScene };
const bool isValid = prefabEntity.IsValid();
return isValid;
}
Expand Down Expand Up @@ -273,7 +271,7 @@ namespace Volt
srcPrefabComp.prefabEntity = newEntity.GetID();
srcPrefabComp.version = m_version;

Entity::Copy(srcEntity, newEntity, true);
Entity::Copy(srcEntity, newEntity);

auto preParentTransform = newEntity.GetComponent<TransformComponent>();

Expand Down
32 changes: 23 additions & 9 deletions Volt/Volt/src/Volt/Scene/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ namespace Volt
auto scenePtr = GetScene();
auto& registry = scenePtr->GetRegistry();

if (!registry.any_of<RelationshipComponent>(m_id))
{
return false;
}

assert(registry.any_of<RelationshipComponent>(m_id) && "Entity must have relationship component!");

auto& relComp = registry.get<RelationshipComponent>(m_id);
Expand Down Expand Up @@ -498,7 +503,7 @@ namespace Volt
return {};
}

void Entity::Copy(Entity srcEntity, Entity dstEntity, bool skipRelationships)
void Entity::Copy(Entity srcEntity, Entity dstEntity, const EntityCopyFlags copyFlags)
{
auto srcScene = srcEntity.GetScene();
auto& srcRegistry = srcScene->GetRegistry();
Expand Down Expand Up @@ -534,18 +539,27 @@ namespace Volt
void* voidCompPtr = Volt::ComponentRegistry::Helpers::GetComponentWithGUID(componentDesc->GetGUID(), dstRegistry, dstEntity.GetID());
uint8_t* componentData = reinterpret_cast<uint8_t*>(voidCompPtr);

if (componentDesc->GetGUID() == GetTypeGUID<PrefabComponent>() && (copyFlags & EntityCopyFlags::SkipPrefab) != EntityCopyFlags::None)
{
continue;
}
else if ((componentDesc->GetGUID() == GetTypeGUID<RelationshipComponent>() && (copyFlags & EntityCopyFlags::SkipRelationships) != EntityCopyFlags::None))
{
continue;
}
else if ((componentDesc->GetGUID() == GetTypeGUID<TransformComponent>() && (copyFlags & EntityCopyFlags::SkipTransform) != EntityCopyFlags::None))
{
continue;
}
else if (componentDesc->GetGUID() == GetTypeGUID<CommonComponent>() && (copyFlags & EntityCopyFlags::SkipCommonData) != EntityCopyFlags::None)
{
continue;
}

CopyComponent(reinterpret_cast<const uint8_t*>(storage.get(srcEntity.GetID())), componentData, 0, componentDesc);
}

CopyMonoScripts(srcEntity, dstEntity);

// Clear the relationship component, as this is a standalone entity
if (skipRelationships)
{
RelationshipComponent& relComp = dstEntity.GetComponent<RelationshipComponent>();
relComp.children.clear();
relComp.parent = entt::null;
}
}

Entity Entity::Duplicate(Entity srcEntity, Ref<Scene> targetScene, Entity parent)
Expand Down
13 changes: 12 additions & 1 deletion Volt/Volt/src/Volt/Scene/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ namespace Volt
template<class T>
concept EntityId = std::is_same<T, uint32_t>::value || std::is_same<T, entt::entity>::value;

enum class EntityCopyFlags
{
None = 0,
SkipRelationships = BIT(0),
SkipPrefab = BIT(1),
SkipTransform = BIT(2),
SkipCommonData = BIT(3)
};

VT_SETUP_ENUM_CLASS_OPERATORS(EntityCopyFlags);

class Entity
{
public:
Expand Down Expand Up @@ -104,7 +115,7 @@ namespace Volt
static Entity Null();

// Copies a single entity
static void Copy(Entity srcEntity, Entity dstEntity, bool skipRelationships = true);
static void Copy(Entity srcEntity, Entity dstEntity, const EntityCopyFlags copyFlags = EntityCopyFlags::SkipRelationships);

// Duplicates an entire entity tree
static Entity Duplicate(Entity srcEntity, Ref<Scene> targetScene = nullptr, Entity parent = Entity::Null());
Expand Down
2 changes: 1 addition & 1 deletion Volt/Volt/src/Volt/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ namespace Volt
m_registry.each([&](entt::entity id)
{
id = otherScene->m_registry.create(id);
Entity::Copy(Entity{ id, this }, Entity{ id, otherScene }, false);
Entity::Copy(Entity{ id, this }, Entity{ id, otherScene }, EntityCopyFlags::None);
});
}

Expand Down

0 comments on commit 8adc457

Please sign in to comment.