Can finally deserialize starting scene, play and stop which saves and reloads the scene.

This commit is contained in:
Sri Sham Haran 2022-11-01 21:07:56 +08:00
parent 8b4ebc557c
commit 6524639409
12 changed files with 145 additions and 253 deletions

View File

@ -1,4 +1,4 @@
Start in Fullscreen: false
Starting Scene ID: 85177200
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

@ -1,176 +0,0 @@
- EID: 0
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 1, y: -2, z: -4.77791452}
Rotate: {x: 1.48352981, y: 326.085083, z: 1.48352981}
Scale: {x: 1, y: 1, z: 1}
Camera Component:
Position: {x: 1, y: -2, z: -4.77791452}
Pitch: 84.9999924
Yaw: 323.298828
Roll: 84.9999924
Width: 1920
Height: 1080
Near: 0.00999999978
Far: 10000
Perspective: true
Renderable Component:
Mesh: 0
Material: 0
Light Component:
Position: {x: 0, y: 0, z: 0}
Type: Directional
Direction: {x: 0, y: 0, z: 1}
Color: {x: 1, y: 1, z: 1, w: 1}
Layer: 4294967295
Strength: 0
Scripts: ~
- EID: 1
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 1, y: -1.89999998, z: -5.80951977}
Rotate: {x: 79.572258, y: 328.815308, z: 348.792389}
Scale: {x: 1, y: 1, z: 1}
Renderable Component:
Mesh: 0
Material: 0
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.5, y: 0.5, z: 0.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Scripts: ~
- EID: 2
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 1, y: -1.79999995, z: -5.05146122}
Rotate: {x: 196.999405, y: 35.1145439, z: 110.940132}
Scale: {x: 1, y: 1, z: 1}
Renderable Component:
Mesh: 0
Material: 0
RigidBody Component:
Type: Dynamic
Mass: 1
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 0.5, y: 0.5, z: 0.5}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Scripts: ~
- EID: 3
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: -3, y: -1, z: -1}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 5, y: 5, z: 5}
Renderable Component:
Mesh: 0
Material: 0
Scripts:
- Type: RaccoonSpin
RotateSpeed: 1
- EID: 4
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: -3, z: -5}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 7.5, y: 0.5, z: 7.5}
Renderable Component:
Mesh: 0
Material: 0
RigidBody Component:
Type: Static
Mass: 1
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Interpolate: true
Freeze Position X: false
Freeze Position Y: false
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
Collider Component:
Colliders:
- Is Trigger: false
Type: Box
Half Extents: {x: 3.75, y: 0.25, z: 3.75}
Friction: 0.400000006
Bounciness: 0
Density: 1
Position Offset: {x: 0, y: 0, z: 0}
Scripts: ~
- EID: 5
Name: Default
IsActive: true
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 3, y: -1, z: -1}
Rotate: {x: 0, y: 0, z: 0}
Scale: {x: 5, y: 5, z: 5}
Renderable Component:
Mesh: 0
Material: 0
Scripts: ~
- EID: 6
Name: Default
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: 0.25
Scripts: ~

View File

@ -1,3 +0,0 @@
Name: TestScene
ID: 85177200
Type: 5

View File

@ -36,41 +36,10 @@ namespace Sandbox
void SBMainScene::Load()
{
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();
}
void SBMainScene::Init()
{
SHADE::SHGraphicsSystem* graphicsSystem = static_cast<SHADE::SHGraphicsSystem*>(SHADE::SHSystemManager::GetSystem<SHADE::SHGraphicsSystem>());
// 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);
sceneName = SHSerialization::DeserializeSceneFromFile(sceneAssetID);
}

View File

@ -373,6 +373,15 @@ namespace SHADE
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 result;

View File

@ -91,6 +91,8 @@ namespace SHADE
static FolderPointer GetRootFolder() noexcept;
static AssetType GetType(AssetID id) noexcept;
private:
static void InitLoaders() noexcept;

View File

@ -13,12 +13,18 @@
//#==============================================================#
//|| Library Includes ||
//#==============================================================#
#include "Editor/SHEditorWidgets.hpp"
#include <imgui.h>
#include <imgui_internal.h>
#include <misc/cpp/imgui_stdlib.h>
#include <rttr/type>
#include "Assets/SHAssetManager.h"
#include "Assets/Asset Types/SHSceneAsset.h"
#include "Scene/SHSceneManager.h"
#include "Serialization/SHSerialization.h"
#include "Serialization/Configurations/SHConfigurationManager.h"
namespace SHADE
{
@ -40,7 +46,7 @@ namespace SHADE
{
SHEditorWindow::Init();
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());
}
@ -76,32 +82,32 @@ namespace SHADE
{
if (ImGui::BeginMenu("File"))
{
if(ImGui::Selectable("New"))
if (ImGui::Selectable("New"))
{
auto editor = SHSystemManager::GetSystem<SHEditor>();
editor->NewScene();
}
if(ImGui::Selectable("Save"))
if (ImGui::Selectable("Save"))
{
auto editor = SHSystemManager::GetSystem<SHEditor>();
editor->SaveScene();
}
if(ImGui::Selectable("Load"))
if (ImGui::Selectable("Load"))
{
SHSerialization::DeserializeSceneFromFile(SHSceneManager::GetCurrentSceneAssetID());
}
ImGui::EndMenu();
}
if(ImGui::BeginMenu("Edit"))
if (ImGui::BeginMenu("Edit"))
{
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();
}
ImGui::EndDisabled();
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();
}
@ -151,17 +157,46 @@ namespace SHADE
}
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::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();
}
@ -174,15 +209,15 @@ namespace SHADE
void SHEditorMenuBar::DrawSecondaryBar() const noexcept
{
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::SetCursorPosX(ImGui::GetContentRegionAvail().x * 0.5f - 80.f);
const auto editor = SHSystemManager::GetSystem<SHEditor>();
ImGui::BeginDisabled(editor->editorState == SHEditor::State::PLAY);
if(ImGui::SmallButton(ICON_MD_PLAY_ARROW))
if (ImGui::SmallButton(ICON_MD_PLAY_ARROW))
{
if(editor->SaveScene()) //Set play state and invoke event only if we managed to save successfully
if (editor->SaveScene()) //Set play state and invoke event only if we managed to save successfully
{
const SHEditorStateChangeEvent STATE_CHANGE_EVENT
{
@ -195,7 +230,7 @@ namespace SHADE
}
ImGui::EndDisabled();
ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE);
if(ImGui::SmallButton(ICON_MD_PAUSE))
if (ImGui::SmallButton(ICON_MD_PAUSE))
{
const SHEditorStateChangeEvent STATE_CHANGE_EVENT
{
@ -207,7 +242,7 @@ namespace SHADE
}
ImGui::EndDisabled();
ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP);
if(ImGui::SmallButton(ICON_MD_STOP))
if (ImGui::SmallButton(ICON_MD_STOP))
{
const SHEditorStateChangeEvent STATE_CHANGE_EVENT
{

View File

@ -198,7 +198,14 @@ namespace SHADE
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->SetProperty("data.textureIndex", tex->TextureArrayIndex);
}
void SHGraphicsSystem::InitMiddleEnd(void) noexcept
@ -372,6 +379,9 @@ namespace SHADE
// Bind all the buffers required for meshes
for (auto& [buffer, bindingPoint] : MESH_DATA)
{
if (!buffer)
continue;
if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eVertexBuffer)
currentCmdBuffer->BindVertexBuffer(bindingPoint, buffer, 0);
else if (buffer->GetUsageBits() & vk::BufferUsageFlagBits::eIndexBuffer)
@ -715,11 +725,6 @@ namespace SHADE
if (!renderable.HasChanged())
continue;
if (!renderable.GetMesh())
{
SHLOG_CRITICAL("NULL Mesh provided!");
}
// Remove from the SuperBatch it is previously in (prevMat if mat has changed)
Handle<SHMaterialInstance> prevMaterial = renderable.HasMaterialChanged() ? renderable.GetPrevMaterial() : renderable.GetMaterial();
if (prevMaterial)
@ -728,9 +733,9 @@ namespace SHADE
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();
if (newMatInstance)
if (newMatInstance && renderable.GetMesh())
{
Handle<SHSuperBatch> newSuperBatch = newMatInstance->GetBaseMaterial()->GetPipeline()->GetPipelineState().GetSubpass()->GetSuperBatch();
newSuperBatch->Add(&renderable);

View File

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

View File

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