Load the previously loaded project and scene on startup
(read from an ini file)
This commit is contained in:
parent
145338d666
commit
282844b905
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -36,3 +36,6 @@
|
|||||||
[submodule "libs/nativefiledialog"]
|
[submodule "libs/nativefiledialog"]
|
||||||
path = libs/nativefiledialog
|
path = libs/nativefiledialog
|
||||||
url = https://git.barink.dev/Nigel/nativefiledialog.git
|
url = https://git.barink.dev/Nigel/nativefiledialog.git
|
||||||
|
[submodule "libs/mINI"]
|
||||||
|
path = libs/mINI
|
||||||
|
url = https://github.com/pulzed/mINI.git
|
||||||
|
Binary file not shown.
@ -30,6 +30,7 @@ includedirs{
|
|||||||
incfolder["entt"],
|
incfolder["entt"],
|
||||||
incfolder["yamlcpp"],
|
incfolder["yamlcpp"],
|
||||||
incfolder["nativefiledialog"],
|
incfolder["nativefiledialog"],
|
||||||
|
incfolder["mINI"]
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,9 @@ void MainMenuBar::ApplicationMenu(Project& project) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Preferences"))
|
if (ImGui::MenuItem("Preferences"))
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -72,6 +75,9 @@ void MainMenuBar::SceneMenu(Project& project, YoggieEngine::Scene& scene) {
|
|||||||
switch (result) {
|
switch (result) {
|
||||||
case(NFD_OKAY):
|
case(NFD_OKAY):
|
||||||
SaveScene(path, scene);
|
SaveScene(path, scene);
|
||||||
|
|
||||||
|
project.AddScene(scene);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case(NFD_CANCEL):
|
case(NFD_CANCEL):
|
||||||
break;
|
break;
|
||||||
|
@ -13,6 +13,15 @@ void Project::SaveProject(std::filesystem::path path, Project& project)
|
|||||||
projectYAML << YAML::Key << "Project" << YAML::Value << project.Name;
|
projectYAML << YAML::Key << "Project" << YAML::Value << project.Name;
|
||||||
projectYAML << YAML::Key << "Directory" << YAML::Value << path.parent_path().u8string();
|
projectYAML << YAML::Key << "Directory" << YAML::Value << path.parent_path().u8string();
|
||||||
projectYAML << YAML::EndMap;
|
projectYAML << YAML::EndMap;
|
||||||
|
projectYAML << YAML::BeginMap;
|
||||||
|
|
||||||
|
|
||||||
|
projectYAML << YAML::Key << "Scenes" << YAML::Value << YAML::BeginSeq;
|
||||||
|
for (auto scene : project.Scenes) {
|
||||||
|
projectYAML << scene->name;
|
||||||
|
}
|
||||||
|
projectYAML << YAML::EndSeq;
|
||||||
|
|
||||||
std::ofstream projectFile;
|
std::ofstream projectFile;
|
||||||
|
|
||||||
projectFile.open(path.u8string());
|
projectFile.open(path.u8string());
|
||||||
@ -56,10 +65,12 @@ namespace YAML {
|
|||||||
return false;
|
return false;
|
||||||
rhs.setName(node["Project"].as<std::string>());
|
rhs.setName(node["Project"].as<std::string>());
|
||||||
rhs.setProjectDirectory(node["Directory"].as<std::string>());
|
rhs.setProjectDirectory(node["Directory"].as<std::string>());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../../YoggieEngine/src/YoggieEngine.h"
|
||||||
|
#include <yaml-cpp/yaml.h>
|
||||||
|
|
||||||
|
|
||||||
class Project {
|
class Project {
|
||||||
public:
|
public:
|
||||||
Project() = default;
|
Project() = default;
|
||||||
@ -13,10 +17,21 @@ public:
|
|||||||
void setProjectDirectory(std::string& path) { ProjectDirectory = std::filesystem::path(path); }
|
void setProjectDirectory(std::string& path) { ProjectDirectory = std::filesystem::path(path); }
|
||||||
const std::filesystem::path GetProjectDirectory() { return ProjectDirectory; }
|
const std::filesystem::path GetProjectDirectory() { return ProjectDirectory; }
|
||||||
|
|
||||||
|
|
||||||
|
void AddScene(YoggieEngine::Scene& scene)
|
||||||
|
{
|
||||||
|
Scenes.push_back(&scene);
|
||||||
|
}
|
||||||
|
|
||||||
static void SaveProject(std::filesystem::path path, Project& project);
|
static void SaveProject(std::filesystem::path path, Project& project);
|
||||||
static void LoadProject(std::filesystem::path path, Project& project);
|
static void LoadProject(std::filesystem::path path, Project& project);
|
||||||
private:
|
private:
|
||||||
std::string Name;
|
std::string Name;
|
||||||
std::filesystem::path ProjectDirectory;
|
std::filesystem::path ProjectDirectory;
|
||||||
|
|
||||||
|
std::vector<YoggieEngine::Scene*> Scenes;
|
||||||
|
|
||||||
|
friend class YAML::convert<Project>;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
#include "../../YoggieEngine/src/EntryPoint.h"
|
#include "../../YoggieEngine/src/EntryPoint.h"
|
||||||
#include "../../YoggieEngine/src/AssetManager/ModelImporter.h"
|
#include <mini/ini.h>
|
||||||
#include "../../YoggieEngine/src/Physics/Physics.h"
|
|
||||||
|
|
||||||
#include <nfd.h>
|
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
#include "Project/Project.h"
|
|
||||||
#include "AssetManagement/SceneSerializer.h"
|
#include "AssetManagement/SceneSerializer.h"
|
||||||
#include "AssetManagement/AssetManager.h"
|
#include "AssetManagement/AssetManager.h"
|
||||||
|
|
||||||
@ -31,9 +27,15 @@ public:
|
|||||||
|
|
||||||
void Run() override
|
void Run() override
|
||||||
{
|
{
|
||||||
|
std::string path = (std::filesystem::current_path()).string();
|
||||||
|
project.setProjectDirectory(path);
|
||||||
|
|
||||||
|
AssetManager::Init();
|
||||||
|
AssetManager::setAssetPath(project.GetProjectDirectory());
|
||||||
|
AssetManager::BuildAssetView();
|
||||||
|
|
||||||
LoadLastOrEmptyProject();
|
LoadLastOrEmptyProject();
|
||||||
|
|
||||||
MainMenuBar menuBar = MainMenuBar();
|
|
||||||
ProjectInfo projectInfo(project);
|
ProjectInfo projectInfo(project);
|
||||||
Viewport sceneview = Viewport(scene);
|
Viewport sceneview = Viewport(scene);
|
||||||
RuntimeControls rc = RuntimeControls();
|
RuntimeControls rc = RuntimeControls();
|
||||||
@ -114,14 +116,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
GuiBegin();
|
GuiBegin();
|
||||||
|
{
|
||||||
|
MainMenuBar menuBar = MainMenuBar();
|
||||||
|
|
||||||
// Show a menu bar
|
// Show a menu bar
|
||||||
menuBar.ApplicationMenu(project);
|
menuBar.ApplicationMenu(project);
|
||||||
menuBar.SceneMenu(project, scene);
|
menuBar.SceneMenu(project, scene);
|
||||||
menuBar.SelectMenu();
|
menuBar.SelectMenu();
|
||||||
menuBar.WindowMenu();
|
menuBar.WindowMenu();
|
||||||
menuBar.DebugMenu();
|
menuBar.DebugMenu();
|
||||||
menuBar.Help();
|
menuBar.Help();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (scene.getReg().valid(Selected)) {
|
if (scene.getReg().valid(Selected)) {
|
||||||
@ -156,43 +162,29 @@ public:
|
|||||||
// Otherwise load no project..
|
// Otherwise load no project..
|
||||||
// OR
|
// OR
|
||||||
// Load an empty project.
|
// Load an empty project.
|
||||||
|
mINI::INIStructure ini;
|
||||||
std::string path = (std::filesystem::current_path()).string();
|
|
||||||
project.setProjectDirectory(path);
|
|
||||||
|
|
||||||
AssetManager::Init();
|
|
||||||
AssetManager::setAssetPath(project.GetProjectDirectory());
|
|
||||||
AssetManager::BuildAssetView();
|
|
||||||
|
|
||||||
// Create a level and load it as the current level
|
|
||||||
auto importer = ModelImporter();
|
|
||||||
|
|
||||||
|
|
||||||
// create an ambient light source
|
if (std::filesystem::exists("build\\Debug\\Editor.ini"))
|
||||||
auto light = scene.AddEntity("Light");
|
{
|
||||||
auto& lightComponent = light.AddComponent<LightComponent>();
|
mINI::INIFile file("build\\Debug\\Editor.ini");
|
||||||
lightComponent.Color = glm::vec3(1.0f);
|
file.read(ini);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
spdlog::debug("Could not find an `Editor.ini` file.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ini["editor"]["openlastproject"] == "TRUE")
|
||||||
|
{
|
||||||
|
Project::LoadProject(ini["cache"]["project"], project);
|
||||||
|
LoadScene(ini["cache"]["scene"], scene);
|
||||||
|
|
||||||
// Create a cube
|
}
|
||||||
auto model = importer.Import("build/Debug/Models/Cube.obj");
|
else
|
||||||
|
{
|
||||||
auto cube = scene.AddEntity("Cube");
|
spdlog::debug("Starting without a project. Please create one.");
|
||||||
auto& render3DComponent = cube.AddComponent<Render3DComponent>();
|
}
|
||||||
render3DComponent.mesh = *(model->renderable->mesh);
|
|
||||||
|
|
||||||
cube.GetComponent<TransformComponent>().Position = glm::vec3(1.0f, 0.0f, 5.0f);
|
|
||||||
|
|
||||||
auto cube2 = scene.AddEntity("Cube2");
|
|
||||||
auto& rendercube2 = cube2.AddComponent<Render3DComponent>();
|
|
||||||
rendercube2.mesh = *(model->renderable->mesh);
|
|
||||||
auto& relationcube = cube.AddComponent<RelationComponent>(cube2);
|
|
||||||
auto& rigidbodycomp = cube.AddComponent<RigidBody>();
|
|
||||||
auto& rigidbodycomp2 = cube2.AddComponent<RigidBody>();
|
|
||||||
|
|
||||||
|
|
||||||
auto Grass = scene.AddEntity("Grass/Window-Pane");
|
|
||||||
//auto& renderGrass = Grass.AddComponent<Render3DComponent>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -4,6 +4,11 @@
|
|||||||
using namespace entt;
|
using namespace entt;
|
||||||
|
|
||||||
namespace YoggieEngine{
|
namespace YoggieEngine{
|
||||||
|
|
||||||
|
Scene::Scene(const std::string& name): name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Scene::Scene()
|
Scene::Scene()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ namespace YoggieEngine {
|
|||||||
class Scene
|
class Scene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Scene(const std::string& name );
|
||||||
Scene();
|
Scene();
|
||||||
~Scene();
|
~Scene();
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ namespace YoggieEngine {
|
|||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
entt::registry& getReg() { return m_registry; }
|
entt::registry& getReg() { return m_registry; }
|
||||||
|
std::string name;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
entt::registry m_registry;
|
entt::registry m_registry;
|
||||||
|
@ -6,7 +6,7 @@ incfolder["assimp"] = "%{wks.location}/libs/assimp/include"
|
|||||||
incfolder["glm"] = "%{wks.location}/libs/glm"
|
incfolder["glm"] = "%{wks.location}/libs/glm"
|
||||||
incfolder["entt"] = "%{wks.location}/libs/entt/src"
|
incfolder["entt"] = "%{wks.location}/libs/entt/src"
|
||||||
incfolder["yamlcpp"] = "%{wks.location}/libs/yaml-cpp/include"
|
incfolder["yamlcpp"] = "%{wks.location}/libs/yaml-cpp/include"
|
||||||
|
incfolder["mINI"] = "%{wks.location}/libs/mINI/src"
|
||||||
-- Graphics
|
-- Graphics
|
||||||
incfolder["glad"] = "%{wks.location}/libs/glad/include"
|
incfolder["glad"] = "%{wks.location}/libs/glad/include"
|
||||||
incfolder["glfw"] = "%{wks.location}/libs/glfw/include"
|
incfolder["glfw"] = "%{wks.location}/libs/glfw/include"
|
||||||
|
1
libs/mINI
Submodule
1
libs/mINI
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit a1ff72e8898db8b53282e9eb7c7ec5973519787e
|
Loading…
Reference in New Issue
Block a user