Skip to content

Commit

Permalink
Reimplemented some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Mar 13, 2024
1 parent 2e7c819 commit 11845fb
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 58 deletions.
30 changes: 19 additions & 11 deletions Volt/Navigation/src/Navigation/Core/NavigationSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Volt::AI::NavMesh>(scenePath));
SetVTNavMesh(Volt::AssetManager::GetAsset<Volt::AI::NavMesh>(scenePath));

//if (myActiveScene->IsPlaying())
//{
// ClearAgents();
// InitAgents();
//}
if (myActiveScene->IsPlaying())
{
ClearAgents();
InitAgents();
}
return false;
}

Expand Down
113 changes: 66 additions & 47 deletions Volt/Volt/src/Volt/Net/Serialization/NetSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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<Volt::Prefab>(data.handle);
//const auto& prefabComponent = ent.GetComponent<Volt::PrefabComponent>();

// #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<Volt::MonoScriptComponent>(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<Volt::RelationshipComponent>()) return;
//auto children = ent.GetComponent<Volt::RelationshipComponent>().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<Volt::Prefab>(data.handle);
const auto& prefabComponent = ent.GetComponent<Volt::PrefabComponent>();

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<Volt::MonoScriptComponent>())
{
continue;
}

if (compTypeDesc->GetGUID() == Volt::GetTypeGUID<Volt::MonoScriptComponent>())
{
auto& monoScriptComponent = ent.GetComponent<Volt::MonoScriptComponent>();
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<Volt::RelationshipComponent>()) return;
auto children = ent.GetComponent<Volt::RelationshipComponent>().children;
for (const auto& c : children)
{
RecursiveOwnerShipControll(c, data);
}
}

// #mmax: should be called on play :P
Expand Down
5 changes: 5 additions & 0 deletions Volt/Volt/src/Volt/Scene/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions Volt/Volt/src/Volt/Scene/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <entt.hpp>

Expand Down Expand Up @@ -106,6 +107,7 @@ namespace Volt
template<typename T, typename... Args> T& AddComponent(Args&&... args);
template<typename T> void RemoveComponent();

void RemoveComponent(const VoltGUID& guid);
const bool HasComponent(std::string_view componentName) const;

Entity& operator=(const Entity& entity);
Expand Down

0 comments on commit 11845fb

Please sign in to comment.