From c9db3b283d4b47a18a0857e64681efe025b37687 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Fri, 11 Nov 2022 14:00:51 +0800 Subject: [PATCH 1/7] asset browser --- .../AssetBrowser/SHAssetBrowser.cpp | 42 +++++++++++++++---- .../AssetBrowser/SHAssetBrowser.h | 3 +- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 37b8ecd4..0f17d2db 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -47,10 +47,12 @@ namespace SHADE } } + //if !compiled, set genMeta to true + ImRect SHAssetBrowser::RecursivelyDrawTree(FolderPointer folder) { auto const& subFolders = folder->subFolders; - auto const& files = folder->files; + auto files = folder->files; const bool isSelected = std::ranges::find(selectedFolders, folder) != selectedFolders.end(); ImGuiTreeNodeFlags flags = (subFolders.empty() && files.empty()) ? ImGuiTreeNodeFlags_Leaf : ImGuiTreeNodeFlags_OpenOnArrow; if (isSelected) @@ -100,12 +102,10 @@ namespace SHADE drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); vertLineEnd.y = midPoint; } - for (auto const& file : files) + for (auto& file : files) { - if(file.assetMeta == nullptr) - continue; const float horizontalLineSize = 25.0f; - const ImRect childRect = DrawFile(file.assetMeta); + const ImRect childRect = DrawFile(file); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); vertLineEnd.y = midPoint; @@ -148,7 +148,32 @@ namespace SHADE //} } - ImRect SHAssetBrowser::DrawFile(SHAsset const* const asset) noexcept + ImRect SHAssetBrowser::DrawFile(SHFile& file) noexcept + { + if(file.compilable) + { + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf; + static constexpr std::string_view icon = ICON_MD_FILE_PRESENT; + ImGui::PushID(file.name.data()); + bool const isOpen = ImGui::TreeNodeEx(file.name.data(), flags, "%s %s%s", icon.data(), file.name.data(), file.ext.data()); + const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); + if(ImGui::BeginPopupContextItem()) + { + if(ImGui::Selectable("Compile")) + { + SHAssetManager::CompileAsset(file.path, !file.compiled); + } + ImGui::EndPopup(); + } + ImGui::TreePop(); + ImGui::PopID(); + return nodeRect; + } + if(file.assetMeta) + DrawAsset(file.assetMeta, file.ext); + } + + ImRect SHAssetBrowser::DrawAsset(SHAsset const* const asset, FileExt const& ext /*= ""*/) noexcept { if (asset == nullptr) return ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); @@ -173,7 +198,7 @@ namespace SHADE default:; } - bool const isOpen = ImGui::TreeNodeEx(asset, flags, "%s %s", icon.data(), asset->name.data()); + bool const isOpen = ImGui::TreeNodeEx(asset, flags, "%s %s%s", icon.data(), asset->name.data(), ext.data()); const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); if (SHDragDrop::BeginSource()) { @@ -212,7 +237,6 @@ namespace SHADE case AssetType::MAX_COUNT: break; default:; } - } //TODO: Combine Draw asset and Draw Folder recursive drawing @@ -227,7 +251,7 @@ namespace SHADE for(auto const& subAsset : asset->subAssets) { const float horizontalLineSize = 25.0f; - const ImRect childRect = DrawFile(subAsset); + const ImRect childRect = DrawAsset(subAsset); const float midPoint = (childRect.Min.y + childRect.Max.y) * 0.5f; drawList->AddLine(ImVec2(vertLineStart.x, midPoint), ImVec2(vertLineStart.x + horizontalLineSize, midPoint), treeLineColor, 1); vertLineEnd.y = midPoint; diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h index 00023ebe..6b6316c8 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h @@ -21,7 +21,8 @@ namespace SHADE void DrawMenuBar(); ImRect RecursivelyDrawTree(FolderPointer folder); void DrawCurrentFolder(); - ImRect DrawFile(SHAsset const* const asset) noexcept; + ImRect DrawFile(SHFile& file) noexcept; + ImRect DrawAsset(SHAsset const* const asset, FileExt const& ext = "") noexcept; void DrawAssetBeingCreated() noexcept; FolderPointer rootFolder, prevFolder, currentFolder; From 153f040c407909acb18010dc81de37b7990a4836 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Fri, 11 Nov 2022 20:41:05 +0800 Subject: [PATCH 2/7] Refresh --- .../AssetBrowser/SHAssetBrowser.cpp | 26 ++++++++++++++++--- .../AssetBrowser/SHAssetBrowser.h | 5 +++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index 0f17d2db..dca8a34b 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -36,13 +36,30 @@ namespace SHADE DrawCurrentFolder(); } ImGui::End(); + if(refreshQueued) + Refresh(); + } + + void SHAssetBrowser::QueueRefresh() noexcept + { + refreshQueued = true; + } + + void SHAssetBrowser::Refresh() noexcept + { + SHAssetManager::RefreshDirectory(); + rootFolder = SHAssetManager::GetRootFolder(); + refreshQueued = false; } void SHAssetBrowser::DrawMenuBar() { if (ImGui::BeginMenuBar()) { - + if(ImGui::SmallButton(ICON_MD_SYNC)) + { + QueueRefresh(); + } ImGui::EndMenuBar(); } } @@ -71,7 +88,7 @@ namespace SHADE //TODO: Change to rttr type enum align if (ImGui::Selectable("Material")) { - assetBeingCreated = { folder, AssetType::MATERIAL, "New Material" }; + assetBeingCreated = { folder, AssetType::MATERIAL, "NewMaterial" }; ImGui::TreeNodeSetOpen(folderID, true); isOpen = true; } @@ -162,6 +179,7 @@ namespace SHADE if(ImGui::Selectable("Compile")) { SHAssetManager::CompileAsset(file.path, !file.compiled); + QueueRefresh(); } ImGui::EndPopup(); } @@ -269,7 +287,7 @@ namespace SHADE auto& path = std::get<0>(assetBeingCreated.value()); auto& type = std::get<1>(assetBeingCreated.value()); auto& assetName = std::get<2>(assetBeingCreated.value()); - if (ImGui::InputText("##newAssetName", &assetName, ImGuiInputTextFlags_EnterReturnsTrue)) + if (ImGui::InputText("##newAssetName", &assetName, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsNoBlank)) { AssetID assetId = SHAssetManager::CreateNewAsset(type, assetName); if (auto matInspector = SHEditorWindowManager::GetEditorWindow()) @@ -277,6 +295,8 @@ namespace SHADE matInspector->OpenMaterial(assetId, true); } assetBeingCreated.reset(); + QueueRefresh(); } + ImGui::ActivateItem(ImGui::GetItemID()); } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h index 6b6316c8..d6c2c191 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h @@ -16,7 +16,7 @@ namespace SHADE void Init(); void Update(); - void Refresh(); + void QueueRefresh() noexcept; private: void DrawMenuBar(); ImRect RecursivelyDrawTree(FolderPointer folder); @@ -25,10 +25,13 @@ namespace SHADE ImRect DrawAsset(SHAsset const* const asset, FileExt const& ext = "") noexcept; void DrawAssetBeingCreated() noexcept; + void Refresh() noexcept; + FolderPointer rootFolder, prevFolder, currentFolder; std::optional assetBeingCreated; std::vector selectedFolders; std::vector selectedAssets; static constexpr float tileWidth = 50.0f; + bool refreshQueued = false; }; } From 7c7589ce8e01a4120fcd66b15ffc18ec6a977311 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Fri, 11 Nov 2022 21:12:08 +0800 Subject: [PATCH 3/7] idk why creation of new material is not working here send help. Change to popup for asset creation --- .../AssetBrowser/SHAssetBrowser.cpp | 84 ++++++++++++------- .../AssetBrowser/SHAssetBrowser.h | 5 +- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp index dca8a34b..37521581 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.cpp @@ -17,7 +17,7 @@ namespace SHADE { SHAssetBrowser::SHAssetBrowser() - :SHEditorWindow("\xee\x8b\x87 Asset Browser", ImGuiWindowFlags_MenuBar), rootFolder(SHAssetManager::GetRootFolder()), prevFolder(rootFolder), currentFolder(rootFolder), assetBeingCreated(std::nullopt) + :SHEditorWindow("\xee\x8b\x87 Asset Browser", ImGuiWindowFlags_MenuBar), rootFolder(SHAssetManager::GetRootFolder()), prevFolder(rootFolder), currentFolder(rootFolder) { } @@ -34,6 +34,8 @@ namespace SHADE RecursivelyDrawTree(rootFolder); DrawMenuBar(); DrawCurrentFolder(); + DrawAssetBeingCreated(); + } ImGui::End(); if(refreshQueued) @@ -60,6 +62,10 @@ namespace SHADE { QueueRefresh(); } + if(ImGui::SmallButton(ICON_FA_CIRCLE_PLUS)) + { + isAssetBeingCreated = true; + } ImGui::EndMenuBar(); } } @@ -81,21 +87,10 @@ namespace SHADE ImGuiID folderID = ImGui::GetItemID(); const ImRect nodeRect = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()); - if (ImGui::BeginPopupContextItem()) - { - if (ImGui::BeginMenu("Create Asset")) - { - //TODO: Change to rttr type enum align - if (ImGui::Selectable("Material")) - { - assetBeingCreated = { folder, AssetType::MATERIAL, "NewMaterial" }; - ImGui::TreeNodeSetOpen(folderID, true); - isOpen = true; - } - ImGui::EndMenu(); - } - ImGui::EndPopup(); - } + //if (ImGui::BeginPopupContextItem()) + //{ + // ImGui::EndPopup(); + //} if (ImGui::IsItemClicked()) { @@ -128,8 +123,6 @@ namespace SHADE vertLineEnd.y = midPoint; } drawList->AddLine(vertLineStart, vertLineEnd, treeLineColor, 1); - if(assetBeingCreated.has_value() && std::get<0>(assetBeingCreated.value()) == folder) - DrawAssetBeingCreated(); ImGui::TreePop(); } @@ -282,21 +275,52 @@ namespace SHADE void SHAssetBrowser::DrawAssetBeingCreated() noexcept { - if (!assetBeingCreated.has_value()) - return; - auto& path = std::get<0>(assetBeingCreated.value()); - auto& type = std::get<1>(assetBeingCreated.value()); - auto& assetName = std::get<2>(assetBeingCreated.value()); - if (ImGui::InputText("##newAssetName", &assetName, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsNoBlank)) + if(isAssetBeingCreated) + ImGui::OpenPopup(newAssetPopup.data()); + + if(ImGui::BeginPopupModal(newAssetPopup.data(), &isAssetBeingCreated)) { - AssetID assetId = SHAssetManager::CreateNewAsset(type, assetName); - if (auto matInspector = SHEditorWindowManager::GetEditorWindow()) + ImGui::RadioButton("Material", true); + ImGui::SameLine(); + if (ImGui::InputText("##newAssetName", &nameOfAssetBeingCreated, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_AutoSelectAll)) { - matInspector->OpenMaterial(assetId, true); + AssetID assetId = SHAssetManager::CreateNewAsset(AssetType::MATERIAL, nameOfAssetBeingCreated); + if (auto matInspector = SHEditorWindowManager::GetEditorWindow()) + { + matInspector->OpenMaterial(assetId, true); + } + nameOfAssetBeingCreated.clear(); + QueueRefresh(); + isAssetBeingCreated = false; + ImGui::CloseCurrentPopup(); } - assetBeingCreated.reset(); - QueueRefresh(); + ImGui::EndPopup(); } - ImGui::ActivateItem(ImGui::GetItemID()); + //if (ImGui::BeginMenu("Create Asset")) + //{ + // //TODO: Change to rttr type enum align + // if (ImGui::Selectable("Material")) + // { + // assetBeingCreated = { folder, AssetType::MATERIAL, "NewMaterial" }; + // ImGui::TreeNodeSetOpen(folderID, true); + // isOpen = true; + // } + // ImGui::EndMenu(); + //} + //if (!assetBeingCreated.has_value()) + // return; + //auto& path = std::get<0>(assetBeingCreated.value()); + //auto& type = std::get<1>(assetBeingCreated.value()); + //auto& assetName = std::get<2>(assetBeingCreated.value()); + //if (ImGui::InputText("##newAssetName", &assetName, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_AutoSelectAll)) + //{ + // AssetID assetId = SHAssetManager::CreateNewAsset(type, assetName); + // if (auto matInspector = SHEditorWindowManager::GetEditorWindow()) + // { + // matInspector->OpenMaterial(assetId, true); + // } + // assetBeingCreated.reset(); + // QueueRefresh(); + //} } } diff --git a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h index d6c2c191..6d3c5eb4 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h +++ b/SHADE_Engine/src/Editor/EditorWindow/AssetBrowser/SHAssetBrowser.h @@ -10,7 +10,6 @@ namespace SHADE class SHAssetBrowser final : public SHEditorWindow { public: - using AssetEntry = std::tuple; SHAssetBrowser(); void Init(); @@ -28,10 +27,12 @@ namespace SHADE void Refresh() noexcept; FolderPointer rootFolder, prevFolder, currentFolder; - std::optional assetBeingCreated; std::vector selectedFolders; std::vector selectedAssets; static constexpr float tileWidth = 50.0f; bool refreshQueued = false; + bool isAssetBeingCreated = false; + static constexpr std::string_view newAssetPopup = "Create New Asset"; + std::string nameOfAssetBeingCreated; }; } From 340299218995a652dfe311af4de3cfc7a33de760 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sat, 12 Nov 2022 18:09:55 +0800 Subject: [PATCH 4/7] dont draw gizmos on play --- .../ViewportWindow/SHEditorViewport.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp index d6ef8d19..7b3b5411 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp @@ -40,6 +40,7 @@ namespace SHADE shouldUpdateCamera = false; } ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + SHEditor* editor = SHSystemManager::GetSystem(); if (Begin()) { @@ -51,7 +52,6 @@ namespace SHADE beginCursorPos = ImGui::GetCursorScreenPos(); viewportMousePos = { mousePos.x - beginCursorPos.x, mousePos.y - beginCursorPos.y }; gfxSystem->GetMousePickSystem()->SetViewportMousePos(viewportMousePos); - ImGui::Image((ImTextureID)descriptorSet, { beginContentRegionAvailable.x, beginContentRegionAvailable.y }); if (ImGui::IsWindowHovered() && ImGui::IsMouseDown(ImGuiMouseButton_Right)) @@ -64,24 +64,25 @@ namespace SHADE shouldUpdateCamera = true; } - if (ImGui::IsWindowFocused() && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) + if (editor->editorState != SHEditor::State::PLAY && ImGui::IsWindowFocused() && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) { - if (ImGui::IsKeyReleased(ImGuiKey_Q)) + if (ImGui::IsKeyReleased(ImGuiKey_W)) { transformGizmo.operation = SHTransformGizmo::Operation::TRANSLATE; } - if (ImGui::IsKeyReleased(ImGuiKey_W)) + if (ImGui::IsKeyReleased(ImGuiKey_E)) { transformGizmo.operation = SHTransformGizmo::Operation::ROTATE; } - if (ImGui::IsKeyReleased(ImGuiKey_E)) + if (ImGui::IsKeyReleased(ImGuiKey_R)) { transformGizmo.operation = SHTransformGizmo::Operation::SCALE; } } } ImGuizmo::SetRect(beginCursorPos.x, beginCursorPos.y, beginContentRegionAvailable.x, beginContentRegionAvailable.y); - transformGizmo.Draw(); + if(editor->editorState != SHEditor::State::PLAY) + transformGizmo.Draw(); ImGui::End(); ImGui::PopStyleVar(); } From 78ca464c6537823445e2683f05455051be0bdbc1 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sat, 12 Nov 2022 18:22:45 +0800 Subject: [PATCH 5/7] Editor now uses separate stacks; 1 set of stacks when in play and another set of stacks otherwise. CommandStack now uses SHDeque --- .../src/Editor/Command/SHCommandManager.cpp | 77 ++++++++++++++----- .../src/Editor/Command/SHCommandManager.h | 13 +++- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 4 +- SHADE_Engine/src/Tools/SHDeque.h | 69 +++++++++++++++++ 4 files changed, 141 insertions(+), 22 deletions(-) create mode 100644 SHADE_Engine/src/Tools/SHDeque.h diff --git a/SHADE_Engine/src/Editor/Command/SHCommandManager.cpp b/SHADE_Engine/src/Editor/Command/SHCommandManager.cpp index 3c0ee5dd..b86f9247 100644 --- a/SHADE_Engine/src/Editor/Command/SHCommandManager.cpp +++ b/SHADE_Engine/src/Editor/Command/SHCommandManager.cpp @@ -10,63 +10,102 @@ namespace SHADE { - SHCommandManager::CommandStack SHCommandManager::undoStack{}; - SHCommandManager::CommandStack SHCommandManager::redoStack{}; + + SHCommandManager::CommandStack SHCommandManager::undoStack(defaultStackSize); + SHCommandManager::CommandStack SHCommandManager::redoStack(defaultStackSize); + SHCommandManager::CommandStack SHCommandManager::secondaryUndoStack(defaultStackSize); + SHCommandManager::CommandStack SHCommandManager::secondaryRedoStack(defaultStackSize); + + SHCommandManager::CommandStackPtr SHCommandManager::pCurrUndoStack(&undoStack); + SHCommandManager::CommandStackPtr SHCommandManager::pCurrRedoStack(&redoStack); void SHCommandManager::PerformCommand(BaseCommandPtr commandPtr, bool const& overrideValue) { - redoStack = CommandStack(); + *pCurrRedoStack = CommandStack(defaultStackSize); commandPtr->Execute(); - if (overrideValue && !undoStack.empty()) + if (overrideValue && !pCurrUndoStack->Empty()) { - undoStack.top()->Merge(commandPtr); + pCurrUndoStack->Top()->Merge(commandPtr); } else { - undoStack.push(commandPtr); + pCurrUndoStack->Push(commandPtr); } } void SHCommandManager::RegisterCommand(BaseCommandPtr commandPtr) { - undoStack.push(commandPtr); + pCurrUndoStack->Push(commandPtr); } void SHCommandManager::UndoCommand() { - if (undoStack.empty()) + if (pCurrUndoStack->Empty()) return; - undoStack.top()->Undo(); - redoStack.push(undoStack.top()); - undoStack.pop(); + pCurrUndoStack->Top()->Undo(); + pCurrRedoStack->Push(pCurrUndoStack->Top()); + pCurrUndoStack->Pop(); } void SHCommandManager::RedoCommand() { - if (redoStack.empty()) + if (pCurrRedoStack->Empty()) return; - redoStack.top()->Execute(); - undoStack.push(redoStack.top()); - redoStack.pop(); + pCurrRedoStack->Top()->Execute(); + pCurrUndoStack->Push(pCurrRedoStack->Top()); + pCurrRedoStack->Pop(); } std::size_t SHCommandManager::GetUndoStackSize() { - return undoStack.size(); + return pCurrUndoStack->Size(); } std::size_t SHCommandManager::GetRedoStackSize() { - return redoStack.size(); + return pCurrRedoStack->Size(); } void SHCommandManager::PopLatestCommandFromRedoStack() { - redoStack.pop(); + pCurrRedoStack->Pop(); } void SHCommandManager::PopLatestCommandFromUndoStack() { - undoStack.pop(); + pCurrUndoStack->Pop(); } + + void SHCommandManager::SwapStacks() + { + if (pCurrUndoStack == &undoStack) + { + pCurrUndoStack = &secondaryUndoStack; + } + else + { + secondaryUndoStack.Clear(); + pCurrUndoStack = &undoStack; + } + + if (pCurrRedoStack == &redoStack) + { + pCurrRedoStack = &secondaryRedoStack; + } + else + { + secondaryRedoStack.Clear(); + pCurrRedoStack = &redoStack; + } + } + + void SHCommandManager::ClearAll() + { + undoStack.Clear(); + redoStack.Clear(); + + secondaryUndoStack.Clear(); + secondaryRedoStack.Clear(); + } + }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/Command/SHCommandManager.h b/SHADE_Engine/src/Editor/Command/SHCommandManager.h index a514c464..178347b5 100644 --- a/SHADE_Engine/src/Editor/Command/SHCommandManager.h +++ b/SHADE_Engine/src/Editor/Command/SHCommandManager.h @@ -10,6 +10,7 @@ //#==============================================================# #include "SHCommand.hpp" #include "SH_API.h" +#include "Tools/SHDeque.h" namespace SHADE { @@ -22,7 +23,8 @@ namespace SHADE using BaseCommandPtr = std::shared_ptr; template using SHCommandPtr = std::shared_ptr>; - using CommandStack = std::stack; + using CommandStack = SHDeque; + using CommandStackPtr = CommandStack*; static void PerformCommand(BaseCommandPtr commandPtr, bool const& overrideValue = false); static void RegisterCommand(BaseCommandPtr commandPtr); @@ -34,8 +36,17 @@ namespace SHADE static void PopLatestCommandFromRedoStack(); static void PopLatestCommandFromUndoStack(); + static void SwapStacks(); + static void ClearAll(); + + static constexpr CommandStack::SizeType defaultStackSize = 100; private: + static CommandStackPtr pCurrUndoStack; + static CommandStackPtr pCurrRedoStack; + static CommandStack undoStack; + static CommandStack secondaryUndoStack; static CommandStack redoStack; + static CommandStack secondaryRedoStack; }; }//namespace SHADE diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index cfb36cd0..fdde55e1 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -228,7 +228,7 @@ namespace SHADE .previousState = editor->editorState }; editor->editorState = SHEditor::State::PLAY; - + SHCommandManager::SwapStacks(); SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT); } } @@ -253,7 +253,7 @@ namespace SHADE .previousState = editor->editorState }; editor->editorState = SHEditor::State::STOP; - + SHCommandManager::SwapStacks(); SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT); editor->LoadScene(SHSceneManager::GetCurrentSceneAssetID()); } diff --git a/SHADE_Engine/src/Tools/SHDeque.h b/SHADE_Engine/src/Tools/SHDeque.h new file mode 100644 index 00000000..99df910a --- /dev/null +++ b/SHADE_Engine/src/Tools/SHDeque.h @@ -0,0 +1,69 @@ +#pragma once +#pragma once + +#include "SH_API.h" +#include + +namespace SHADE +{ + template + class SH_API SHDeque + { + public: + using ValueType = T; + using Pointer = T*; + using ValueRef = T&; + using ValueConstRef = T const&; + using SizeType = uint32_t; + using ContainerType = std::deque; + using ContainerTypeConstRef = std::deque; + + SHDeque(SizeType n) : max_size(n) {} + + ContainerTypeConstRef const& GetDeque() const + { + return deque; + } + + void Push(ValueConstRef obj) + { + if (deque.size() < max_size) + deque.push_front(std::move(obj)); + else + { + deque.pop_back(); + deque.push_front(std::move(obj)); + } + } + + bool Empty() + { + return deque.empty(); + } + + void Pop() + { + deque.pop_front(); + } + + ValueConstRef Top() + { + return deque.front(); + } + + SizeType Size() const noexcept + { + return deque.size(); + } + + void Clear() + { + deque.clear(); + } + + private: + int max_size; + ContainerType deque{}; + + }; +} \ No newline at end of file From 69ac074926530530d640798462ecc170c2e7503d Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sat, 12 Nov 2022 18:38:57 +0800 Subject: [PATCH 6/7] change entity active to scene node active --- .../src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp | 5 +++-- SHADE_Engine/src/Scene/SHSceneNode.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index 2fecae25..dde49838 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -93,13 +93,14 @@ namespace SHADE { EntityID const& eid = editor->selectedEntities[0]; SHEntity* entity = SHEntityManager::GetEntityByID(eid); - if(!entity) + SHSceneNode* entityNode = SHSceneManager::GetCurrentSceneGraph().GetNode(eid); + if(!entity || !entityNode) { ImGui::End(); return; } ImGui::TextColored(ImGuiColors::green, "EID: %zu", eid); - SHEditorWidgets::CheckBox("##IsActive", [entity]()->bool {return entity->GetActive(); }, [entity](bool const& active) {entity->SetActive(active); }); + SHEditorWidgets::CheckBox("##IsActive", [entityNode]()->bool {return entityNode->IsActive(); }, [entityNode](bool const& active) {entityNode->SetActive(active); }); ImGui::SameLine(); ImGui::InputText("##EntityName", &entity->name); diff --git a/SHADE_Engine/src/Scene/SHSceneNode.cpp b/SHADE_Engine/src/Scene/SHSceneNode.cpp index b619d464..8dac20bd 100644 --- a/SHADE_Engine/src/Scene/SHSceneNode.cpp +++ b/SHADE_Engine/src/Scene/SHSceneNode.cpp @@ -136,7 +136,7 @@ namespace SHADE for (auto* child : children) { - SetActive(newActiveState); + child->SetActive(newActiveState); } } From e2bcb0bbbbc192dd121189257c5eeeabaac4dda5 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sat, 12 Nov 2022 23:57:12 +0800 Subject: [PATCH 7/7] play pause stop bound to F5 F6 F7 --- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 25 +-------- SHADE_Engine/src/Editor/SHEditor.cpp | 56 ++++++++++++++++++- SHADE_Engine/src/Editor/SHEditor.h | 4 ++ 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index fdde55e1..ce3ca8b5 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -223,39 +223,20 @@ namespace SHADE { if(editor->SaveScene()) { - const SHEditorStateChangeEvent STATE_CHANGE_EVENT - { - .previousState = editor->editorState - }; - editor->editorState = SHEditor::State::PLAY; - SHCommandManager::SwapStacks(); - SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT); + editor->Play(); } } ImGui::EndDisabled(); ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE); if(ImGui::SmallButton(ICON_MD_PAUSE)) { - const SHEditorStateChangeEvent STATE_CHANGE_EVENT - { - .previousState = editor->editorState - }; - editor->editorState = SHEditor::State::PAUSE; - - SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PAUSE_EVENT); + editor->Pause(); } ImGui::EndDisabled(); ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP); if(ImGui::SmallButton(ICON_MD_STOP)) { - const SHEditorStateChangeEvent STATE_CHANGE_EVENT - { - .previousState = editor->editorState - }; - editor->editorState = SHEditor::State::STOP; - SHCommandManager::SwapStacks(); - SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT); - editor->LoadScene(SHSceneManager::GetCurrentSceneAssetID()); + editor->Stop(); } ImGui::EndDisabled(); ImGui::EndMenuBar(); diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index c4ad3459..90655a62 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -168,7 +168,19 @@ namespace SHADE { SHCommandManager::UndoCommand(); } - + if(ImGui::IsKeyReleased(ImGuiKey_F5)) + { + Play(); + } + else if (ImGui::IsKeyReleased(ImGuiKey_F6)) + { + Pause(); + } + else if (ImGui::IsKeyReleased(ImGuiKey_F7)) + { + Stop(); + } + Render(); } @@ -597,6 +609,48 @@ namespace SHADE } } + void SHEditor::Play() + { + if(editorState == State::PLAY) + return; + if (SaveScene()) + { + const SHEditorStateChangeEvent STATE_CHANGE_EVENT + { + .previousState = editorState + }; + editorState = State::PLAY; + SHCommandManager::SwapStacks(); + SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT); + } + } + + void SHEditor::Pause() + { + if (editorState == State::PAUSE) + return; + const SHEditorStateChangeEvent STATE_CHANGE_EVENT + { + .previousState = editorState + }; + editorState = State::PAUSE; + SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PAUSE_EVENT); + } + + void SHEditor::Stop() + { + if (editorState == State::STOP) + return; + const SHEditorStateChangeEvent STATE_CHANGE_EVENT + { + .previousState = editorState + }; + editorState = SHEditor::State::STOP; + SHCommandManager::SwapStacks(); + SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT); + LoadScene(SHSceneManager::GetCurrentSceneAssetID()); + } + void SHEditor::NewFrame() { SDL_Event event; diff --git a/SHADE_Engine/src/Editor/SHEditor.h b/SHADE_Engine/src/Editor/SHEditor.h index 0f5a3aaa..0de7796a 100644 --- a/SHADE_Engine/src/Editor/SHEditor.h +++ b/SHADE_Engine/src/Editor/SHEditor.h @@ -184,6 +184,10 @@ namespace SHADE void LoadScene(AssetID const& assetID) noexcept; + void Play(); + void Pause(); + void Stop(); + // List of selected entities std::vector selectedEntities;