diff --git a/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp b/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp index 80b26ed2f..de39489af 100644 --- a/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp +++ b/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include @@ -58,7 +58,7 @@ struct TypeIndexContainer }; static std::unordered_map s_preV113PropTypeToTypeIndexMap; -static std::unordered_map> s_arrayDeserializers; +static std::unordered_map> s_arrayDeserializers; static std::unordered_map> s_componentMemberRemap; static bool s_initialize = false; @@ -66,7 +66,7 @@ static bool s_initialize = false; template void RegisterArrayDeserializationFunction() { - s_arrayDeserializers[std::type_index{ typeid(T) }] = [](Volt::YAMLStreamReader& streamReader, uint8_t* data, const size_t offset) + s_arrayDeserializers[std::type_index{ typeid(T) }] = [](Volt::YAMLFileStreamReader& streamReader, uint8_t* data, const size_t offset) { *reinterpret_cast(&data[offset]) = streamReader.ReadKey("value", T()); }; @@ -291,7 +291,7 @@ void ProjectUpgradeModal::ConvertAnimationGraphsToV0_1_2() { for (const auto& characterPath : characterAssets) { - Volt::YAMLStreamReader metaStreamReader{}; + Volt::YAMLFileStreamReader metaStreamReader{}; if (!metaStreamReader.OpenFile(characterPath.string() + ".vtmeta")) { @@ -306,7 +306,7 @@ void ProjectUpgradeModal::ConvertAnimationGraphsToV0_1_2() if (characterAssetHandle == handle) { - Volt::YAMLStreamReader charStreamReader{}; + Volt::YAMLFileStreamReader charStreamReader{}; if (!charStreamReader.OpenFile(characterPath)) { @@ -337,7 +337,7 @@ void ProjectUpgradeModal::ConvertAnimationGraphsToV0_1_2() AnimGraphDescriptor& descriptor = animGraphDescriptors.emplace_back(); { // convert the animgraph {// parse meta - Volt::YAMLStreamReader metaStreamReader{}; + Volt::YAMLFileStreamReader metaStreamReader{}; if (!metaStreamReader.OpenFile(animGraphPath.string() + ".vtmeta")) { @@ -677,7 +677,7 @@ void ProjectUpgradeModal::ConvertScenesToV113() // Load scene name { - Volt::YAMLStreamReader streamReader{}; + Volt::YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(sceneFilePath)) { VT_CORE_ERROR("[Project Upgrade]: Unable to open scene file! Skipping!"); @@ -717,7 +717,7 @@ void ProjectUpgradeModal::ConvertScenesToV113() void ProjectUpgradeModal::ConvertPreV113Prefab(const std::filesystem::path& filePath) { - Volt::YAMLStreamReader streamReader{}; + Volt::YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(filePath)) { return; @@ -768,7 +768,7 @@ void ProjectUpgradeModal::ConvertPreV113Prefab(const std::filesystem::path& file void ProjectUpgradeModal::DeserializePreV113SceneLayer(Ref scene, Volt::SceneLayer& sceneLayer, const std::filesystem::path& layerPath, std::map& entityRemapping) { - Volt::YAMLStreamReader streamReader{}; + Volt::YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(layerPath)) { @@ -790,7 +790,7 @@ void ProjectUpgradeModal::DeserializePreV113SceneLayer(Ref scene, V streamReader.ExitScope(); } -void ProjectUpgradeModal::DeserializePreV113Entity(Ref scene, Volt::YAMLStreamReader& streamReader, std::map& entityRemapping, bool isPrefabEntity) +void ProjectUpgradeModal::DeserializePreV113Entity(Ref scene, Volt::YAMLFileStreamReader& streamReader, std::map& entityRemapping, bool isPrefabEntity) { if (!isPrefabEntity) { @@ -927,7 +927,7 @@ void ProjectUpgradeModal::DeserializePreV113Entity(Ref scene, Volt: } } -void ProjectUpgradeModal::DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLStreamReader& streamReader) +void ProjectUpgradeModal::DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLFileStreamReader& streamReader) { const auto& typeDeserializers = Volt::SceneImporter::GetTypeDeserializers(); @@ -1009,7 +1009,7 @@ void ProjectUpgradeModal::DeserializePreV113Component(uint8_t* componentData, co }); } -void ProjectUpgradeModal::DeserializePreV113MonoScripts(Ref scene, const Volt::EntityID entityId, Volt::YAMLStreamReader& streamReader) +void ProjectUpgradeModal::DeserializePreV113MonoScripts(Ref scene, const Volt::EntityID entityId, Volt::YAMLFileStreamReader& streamReader) { Volt::Entity entity = scene->GetEntityFromUUID(entityId); const auto& typeDeserializers = Volt::SceneImporter::GetTypeDeserializers(); @@ -1288,7 +1288,7 @@ const Volt::ComponentMember* ProjectUpgradeModal::TryGetComponentMemberFromName( std::pair ProjectUpgradeModal::DeserializeV0MetaFile(const std::filesystem::path& metaPath) { - Volt::YAMLStreamReader streamReader{}; + Volt::YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(metaPath)) { diff --git a/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.h b/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.h index aa4e5c744..4e1d95a44 100644 --- a/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.h +++ b/Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.h @@ -14,7 +14,7 @@ namespace Volt class Scene; struct SceneLayer; - class YAMLStreamReader; + class YAMLFileStreamReader; } class ProjectUpgradeModal : public Modal @@ -40,9 +40,9 @@ class ProjectUpgradeModal : public Modal void ConvertPreV113Prefab(const std::filesystem::path& filePath); void DeserializePreV113SceneLayer(Ref scene, Volt::SceneLayer& sceneLayer, const std::filesystem::path& layerPath, std::map& entityRemapping); - void DeserializePreV113Entity(Ref scene, Volt::YAMLStreamReader& streamReader, std::map& entityRemapping, bool isPrefabEntity); - void DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLStreamReader& streamReader); - void DeserializePreV113MonoScripts(Ref scene, const Volt::EntityID entityId, Volt::YAMLStreamReader& streamReader); + void DeserializePreV113Entity(Ref scene, Volt::YAMLFileStreamReader& streamReader, std::map& entityRemapping, bool isPrefabEntity); + void DeserializePreV113Component(uint8_t* componentData, const Volt::IComponentTypeDesc* componentDesc, Volt::YAMLFileStreamReader& streamReader); + void DeserializePreV113MonoScripts(Ref scene, const Volt::EntityID entityId, Volt::YAMLFileStreamReader& streamReader); void HandleEntityRemapping(Ref scene, const std::map& entityRemapping); void HandleEntityArrayRemapping(Ref scene, const std::map& entityRemapping, const Volt::ComponentMember& componentMember, uint8_t* componentData); diff --git a/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp b/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp index 12cdf9c47..e0fc82e75 100644 --- a/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp +++ b/Volt/Volt/src/Volt/Asset/Importers/PrefabImporter.cpp @@ -7,7 +7,7 @@ #include "Volt/Asset/Importers/SceneImporter.h" #include "Volt/Utility/FileIO/YAMLFileStreamWriter.h" -#include "Volt/Utility/FileIO/YAMLStreamReader.h" +#include "Volt/Utility/FileIO/YAMLFileStreamReader.h" namespace Volt { @@ -30,7 +30,7 @@ namespace Volt Ref prefabScene = CreateRef(); - YAMLStreamReader streamReader{}; + YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(filePath)) { VT_CORE_ERROR("Failed to open file {0}!", metadata.filePath); diff --git a/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp b/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp index 6585b0570..d7926e8ca 100644 --- a/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp +++ b/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.cpp @@ -34,11 +34,11 @@ namespace Volt } template - void RegisterDeserializationFunction(std::unordered_map>& outTypes) + void RegisterDeserializationFunction(std::unordered_map>& outTypes) { VT_PROFILE_FUNCTION(); - outTypes[std::type_index{ typeid(T) }] = [](YAMLStreamReader& streamReader, uint8_t* data, const size_t offset) + outTypes[std::type_index{ typeid(T) }] = [](YAMLFileStreamReader& streamReader, uint8_t* data, const size_t offset) { *reinterpret_cast(&data[offset]) = streamReader.ReadKey("data", T()); }; @@ -136,7 +136,7 @@ namespace Volt return false; } - YAMLStreamReader streamReader{}; + YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(filePath)) { @@ -244,7 +244,7 @@ namespace Volt auto& sceneLayer = sceneLayers.emplace_back(); - YAMLStreamReader streamReader{}; + YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(layerPath)) { continue; @@ -399,7 +399,7 @@ namespace Volt const auto& path = entityPaths.at(i); - YAMLStreamReader streamReader{}; + YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(path)) { return; @@ -435,7 +435,7 @@ namespace Volt streamWriter.EndMap(); } - void SceneImporter::DeserializeWorldEngine(const Ref& scene, YAMLStreamReader& streamReader) const + void SceneImporter::DeserializeWorldEngine(const Ref& scene, YAMLFileStreamReader& streamReader) const { auto& worldEngine = scene->m_worldEngine; @@ -482,7 +482,7 @@ namespace Volt { const auto& path = entityPaths.at(i); - YAMLStreamReader streamReader{}; + YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(path)) { return; @@ -762,7 +762,7 @@ namespace Volt streamWriter.EndSequence(); } - void SceneImporter::DeserializeEntity(const Ref& scene, const AssetMetadata& metadata, YAMLStreamReader& streamReader) const + void SceneImporter::DeserializeEntity(const Ref& scene, const AssetMetadata& metadata, YAMLFileStreamReader& streamReader) const { VT_PROFILE_FUNCTION(); @@ -856,7 +856,7 @@ namespace Volt streamReader.ExitScope(); } - void SceneImporter::DeserializeClass(uint8_t* data, const size_t offset, const IComponentTypeDesc* compDesc, YAMLStreamReader& streamReader) const + void SceneImporter::DeserializeClass(uint8_t* data, const size_t offset, const IComponentTypeDesc* compDesc, YAMLFileStreamReader& streamReader) const { VT_PROFILE_FUNCTION(); @@ -909,7 +909,7 @@ namespace Volt }); } - void SceneImporter::DeserializeArray(uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLStreamReader& streamReader) const + void SceneImporter::DeserializeArray(uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLFileStreamReader& streamReader) const { VT_PROFILE_FUNCTION(); @@ -966,7 +966,7 @@ namespace Volt }); } - void SceneImporter::DeserializeMono(entt::entity id, const Ref& scene, YAMLStreamReader& streamReader) const + void SceneImporter::DeserializeMono(entt::entity id, const Ref& scene, YAMLFileStreamReader& streamReader) const { VT_PROFILE_FUNCTION(); @@ -1097,7 +1097,7 @@ namespace Volt const auto& path = entityPaths.at(i); - YAMLStreamReader streamReader{}; + YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(path)) { return; diff --git a/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.h b/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.h index b7be92041..689bdc8f7 100644 --- a/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.h +++ b/Volt/Volt/src/Volt/Asset/Importers/SceneImporter.h @@ -3,7 +3,7 @@ #include "Volt/Asset/Importers/AssetImporter.h" #include "Volt/Utility/FileIO/YAMLFileStreamWriter.h" -#include "Volt/Utility/FileIO/YAMLStreamReader.h" +#include "Volt/Utility/FileIO/YAMLFileStreamReader.h" #include "Volt/Scene/Entity.h" @@ -33,8 +33,8 @@ namespace Volt void Save(const AssetMetadata& metadata, const Ref& asset) const override; void SerializeEntity(entt::entity id, const AssetMetadata& metadata, const Ref& scene, YAMLFileStreamWriter& streamWriter) const; - void DeserializeEntity(const Ref& scene, const AssetMetadata& metadata, YAMLStreamReader& streamReader) const; - void DeserializeMono(entt::entity id, const Ref& scene, YAMLStreamReader& streamReader) const; + void DeserializeEntity(const Ref& scene, const AssetMetadata& metadata, YAMLFileStreamReader& streamReader) const; + void DeserializeMono(entt::entity id, const Ref& scene, YAMLFileStreamReader& streamReader) const; void LoadWorldCell(const Ref& scene, const WorldCell& worldCell) const; @@ -51,7 +51,7 @@ namespace Volt void LoadEntities(const AssetMetadata& metadata, const Ref& scene, const std::filesystem::path& sceneDirectory) const; void SerializeWorldEngine(const Ref& scene, YAMLFileStreamWriter& streamWriter) const; - void DeserializeWorldEngine(const Ref& scene, YAMLStreamReader& streamReader) const; + void DeserializeWorldEngine(const Ref& scene, YAMLFileStreamReader& streamReader) const; void LoadCellEntities(const AssetMetadata& metadata, const Ref& scene, const std::filesystem::path& sceneDirectory) const; @@ -61,10 +61,10 @@ namespace Volt void SerializeArray(const uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLFileStreamWriter& streamWriter) const; void SerializeMono(entt::entity id, const Ref& scene, YAMLFileStreamWriter& streamWriter) const; - void DeserializeClass(uint8_t* data, const size_t offset, const IComponentTypeDesc* compDesc, YAMLStreamReader& streamReader) const; - void DeserializeArray(uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLStreamReader& streamReader) const; + void DeserializeClass(uint8_t* data, const size_t offset, const IComponentTypeDesc* compDesc, YAMLFileStreamReader& streamReader) const; + void DeserializeArray(uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLFileStreamReader& streamReader) const; inline static std::unordered_map> s_typeSerializers; - inline static std::unordered_map> s_typeDeserializers; + inline static std::unordered_map> s_typeDeserializers; }; } diff --git a/Volt/Volt/src/Volt/Asset/ImportersNew/AssetSerializer.cpp b/Volt/Volt/src/Volt/Asset/ImportersNew/AssetSerializer.cpp index e5f67b16f..2432b5720 100644 --- a/Volt/Volt/src/Volt/Asset/ImportersNew/AssetSerializer.cpp +++ b/Volt/Volt/src/Volt/Asset/ImportersNew/AssetSerializer.cpp @@ -9,6 +9,7 @@ namespace Volt serializedMetadata.handle = metadata.handle; serializedMetadata.type = metadata.type; serializedMetadata.version = version; + serializedMetadata.dependencies = metadata.dependencies; return streamWriter.Write(serializedMetadata); } diff --git a/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.cpp b/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.cpp index f3df0372e..7cf5be0b0 100644 --- a/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.cpp +++ b/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.cpp @@ -20,7 +20,7 @@ #include "Volt/Utility/FileSystem.h" #include "Volt/Utility/FileIO/YAMLMemoryStreamWriter.h" -#include "Volt/Utility/FileIO/YAMLStreamReader.h" +#include "Volt/Utility/FileIO/YAMLFileStreamReader.h" namespace Volt { @@ -40,11 +40,11 @@ namespace Volt } template - void RegisterDeserializationFunction(std::unordered_map>& outTypes) + void RegisterDeserializationFunction(std::unordered_map>& outTypes) { VT_PROFILE_FUNCTION(); - outTypes[std::type_index{ typeid(T) }] = [](YAMLStreamReader& streamReader, uint8_t* data, const size_t offset) + outTypes[std::type_index{ typeid(T) }] = [](YAMLFileStreamReader& streamReader, uint8_t* data, const size_t offset) { *reinterpret_cast(&data[offset]) = streamReader.ReadKey("data", T()); }; @@ -136,6 +136,11 @@ namespace Volt directoryPath = directoryPath.parent_path(); } + if (!std::filesystem::exists(directoryPath)) + { + std::filesystem::create_directories(directoryPath); + } + std::filesystem::path scenePath = directoryPath / (metadata.filePath.stem().string() + ".vtasset"); // Serialize scene file @@ -164,13 +169,38 @@ namespace Volt sceneFileWriter.Write(buffer); buffer.Release(); - sceneFileWriter.WriteToDisk(scenePath, true, compressedDataOffset); // #TODO_Ivar: Fix compressed offset + sceneFileWriter.WriteToDisk(scenePath, true, compressedDataOffset); + } + + if (scene->m_sceneSettings.useWorldEngine) + { + SerializeEntities(metadata, scene, directoryPath); } } bool SceneSerializer::Deserialize(const AssetMetadata& metadata, Ref destinationAsset) const { - return false; + Ref scene = reinterpret_pointer_cast(destinationAsset); + + const auto filePath = AssetManager::GetFilesystemPath(metadata.filePath); + + if (!std::filesystem::exists(filePath)) + { + VT_CORE_ERROR("File {0} not found!", metadata.filePath); + destinationAsset->SetFlag(AssetFlag::Missing, true); + return false; + } + + BinaryStreamReader streamReader{ filePath }; + if (!streamReader.IsStreamValid()) + { + VT_CORE_ERROR("Failed to open file {0}!", metadata.filePath); + destinationAsset->SetFlag(AssetFlag::Invalid, true); + return false; + } + + + return true; } void SceneSerializer::SerializeEntity(entt::entity id, const AssetMetadata& metadata, const Ref& scene, YAMLMemoryStreamWriter& streamWriter) const diff --git a/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.h b/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.h index 63327d0b0..5886f1604 100644 --- a/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.h +++ b/Volt/Volt/src/Volt/Asset/ImportersNew/SceneSerializer.h @@ -9,7 +9,7 @@ namespace Volt { class YAMLMemoryStreamWriter; - class YAMLStreamReader; + class YAMLFileStreamReader; class Scene; class IArrayTypeDesc; @@ -26,14 +26,14 @@ namespace Volt bool Deserialize(const AssetMetadata& metadata, Ref destinationAsset) const override; void SerializeEntity(entt::entity id, const AssetMetadata& metadata, const Ref& scene, YAMLMemoryStreamWriter& streamWriter) const; - void DeserializeEntity(const Ref& scene, const AssetMetadata& metadata, YAMLStreamReader& streamReader) const; - void DeserializeMono(entt::entity id, const Ref& scene, YAMLStreamReader& streamReader) const; + void DeserializeEntity(const Ref& scene, const AssetMetadata& metadata, YAMLFileStreamReader& streamReader) const; + void DeserializeMono(entt::entity id, const Ref& scene, YAMLFileStreamReader& streamReader) const; private: inline static SceneSerializer* s_instance = nullptr; void SerializeWorldEngine(const Ref& scene, YAMLMemoryStreamWriter& streamWriter) const; - void DeserializeWorldEngine(const Ref& scene, YAMLStreamReader& streamReader) const; + void DeserializeWorldEngine(const Ref& scene, YAMLFileStreamReader& streamReader) const; void SerializeEntities(const AssetMetadata& metadata, const Ref& scene, const std::filesystem::path& sceneDirectory) const; @@ -45,10 +45,10 @@ namespace Volt void SerializeArray(const uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLMemoryStreamWriter& streamWriter) const; void SerializeMono(entt::entity id, const Ref& scene, YAMLMemoryStreamWriter& streamWriter) const; - void DeserializeClass(uint8_t* data, const size_t offset, const IComponentTypeDesc* compDesc, YAMLStreamReader& streamReader) const; - void DeserializeArray(uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLStreamReader& streamReader) const; + void DeserializeClass(uint8_t* data, const size_t offset, const IComponentTypeDesc* compDesc, YAMLFileStreamReader& streamReader) const; + void DeserializeArray(uint8_t* data, const size_t offset, const IArrayTypeDesc* arrayDesc, YAMLFileStreamReader& streamReader) const; inline static std::unordered_map> s_typeSerializers; - inline static std::unordered_map> s_typeDeserializers; + inline static std::unordered_map> s_typeDeserializers; }; } diff --git a/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.cpp b/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.cpp index 834bb90f0..9476071b5 100644 --- a/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.cpp +++ b/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.cpp @@ -11,6 +11,7 @@ namespace Volt streamWriter.Write(data.handle); streamWriter.Write(data.type); streamWriter.Write(data.version); + streamWriter.Write(data.dependencies); } void SerializedAssetMetadata::Deserialize(BinaryStreamReader& streamReader, SerializedAssetMetadata& outData) @@ -18,5 +19,6 @@ namespace Volt streamReader.Read(outData.handle); streamReader.Read(outData.type); streamReader.Read(outData.version); + streamReader.Read(outData.dependencies); } } diff --git a/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.h b/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.h index d87830f4b..52b1c2d1b 100644 --- a/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.h +++ b/Volt/Volt/src/Volt/Asset/Serialization/AssetSerializationCommon.h @@ -13,6 +13,8 @@ namespace Volt AssetType type; uint32_t version; + std::vector dependencies; + static void Serialize(BinaryStreamWriter& streamWriter, const SerializedAssetMetadata& data); static void Deserialize(BinaryStreamReader& streamReader, SerializedAssetMetadata& outData); }; diff --git a/Volt/Volt/src/Volt/Core/Application.cpp b/Volt/Volt/src/Volt/Core/Application.cpp index fd4af858b..74e2cc20d 100644 --- a/Volt/Volt/src/Volt/Core/Application.cpp +++ b/Volt/Volt/src/Volt/Core/Application.cpp @@ -45,6 +45,7 @@ #include #include "Volt/Asset/ImportersNew/MeshSerializer.h" +#include "Volt/Asset/ImportersNew/SceneSerializer.h" namespace Volt { @@ -146,9 +147,15 @@ namespace Volt metadata.filePath = "Assets/TestCube.vtasset"; serializer->Serialize(metadata, mesh); - + Ref testMesh = CreateRef(); serializer->Deserialize(metadata, testMesh); + + Ref sceneSerializer = CreateRef(); + Ref scene = Scene::CreateDefaultScene("TestScene"); + + metadata.filePath = "Assets/TestScene/TestScene.vtasset"; + sceneSerializer->Serialize(metadata, scene); } Application::~Application() diff --git a/Volt/Volt/src/Volt/Project/ProjectManager.cpp b/Volt/Volt/src/Volt/Project/ProjectManager.cpp index db44dafb3..712f8baaa 100644 --- a/Volt/Volt/src/Volt/Project/ProjectManager.cpp +++ b/Volt/Volt/src/Volt/Project/ProjectManager.cpp @@ -7,7 +7,7 @@ #include "Volt/Utility/YAMLSerializationHelpers.h" #include "Volt/Utility/SerializationMacros.h" -#include "Volt/Utility/FileIO/YAMLStreamReader.h" +#include "Volt/Utility/FileIO/YAMLFileStreamReader.h" #include "Volt/Utility/FileIO/YAMLFileStreamWriter.h" namespace Volt @@ -65,7 +65,7 @@ namespace Volt void ProjectManager::DeserializeProject() { - YAMLStreamReader streamReader{}; + YAMLFileStreamReader streamReader{}; if (!streamReader.OpenFile(m_currentProject->projectFilePath)) { diff --git a/Volt/Volt/src/Volt/Scene/Scene.cpp b/Volt/Volt/src/Volt/Scene/Scene.cpp index 37537c427..032b55990 100644 --- a/Volt/Volt/src/Volt/Scene/Scene.cpp +++ b/Volt/Volt/src/Volt/Scene/Scene.cpp @@ -737,6 +737,8 @@ namespace Volt } } + newScene->m_sceneSettings.useWorldEngine = true; + return newScene; } diff --git a/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamReader.h b/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamReader.h index 8ebb6a852..76023850c 100644 --- a/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamReader.h +++ b/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamReader.h @@ -117,10 +117,7 @@ namespace Volt { for (size_t i = 0; i < data.size(); i++) { - TypeHeader serializedObjectTypeHeader = ReadTypeHeader(); - VT_CORE_ASSERT(serializedObjectTypeHeader.baseTypeSize == sizeof(F), "Type sizes must match!"); - - F::Deserialize(*this, data[i]); + Read(data[i]); } } } @@ -154,10 +151,7 @@ namespace Volt { for (size_t i = 0; i < data.size(); i++) { - TypeHeader serializedObjectTypeHeader = ReadTypeHeader(); - VT_CORE_ASSERT(serializedObjectTypeHeader.baseTypeSize == sizeof(F), "Type sizes must match!"); - - F::Deserialize(*this, data[i]); + Read(data[i]); } } } diff --git a/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.cpp b/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.cpp index 14e7e1160..d2deea77c 100644 --- a/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.cpp +++ b/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.cpp @@ -42,6 +42,7 @@ namespace Volt emptyEncodingHeader.fill(0); m_data.insert(m_data.begin(), emptyEncodingHeader.begin(), emptyEncodingHeader.end()); + writePtr = m_data.data(); size = m_data.size(); } diff --git a/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.h b/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.h index cceb3514d..bc783cc2d 100644 --- a/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.h +++ b/Volt/Volt/src/Volt/Utility/FileIO/BinaryStreamWriter.h @@ -151,7 +151,7 @@ namespace Volt { TypeHeader header{}; header.baseTypeSize = sizeof(Buffer); - header.totalTypeSize = static_cast(buffer.GetSize()); + header.totalTypeSize = static_cast(buffer.GetSize()); WriteTypeHeader(header); WriteData(buffer.As(), buffer.GetSize()); @@ -176,12 +176,7 @@ namespace Volt { for (const auto& obj : data) { - TypeHeader objectHeader{}; - objectHeader.baseTypeSize = sizeof(F); - objectHeader.totalTypeSize = sizeof(F); - - WriteTypeHeader(objectHeader); - F::Serialize(*this, obj); + Write(obj); } } @@ -218,12 +213,7 @@ namespace Volt { for (const auto& obj : data) { - TypeHeader objectHeader{}; - objectHeader.baseTypeSize = sizeof(F); - objectHeader.totalTypeSize = sizeof(F); - - WriteTypeHeader(objectHeader); - F::Serialize(*this, obj); + Write(obj); } } diff --git a/Volt/Volt/src/Volt/Utility/FileIO/YAMLFileStreamReader.cpp b/Volt/Volt/src/Volt/Utility/FileIO/YAMLFileStreamReader.cpp new file mode 100644 index 000000000..62f1e3d17 --- /dev/null +++ b/Volt/Volt/src/Volt/Utility/FileIO/YAMLFileStreamReader.cpp @@ -0,0 +1,36 @@ +#include "vtpch.h" +#include "YAMLFileStreamReader.h" + +namespace Volt +{ + const bool YAMLFileStreamReader::OpenFile(const std::filesystem::path& filePath) + { + if (!std::filesystem::exists(filePath)) + { + return false; + } + + std::ifstream file(filePath); + if (!file.is_open()) + { + return false; + } + + std::stringstream strStream; + strStream << file.rdbuf(); + file.close(); + + try + { + m_rootNode = YAML::Load(strStream.str()); + m_currentNode = m_rootNode; + } + catch (std::exception& e) + { + VT_CORE_ERROR("[YAMLFileStreamReader] File {0} contains invalid YAML! Please correct it! Error: {1}", filePath.string(), e.what()); + return false; + } + + return true; + } +} diff --git a/Volt/Volt/src/Volt/Utility/FileIO/YAMLFileStreamReader.h b/Volt/Volt/src/Volt/Utility/FileIO/YAMLFileStreamReader.h new file mode 100644 index 000000000..817349dca --- /dev/null +++ b/Volt/Volt/src/Volt/Utility/FileIO/YAMLFileStreamReader.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Volt/Utility/FileIO/YAMLStreamReader.h" + +namespace Volt +{ + class YAMLFileStreamReader : public YAMLStreamReader + { + public: + ~YAMLFileStreamReader() override = default; + const bool OpenFile(const std::filesystem::path& filePath); + }; +} diff --git a/Volt/Volt/src/Volt/Utility/FileIO/YAMLMemoryStreamReader.cpp b/Volt/Volt/src/Volt/Utility/FileIO/YAMLMemoryStreamReader.cpp new file mode 100644 index 000000000..dee0086e9 --- /dev/null +++ b/Volt/Volt/src/Volt/Utility/FileIO/YAMLMemoryStreamReader.cpp @@ -0,0 +1,34 @@ +#include "vtpch.h" +#include "YAMLMemoryStreamReader.h" + +#include "Volt/Core/Buffer.h" +#include "Volt/Log/Log.h" + +namespace Volt +{ + const bool YAMLMemoryStreamReader::ReadBuffer(const Buffer& buffer) + { + if (!buffer.IsValid()) + { + return false; + } + + std::string tempStr; + tempStr.resize(buffer.GetSize()); + + memcpy_s(tempStr.data(), tempStr.size(), buffer.As(), buffer.GetSize()); + + try + { + m_rootNode = YAML::Load(tempStr); + m_currentNode = m_rootNode; + } + catch (std::exception& e) + { + VT_CORE_ERROR("[YAMLStreamReader] Buffer contains invalid YAML! Please correct it! Error: {0}", e.what()); + return false; + } + + return true; + } +} diff --git a/Volt/Volt/src/Volt/Utility/FileIO/YAMLMemoryStreamReader.h b/Volt/Volt/src/Volt/Utility/FileIO/YAMLMemoryStreamReader.h new file mode 100644 index 000000000..4ab5d728b --- /dev/null +++ b/Volt/Volt/src/Volt/Utility/FileIO/YAMLMemoryStreamReader.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Volt/Utility/FileIO/YAMLStreamReader.h" + +namespace Volt +{ + class Buffer; + + class YAMLMemoryStreamReader : public YAMLStreamReader + { + public: + ~YAMLMemoryStreamReader() override = default; + + const bool ReadBuffer(const Buffer& buffer); + }; +} diff --git a/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.cpp b/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.cpp index 434c00688..2c20ef5df 100644 --- a/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.cpp +++ b/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.cpp @@ -3,8 +3,6 @@ #include "Volt/Log/Log.h" -#include "Volt/Core/Profiling.h" - namespace Volt { YAMLStreamReader::YAMLStreamReader() @@ -12,40 +10,6 @@ namespace Volt m_nodeStack.reserve(100); } - const bool YAMLStreamReader::OpenFile(const std::filesystem::path& filePath) - { - VT_PROFILE_FUNCTION(); - - if (!std::filesystem::exists(filePath)) - { - return false; - } - - std::ifstream file(filePath); - if (!file.is_open()) - { - return false; - } - - std::stringstream strStream; - strStream << file.rdbuf(); - file.close(); - - try - { - VT_PROFILE_SCOPE("Parse YAML"); - m_rootNode = YAML::Load(strStream.str()); - m_currentNode = m_rootNode; - } - catch (std::exception& e) - { - VT_CORE_ERROR("[YAMLStreamReader] File {0} contains invalid YAML! Please correct it! Error: {1}", filePath.string(), e.what()); - return false; - } - - return true; - } - const bool YAMLStreamReader::HasKey(const std::string& key) { if (m_currentNode[key]) diff --git a/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.h b/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.h index 7ca9f79b1..ddf792391 100644 --- a/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.h +++ b/Volt/Volt/src/Volt/Utility/FileIO/YAMLStreamReader.h @@ -10,8 +10,8 @@ namespace Volt { public: YAMLStreamReader(); + virtual ~YAMLStreamReader() = default; - const bool OpenFile(const std::filesystem::path& filePath); const bool HasKey(const std::string& key); const bool IsSequenceEmpty(const std::string& key); @@ -24,7 +24,7 @@ namespace Volt void ForEach(const std::string& key, std::function function); - private: + protected: YAML::Node m_currentNode; std::vector m_nodeStack;