diff --git a/Volt/Navigation/src/Navigation/Core/NavigationSystem.cpp b/Volt/Navigation/src/Navigation/Core/NavigationSystem.cpp index 0325031f3..9a8dc047e 100644 --- a/Volt/Navigation/src/Navigation/Core/NavigationSystem.cpp +++ b/Volt/Navigation/src/Navigation/Core/NavigationSystem.cpp @@ -113,21 +113,29 @@ namespace Volt bool NavigationSystem::OnSceneLoadedEvent(Volt::OnSceneLoadedEvent& e) { - //#TODO_Ivar: Reimplement + myActiveScene = e.GetScene(); + const auto& metadata = AssetManager::GetMetadataFromHandle(myActiveScene->handle); - //myActiveScene = e.GetScene(); - //if (myActiveScene->path.empty() && myActiveScene->GetName() != "New Scene") { return false; } + if (!metadata.IsValid()) + { + return false; + } + + auto scenePath = metadata.filePath; + if (std::filesystem::is_directory(scenePath)) + { + scenePath /= (myActiveScene->assetName + ".vtasset"); + } - //auto scenePath = myActiveScene->path; - //scenePath.replace_extension(".vtnavmesh"); + scenePath.replace_extension(".vtnavmesh"); - //SetVTNavMesh(Volt::AssetManager::Get().GetAsset(scenePath)); + SetVTNavMesh(Volt::AssetManager::GetAsset(scenePath)); - //if (myActiveScene->IsPlaying()) - //{ - // ClearAgents(); - // InitAgents(); - //} + if (myActiveScene->IsPlaying()) + { + ClearAgents(); + InitAgents(); + } return false; } diff --git a/Volt/Volt/src/Volt/Net/Serialization/NetSerialization.cpp b/Volt/Volt/src/Volt/Net/Serialization/NetSerialization.cpp index cd78f6294..19ead8697 100644 --- a/Volt/Volt/src/Volt/Net/Serialization/NetSerialization.cpp +++ b/Volt/Volt/src/Volt/Net/Serialization/NetSerialization.cpp @@ -13,6 +13,7 @@ #include "Volt/Net/SceneInteraction/NetContract.h" #include "Volt/Scripting/Mono/MonoScriptEngine.h" #include "Volt/Components/PhysicsComponents.h" +#include "Volt/Scene/Reflection/ComponentRegistry.h" #include "Volt/Physics/PhysicsScene.h" #include "Volt/Physics/Physics.h" @@ -474,57 +475,75 @@ void HandleComponent(Volt::EntityID in_id, const std::string& in_comp, bool in_k if (in_keep) return; auto ent = Volt::SceneManager::GetActiveScene()->GetEntityFromUUID(in_id); - //scenePtr->GetRegistry().RemoveComponent(Wire::ComponentRegistry::GetRegistryDataFromName(in_comp).guid, in_id); + ent.RemoveComponent(Volt::ComponentRegistry::GetGUIDFromTypeName(in_comp)); } void RecursiveOwnerShipControll(Volt::EntityID in_id, const Volt::RepPrefabData& data) { - //auto contract = Volt::NetContractContainer::GetContract(data.handle); - - //auto scenePtr = Volt::SceneManager::GetActiveScene(); - - //auto ent = Volt::Entity(in_id, scenePtr.get()); - //const auto prefabData = Volt::AssetManager::GetAsset(data.handle); - //const auto& prefabComponent = ent.GetComponent(); - - // #TODO_Ivar: Reimplement - //auto prefabRegistry = prefabData->GetRegistry(); - //auto sceneRegistry = scenePtr->GetRegistry(); - - //auto isOwner = Volt::Application::Get().GetNetHandler().IsOwner(data.repId); - //auto isHost = Volt::Application::Get().GetNetHandler().IsHost(); - - //// Components - //if (contract) if (contract->rules.contains(prefabComponent.prefabEntity)) - //{ - // for (const auto& [guid, pool] : sceneRegistry.GetPools()) - // { - // if (!sceneRegistry.HasComponent(guid, in_id)) continue; - // const auto& registryInfo = Wire::ComponentRegistry::GetRegistryDataFromGUID(guid); - // if (!Volt::NetContractContainer::RuleExists(data.handle, registryInfo.name, prefabComponent.prefabEntity) && registryInfo.guid != Volt::MonoScriptComponent::comp_guid) continue; - // if (registryInfo.guid == Volt::MonoScriptComponent::comp_guid) - // { - // auto& monoScriptComponent = sceneRegistry.GetComponent(in_id); - // for (uint32_t i = 0; i < monoScriptComponent.scriptIds.size(); i++) - // { - // if (!contract->rules.at(prefabComponent.prefabEntity).contains(monoScriptComponent.scriptNames[i])) continue; - // HandleScript(in_id, monoScriptComponent.scriptNames[i], contract->rules.at(prefabComponent.prefabEntity).at(monoScriptComponent.scriptNames[i]).ShouldKeep(isHost, isOwner)); - // } - // } - // else - // { - // HandleComponent(in_id, registryInfo.name, contract->rules.at(prefabComponent.prefabEntity)[registryInfo.name].ShouldKeep(isHost, isOwner)); - // } - // } - //} - - //// Children - //if (!ent.HasComponent()) return; - //auto children = ent.GetComponent().Children; - //for (const auto& c : children) - //{ - // RecursiveOwnerShipControll(c, data); - //} + auto contract = Volt::NetContractContainer::GetContract(data.handle); + + auto scenePtr = Volt::SceneManager::GetActiveScene(); + + auto ent = scenePtr->GetEntityFromUUID(in_id); + const auto prefabData = Volt::AssetManager::GetAsset(data.handle); + const auto& prefabComponent = ent.GetComponent(); + + auto& registry = scenePtr->GetRegistry(); + + auto isOwner = Volt::Application::Get().GetNetHandler().IsOwner(data.repId); + auto isHost = Volt::Application::Get().GetNetHandler().IsHost(); + + // Components + if (contract) + { + if (contract->rules.contains(prefabComponent.prefabEntity)) + { + for (auto&& curr : registry.storage()) + { + auto& storage = curr.second; + + if (!storage.contains(ent)) + { + continue; + } + + const std::string componentName = std::string(storage.type().name()); + const Volt::ICommonTypeDesc* compTypeDesc = Volt::ComponentRegistry::GetTypeDescFromName(componentName); + + // #TODO_Ivar: Name matching might not work anymore, should move to GUIDs + if (!Volt::NetContractContainer::RuleExists(data.handle, componentName, prefabComponent.prefabEntity) && compTypeDesc->GetGUID() != Volt::GetTypeGUID()) + { + continue; + } + + if (compTypeDesc->GetGUID() == Volt::GetTypeGUID()) + { + auto& monoScriptComponent = ent.GetComponent(); + for (uint32_t i = 0; i < monoScriptComponent.scriptIds.size(); i++) + { + if (!contract->rules.at(prefabComponent.prefabEntity).contains(monoScriptComponent.scriptNames[i])) + { + continue; + } + + HandleScript(in_id, monoScriptComponent.scriptNames[i], contract->rules.at(prefabComponent.prefabEntity).at(monoScriptComponent.scriptNames[i]).ShouldKeep(isHost, isOwner)); + } + } + else + { + HandleComponent(in_id, componentName, contract->rules.at(prefabComponent.prefabEntity)[componentName].ShouldKeep(isHost, isOwner)); + } + } + } + } + + // Children + if (!ent.HasComponent()) return; + auto children = ent.GetComponent().children; + for (const auto& c : children) + { + RecursiveOwnerShipControll(c, data); + } } // #mmax: should be called on play :P diff --git a/Volt/Volt/src/Volt/Scene/Entity.cpp b/Volt/Volt/src/Volt/Scene/Entity.cpp index 86ed0e65a..b58d5f4a5 100644 --- a/Volt/Volt/src/Volt/Scene/Entity.cpp +++ b/Volt/Volt/src/Volt/Scene/Entity.cpp @@ -388,6 +388,11 @@ namespace Volt return parentEntity.IsValid(); } + void Entity::RemoveComponent(const VoltGUID& guid) + { + ComponentRegistry::Helpers::RemoveComponentWithGUID(guid, m_scene->GetRegistry(), m_handle); + } + const bool Entity::HasComponent(std::string_view componentName) const { const std::string lowerCompName = ::Utility::ToLower(std::string(componentName)); diff --git a/Volt/Volt/src/Volt/Scene/Entity.h b/Volt/Volt/src/Volt/Scene/Entity.h index 3cb8ee78e..26e50980d 100644 --- a/Volt/Volt/src/Volt/Scene/Entity.h +++ b/Volt/Volt/src/Volt/Scene/Entity.h @@ -3,6 +3,7 @@ #include "Volt/Core/Base.h" #include "Volt/Scene/Scene.h" #include "Volt/Scene/EntityID.h" +#include "Volt/Scene/Reflection/VoltGUID.h" #include @@ -106,6 +107,7 @@ namespace Volt template T& AddComponent(Args&&... args); template void RemoveComponent(); + void RemoveComponent(const VoltGUID& guid); const bool HasComponent(std::string_view componentName) const; Entity& operator=(const Entity& entity);