From 1f3ec66fd119a571b3c2ee6f6de28ce2aa9c08ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20J=C3=B6nsson?= Date: Wed, 27 Sep 2023 20:00:12 +0200 Subject: [PATCH] All features are now reimplemented! --- .../Source/Volt/Scene/Components.cs | 1 - .../Utility/ComponentPropertyUtilities.cpp | 2 +- .../Sandbox/Window/Net/NetContractPanel.cpp | 98 +++++++++++-------- Volt/Volt/src/Volt/Scene/Scene.cpp | 9 -- .../Volt/Scripting/Mono/MonoTypeRegistry.cpp | 10 ++ .../Volt/Scripting/Mono/MonoTypeRegistry.h | 6 +- 6 files changed, 74 insertions(+), 52 deletions(-) diff --git a/Engine/Volt-ScriptCore/Source/Volt/Scene/Components.cs b/Engine/Volt-ScriptCore/Source/Volt/Scene/Components.cs index bfaa5666f..9f027b7a3 100644 --- a/Engine/Volt-ScriptCore/Source/Volt/Scene/Components.cs +++ b/Engine/Volt-ScriptCore/Source/Volt/Scene/Components.cs @@ -1,7 +1,6 @@ namespace Volt { - // #TODO_Ivar: Add guids to all components public enum VideoStatus : uint { Stopped = 0, diff --git a/Volt/Sandbox/src/Sandbox/Utility/ComponentPropertyUtilities.cpp b/Volt/Sandbox/src/Sandbox/Utility/ComponentPropertyUtilities.cpp index 67af91c8a..d07c20191 100644 --- a/Volt/Sandbox/src/Sandbox/Utility/ComponentPropertyUtilities.cpp +++ b/Volt/Sandbox/src/Sandbox/Utility/ComponentPropertyUtilities.cpp @@ -624,7 +624,7 @@ void ComponentPropertyUtility::DrawMonoMembers(Weak scene, const Vo fontChanged = true; UI::PushFont(FontType::Bold_17); } - else if (memcmp(currentField->data.As(), defaultFieldValueMap.at(name)->data.As(), currentField->data.GetSize()) != 0) // #TODO_Ivar: Reimplement to use custom function instead + else if (!currentField->field.type.equalFunc(currentField->data.As(), defaultFieldValueMap.at(name)->data.As())) { fontChanged = true; UI::PushFont(FontType::Bold_17); diff --git a/Volt/Sandbox/src/Sandbox/Window/Net/NetContractPanel.cpp b/Volt/Sandbox/src/Sandbox/Window/Net/NetContractPanel.cpp index d2830cc81..9f9961005 100644 --- a/Volt/Sandbox/src/Sandbox/Window/Net/NetContractPanel.cpp +++ b/Volt/Sandbox/src/Sandbox/Window/Net/NetContractPanel.cpp @@ -15,10 +15,9 @@ NetContractPanel::NetContractPanel() { m_scene = Volt::Scene::CreateDefaultScene("NetContract scene", false); m_blocked = { - "VisualScriptingComponent", "TagComponent", "TransformComponent", - "EntityDataComponent", + "CommonComponent", "RelationshipComponent", "PrefabComponent", "NetActorComponent" @@ -82,9 +81,9 @@ void NetContractPanel::DrawActions() auto contract = Volt::NetContractContainer::GetContract(m_handle); if (!std::filesystem::exists(Volt::ProjectManager::GetProjectDirectory() / "Assets/Networking/Contracts")) { - std::filesystem::create_directory(Volt::ProjectManager::GetProjectDirectory() / "Assets/Networking/Contracts"); + std::filesystem::create_directories(Volt::ProjectManager::GetProjectDirectory() / "Assets/Networking/Contracts"); } - Volt::AssetManager::Get().SaveAsset(contract); + Volt::AssetManager::SaveAsset(contract); } else { @@ -103,20 +102,26 @@ void NetContractPanel::DrawActions() } } ImGui::SameLine(); - if (EditorUtils::Property("Prefab:", m_handle, Volt::AssetType::Prefab)) + + if (UI::BeginProperties("actions")) { - if (m_entityId != entt::null) + if (EditorUtils::Property("Prefab:", m_handle, Volt::AssetType::Prefab)) { - m_scene->RemoveEntity(Volt::Entity(m_entityId, m_scene.get())); - Volt::NetContractContainer::Clear(); - Volt::NetContractContainer::Load(); - } - if (m_handle != 0) - { - m_entityId = Volt::AssetManager::GetAsset(m_handle)->Instantiate(m_scene).GetID(); - Volt::NetContractContainer::Clear(); - Volt::NetContractContainer::Load(); + if (m_entityId != entt::null) + { + m_scene->RemoveEntity(Volt::Entity(m_entityId, m_scene.get())); + Volt::NetContractContainer::Clear(); + Volt::NetContractContainer::Load(); + } + if (m_handle != 0) + { + m_entityId = Volt::AssetManager::GetAsset(m_handle)->Instantiate(m_scene).GetID(); + Volt::NetContractContainer::Clear(); + Volt::NetContractContainer::Load(); + } } + + UI::EndProperties(); } } @@ -125,12 +130,14 @@ void NetContractPanel::DrawCalls(Ref in_contract) // Manage Calls static int addEvent = 0; - // #TODO_Ivar: Reimplement - /*auto& enumData = Wire::ComponentRegistry::EnumData(); - if (enumData.find("eNetEvent") != enumData.end()) + if (UI::BeginProperties("test2")) { - UI::ComboProperty("Manage Calls", addEvent, enumData.at("eNetEvent")); - }*/ + const Volt::IEnumTypeDesc* netEventTypeDesc = Volt::GetTypeDesc(); + UI::ComboProperty("Manage Calls", addEvent, netEventTypeDesc->GetConstantNames()); + + UI::EndProperties(); + } + float halfSize = ImGui::GetContentRegionAvail().x * 0.5f; if (ImGui::Button("+##NetContractAddEvent", { halfSize , 0 })) { @@ -149,18 +156,19 @@ void NetContractPanel::DrawCalls(Ref in_contract) } // Calls - /*if (UI::BeginProperties("yes")) + if (UI::BeginProperties("yes")) { for (auto& e : in_contract->calls) { - if (enumData.find("eNetEvent") == enumData.end()) continue; - if (enumData.at("eNetEvent").size() > (uint8_t)e.first) + const Volt::IEnumTypeDesc* netEventTypeDesc = Volt::GetTypeDesc(); + + if (netEventTypeDesc->GetConstants().size() > (size_t)e.first) { - UI::Property(enumData.at("eNetEvent")[(uint8_t)e.first], e.second); + UI::Property(netEventTypeDesc->GetConstantNames()[(size_t)e.first], e.second); } } UI::EndProperties(); - }*/ + } } void NetContractPanel::DrawComponentRules(Ref in_contract) @@ -237,7 +245,7 @@ void NetContractPanel::RuleEntry(const std::string& in_name, Volt::NetRule& in_r } } -bool NetContractPanel::BlockStandardComponents(const std::string& in_name) +bool NetContractPanel::BlockStandardComponents(const std::string &in_name) { if (m_blocked.contains(in_name)) return true; return false; @@ -247,26 +255,38 @@ void NetContractPanel::DrawRuleSet(Ref in_contract, entt::ent { auto entity = Volt::Entity(in_id, m_scene.get()); - // #TODO_Ivar: Reimplement - /*for (const auto& [guid, pool] : registry.GetPools()) + for (auto&& curr : entity.GetScene()->GetRegistry().storage()) { - if (!registry.HasComponent(guid, in_id)) continue; + if (auto& storage = curr.second; storage.contains(in_id)) + { + auto typeDesc = Volt::ComponentRegistry::GetTypeDescFromName(storage.type().name()); + if (!typeDesc) + { + continue; + } - const auto& registryInfo = Wire::ComponentRegistry::GetRegistryDataFromGUID(guid); + std::string label = std::string(typeDesc->GetLabel()); + label.erase(std::remove_if(label.begin(), label.end(), ::isspace)); - if (BlockStandardComponents(registryInfo.name)) continue; + if (BlockStandardComponents(label)) + { + continue; + } - if (registryInfo.name == "MonoScriptComponent") - { - auto& monoScriptComponent = registry.GetComponent(in_id); - for (uint32_t i = 0; i < monoScriptComponent.scriptIds.size(); i++) + if (typeDesc->GetGUID() == Volt::MonoScriptComponent::guid) { - RuleEntry(monoScriptComponent.scriptNames[i], in_contract->rules[entity.GetComponent().prefabEntity][monoScriptComponent.scriptNames[i]], entity.GetTag()); + auto& monoScriptComponent = entity.GetComponent(); + for (uint32_t i = 0; i < monoScriptComponent.scriptIds.size(); i++) + { + RuleEntry(monoScriptComponent.scriptNames[i], in_contract->rules[entity.GetComponent().prefabEntity][monoScriptComponent.scriptNames[i]], entity.GetTag()); + } + } + else + { + RuleEntry(label, in_contract->rules[entity.GetComponent().prefabEntity][label], entity.GetTag()); } - continue; } - RuleEntry(registryInfo.name, in_contract->rules[entity.GetComponent().prefabEntity][registryInfo.name], entity.GetTag()); - }*/ + } } diff --git a/Volt/Volt/src/Volt/Scene/Scene.cpp b/Volt/Volt/src/Volt/Scene/Scene.cpp index ef746e91c..21dc88617 100644 --- a/Volt/Volt/src/Volt/Scene/Scene.cpp +++ b/Volt/Volt/src/Volt/Scene/Scene.cpp @@ -341,15 +341,6 @@ namespace Volt Physics::GetScene()->Simulate(aDeltaTime); m_statistics.entityCount = static_cast(m_registry.alive()); - - // Update scene data - { - // #TODO_Ivar: Reimplement - - SceneData sceneData; - sceneData.deltaTime = aDeltaTime; - sceneData.timeSinceStart = m_timeSinceStart; - } } Entity Scene::CreateEntity(const std::string& tag, const entt::entity hintId) diff --git a/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.cpp b/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.cpp index bff8b2bae..a92bbb2cd 100644 --- a/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.cpp +++ b/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.cpp @@ -14,6 +14,16 @@ namespace Volt newType.typeFlags = typeFlags; newType.typeSize = sizeof(T); newType.typeName = std::string(monoTypeName); + + newType.equalFunc = [](const void* lhs, const void* rhs) -> bool + { + if (!lhs || !rhs) + { + return false; + } + + return (*reinterpret_cast(lhs)) == (*reinterpret_cast(rhs)); + }; } void MonoTypeRegistry::Initialize() diff --git a/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.h b/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.h index 00dc2b788..736096d34 100644 --- a/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.h +++ b/Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.h @@ -25,8 +25,10 @@ namespace Volt std::type_index typeIndex = typeid(void); size_t typeSize = 0; - AssetType assetType; - MonoTypeFlags typeFlags; + AssetType assetType = AssetType::None; + MonoTypeFlags typeFlags = MonoTypeFlags::None; + + std::function equalFunc; [[nodiscard]] inline const bool IsEntity() const { return typeIndex == typeid(entt::entity); } [[nodiscard]] inline const bool IsAsset() const { return typeIndex == typeid(AssetHandle) && assetType != AssetType::None; }