Skip to content

Commit

Permalink
Added engine versioning and implemented ability to upgrade projects
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkTreasure1 committed Sep 11, 2023
1 parent ca63c94 commit caa260c
Show file tree
Hide file tree
Showing 23 changed files with 711 additions and 180 deletions.
4 changes: 2 additions & 2 deletions Engine/Launcher.exe
Git LFS file not shown
4 changes: 2 additions & 2 deletions Engine/Sandbox.exe
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata:
assetHandle: 4375374330609413162
filePath: Assets/Materials\M_Grey.vtmat
filePath: Assets/Materials/M_Grey.vtmat
type: 32
Dependencies:
[]
Expand Down
15 changes: 8 additions & 7 deletions Engine/Templates/Project/Project.vtproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Project:
Name: Project
CompanyName: Default
AssetsPath: Assets
AudioBanksPath: Audio/Banks # Starts in the defined assets path
IconPath: ""
CursorPath: ""
StartScene: ""
EngineVersion: 0.1.2
Name: Project
CompanyName: None
AssetsDirectory: Assets
AudioBanksDirectory: Audio/Banks
IconPath: ""
CursorPath: ""
StartScenePath: ""
139 changes: 139 additions & 0 deletions Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "sbpch.h"
#include "ProjectUpgradeModal.h"

#include <Volt/Utility/UIUtility.h>
#include <Volt/Utility/FileIO/YAMLStreamReader.h>

#include <imgui.h>

ProjectUpgradeModal::ProjectUpgradeModal(const std::string& strId)
: Modal(strId)
{
}

void ProjectUpgradeModal::DrawModalContent()
{
const std::string engineVersion = Volt::Application::Get().GetInfo().version.ToString();
const std::string projectVersion = Volt::ProjectManager::GetProject().engineVersion.ToString();

ImGui::TextUnformatted("The loaded project is not compatible with this version of the engine!");

if (projectVersion.empty())
{
ImGui::Text("Would you like to upgrade the project to version %s?", engineVersion.c_str());
}
else
{
ImGui::Text("Would you like to upgrade the project from version %s to version %s?", projectVersion.c_str(), engineVersion.c_str());
}

if (ImGui::Button("Yes"))
{
UpgradeCurrentProject();

ImGui::CloseCurrentPopup();
}

ImGui::SameLine();

if (ImGui::Button("No"))
{
ImGui::CloseCurrentPopup();
}
}

void ProjectUpgradeModal::OnOpen()
{
}

void ProjectUpgradeModal::OnClose()
{
}

void ProjectUpgradeModal::UpgradeCurrentProject()
{
const Volt::Version engineVersion = Volt::Application::Get().GetInfo().version;
const Volt::Version projectVersion = Volt::ProjectManager::GetProject().engineVersion;

if (projectVersion.GetMinor() < 1 && projectVersion.GetMajor() == 0)
{
ConvertMetaFilesFromV0();
}

Volt::ProjectManager::OnProjectUpgraded();
Volt::ProjectManager::SerializeProject();
}

void ProjectUpgradeModal::ConvertMetaFilesFromV0()
{
auto& project = Volt::ProjectManager::GetProject();

const std::filesystem::path assetsPath = project.projectDirectory / project.assetsDirectory;

std::vector<std::filesystem::path> metaFilesToConvert;

for (const auto& entry : std::filesystem::recursive_directory_iterator(assetsPath))
{
if (entry.path().extension().string() != ".vtmeta")
{
continue;
}

metaFilesToConvert.emplace_back(entry.path());
}

struct AssetDescriptor
{
Volt::AssetHandle handle;
std::filesystem::path assetFilePath;
};

std::vector<AssetDescriptor> assetDescriptors;

for (const auto& metaPath : metaFilesToConvert)
{
const auto [assetPath, handle] = DeserializeV0MetaFile(metaPath);
assetDescriptors.emplace_back(handle, assetPath);

if (std::filesystem::exists(metaPath))
{
std::filesystem::remove(metaPath);
}
}

for (const auto& descriptor : assetDescriptors)
{
Volt::AssetManager::Get().AddAssetToRegistry(descriptor.assetFilePath, descriptor.handle);
}
}

std::pair<std::filesystem::path, Volt::AssetHandle> ProjectUpgradeModal::DeserializeV0MetaFile(const std::filesystem::path& metaPath)
{
Volt::YAMLStreamReader streamReader{};

if (!streamReader.OpenFile(metaPath))
{
return {};
}

std::filesystem::path resultAssetFilePath;
Volt::AssetHandle resultAssetHandle = 0;

// Is new
if (streamReader.HasKey("Metadata"))
{
streamReader.EnterScope("Metadata");

resultAssetFilePath = streamReader.ReadKey("filePath", std::string(""));
resultAssetHandle = streamReader.ReadKey("assetHandle", 0u);

streamReader.ExitScope();
}
else if (streamReader.HasKey("Handle"))
{
resultAssetHandle = streamReader.ReadKey("Handle", uint64_t(0));
resultAssetFilePath = streamReader.ReadKey("Path", std::string(""));
}

return { resultAssetFilePath, resultAssetHandle };
}
23 changes: 23 additions & 0 deletions Volt/Sandbox/src/Sandbox/Modals/ProjectUpgradeModal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "Sandbox/Modals/Modal.h"

#include <Volt/Asset/Asset.h>

class ProjectUpgradeModal : public Modal
{
public:
ProjectUpgradeModal(const std::string& strId);
~ProjectUpgradeModal() override = default;

protected:
void DrawModalContent() override;
void OnOpen() override;
void OnClose() override;

private:
void UpgradeCurrentProject();
void ConvertMetaFilesFromV0();

std::pair<std::filesystem::path, Volt::AssetHandle> DeserializeV0MetaFile(const std::filesystem::path& metaPath);
};
32 changes: 26 additions & 6 deletions Volt/Sandbox/src/Sandbox/Sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "Sandbox/UISystems/ModalSystem.h"

#include "Sandbox/Modals/ProjectUpgradeModal.h"

#include "Sandbox/Window/PropertiesPanel.h"
#include "Sandbox/Window/ViewportPanel.h"
#include "Sandbox/Window/GameViewPanel.h"
Expand Down Expand Up @@ -36,6 +38,10 @@
#include "Sandbox/Window/PostProcessingStackPanel.h"
#include "Sandbox/Window/PostProcessingMaterialPanel.h"
#include "Sandbox/Window/NavigationPanel.h"
#include "Sandbox/Window/Net/NetPanel.h"
#include "Sandbox/Window/Net/NetContractPanel.h"
#include "Sandbox/Window/BehaviourGraph/BehaviorPanel.h"
#include "Sandbox/VertexPainting/VertexPainterPanel.h"

#include "Sandbox/Utility/EditorResources.h"
#include "Sandbox/Utility/EditorLibrary.h"
Expand All @@ -44,9 +50,6 @@

#include "Sandbox/UserSettingsManager.h"

#include "Sandbox/Window/BehaviourGraph/BehaviorPanel.h"
#include "Sandbox/VertexPainting/VertexPainterPanel.h"

#include <Volt/Core/Application.h>
#include <Volt/Core/Window.h>

Expand Down Expand Up @@ -85,9 +88,6 @@

#include <imgui.h>

#include "Sandbox/Window/Net/NetPanel.h"
#include "Sandbox/Window/Net/NetContractPanel.h"

Sandbox::Sandbox()
{
VT_ASSERT(!myInstance, "Sandbox already exists!");
Expand Down Expand Up @@ -198,6 +198,8 @@ void Sandbox::OnAttach()
}
}

InitializeModals();

if (!userSettings.sceneSettings.lastOpenScene.empty())
{
OpenScene(userSettings.sceneSettings.lastOpenScene);
Expand Down Expand Up @@ -317,9 +319,18 @@ void Sandbox::SetupNewSceneData()
Volt::Application::Get().OnEvent(loadEvent);
}

void Sandbox::InitializeModals()
{
{
auto& modal = ModalSystem::AddModal<ProjectUpgradeModal>("Upgrade Project");
m_projectUpgradeModal = modal.GetID();
}
}

void Sandbox::OnDetach()
{
m_isInitialized = false;

Volt::Log::ClearCallbacks();

if (mySceneState == SceneState::Play)
Expand Down Expand Up @@ -365,6 +376,7 @@ void Sandbox::OnEvent(Volt::Event& e)
{
return;
}

Volt::EventDispatcher dispatcher(e);
dispatcher.Dispatch<Volt::AppUpdateEvent>(VT_BIND_EVENT_FN(Sandbox::OnUpdateEvent));
dispatcher.Dispatch<Volt::AppImGuiUpdateEvent>(VT_BIND_EVENT_FN(Sandbox::OnImGuiUpdateEvent));
Expand Down Expand Up @@ -802,6 +814,14 @@ bool Sandbox::OnUpdateEvent(Volt::AppUpdateEvent& e)

bool Sandbox::OnImGuiUpdateEvent(Volt::AppImGuiUpdateEvent& e)
{
static bool shouldOpenProjectUpgradeModal = Volt::ProjectManager::IsCurrentProjectDeprecated();
if (shouldOpenProjectUpgradeModal)
{
ModalSystem::GetModal<ProjectUpgradeModal>(m_projectUpgradeModal).Open();

shouldOpenProjectUpgradeModal = false;
}

ImGuizmo::BeginFrame();

if (SaveReturnState returnState = EditorUtils::SaveFilePopup("Do you want to save scene?##OpenScene"); returnState != SaveReturnState::None)
Expand Down
5 changes: 5 additions & 0 deletions Volt/Sandbox/src/Sandbox/Sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class Sandbox : public Volt::Layer
void CreateWatches();

void SetupNewSceneData();
void InitializeModals();

/////ImGui/////
void UpdateDockSpace();
Expand All @@ -115,6 +116,10 @@ class Sandbox : public Volt::Layer
void RenderGameView();
///////////////

///// Modals /////
Volt::UUID m_projectUpgradeModal = 0;
//////////////////

///// Debug Rendering /////
void RenderSelection(Ref<Volt::Camera> camera);
void RenderGizmos(Ref<Volt::Scene> scene, Ref<Volt::Camera> camera);
Expand Down
Loading

0 comments on commit caa260c

Please sign in to comment.