Skip to content

Commit

Permalink
Started implementing serialization / deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Sep 17, 2023
1 parent 1e5d0c2 commit 94edf6c
Show file tree
Hide file tree
Showing 33 changed files with 818 additions and 773 deletions.
2 changes: 1 addition & 1 deletion Engine/Scripts/Volt-ScriptCore.dll
Git LFS file not shown
5 changes: 5 additions & 0 deletions Volt/Sandbox/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ project "Sandbox"
"/WHOLEARCHIVE:GraphKey"
}

buildoptions
{
"/bigobj"
}

defines
{
"_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS",
Expand Down
2 changes: 1 addition & 1 deletion Volt/Sandbox/src/Sandbox/ImGuiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ void Sandbox::SaveSceneAsModal()

const auto relPath = Volt::AssetManager::Get().GetRelativePath(destPath.string() + "\\" + mySaveSceneData.name + ".vtscene");

myRuntimeScene->CopyTo(myRuntimeScene);
//myRuntimeScene->CopyTo(myRuntimeScene);
myRuntimeScene->handle = {};

Volt::AssetManager::SaveAssetAs(myRuntimeScene, relPath);
Expand Down
54 changes: 33 additions & 21 deletions Volt/Sandbox/src/Sandbox/Utility/ComponentPropertyUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include "Sandbox/Utility/Theme.h"
#include "Sandbox/Utility/EditorUtilities.h"

#include <Volt/Scene/Serialization/ComponentReflection.h>
#include <Volt/Scene/Serialization/ComponentRegistry.h>
#include <Volt/Scene/Reflection/ComponentReflection.h>
#include <Volt/Scene/Reflection/ComponentRegistry.h>

#include <Volt/Components/LightComponents.h>

Expand Down Expand Up @@ -74,23 +74,16 @@ void ComponentPropertyUtility::DrawComponentProperties(Weak<Volt::Scene> scene,
{
case Volt::ValueType::Component:
{
const Volt::IComponentTypeDesc* compTypeDesc = reinterpret_cast<const Volt::IComponentTypeDesc*>(typeDesc);
if (compTypeDesc->GetGUID() == "{EC5514FF-9DE7-44CA-BCD9-8A9F08883F59}"_guid)
{
Volt::DirectionalLightComponent& dirComp = *(Volt::DirectionalLightComponent*)storage.get(entity.GetID());
bool test = dirComp.castShadows;
test;
}

DrawComponent(compTypeDesc, storage.get(entity.GetID()));
const Volt::IComponentTypeDesc* compTypeDesc = reinterpret_cast<const Volt::IComponentTypeDesc*>(typeDesc);
DrawComponent(scene, compTypeDesc, storage.get(entity.GetID()));
break;
}
}
}
}
}

void ComponentPropertyUtility::DrawComponent(const Volt::IComponentTypeDesc* componentType, void* data)
void ComponentPropertyUtility::DrawComponent(Weak<Volt::Scene> scene, const Volt::IComponentTypeDesc* componentType, void* data)
{
if (componentType->IsHidden())
{
Expand Down Expand Up @@ -135,30 +128,30 @@ void ComponentPropertyUtility::DrawComponent(const Volt::IComponentTypeDesc* com
case Volt::ValueType::Component:
{
const Volt::IComponentTypeDesc* compDesc = reinterpret_cast<const Volt::IComponentTypeDesc*>(member.typeDesc);
DrawComponentSubSection(compDesc, data, member.offset);
DrawComponentSubSection(scene, compDesc, data, member.offset);

break;
}

case Volt::ValueType::Enum:
{
const Volt::IEnumTypeDesc* enumDesc = reinterpret_cast<const Volt::IEnumTypeDesc*>(member.typeDesc);
DrawComponentEnum(member, enumDesc, data, member.offset);
DrawComponentEnum(scene, member, enumDesc, data, member.offset);
break;
}
}
}
else
{
DrawComponentDefaultMember(member, data, 0);
DrawComponentDefaultMember(scene, member, data, 0);
}
}

UI::EndProperties();
}
}

void ComponentPropertyUtility::DrawComponentSubSection(const Volt::IComponentTypeDesc* componentType, void* data, const size_t offset)
void ComponentPropertyUtility::DrawComponentSubSection(Weak<Volt::Scene> scene, const Volt::IComponentTypeDesc* componentType, void* data, const size_t offset)
{
if (componentType->IsHidden())
{
Expand All @@ -177,30 +170,30 @@ void ComponentPropertyUtility::DrawComponentSubSection(const Volt::IComponentTyp
case Volt::ValueType::Component:
{
const Volt::IComponentTypeDesc* compDesc = reinterpret_cast<const Volt::IComponentTypeDesc*>(member.typeDesc);
DrawComponentSubSection(compDesc, data, offset + member.offset);
DrawComponentSubSection(scene, compDesc, data, offset + member.offset);

break;
}

case Volt::ValueType::Enum:
{
const Volt::IEnumTypeDesc* enumDesc = reinterpret_cast<const Volt::IEnumTypeDesc*>(member.typeDesc);
DrawComponentEnum(member, enumDesc, data, offset + member.offset);
DrawComponentEnum(scene, member, enumDesc, data, offset + member.offset);
break;
}
}
}
else
{
DrawComponentDefaultMember(member, data, offset);
DrawComponentDefaultMember(scene, member, data, offset);
}
}

UI::EndProperties();
}
}

void ComponentPropertyUtility::DrawComponentDefaultMember(const Volt::ComponentMember& member, void* data, const size_t offset)
void ComponentPropertyUtility::DrawComponentDefaultMember(Weak<Volt::Scene> scene, const Volt::ComponentMember& member, void* data, const size_t offset)
{
uint8_t* bytePtr = reinterpret_cast<uint8_t*>(data);

Expand All @@ -210,6 +203,25 @@ void ComponentPropertyUtility::DrawComponentDefaultMember(const Volt::ComponentM
return;
}

if ((member.flags & Volt::ComponentMemberFlag::Color3) != Volt::ComponentMemberFlag::None)
{
UI::PropertyColor(std::string(member.label), *reinterpret_cast<glm::vec3*>(&bytePtr[offset + member.offset]));
return;
}

if ((member.flags & Volt::ComponentMemberFlag::Color4) != Volt::ComponentMemberFlag::None)
{
UI::PropertyColor(std::string(member.label), *reinterpret_cast<glm::vec4*>(&bytePtr[offset + member.offset]));
return;
}

// Special case for entities
if (member.typeIndex == std::type_index{ typeid(entt::entity) })
{
UI::PropertyEntity(std::string(member.label), scene.lock(), *reinterpret_cast<entt::entity*>(&bytePtr[offset + member.offset]));
return;
}

if (!s_propertyFunctions.contains(member.typeIndex))
{
return;
Expand All @@ -218,7 +230,7 @@ void ComponentPropertyUtility::DrawComponentDefaultMember(const Volt::ComponentM
s_propertyFunctions.at(member.typeIndex)(member.label, data, offset + member.offset);
}

void ComponentPropertyUtility::DrawComponentEnum(const Volt::ComponentMember& member, const Volt::IEnumTypeDesc* enumType, void* data, const size_t offset)
void ComponentPropertyUtility::DrawComponentEnum(Weak<Volt::Scene> scene, const Volt::ComponentMember& member, const Volt::IEnumTypeDesc* enumType, void* data, const size_t offset)
{
uint8_t* bytePtr = reinterpret_cast<uint8_t*>(data);
const auto& constants = enumType->GetConstants();
Expand Down
8 changes: 4 additions & 4 deletions Volt/Sandbox/src/Sandbox/Utility/ComponentPropertyUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ComponentPropertyUtility
private:
static void Initialize();

static void DrawComponent(const Volt::IComponentTypeDesc* componentType, void* data);
static void DrawComponentSubSection(const Volt::IComponentTypeDesc* componentType, void* data, const size_t offset);
static void DrawComponentDefaultMember(const Volt::ComponentMember& member, void* data, const size_t offset);
static void DrawComponentEnum(const Volt::ComponentMember& member, const Volt::IEnumTypeDesc* enumType, void* data, const size_t offset);
static void DrawComponent(Weak<Volt::Scene> scene, const Volt::IComponentTypeDesc* componentType, void* data);
static void DrawComponentSubSection(Weak<Volt::Scene> scene, const Volt::IComponentTypeDesc* componentType, void* data, const size_t offset);
static void DrawComponentDefaultMember(Weak<Volt::Scene> scene, const Volt::ComponentMember& member, void* data, const size_t offset);
static void DrawComponentEnum(Weak<Volt::Scene> scene, const Volt::ComponentMember& member, const Volt::IEnumTypeDesc* enumType, void* data, const size_t offset);

inline static bool s_initialized = false;
inline static std::unordered_map<std::type_index, std::function<bool(std::string_view, void*, const size_t)>> s_propertyFunctions;
Expand Down
Loading

0 comments on commit 94edf6c

Please sign in to comment.