Compare commits

...

7 Commits

Author SHA1 Message Date
Sri Sham Haran 6524639409 Can finally deserialize starting scene, play and stop which saves and reloads the scene. 2022-11-01 21:07:56 +08:00
Sri Sham Haran 8b4ebc557c Merge branch 'main' into SP3-305-configurations 2022-11-01 20:08:09 +08:00
Sri Sham Haran 87f6252d3e some fixes. still cant reload scene. jesus wept 2022-11-01 01:57:55 +08:00
Xiao Qi 943f756721 Added file name and extensions to path to save asset 2022-11-01 01:19:50 +08:00
Sri Sham Haran 7ac13b370f Merge branch 'main' into SP3-305-configurations 2022-11-01 01:09:19 +08:00
Sri Sham Haran 67ad65a2d5 get window from application for now 2022-11-01 00:41:37 +08:00
Sri Sham Haran 917009a5cb Scene loading 2022-10-31 22:04:19 +08:00
29 changed files with 689 additions and 341 deletions

View File

@ -0,0 +1,4 @@
Start in Fullscreen: false
Starting Scene ID: 94511900
Window Size: {x: 1920, y: 1080}
Window Title: SHADE Engine

View File

@ -0,0 +1,46 @@
- EID: 0
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 1, y: 1, z: 1}
Camera Component:
Position: {x: 0, y: 0, z: 0}
Pitch: 0
Yaw: 0
Roll: 0
Width: 1250
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
Scripts: ~
- EID: 1
Name: Ambient Light
IsActive: true
NumberOfChildren: 0
Components:
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Ambient
Direction: {x: 0, y: 0, z: 1}
Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295
Strength: 1.39999998
Scripts: ~
- EID: 2
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -2.9000001, z: -7}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 7, y: 7, z: 7}
Renderable Component:
Mesh: 80365422
Material: 0
Scripts: ~

View File

@ -0,0 +1,3 @@
Name: Scene01
ID: 94511900
Type: 5

View File

@ -22,7 +22,7 @@
// Managers // Managers
#include "ECS_Base/Managers/SHEntityManager.h" #include "ECS_Base/Managers/SHEntityManager.h"
#include "Scene/SHSceneManager.h" #include "Scene/SHSceneManager.h"
#include "Serialization/Configurations/SHConfigurationManager.h"
// Systems // Systems
#include "Scripting/SHScriptEngine.h" #include "Scripting/SHScriptEngine.h"
#include "Physics/SHPhysicsSystem.h" #include "Physics/SHPhysicsSystem.h"
@ -36,7 +36,7 @@
#include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
#include "Scenes/SBTestScene.h" #include "Scenes/SBMainScene.h"
#include "Assets/SHAssetManager.h" #include "Assets/SHAssetManager.h"
@ -58,8 +58,9 @@ namespace Sandbox
{ {
// Set working directory // Set working directory
SHFileUtilities::SetWorkDirToExecDir(); SHFileUtilities::SetWorkDirToExecDir();
WindowData wndData{};
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow); auto const& applicationConfig = SHConfigurationManager::LoadApplicationConfig(&wndData);
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow, wndData);
// Create Systems // Create Systems
SHSystemManager::CreateSystem<SHGraphicsSystem>(); SHSystemManager::CreateSystem<SHGraphicsSystem>();
@ -71,10 +72,13 @@ namespace Sandbox
SHSystemManager::CreateSystem<SHCameraSystem>(); SHSystemManager::CreateSystem<SHCameraSystem>();
#ifdef SHEDITOR #ifdef SHEDITOR
SDL_Init(SDL_INIT_VIDEO); SDL_Init(SDL_INIT_VIDEO);
sdlWindow = SDL_CreateWindowFrom(window.GetHWND()); sdlWindow = SDL_CreateWindowFrom(window.GetHWND());
SHSystemManager::CreateSystem<SHEditor>(); SHSystemManager::CreateSystem<SHEditor>();
SHSystemManager::GetSystem<SHEditor>()->SetSDLWindow(sdlWindow); auto editor = SHSystemManager::GetSystem<SHEditor>();
editor->SetSDLWindow(sdlWindow);
editor->SetSHWindow(&window);
#endif #endif
// Create Routines // Create Routines
@ -120,7 +124,7 @@ namespace Sandbox
SHSystemManager::Init(); SHSystemManager::Init();
SHSceneManager::InitSceneManager<SBTestScene>("TestScene"); SHSceneManager::InitSceneManager<SBMainScene>(applicationConfig.startingSceneID);
SHFrameRateController::UpdateFRC(); SHFrameRateController::UpdateFRC();
} }

View File

@ -0,0 +1,62 @@
#include "SBpch.h"
#include "SBMainScene.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h"
#include "ECS_Base/Managers/SHEntityManager.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Scene/SHSceneManager.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "Scripting/SHScriptEngine.h"
#include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "Physics/Components/SHRigidBodyComponent.h"
#include "Physics/Components/SHColliderComponent.h"
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
#include "Assets/SHAssetManager.h"
#include "Camera/SHCameraComponent.h"
#include "Resource/SHResourceManager.h"
#include "Serialization/SHSerialization.h"
using namespace SHADE;
namespace Sandbox
{
void SBMainScene::WindowFocusFunc([[maybe_unused]] void* window, int focused)
{
if (focused)
{
}
else
{
}
}
void SBMainScene::Load()
{
}
void SBMainScene::Init()
{
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
}
void SBMainScene::Update(float dt)
{
}
void SBMainScene::Render()
{
}
void SBMainScene::Unload()
{
}
void SBMainScene::Free()
{
//SHSerialization::SerializeScene("resources/scenes/Scene01.SHADE");
}
}

View File

@ -5,7 +5,7 @@
namespace Sandbox namespace Sandbox
{ {
class SBTestScene : public SHADE::SHScene class SBMainScene : public SHADE::SHScene
{ {
private: private:
EntityID camera; EntityID camera;
@ -23,7 +23,7 @@ namespace Sandbox
//TODO: Change to new window DO IT IN CPP TOO //TODO: Change to new window DO IT IN CPP TOO
void WindowFocusFunc(void* window, int focused); void WindowFocusFunc(void* window, int focused);
SBTestScene(void) = default; SBMainScene(void) = default;
}; };
} }

View File

@ -1,204 +0,0 @@
#include "SBpch.h"
#include "SBTestScene.h"
#include "ECS_Base/Managers/SHSystemManager.h"
#include "Graphics/MiddleEnd/Meshes/SHPrimitiveGenerator.h"
#include "ECS_Base/Managers/SHEntityManager.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Scene/SHSceneManager.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "Scripting/SHScriptEngine.h"
#include "Math/Transform/SHTransformComponent.h"
#include "Graphics/MiddleEnd/Interface/SHMaterialInstance.h"
#include "Physics/Components/SHRigidBodyComponent.h"
#include "Physics/Components/SHColliderComponent.h"
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
#include "Assets/SHAssetManager.h"
#include "Camera/SHCameraComponent.h"
#include "Resource/SHResourceManager.h"
using namespace SHADE;
namespace Sandbox
{
void SBTestScene::WindowFocusFunc([[maybe_unused]] void* window, int focused)
{
if (focused)
{
}
else
{
}
}
void SBTestScene::Load()
{
}
void SBTestScene::Init()
{
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
// Create temp meshes
const auto CUBE_MESH = SHADE::SHPrimitiveGenerator::Cube(*graphicsSystem);
//Test Racoon mesh
std::vector<Handle<SHMesh>> handles;
std::vector<Handle<SHTexture>> texHandles;
for (const auto& asset : SHAssetManager::GetAllAssets())
{
switch (asset.type)
{
case AssetType::MESH:
if (asset.name == "Cube.012")
handles.emplace_back(SHResourceManager::LoadOrGet<SHMesh>(asset.id));
break;
case AssetType::TEXTURE:
if (asset.name == "RaccoonPreTexturedVer1_Base9")
texHandles.emplace_back(SHResourceManager::LoadOrGet<SHTexture>(asset.id));
break;
}
}
SHResourceManager::FinaliseChanges();
// Create Materials
auto matInst = graphicsSystem->AddOrGetBaseMaterialInstance();
auto customMat = graphicsSystem->AddMaterialInstanceCopy(matInst);
customMat->SetProperty("data.color", SHVec4(0.0f, 1.0f, 1.0f, 1.0f));
customMat->SetProperty("data.textureIndex", 0);
customMat->SetProperty("data.alpha", 0.1f);
// Create Stress Test Objects
static const SHVec3 TEST_OBJ_SCALE = SHVec3::One;
constexpr int NUM_ROWS = 3;
constexpr int NUM_COLS = 1;
static const SHVec3 TEST_OBJ_SPACING = { 0.1f, 0.1f, 0.1f };
static const SHVec3 TEST_OBJ_START_POS = { -(NUM_COLS / 2 * TEST_OBJ_SPACING.x) + 1.0f, -2.0f, -1.0f };
for (int y = 0; y < NUM_ROWS; ++y)
for (int x = 0; x < NUM_COLS; ++x)
{
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent, SHRigidBodyComponent, SHColliderComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
auto& collider = *SHComponentManager::GetComponent_s<SHColliderComponent>(entity);
//renderable.Mesh = handles.front();
renderable.SetMesh(CUBE_MESH);
renderable.SetMaterial(customMat);
if (y == 50)
renderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(1.0f, 0.0f, 0.0f, 1.0f));
//Set initial positions
transform.SetWorldPosition(TEST_OBJ_START_POS + SHVec3{ x * TEST_OBJ_SPACING.x, y * TEST_OBJ_SPACING.y, SHMath::GenerateRandomNumber(-3.5f, -5.0f) });
//transform.SetWorldPosition({-1.0f, -1.0f, -1.0f});
transform.SetWorldRotation(SHMath::GenerateRandomNumber(0.0f, 360.0f), SHMath::GenerateRandomNumber(0.0f, 360.0f), SHMath::GenerateRandomNumber(0.0f, 360.0f));
transform.SetWorldScale(TEST_OBJ_SCALE);
collider.AddBoundingBox(SHVec3::One, SHVec3::Zero);
stressTestObjects.emplace_back(entity);
}
auto raccoonSpin = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonSpin);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(raccoonSpin);
renderable.SetMesh(handles.front());
renderable.SetMaterial(customMat);
renderable.GetModifiableMaterial()->SetProperty("data.color", SHVec4(0.0f, 0.0f, 0.0f, 0.0f));
renderable.GetModifiableMaterial()->SetProperty("data.alpha", 1.0f);
renderable.GetModifiableMaterial()->SetProperty("data.textureIndex", 0);
transform.SetWorldPosition({ -3.0f, -1.0f, -1.0f });
transform.SetLocalScale({ 5.0f, 5.0f, 5.0f });
auto floor = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent, SHRigidBodyComponent, SHColliderComponent>();
auto& floorRenderable = *SHComponentManager::GetComponent_s<SHRenderable>(floor);
auto& floorTransform = *SHComponentManager::GetComponent_s<SHTransformComponent>(floor);
auto& floorRigidBody = *SHComponentManager::GetComponent_s<SHRigidBodyComponent>(floor);
auto& floorCollider = *SHComponentManager::GetComponent_s<SHColliderComponent>(floor);
floorRenderable.SetMesh(CUBE_MESH);
floorRenderable.SetMaterial(graphicsSystem->GetDefaultMaterialInstance());
floorTransform.SetWorldScale({ 7.5f, 0.5f, 7.5 });
floorTransform.SetWorldPosition({ 0.0f, -3.0f, -5.0f });
floorRigidBody.SetType(SHRigidBodyComponent::Type::STATIC);
auto* floorBox = floorCollider.AddBoundingBox();
// Create blank entity with a script
//testObj = SHADE::SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
//auto& testObjRenderable = *SHComponentManager::GetComponent<SHRenderable>(testObj);
//testObjRenderable.Mesh = CUBE_MESH;
//testObjRenderable.SetMaterial(matInst);
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
scriptEngine->AddScript(raccoonSpin, "RaccoonSpin");
auto raccoonShowcase = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderableShowcase = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonShowcase);
auto& transformShowcase = *SHComponentManager::GetComponent_s<SHTransformComponent>(raccoonShowcase);
renderableShowcase.SetMesh(handles.front());
renderableShowcase.SetMaterial(customMat);
renderableShowcase.GetModifiableMaterial()->SetProperty("data.color", SHVec4(0.0f, 0.0f, 0.0f, 0.0f));
renderableShowcase.GetModifiableMaterial()->SetProperty("data.alpha", 1.0f);
renderableShowcase.GetModifiableMaterial()->SetProperty("data.textureIndex", 0);
transformShowcase.SetWorldPosition({ 3.0f, -1.0f, -1.0f });
transformShowcase.SetLocalScale({ 5.0f, 5.0f, 5.0f });
scriptEngine->AddScript(raccoonShowcase, "RaccoonShowcase");
SHComponentManager::AddComponent<SHCameraComponent>(0);
SHComponentManager::AddComponent<SHLightComponent>(0);
SHComponentManager::RemoveComponent <SHRigidBodyComponent>(0);
SHComponentManager::RemoveComponent <SHColliderComponent>(0);
auto ambientLight = SHEntityManager::CreateEntity<SHLightComponent>();
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetColor(SHVec4(1.0f, 1.0f, 1.0f, 1.0f));
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetStrength(0.25f);
SHComponentManager::GetComponent<SHLightComponent>(ambientLight)->SetType(SH_LIGHT_TYPE::AMBIENT);
}
void SBTestScene::Update(float dt)
{
static float rotation = 0.0f;
SHVec3 direction{0.0f, 0.0f, 1.0f};
direction = SHVec3::RotateY(direction, rotation);
auto* lightComp =SHComponentManager::GetComponent<SHLightComponent>(0);
lightComp->SetDirection (direction);
rotation += 0.005f;
//auto& transform = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHTransformComponent>(testObj);
//transform.SetWorldPosition({1.0f, 1.0f, -1.0f});
//transform.SetWorldRotation(0.0f, 0.0f + rotation, 0.0f);
//rotation += dt * 0.2f;
// Destroy entity if space is pressed
if (GetKeyState(VK_SPACE) & 0x8000)
{
rotation = 0.0f;
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
scriptEngine->RemoveAllScripts(testObj);
}
}
void SBTestScene::Render()
{
}
void SBTestScene::Unload()
{
}
void SBTestScene::Free()
{
//SHSerialization::SerializeScene("resources/scenes/Scene01.SHADE");
}
}

View File

@ -157,16 +157,22 @@ namespace SHADE
{ {
case AssetType::PREFAB: case AssetType::PREFAB:
newPath += PREFAB_FOLDER; newPath += PREFAB_FOLDER;
newPath += name;
newPath += PREFAB_EXTENSION;
data = new SHPrefabAsset(); data = new SHPrefabAsset();
break; break;
case AssetType::SCENE: case AssetType::SCENE:
newPath += SCENE_FOLDER; newPath += SCENE_FOLDER;
newPath += name;
newPath += SCENE_EXTENSION;
data = new SHSceneAsset(); data = new SHSceneAsset();
break; break;
case AssetType::MATERIAL: case AssetType::MATERIAL:
newPath += MATERIAL_FOLDER; newPath += MATERIAL_FOLDER;
newPath += name;
newPath += MATERIAL_EXTENSION;
data = new SHMaterialAsset(); data = new SHMaterialAsset();
break; break;
@ -367,6 +373,15 @@ namespace SHADE
return false; return false;
} }
AssetType SHAssetManager::GetType(AssetID id) noexcept
{
if (assetCollection.find(id) == assetCollection.end())
{
return AssetType::INVALID;
}
return assetCollection[id].type;
}
SHAsset SHAssetManager::CreateAssetFromPath(AssetPath path) noexcept SHAsset SHAssetManager::CreateAssetFromPath(AssetPath path) noexcept
{ {
SHAsset result; SHAsset result;

View File

@ -90,6 +90,8 @@ namespace SHADE
static AssetID CompileAsset(AssetPath const& path) noexcept; static AssetID CompileAsset(AssetPath const& path) noexcept;
static FolderPointer GetRootFolder() noexcept; static FolderPointer GetRootFolder() noexcept;
static AssetType GetType(AssetID id) noexcept;
private: private:

View File

@ -13,11 +13,18 @@
//#==============================================================# //#==============================================================#
//|| Library Includes || //|| Library Includes ||
//#==============================================================# //#==============================================================#
#include "Editor/SHEditorWidgets.hpp"
#include <imgui.h> #include <imgui.h>
#include <imgui_internal.h> #include <imgui_internal.h>
#include <misc/cpp/imgui_stdlib.h>
#include <rttr/type> #include <rttr/type>
#include "Assets/SHAssetManager.h"
#include "Assets/Asset Types/SHSceneAsset.h"
#include "Scene/SHSceneManager.h"
#include "Serialization/SHSerialization.h" #include "Serialization/SHSerialization.h"
#include "Serialization/Configurations/SHConfigurationManager.h"
namespace SHADE namespace SHADE
{ {
@ -39,7 +46,7 @@ namespace SHADE
{ {
SHEditorWindow::Init(); SHEditorWindow::Init();
constexpr std::string_view path = "../../Assets/Editor/Layouts"; constexpr std::string_view path = "../../Assets/Editor/Layouts";
for(auto const& entry : std::filesystem::directory_iterator(path)) for (auto const& entry : std::filesystem::directory_iterator(path))
{ {
layoutPaths.push_back(entry.path()); layoutPaths.push_back(entry.path());
} }
@ -75,26 +82,32 @@ namespace SHADE
{ {
if (ImGui::BeginMenu("File")) if (ImGui::BeginMenu("File"))
{ {
if(ImGui::Selectable("Save")) if (ImGui::Selectable("New"))
{ {
SHSerialization::SerializeSceneToFile("../../Assets/Scenes/Test.SHADE"); auto editor = SHSystemManager::GetSystem<SHEditor>();
editor->NewScene();
} }
if(ImGui::Selectable("Load")) if (ImGui::Selectable("Save"))
{ {
SHSerialization::DeserializeSceneFromFile("../../Assets/Scenes/Test.SHADE"); auto editor = SHSystemManager::GetSystem<SHEditor>();
editor->SaveScene();
}
if (ImGui::Selectable("Load"))
{
SHSerialization::DeserializeSceneFromFile(SHSceneManager::GetCurrentSceneAssetID());
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if(ImGui::BeginMenu("Edit")) if (ImGui::BeginMenu("Edit"))
{ {
ImGui::BeginDisabled(!SHCommandManager::GetUndoStackSize()); ImGui::BeginDisabled(!SHCommandManager::GetUndoStackSize());
if(ImGui::Button(std::format("{} Undo", ICON_MD_UNDO).data())) if (ImGui::Button(std::format("{} Undo", ICON_MD_UNDO).data()))
{ {
SHCommandManager::UndoCommand(); SHCommandManager::UndoCommand();
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::BeginDisabled(!SHCommandManager::GetRedoStackSize()); ImGui::BeginDisabled(!SHCommandManager::GetRedoStackSize());
if(ImGui::Button(std::format("{} Redo", ICON_MD_REDO).data())) if (ImGui::Button(std::format("{} Redo", ICON_MD_REDO).data()))
{ {
SHCommandManager::RedoCommand(); SHCommandManager::RedoCommand();
} }
@ -105,18 +118,18 @@ namespace SHADE
{ {
if (ImGui::Selectable("Generate Visual Studio Project")) if (ImGui::Selectable("Generate Visual Studio Project"))
{ {
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>()); auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
scriptEngine->GenerateScriptsCsProjFile(); scriptEngine->GenerateScriptsCsProjFile();
} }
if (ImGui::Selectable("Build Scripts - Debug")) if (ImGui::Selectable("Build Scripts - Debug"))
{ {
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>()); auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
scriptEngine->BuildScriptAssembly(true, true); scriptEngine->BuildScriptAssembly(true, true);
} }
if (ImGui::Selectable("Build Scripts - Release")) if (ImGui::Selectable("Build Scripts - Release"))
{ {
auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>()); auto* scriptEngine = static_cast<SHScriptEngine*>(SHSystemManager::GetSystem<SHScriptEngine>());
scriptEngine->BuildScriptAssembly(false, true); scriptEngine->BuildScriptAssembly(false, true);
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -144,17 +157,46 @@ namespace SHADE
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if(ImGui::BeginMenu("Layout")) if (ImGui::BeginMenu("Layout"))
{ {
for(auto const& entry : layoutPaths) for (auto const& entry : layoutPaths)
{ {
if(ImGui::Selectable(entry.stem().string().c_str())) if (ImGui::Selectable(entry.stem().string().c_str()))
{ {
ImGui::LoadIniSettingsFromDisk(entry.string().c_str()); ImGui::LoadIniSettingsFromDisk(entry.string().c_str());
} }
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Application Config"))
{
auto& appConfig = SHConfigurationManager::applicationConfig;
ImGui::InputText("Window Title", &appConfig.windowTitle);
ImGui::Checkbox("Start in Fullscreen", &appConfig.startInFullScreen);
SHEditorWidgets::DragN<float, 2>("Window Size", { "Width", "Height" }, { &appConfig.windowSize.x, &appConfig.windowSize.y });
//ImGui::InputScalar("Starting Scene", ImGuiDataType_U32, &appConfig.startingSceneID);
auto sceneAsset = SHAssetManager::GetData<SHSceneAsset>(appConfig.startingSceneID);
if(ImGui::BeginCombo("Starting Scne", sceneAsset ? sceneAsset->name.data() : ""))
{
auto scenes = SHAssetManager::GetAllRecordOfType(AssetType::SCENE);
for(auto const& scene : scenes)
{
if(ImGui::Selectable(scene.name.data()))
{
appConfig.startingSceneID = scene.id;
}
}
ImGui::EndCombo();
}
if (ImGui::Button("Save"))
{
SHConfigurationManager::SaveApplicationConfig();
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar(); ImGui::EndMainMenuBar();
} }
@ -167,29 +209,32 @@ namespace SHADE
void SHEditorMenuBar::DrawSecondaryBar() const noexcept void SHEditorMenuBar::DrawSecondaryBar() const noexcept
{ {
ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGuiViewport* viewport = ImGui::GetMainViewport();
if(ImGui::BeginViewportSideBar("##SecondaryMenuBar", viewport, ImGuiDir_Up, ImGui::GetFrameHeight(), ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_MenuBar)) if (ImGui::BeginViewportSideBar("##SecondaryMenuBar", viewport, ImGuiDir_Up, ImGui::GetFrameHeight(), ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_MenuBar))
{ {
ImGui::BeginMenuBar(); ImGui::BeginMenuBar();
ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x * 0.5f - 80.f); ImGui::SetCursorPosX(ImGui::GetContentRegionAvail().x * 0.5f - 80.f);
const auto editor = SHSystemManager::GetSystem<SHEditor>(); const auto editor = SHSystemManager::GetSystem<SHEditor>();
ImGui::BeginDisabled(editor->editorState == SHEditor::State::PLAY); ImGui::BeginDisabled(editor->editorState == SHEditor::State::PLAY);
if(ImGui::SmallButton(ICON_MD_PLAY_ARROW)) if (ImGui::SmallButton(ICON_MD_PLAY_ARROW))
{ {
const SHEditorStateChangeEvent STATE_CHANGE_EVENT if (editor->SaveScene()) //Set play state and invoke event only if we managed to save successfully
{ {
.previousState = editor->editorState const SHEditorStateChangeEvent STATE_CHANGE_EVENT
}; {
editor->editorState = SHEditor::State::PLAY; .previousState = editor->editorState
};
editor->editorState = SHEditor::State::PLAY;
SHEventManager::BroadcastEvent<SHEditorStateChangeEvent>(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT); SHEventManager::BroadcastEvent<SHEditorStateChangeEvent>(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT);
}
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE); ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE);
if(ImGui::SmallButton(ICON_MD_PAUSE)) if (ImGui::SmallButton(ICON_MD_PAUSE))
{ {
const SHEditorStateChangeEvent STATE_CHANGE_EVENT const SHEditorStateChangeEvent STATE_CHANGE_EVENT
{ {
.previousState = editor->editorState .previousState = editor->editorState
}; };
editor->editorState = SHEditor::State::PAUSE; editor->editorState = SHEditor::State::PAUSE;
@ -197,15 +242,15 @@ namespace SHADE
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP); ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP);
if(ImGui::SmallButton(ICON_MD_STOP)) if (ImGui::SmallButton(ICON_MD_STOP))
{ {
const SHEditorStateChangeEvent STATE_CHANGE_EVENT const SHEditorStateChangeEvent STATE_CHANGE_EVENT
{ {
.previousState = editor->editorState .previousState = editor->editorState
}; };
editor->editorState = SHEditor::State::STOP; editor->editorState = SHEditor::State::STOP;
SHEventManager::BroadcastEvent<SHEditorStateChangeEvent>(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT); SHEventManager::BroadcastEvent<SHEditorStateChangeEvent>(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT);
editor->LoadScene(SHSceneManager::GetCurrentSceneAssetID());
} }
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::EndMenuBar(); ImGui::EndMenuBar();

View File

@ -37,7 +37,7 @@ namespace SHADE
proj(1, 1) *= -1; proj(1, 1) *= -1;
static SHMatrix gridMat = SHMatrix::Translate(0, -0.5f, 0.f) * SHMatrix::Identity; static SHMatrix gridMat = SHMatrix::Translate(0, -0.5f, 0.f) * SHMatrix::Identity;
if (selectedEntityTransformComponent == nullptr) if (selectedEntityTransformComponent == nullptr)
{ {
SHEditor* editor = SHSystemManager::GetSystem<SHEditor>(); SHEditor* editor = SHSystemManager::GetSystem<SHEditor>();

View File

@ -25,6 +25,7 @@
#include "SHEditorWidgets.hpp" #include "SHEditorWidgets.hpp"
#include "Math/Transform/SHTransformSystem.h" #include "Math/Transform/SHTransformSystem.h"
#include "Graphics/Windowing/SHWindow.h"
//#==============================================================# //#==============================================================#
//|| Editor Window Includes || //|| Editor Window Includes ||
@ -45,8 +46,11 @@
#include <backends/imgui_impl_sdl.h> #include <backends/imgui_impl_sdl.h>
#include <backends/imgui_impl_vulkan.h> #include <backends/imgui_impl_vulkan.h>
#include "Assets/SHAssetManager.h"
#include "Assets/Asset Types/SHSceneAsset.h"
#include "Graphics/MiddleEnd/Interface/SHMousePickSystem.h" #include "Graphics/MiddleEnd/Interface/SHMousePickSystem.h"
#include "Scene/SHSceneManager.h"
#include "Serialization/SHSerialization.h"
RTTR_REGISTRATION RTTR_REGISTRATION
{ {
using namespace SHADE; using namespace SHADE;
@ -134,6 +138,9 @@ namespace SHADE
window->Update(); window->Update();
} }
} }
RenderUnsavedChangesPrompt();
RenderSceneNamePrompt();
//PollPicking(); //PollPicking();
@ -145,6 +152,11 @@ namespace SHADE
{ {
SHCommandManager::UndoCommand(); SHCommandManager::UndoCommand();
} }
if(ImGui::IsKeyDown(ImGuiKey_LeftCtrl) && ImGui::IsKeyReleased(ImGuiKey_S))
{
SaveScene();
}
Render(); Render();
} }
@ -159,6 +171,60 @@ namespace SHADE
} }
} }
void SHEditor::RenderSceneNamePrompt() noexcept
{
if(isSceneNamePromptOpen)
{
ImGui::OpenPopup(sceneNamePromptName.data());
}
if(ImGui::BeginPopupModal(sceneNamePromptName.data(), &isSceneNamePromptOpen))
{
static std::string newSceneName{};
ImGui::Text("Enter new scene name");
ImGui::InputText("##name", &newSceneName);
ImGui::BeginDisabled(newSceneName.empty());
if(ImGui::Button("Save"))
{
SaveScene(newSceneName);
newSceneName.clear();
isSceneNamePromptOpen = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndDisabled();
ImGui::SameLine();
if(ImGui::Button("Cancel"))
{
isSceneNamePromptOpen = false;
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
void SHEditor::RenderUnsavedChangesPrompt() noexcept
{
if(isUnsavedChangesPromptOpen)
{
ImGui::OpenPopup(unsavedChangesPromptName.data());
}
if(ImGui::BeginPopupModal(unsavedChangesPromptName.data(), &isUnsavedChangesPromptOpen))
{
ImGui::Text("You have unsaved changes!");
if(ImGui::Button("Save"))
{
isSceneNamePromptOpen = true;
}
ImGui::SameLine();
if(ImGui::Button("Cancel"))
{
isUnsavedChangesPromptOpen = false;
ImGui::CloseCurrentPopup();
}
}
}
void SHEditor::InitLayout() noexcept void SHEditor::InitLayout() noexcept
{ {
if(!std::filesystem::exists(io->IniFilename)) if(!std::filesystem::exists(io->IniFilename))
@ -366,6 +432,66 @@ namespace SHADE
} }
} }
void SHEditor::NewScene()
{
if(shWindow->IsUnsavedChanges())
{
//Unsaved changes prompt
sceneToLoad = 0;
isUnsavedChangesPromptOpen = true;
}
else
{
SHSceneManager::RestartScene(0);
shWindow->ToggleUnsavedChanges();
}
}
bool SHEditor::SaveScene(std::string const& newSceneName)
{
auto const data = SHAssetManager::GetData<SHSceneAsset>(SHSceneManager::GetCurrentSceneAssetID());
if (!data)
{
if (newSceneName.empty())
{
//Prompt for scene name
isSceneNamePromptOpen = true;
return false;
}
//Else We have a new name
SHSceneManager::SetCurrentSceneName(newSceneName);
SHSceneManager::SetCurrentSceneAssetID(SHAssetManager::CreateNewAsset(AssetType::SCENE, newSceneName));
}
//Get data, if data is null, asset doesn't exist, prompt for a name and create a new asset with the name
//serialize the scene
if(SHSerialization::SerializeSceneToFile(SHSceneManager::GetCurrentSceneAssetID()))
{
if(shWindow->IsUnsavedChanges())
shWindow->ToggleUnsavedChanges();
return true;
}
return false;
}
void SHEditor::LoadScene(AssetID const& assetID) noexcept
{
if(shWindow->IsUnsavedChanges())
{
//Unsaved changes prompt
isUnsavedChangesPromptOpen = true;
sceneToLoad = assetID;
}
else
{
//Load the scene
sceneToLoad = 0;
SHSceneManager::RestartScene(assetID);
}
}
void SHEditor::NewFrame() void SHEditor::NewFrame()
{ {
SDL_Event event; SDL_Event event;

View File

@ -17,13 +17,15 @@
#include "EditorWindow/SHEditorWindow.h" #include "EditorWindow/SHEditorWindow.h"
#include "Tools/SHLog.h" #include "Tools/SHLog.h"
#include "Gizmos/SHTransformGizmo.h" #include "Gizmos/SHTransformGizmo.h"
#include "Graphics/Windowing/SHWindow.h"
//#==============================================================# //#==============================================================#
//|| Library Includes || //|| Library Includes ||
//#==============================================================# //#==============================================================#
#include <SDL_video.h> #include <SDL_video.h>
#include "Assets/SHAssetMacros.h"
namespace SHADE namespace SHADE
{ {
//#==============================================================# //#==============================================================#
@ -170,9 +172,16 @@ namespace SHADE
void InitBackend(); void InitBackend();
void SetSDLWindow(SDL_Window* inSDLWindow){sdlWindow = inSDLWindow;}; void SetSDLWindow(SDL_Window* inSDLWindow){sdlWindow = inSDLWindow;};
void SetSHWindow(SHWindow* inWindow){shWindow = inWindow;}
void PollPicking(); void PollPicking();
void NewScene();
bool SaveScene(std::string const& newSceneName = {});
void LoadScene(AssetID const& assetID) noexcept;
// List of selected entities // List of selected entities
std::vector<EntityID> selectedEntities; std::vector<EntityID> selectedEntities;
@ -190,16 +199,30 @@ namespace SHADE
*/ */
void Render(); void Render();
void RenderSceneNamePrompt() noexcept;
void RenderUnsavedChangesPrompt() noexcept;
void InitLayout() noexcept; void InitLayout() noexcept;
void InitFonts() noexcept; void InitFonts() noexcept;
bool isSceneNamePromptOpen = false;
bool isUnsavedChangesPromptOpen = false;
static constexpr std::string_view sceneNamePromptName = "Save scene as...";
static constexpr std::string_view unsavedChangesPromptName = "Unsaved Changes";
AssetID sceneToLoad = 0;
// Handle to command pool used for ImGui Vulkan Backend // Handle to command pool used for ImGui Vulkan Backend
Handle<SHVkCommandPool> imguiCommandPool; Handle<SHVkCommandPool> imguiCommandPool;
// Handle to command buffer used for ImGui Vulkan Backend // Handle to command buffer used for ImGui Vulkan Backend
Handle<SHVkCommandBuffer> imguiCommandBuffer; Handle<SHVkCommandBuffer> imguiCommandBuffer;
SDL_Window* sdlWindow {nullptr}; SDL_Window* sdlWindow {nullptr};
SHWindow* shWindow{nullptr};
ImGuiIO* io{nullptr}; ImGuiIO* io{nullptr};

View File

@ -198,7 +198,14 @@ namespace SHADE
worldRenderer->SetCameraDirector(cameraSystem->CreateDirector()); worldRenderer->SetCameraDirector(cameraSystem->CreateDirector());
SHVec4 defaultTexture{1.0f, 1.0f, 1.0f, 1.0f};
std::vector<uint32_t> mipOffsets{};
mipOffsets.push_back(0);
auto tex = AddTexture(1, reinterpret_cast<unsigned char*>(&defaultTexture), 1, 1, SHTexture::TextureFormat::eR32G32B32A32Sfloat, mipOffsets);
BuildTextures();
defaultMaterial = AddMaterial(defaultVertShader, defaultFragShader, gBufferSubpass); defaultMaterial = AddMaterial(defaultVertShader, defaultFragShader, gBufferSubpass);
defaultMaterial->SetProperty("data.textureIndex", tex->TextureArrayIndex);
} }
void SHGraphicsSystem::InitMiddleEnd(void) noexcept void SHGraphicsSystem::InitMiddleEnd(void) noexcept
@ -372,6 +379,9 @@ namespace SHADE
// Bind all the buffers required for meshes // Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA) for (auto& [buffer, bindingPoint] : MESH_DATA)
{ {
if (!buffer)
continue;
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer) if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0); currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer) else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
@ -714,11 +724,6 @@ namespace SHADE
{ {
if (!renderable.HasChanged()) if (!renderable.HasChanged())
continue; continue;
if (!renderable.GetMesh())
{
SHLOG_CRITICAL("NULL Mesh provided!");
}
// Remove from the SuperBatch it is previously in (prevMat if mat has changed) // Remove from the SuperBatch it is previously in (prevMat if mat has changed)
Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial(); Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial();
@ -728,9 +733,9 @@ namespace SHADE
oldSuperBatch->Remove(&renderable); oldSuperBatch->Remove(&renderable);
} }
// Add to new SuperBatch if there is a material // Add to new SuperBatch if there is a material and a mesh to render
Handle<SHMaterialInstance> newMatInstance = renderable.GetMaterial(); Handle<SHMaterialInstance> newMatInstance = renderable.GetMaterial();
if (newMatInstance) if (newMatInstance && renderable.GetMesh())
{ {
Handle<SHSuperBatch> newSuperBatch = newMatInstance->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch(); Handle<SHSuperBatch> newSuperBatch = newMatInstance->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
newSuperBatch->Add(&renderable); newSuperBatch->Add(&renderable);

View File

@ -22,13 +22,15 @@ namespace SHADE
/* SHComponent Lifecycle Functions */ /* SHComponent Lifecycle Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHRenderable::OnCreate() void SHRenderable::OnCreate()
{ {
SHGraphicsSystem* gfxSystem = SHSystemManager::GetSystem<SHGraphicsSystem>();
matChanged = true; matChanged = true;
sharedMaterial = {};
material = {}; material = {};
oldMaterial = {}; oldMaterial = {};
lightLayer = 1; lightLayer = 1;
sharedMaterial = gfxSystem ? gfxSystem->GetDefaultMaterialInstance() : Handle<SHMaterialInstance>();
} }
void SHRenderable::OnDestroy() void SHRenderable::OnDestroy()

View File

@ -154,16 +154,16 @@ namespace SHADE
addJobs.clear(); addJobs.clear();
/* Build Descriptor Set with all the Textures only if there are textures */ /* Build Descriptor Set with all the Textures only if there are textures */
if (!texDescriptors)
{
texDescriptors = descPool->Allocate
(
{ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] },
{ static_cast<uint32_t>(texOrder.size()) }
);
}
if (!texOrder.empty()) if (!texOrder.empty())
{ {
if (!texDescriptors)
{
texDescriptors = descPool->Allocate
(
{ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS] },
{ static_cast<uint32_t>(texOrder.size()) }
);
}
texDescriptors->ModifyWriteDescImage texDescriptors->ModifyWriteDescImage
( (
SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS, SHGraphicsConstants::DescriptorSetIndex::STATIC_GLOBALS,

View File

@ -4,7 +4,6 @@
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "Input/SHInputManager.h" #include "Input/SHInputManager.h"
namespace SHADE namespace SHADE
{ {
SHWindow::SHWindow() SHWindow::SHWindow()
@ -151,11 +150,11 @@ namespace SHADE
SetWindowText(wndHWND, LPCWSTR(wndData.title.c_str())); SetWindowText(wndHWND, LPCWSTR(wndData.title.c_str()));
} }
SHWindow::SHVec2 SHWindow::GetPosition() const SHWindow::WindowSize SHWindow::GetPosition() const
{ {
RECT rect; RECT rect;
GetWindowRect(wndHWND, &rect); GetWindowRect(wndHWND, &rect);
return SHVec2(static_cast<uint32_t>(rect.left), static_cast<uint32_t>(rect.top)); return WindowSize(static_cast<uint32_t>(rect.left), static_cast<uint32_t>(rect.top));
} }
void SHWindow::SetPosition(unsigned x, unsigned y) void SHWindow::SetPosition(unsigned x, unsigned y)
@ -165,18 +164,18 @@ namespace SHADE
wndData.y = y; wndData.y = y;
} }
SHWindow::SHVec2 SHWindow::GetWindowSize() const SHWindow::WindowSize SHWindow::GetWindowSize() const
{ {
RECT rect; RECT rect;
GetClientRect(wndHWND, &rect); GetClientRect(wndHWND, &rect);
return SHVec2(static_cast<uint32_t>(rect.right - rect.left), static_cast<uint32_t>(rect.bottom - rect.top)); return WindowSize(static_cast<uint32_t>(rect.right - rect.left), static_cast<uint32_t>(rect.bottom - rect.top));
} }
SHWindow::SHVec2 SHWindow::GetCurrentDisplaySize() const SHWindow::WindowSize SHWindow::GetCurrentDisplaySize() const
{ {
unsigned screenWidth = GetSystemMetrics(SM_CXSCREEN); unsigned screenWidth = GetSystemMetrics(SM_CXSCREEN);
unsigned screenHeight = GetSystemMetrics(SM_CYSCREEN); unsigned screenHeight = GetSystemMetrics(SM_CYSCREEN);
return SHVec2(screenWidth, screenHeight); return WindowSize(screenWidth, screenHeight);
} }
void SHWindow::SetMouseVisible(bool show) void SHWindow::SetMouseVisible(bool show)
@ -260,7 +259,7 @@ namespace SHADE
return wndHWND; return wndHWND;
} }
const WindowData SHWindow::GetWindowData() const const WindowData SHWindow::GetWindowData() const noexcept
{ {
return wndData; return wndData;
} }
@ -287,6 +286,15 @@ namespace SHADE
windowCloseCallbacks.erase(callbackid); windowCloseCallbacks.erase(callbackid);
} }
void SHWindow::ToggleUnsavedChanges() noexcept
{
unsavedChanges = !unsavedChanges;
std::wstring title = wndData.title;
if(unsavedChanges)
title.append(L"*");
SetWindowText(wndHWND, title.data());
}
LRESULT SHWindow::WndProcStatic(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) LRESULT SHWindow::WndProcStatic(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{ {
auto window = windowMap.GetWindow(hwnd); auto window = windowMap.GetWindow(hwnd);

View File

@ -74,7 +74,7 @@ namespace SHADE
class SH_API SHWindow class SH_API SHWindow
{ {
public: public:
using SHVec2 = std::pair<uint32_t, uint32_t>; using WindowSize = std::pair<uint32_t, uint32_t>;
typedef std::function<void(uint32_t width, uint32_t height)> WindowResizeCallbackFn; typedef std::function<void(uint32_t width, uint32_t height)> WindowResizeCallbackFn;
typedef std::function<void(void)> WindowCloseCallbackFn; typedef std::function<void(void)> WindowCloseCallbackFn;
typedef uint16_t CALLBACKID; typedef uint16_t CALLBACKID;
@ -92,15 +92,15 @@ namespace SHADE
void SetTitle(std::wstring title); void SetTitle(std::wstring title);
SHVec2 GetPosition() const; WindowSize GetPosition() const;
void SetPosition(unsigned x, unsigned y); void SetPosition(unsigned x, unsigned y);
//void SetPosition(SHMathVec2U); //void SetPosition(SHMathVec2U);
SHVec2 GetWindowSize() const; WindowSize GetWindowSize() const;
//Get size of display the window is in (whichever window contains the window origin) //Get size of display the window is in (whichever window contains the window origin)
SHVec2 GetCurrentDisplaySize() const; WindowSize GetCurrentDisplaySize() const;
void SetMouseVisible(bool show); void SetMouseVisible(bool show);
@ -123,7 +123,7 @@ namespace SHADE
HWND GetHWND(); HWND GetHWND();
const WindowData GetWindowData() const; const WindowData GetWindowData() const noexcept;
CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn); CALLBACKID RegisterWindowSizeCallback(WindowResizeCallbackFn);
void UnregisterWindowSizeCallback(CALLBACKID const& callbackid); void UnregisterWindowSizeCallback(CALLBACKID const& callbackid);
@ -131,6 +131,8 @@ namespace SHADE
void UnregisterWindowCloseCallback(CALLBACKID const& callbackid); void UnregisterWindowCloseCallback(CALLBACKID const& callbackid);
bool IsMinimized() const { return wndData.isMinimised; } bool IsMinimized() const { return wndData.isMinimised; }
void ToggleUnsavedChanges() noexcept;
bool IsUnsavedChanges() const noexcept{return unsavedChanges;}
protected: protected:
static LRESULT CALLBACK WndProcStatic(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static LRESULT CALLBACK WndProcStatic(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
@ -164,7 +166,8 @@ namespace SHADE
std::unordered_map<CALLBACKID, WindowCloseCallbackFn> windowCloseCallbacks; std::unordered_map<CALLBACKID, WindowCloseCallbackFn> windowCloseCallbacks;
CALLBACKID windowResizeCallbackCount{}; CALLBACKID windowResizeCallbackCount{};
CALLBACKID windowCloseCallbackCount{}; CALLBACKID windowCloseCallbackCount{};
//TODO: Shift to events abstraction
bool unsavedChanges = false;
void OnCreate(HWND hwnd, LPCREATESTRUCT create_struct); void OnCreate(HWND hwnd, LPCREATESTRUCT create_struct);
void OnClose(); void OnClose();

View File

@ -13,6 +13,7 @@
#include <string> #include <string>
#include "SHSceneGraph.h" #include "SHSceneGraph.h"
#include "Assets/SHAssetMacros.h"
#include "ECS_Base/General/SHFamily.h" #include "ECS_Base/General/SHFamily.h"
namespace SHADE namespace SHADE
@ -32,6 +33,7 @@ namespace SHADE
virtual ~SHScene() = default; virtual ~SHScene() = default;
std::string sceneName; std::string sceneName;
AssetID sceneAssetID;
SHSceneGraph& GetSceneGraph() noexcept { return sceneGraph; } SHSceneGraph& GetSceneGraph() noexcept { return sceneGraph; }

View File

@ -29,7 +29,7 @@ namespace SHADE
std::string SHSceneManager::newSceneName{}; std::string SHSceneManager::newSceneName{};
uint32_t SHSceneManager::currentSceneID = UINT32_MAX; uint32_t SHSceneManager::currentSceneID = UINT32_MAX;
uint32_t SHSceneManager::nextSceneID = UINT32_MAX; uint32_t SHSceneManager::nextSceneID = UINT32_MAX;
AssetID SHSceneManager::currentSceneAssetID{};
SHScene* SHSceneManager::currentScene = nullptr; SHScene* SHSceneManager::currentScene = nullptr;
//SHScene* SHSceneManager::nextScene = nullptr; //SHScene* SHSceneManager::nextScene = nullptr;
@ -107,16 +107,18 @@ namespace SHADE
} }
} }
void SHSceneManager::RestartScene(std::string const& sceneName) noexcept void SHSceneManager::RestartScene(AssetID const& assetID ) noexcept
{ {
if (currentScene->sceneName != sceneName) if (currentScene->sceneAssetID != assetID)
{ {
cleanReload = true; //cleanReload = true;
newSceneName = sceneName; cleanReload = false;
//newSceneName = sceneName;
} }
else else
cleanReload = false; cleanReload = false;
currentScene->sceneAssetID = assetID;
nextSceneID = currentSceneID; nextSceneID = currentSceneID;
sceneChanged = true; sceneChanged = true;
} }
@ -151,4 +153,20 @@ namespace SHADE
{ {
return currentScene->sceneName; return currentScene->sceneName;
} }
void SHSceneManager::SetCurrentSceneName(std::string const& sceneName) noexcept
{
currentScene->sceneName = sceneName;
}
AssetID SHSceneManager::GetCurrentSceneAssetID() noexcept
{
return currentScene->sceneAssetID;
}
void SHSceneManager::SetCurrentSceneAssetID(AssetID const& newAssetID)
{
currentScene->sceneAssetID = newAssetID;
currentSceneAssetID = newAssetID;
}
} }

View File

@ -20,6 +20,7 @@
//Project Headers //Project Headers
#include "SH_API.h" #include "SH_API.h"
#include "ECS_Base/General/SHFamily.h" #include "ECS_Base/General/SHFamily.h"
#include "Assets/SHAssetMacros.h"
namespace SHADE namespace SHADE
{ {
@ -47,6 +48,9 @@ namespace SHADE
//pointer to the current scene //pointer to the current scene
static SHScene* currentScene; static SHScene* currentScene;
//Scene AssetID of the current scene
static AssetID currentSceneAssetID;
//Used in reloading scene. //Used in reloading scene.
static std::string newSceneName; static std::string newSceneName;
@ -80,10 +84,10 @@ namespace SHADE
* None. * None.
***************************************************************************/ ***************************************************************************/
template<typename T> template<typename T>
static std::enable_if_t<std::is_base_of_v<SHScene, T>, void> InitSceneManager(std::string const& sceneName) noexcept static std::enable_if_t<std::is_base_of_v<SHScene, T>, void> InitSceneManager(AssetID const& sceneAssetID) noexcept
{ {
//prevSceneCreate = newScene; //prevSceneCreate = newScene;
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName = sceneName; }; newScene = [sceneAssetID]() { currentScene = new T(); currentScene->sceneAssetID = sceneAssetID; };
//nextSceneID = SHFamilyID<SHScene>::GetID<T>(); //nextSceneID = SHFamilyID<SHScene>::GetID<T>();
nextSceneID = 0; nextSceneID = 0;
@ -99,7 +103,7 @@ namespace SHADE
* None. * None.
***************************************************************************/ ***************************************************************************/
template<typename T> template<typename T>
static std::enable_if_t<std::is_base_of_v<SHScene, T>, void> ChangeScene(std::string const& sceneName) noexcept static std::enable_if_t<std::is_base_of_v<SHScene, T>, void> ChangeScene(AssetID const& sceneAssetID) noexcept
{ {
//check if this new Scene is current Scene (Use RestartScene instead) //check if this new Scene is current Scene (Use RestartScene instead)
if (currentSceneID == SHFamilyID<SHScene>::GetID<T>()) if (currentSceneID == SHFamilyID<SHScene>::GetID<T>())
@ -107,7 +111,7 @@ namespace SHADE
return; return;
} }
//prevSceneCreate = newScene; //prevSceneCreate = newScene;
newScene = [sceneName]() { currentScene = new T(); currentScene->sceneName; }; newScene = [sceneAssetID]() { currentScene = new T(); currentScene->sceneAssetID = sceneAssetID; };
nextSceneID = SHFamilyID<SHScene>::GetID<T>(); nextSceneID = SHFamilyID<SHScene>::GetID<T>();
sceneChanged = true; sceneChanged = true;
} }
@ -137,11 +141,11 @@ namespace SHADE
* Restarts current scene. Only Scene::Init() and Scene::Free() * Restarts current scene. Only Scene::Init() and Scene::Free()
* Scene::Load() and Scene::Unload() will not be called. * Scene::Load() and Scene::Unload() will not be called.
* Edit: allows for RestartScene to restart the scene with a different * Edit: allows for RestartScene to restart the scene with a different
* scene name. * scene asset ID.
* If a sceneName is different from the current one, Load and Unload will * If a scene asset id is different from the current one, Load and Unload will
* run. * run.
***************************************************************************/ ***************************************************************************/
static void RestartScene(std::string const& sceneName ) noexcept; static void RestartScene(AssetID const& assetID ) noexcept;
/*!************************************************************************* /*!*************************************************************************
* \brief * \brief
@ -164,7 +168,10 @@ namespace SHADE
static void Exit() noexcept; static void Exit() noexcept;
static std::string GetSceneName() noexcept; static std::string GetSceneName() noexcept;
static void SetCurrentSceneName(std::string const& sceneName) noexcept;
static AssetID GetCurrentSceneAssetID() noexcept;
//Only if scene doesn't exist, and scene asset id needs to be updated to the new one
static void SetCurrentSceneAssetID(AssetID const& newAssetID);
}; };

View File

@ -0,0 +1,89 @@
#include "SHpch.h"
#include "SHConfigurationManager.h"
#include "Tools/FileIO/SHFileIO.h"
#include "Serialization/SHSerializationHelper.hpp"
namespace SHADE
{
SHApplicationConfig SHConfigurationManager::applicationConfig;
#ifdef SHEDITOR
SHEditorConfig SHConfigurationManager::editorConfig;
#endif
void SHConfigurationManager::SaveApplicationConfig()
{
YAML::Emitter out;
out << SHSerializationHelper::RTTRToNode(applicationConfig);
SHFileIO::WriteStringToFile(applicationConfigPath, out.c_str());
}
SHApplicationConfig& SHConfigurationManager::LoadApplicationConfig(WindowData* wndData)
{
if(!std::filesystem::exists(applicationConfigPath))
{
SaveApplicationConfig();
return applicationConfig;
}
auto const node = YAML::Load(SHFileIO::GetStringFromFile(applicationConfigPath));
auto properties = rttr::type::get<SHApplicationConfig>().get_properties();
for(auto const& property : properties)
{
if(node[property.get_name().data()].IsDefined())
SHSerializationHelper::InitializeProperty(&applicationConfig, property, node[property.get_name().data()]);
}
if(wndData != nullptr)
{
wndData->isFullscreen = applicationConfig.startInFullScreen;
wndData->title = std::wstring(applicationConfig.windowTitle.begin(), applicationConfig.windowTitle.end());
wndData->width = static_cast<uint32_t>(applicationConfig.windowSize.x);
wndData->height = static_cast<uint32_t>(applicationConfig.windowSize.y);
}
return applicationConfig;
}
#ifdef SHEDITOR
void SHConfigurationManager::SaveEditorConfig()
{
YAML::Emitter out;
out << SHSerializationHelper::RTTRToNode(editorConfig);
SHFileIO::WriteStringToFile(editorConfigPath, out.c_str());
}
SHEditorConfig& SHConfigurationManager::LoadEditorConfig()
{
auto const node = YAML::Load(SHFileIO::GetStringFromFile(editorConfigPath));
auto properties = rttr::type::get<SHApplicationConfig>().get_properties();
for(auto const& property : properties)
{
if(node[property.get_name().data()].IsDefined())
SHSerializationHelper::InitializeProperty(&editorConfig, property, node[property.get_name().data()]);
}
return editorConfig;
}
void SHConfigurationManager::FetchEditorCameraData()
{
}
void SHConfigurationManager::SetEditorCameraData()
{
}
#endif
}
RTTR_REGISTRATION
{
using namespace rttr;
using namespace SHADE;
registration::class_<SHApplicationConfig>("Application Config")
.property("Start in Fullscreen", &SHApplicationConfig::startInFullScreen)
.property("Starting Scene ID", &SHApplicationConfig::startingSceneID)
.property("Window Size", &SHApplicationConfig::windowSize)
.property("Window Title", &SHApplicationConfig::windowTitle);
}

View File

@ -0,0 +1,44 @@
#pragma once
#include <rttr/registration>
#include "Assets/SHAssetMacros.h"
#include "Graphics/Windowing/SHWindow.h"
#include "SH_API.h"
#include "Math/Vector/SHVec2.h"
namespace SHADE
{
struct SHApplicationConfig
{
bool startInFullScreen{ false };
AssetID startingSceneID{};
SHVec2 windowSize {1920, 1080};
std::string windowTitle {"SHADE Engine"};
RTTR_ENABLE()
};
struct SHEditorConfig
{
};
class SH_API SHConfigurationManager
{
public:
static constexpr std::string_view applicationConfigPath{"../../Assets/Application.SHConfig"};
static constexpr std::string_view editorConfigPath{"../../Assets/Editor/Editor.SHConfig"};
static void SaveApplicationConfig();
static SHApplicationConfig& LoadApplicationConfig(WindowData* wndData = nullptr);
static SHApplicationConfig applicationConfig;
#ifdef SHEDITOR
static void SaveEditorConfig();
static SHEditorConfig& LoadEditorConfig();
static SHEditorConfig editorConfig;
private:
static void FetchEditorCameraData();
static void SetEditorCameraData();
#endif
};
}

View File

@ -10,6 +10,7 @@
#include "Assets/SHAssetManager.h" #include "Assets/SHAssetManager.h"
#include <fstream> #include <fstream>
#include "Assets/Asset Types/SHSceneAsset.h"
#include "Camera/SHCameraComponent.h" #include "Camera/SHCameraComponent.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Math/Transform/SHTransformComponent.h" #include "Math/Transform/SHTransformComponent.h"
@ -17,19 +18,23 @@
#include "ECS_Base/Managers/SHSystemManager.h" #include "ECS_Base/Managers/SHSystemManager.h"
#include "Graphics/MiddleEnd/Lights/SHLightComponent.h" #include "Graphics/MiddleEnd/Lights/SHLightComponent.h"
#include "Scripting/SHScriptEngine.h" #include "Scripting/SHScriptEngine.h"
#include "Tools/FileIO/SHFileIO.h"
namespace SHADE namespace SHADE
{ {
void SHSerialization::SerializeSceneToFile(std::filesystem::path const& path) bool SHSerialization::SerializeSceneToFile(AssetID const& sceneAssetID)
{ {
auto assetData = SHAssetManager::GetData<SHSceneAsset>(sceneAssetID);
if(!assetData)
{
SHLOG_ERROR("Asset does not exist: {}", sceneAssetID);
return false;
}
YAML::Emitter out; YAML::Emitter out;
SerializeSceneToEmitter(out); SerializeSceneToEmitter(out);
std::ofstream file(path.c_str()); assetData->data = out.c_str();
if (file.good())
{ return SHAssetManager::SaveAsset(sceneAssetID);
file << out.c_str();
file.close();
}
} }
std::string SHSerialization::SerializeSceneToString() std::string SHSerialization::SerializeSceneToString()
@ -91,31 +96,16 @@ namespace SHADE
return eid; return eid;
} }
void SHSerialization::DeserializeSceneFromFile(std::filesystem::path const& path) std::string SHSerialization::DeserializeSceneFromFile(AssetID const& sceneAssetID) noexcept
{ {
//TODO:Shift to using XQ's FileIO auto assetData = SHAssetManager::GetData<SHSceneAsset>(sceneAssetID);
std::ifstream iFile; if(!assetData)
iFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
std::string fileContent = "";
try
{ {
// Open file SHLOG_ERROR("Attempted to load scene that doesn't exist {}", sceneAssetID)
// Read file's buffer contents into streams SHSceneManager::SetCurrentSceneAssetID(0);
iFile.open(path); return NewSceneName.data();
std::stringstream fileStream;
fileStream << iFile.rdbuf();
fileContent = fileStream.str();
// Close file handler
iFile.close();
} }
catch (std::ifstream::failure e) YAML::Node entities = YAML::Load(assetData->data);
{
SHLOG_ERROR("Could not read file");
}
YAML::Node entities = YAML::Load(fileContent);
std::vector<EntityID> createdEntities{}; std::vector<EntityID> createdEntities{};
//Create Entities //Create Entities
@ -126,7 +116,7 @@ namespace SHADE
if (createdEntities.empty()) if (createdEntities.empty())
{ {
SHLOG_ERROR("Failed to create entities from deserializaiton") SHLOG_ERROR("Failed to create entities from deserializaiton")
return; return NewSceneName.data();
} }
//Initialize Entity //Initialize Entity
auto entityVecIt = createdEntities.begin(); auto entityVecIt = createdEntities.begin();
@ -134,7 +124,9 @@ namespace SHADE
{ {
InitializeEntity(*it, *entityVecIt++); InitializeEntity(*it, *entityVecIt++);
} }
}
return assetData->name;
}
void SHSerialization::EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out) void SHSerialization::EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out)
{ {

View File

@ -5,6 +5,7 @@
#include <filesystem> #include <filesystem>
#include <ECS_Base/Components/SHComponent.h> #include <ECS_Base/Components/SHComponent.h>
#include <Assets/SHAssetMacros.h>
namespace YAML namespace YAML
{ {
@ -25,12 +26,11 @@ namespace SHADE
struct SH_API SHSerialization struct SH_API SHSerialization
{ {
//TODO: change paths to resource ID static bool SerializeSceneToFile(AssetID const& sceneAssetID);
static void SerializeSceneToFile(std::filesystem::path const& path);
static std::string SerializeSceneToString(); static std::string SerializeSceneToString();
static void SerializeSceneToEmitter(YAML::Emitter& out); static void SerializeSceneToEmitter(YAML::Emitter& out);
static void DeserializeSceneFromFile(std::filesystem::path const& path); static std::string DeserializeSceneFromFile(AssetID const& sceneAssetID) noexcept;
static void EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out); static void EmitEntity(SHSceneNode* entityNode, YAML::Emitter& out);
@ -44,5 +44,7 @@ namespace SHADE
static std::vector<ComponentTypeID> GetComponentIDList(YAML::Node const& componentsNode); static std::vector<ComponentTypeID> GetComponentIDList(YAML::Node const& componentsNode);
private: private:
static void InitializeEntity(YAML::Node const& entityNode, EntityID const& eid); static void InitializeEntity(YAML::Node const& entityNode, EntityID const& eid);
static constexpr std::string_view NewSceneName = "New Scene";
}; };
} }

View File

@ -460,6 +460,8 @@ namespace SHADE
node = YAML::Null; node = YAML::Null;
} }
} }
else if (varType == rttr::type::get<std::string>())
node = var.to_string();
else else
{ {
auto properties = var.get_type().get_properties(); auto properties = var.get_type().get_properties();
@ -495,63 +497,65 @@ namespace SHADE
return node; return node;
} }
template <typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true> template <typename Type>
static void InitializeProperty(ComponentType* component, rttr::property const& prop, YAML::Node const& propertyNode) static void InitializeProperty(Type* object, rttr::property const& prop, YAML::Node const& propertyNode)
{ {
auto propType = prop.get_type(); auto propType = prop.get_type();
if (propType == rttr::type::get<SHVec4>()) if (propType == rttr::type::get<SHVec4>())
{ {
SHVec4 vec = propertyNode.as<SHVec4>(); SHVec4 vec = propertyNode.as<SHVec4>();
prop.set_value(component, vec); prop.set_value(object, vec);
} }
else if (propType == rttr::type::get<SHVec3>()) else if (propType == rttr::type::get<SHVec3>())
{ {
SHVec3 vec = propertyNode.as<SHVec3>(); SHVec3 vec = propertyNode.as<SHVec3>();
prop.set_value(component, vec); prop.set_value(object, vec);
} }
else if (propType == rttr::type::get<SHVec2>()) else if (propType == rttr::type::get<SHVec2>())
{ {
SHVec2 vec = propertyNode.as<SHVec2>(); SHVec2 vec = propertyNode.as<SHVec2>();
prop.set_value(component, vec); prop.set_value(object, vec);
} }
else if (propType.is_arithmetic()) else if (propType.is_arithmetic())
{ {
bool ok = false; bool ok = false;
if (propType == rttr::type::get<bool>()) if (propType == rttr::type::get<bool>())
prop.set_value(component, propertyNode.as<bool>()); prop.set_value(object, propertyNode.as<bool>());
else if (propType == rttr::type::get<int8_t>()) else if (propType == rttr::type::get<int8_t>())
prop.set_value(component, propertyNode.as<int8_t>()); prop.set_value(object, propertyNode.as<int8_t>());
else if (propType == rttr::type::get<int16_t>()) else if (propType == rttr::type::get<int16_t>())
prop.set_value(component, propertyNode.as<int16_t>()); prop.set_value(object, propertyNode.as<int16_t>());
else if (propType == rttr::type::get<int32_t>()) else if (propType == rttr::type::get<int32_t>())
prop.set_value(component, propertyNode.as<int32_t>()); prop.set_value(object, propertyNode.as<int32_t>());
else if (propType == rttr::type::get<int64_t>()) else if (propType == rttr::type::get<int64_t>())
prop.set_value(component, propertyNode.as<int64_t>()); prop.set_value(object, propertyNode.as<int64_t>());
else if (propType == rttr::type::get<uint8_t>()) else if (propType == rttr::type::get<uint8_t>())
prop.set_value(component, propertyNode.as<uint8_t>()); prop.set_value(object, propertyNode.as<uint8_t>());
else if (propType == rttr::type::get<uint16_t>()) else if (propType == rttr::type::get<uint16_t>())
prop.set_value(component, propertyNode.as<uint16_t>()); prop.set_value(object, propertyNode.as<uint16_t>());
else if (propType == rttr::type::get<uint32_t>()) else if (propType == rttr::type::get<uint32_t>())
prop.set_value(component, propertyNode.as<uint32_t>()); prop.set_value(object, propertyNode.as<uint32_t>());
else if (propType == rttr::type::get<uint64_t>()) else if (propType == rttr::type::get<uint64_t>())
prop.set_value(component, propertyNode.as<uint64_t>()); prop.set_value(object, propertyNode.as<uint64_t>());
else if (propType == rttr::type::get<float>()) else if (propType == rttr::type::get<float>())
prop.set_value(component, propertyNode.as<float>()); prop.set_value(object, propertyNode.as<float>());
else if (propType == rttr::type::get<double>()) else if (propType == rttr::type::get<double>())
prop.set_value(component, propertyNode.as<double>()); prop.set_value(object, propertyNode.as<double>());
} }
else if (propType.is_enumeration()) else if (propType.is_enumeration())
{ {
auto enumAlign = prop.get_enumeration(); auto enumAlign = prop.get_enumeration();
prop.set_value(component, enumAlign.name_to_value(propertyNode.as<std::string>())); prop.set_value(object, enumAlign.name_to_value(propertyNode.as<std::string>()));
} }
else if (propType == rttr::type::get<std::string>())
prop.set_value(object, propertyNode.as<std::string>());
else else
{ {
auto properties = propType.get_properties(); auto properties = propType.get_properties();
for (auto const& property : properties) for (auto const& property : properties)
{ {
if(propertyNode[property.get_name().data()].IsDefined()) if(propertyNode[property.get_name().data()].IsDefined())
InitializeProperty(component, property, propertyNode[property.get_name().data()]); InitializeProperty(object, property, propertyNode[property.get_name().data()]);
} }
} }
} }

View File

@ -0,0 +1,31 @@
#include "SHpch.h"
#include "SHFileIO.h"
#include <fstream>
namespace SHADE
{
int SHFileIO::WriteStringToFile(std::filesystem::path const& filePath, std::string_view const& strView)
{
std::ofstream file(filePath);
if(file.good())
{
file << strView;
file.close();
return 1;
}
return 0;
}
std::string SHFileIO::GetStringFromFile(std::filesystem::path const& filePath)
{
std::ifstream iFile;
iFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);
std::string fileData{};
iFile.open(filePath, std::iostream::binary);
std::stringstream ss;
ss << iFile.rdbuf();
fileData = ss.str();
iFile.close();
return fileData;
}
}

View File

@ -0,0 +1,14 @@
#pragma once
#include <filesystem>
#include <string>
#include <string_view>
#include <SH_API.h>
namespace SHADE
{
struct SH_API SHFileIO
{
static int WriteStringToFile(std::filesystem::path const& filePath, std::string_view const& strView);
static std::string GetStringFromFile(std::filesystem::path const& file);
};
}

View File

@ -38,6 +38,7 @@ project "SHADE_Managed"
"%{IncludeDir.RTTR}/include", "%{IncludeDir.RTTR}/include",
"%{IncludeDir.dotnet}\\include", "%{IncludeDir.dotnet}\\include",
"%{IncludeDir.reactphysics3d}\\include", "%{IncludeDir.reactphysics3d}\\include",
"%{IncludeDir.VULKAN}\\include",
"%{wks.location}/SHADE_Engine/src" "%{wks.location}/SHADE_Engine/src"
} }