Skip to content

Commit

Permalink
All features are now reimplemented!
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Sep 27, 2023
1 parent fe98fa3 commit 1f3ec66
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 52 deletions.
1 change: 0 additions & 1 deletion Engine/Volt-ScriptCore/Source/Volt/Scene/Components.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Volt
{

// #TODO_Ivar: Add guids to all components
public enum VideoStatus : uint
{
Stopped = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void ComponentPropertyUtility::DrawMonoMembers(Weak<Volt::Scene> scene, const Vo
fontChanged = true;
UI::PushFont(FontType::Bold_17);
}
else if (memcmp(currentField->data.As<void>(), defaultFieldValueMap.at(name)->data.As<void>(), currentField->data.GetSize()) != 0) // #TODO_Ivar: Reimplement to use custom function instead
else if (!currentField->field.type.equalFunc(currentField->data.As<void>(), defaultFieldValueMap.at(name)->data.As<void>()))
{
fontChanged = true;
UI::PushFont(FontType::Bold_17);
Expand Down
98 changes: 59 additions & 39 deletions Volt/Sandbox/src/Sandbox/Window/Net/NetContractPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ NetContractPanel::NetContractPanel()
{
m_scene = Volt::Scene::CreateDefaultScene("NetContract scene", false);
m_blocked = {
"VisualScriptingComponent",
"TagComponent",
"TransformComponent",
"EntityDataComponent",
"CommonComponent",
"RelationshipComponent",
"PrefabComponent",
"NetActorComponent"
Expand Down Expand Up @@ -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
{
Expand All @@ -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<Volt::Prefab>(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<Volt::Prefab>(m_handle)->Instantiate(m_scene).GetID();
Volt::NetContractContainer::Clear();
Volt::NetContractContainer::Load();
}
}

UI::EndProperties();
}
}

Expand All @@ -125,12 +130,14 @@ void NetContractPanel::DrawCalls(Ref<Volt::NetContract> 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<Volt::eNetEvent>();
UI::ComboProperty("Manage Calls", addEvent, netEventTypeDesc->GetConstantNames());

UI::EndProperties();
}

float halfSize = ImGui::GetContentRegionAvail().x * 0.5f;
if (ImGui::Button("+##NetContractAddEvent", { halfSize , 0 }))
{
Expand All @@ -149,18 +156,19 @@ void NetContractPanel::DrawCalls(Ref<Volt::NetContract> 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<Volt::eNetEvent>();

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<Volt::NetContract> in_contract)
Expand Down Expand Up @@ -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;
Expand All @@ -247,26 +255,38 @@ void NetContractPanel::DrawRuleSet(Ref<Volt::NetContract> 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<Volt::MonoScriptComponent>(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<Volt::PrefabComponent>().prefabEntity][monoScriptComponent.scriptNames[i]], entity.GetTag());
auto& monoScriptComponent = entity.GetComponent<Volt::MonoScriptComponent>();
for (uint32_t i = 0; i < monoScriptComponent.scriptIds.size(); i++)
{
RuleEntry(monoScriptComponent.scriptNames[i], in_contract->rules[entity.GetComponent<Volt::PrefabComponent>().prefabEntity][monoScriptComponent.scriptNames[i]], entity.GetTag());
}
}
else
{
RuleEntry(label, in_contract->rules[entity.GetComponent<Volt::PrefabComponent>().prefabEntity][label], entity.GetTag());
}
continue;
}
RuleEntry(registryInfo.name, in_contract->rules[entity.GetComponent<Volt::PrefabComponent>().prefabEntity][registryInfo.name], entity.GetTag());
}*/
}
}


Expand Down
9 changes: 0 additions & 9 deletions Volt/Volt/src/Volt/Scene/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,6 @@ namespace Volt
Physics::GetScene()->Simulate(aDeltaTime);

m_statistics.entityCount = static_cast<uint32_t>(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)
Expand Down
10 changes: 10 additions & 0 deletions Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const T*>(lhs)) == (*reinterpret_cast<const T*>(rhs));
};
}

void MonoTypeRegistry::Initialize()
Expand Down
6 changes: 4 additions & 2 deletions Volt/Volt/src/Volt/Scripting/Mono/MonoTypeRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool(const void* lhs, const void* rhs)> 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; }
Expand Down

0 comments on commit 1f3ec66

Please sign in to comment.