Added command buffer implementation in the editor layer

This commit is contained in:
Antoine Pilote
2024-04-27 19:13:11 -04:00
parent bff56e9e39
commit f9081f669e
9 changed files with 99 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
#pragma once
#include "ICommand.h"
#include <vector>
@@ -7,11 +8,23 @@ namespace NuakeEditor
class CommandBuffer
{
private:
std::vector<ICommand> mCommands;
public:
CommandBuffer();
~CommandBuffer();
CommandBuffer() : mCommands(std::vector<ICommand>()) {}
~CommandBuffer() = default;
void PushCommand(ICommand& command)
{
command.Execute();
mCommands.push_back(command);
}
void PopCommand()
{
}
};
}

View File

@@ -0,0 +1,19 @@
#include "Commands.h"
#include <Engine.h>
namespace NuakeEditor
{
bool SaveSceneCommand::Execute()
{
return true;
}
bool SaveProjectCommand::Execute()
{
Engine::GetProject()->Save();
Engine::GetCurrentScene()->Save();
return true;
}
}

View File

@@ -1,23 +1,35 @@
#pragma once
#include "../ICommand.h"
#include <src/Core/Core.h>
#include <src/Scene/Scene.h>
#include <src/Resource/Project.h>
namespace NuakeEditor {
class SaveSceneCommand : ICommand
using namespace Nuake;
class SaveSceneCommand : public ICommand
{
private:
Ref<Scene> mScene;
public:
void Execute() override;
SaveSceneCommand(Ref<Scene> scene) : mScene(scene) {}
bool Execute() override;
};
class SaveProjectCommand : ICommand
class SaveProjectCommand : public ICommand
{
private:
Ref<Project> mProject;
public:
void Execute() override;
SaveProjectCommand(Ref<Project> project) : mProject(project) {}
bool Execute() override;
};
class SaveProjectCommand : ICommand
{
public:
void Execute() override;
};
}

View File

@@ -5,7 +5,16 @@ namespace NuakeEditor
class ICommand
{
public:
virtual void Execute() = 0;
virtual void Undo() = 0;
ICommand() = default;
virtual bool Execute()
{
return false;
}
virtual bool Undo()
{
return false;
}
};
}

View File

@@ -5,9 +5,15 @@
#include "Windows/EditorInterface.h"
#include "Misc/GizmoDrawer.h"
#include "Commands/CommandBuffer.h"
using namespace NuakeEditor;
class EditorApplication : public Nuake::Application
{
private:
CommandBuffer mCommandBuffer;
public:
EditorApplication(const Nuake::ApplicationSpecification& specification)
: Application(specification),
@@ -16,6 +22,7 @@ public:
}
virtual void OnInit() override;
// virtual void OnUpdate() override;
virtual void OnShutdown() override;

View File

@@ -8,7 +8,7 @@
void EditorLayer::OnAttach()
{
m_EditorInterface = new Nuake::EditorInterface();
m_EditorInterface = new Nuake::EditorInterface(mCommandBuffer);
m_GizmoDrawer = new GizmoDrawer(m_EditorInterface);
}
@@ -21,7 +21,6 @@ void EditorLayer::OnUpdate()
auto sceneFramebuffer = GetApplication().GetWindow()->GetFrameBuffer();
// Draw gizmos
if (Ref<Nuake::Scene> currentScene = Nuake::Engine::GetCurrentScene(); currentScene)
{
@@ -64,6 +63,7 @@ void EditorLayer::OnUpdate()
m_EditorInterface->Draw();
m_EditorInterface->Update(Nuake::Engine::GetTimestep());
Nuake::Engine::EndDraw();
}

View File

@@ -1,5 +1,6 @@
#pragma once
#include <src/Application/Layer.h>
#include "Commands/CommandBuffer.h"
namespace Nuake {
@@ -9,15 +10,19 @@ namespace Nuake {
class GizmoDrawer;
using namespace NuakeEditor;
class EditorLayer : public Nuake::Layer
{
public:
EditorLayer() : mCommandBuffer() {}
virtual void OnAttach() override;
virtual void OnUpdate() override;
virtual void OnDetach() override;
private:
CommandBuffer mCommandBuffer;
Nuake::EditorInterface* m_EditorInterface;
GizmoDrawer* m_GizmoDrawer;
};

View File

@@ -54,6 +54,7 @@
#include <src/Resource/StaticResources.h>
#include <src/Scripting/ScriptingEngineNet.h>
#include <src/Threading/JobSystem.h>
#include "../Commands/Commands/Commands.h"
namespace Nuake {
@@ -62,7 +63,8 @@ namespace Nuake {
ImFont* boldFont;
ImFont* EditorInterface::bigIconFont;
EditorInterface::EditorInterface()
EditorInterface::EditorInterface(CommandBuffer& commandBuffer) :
mCommandBuffer(&commandBuffer)
{
Logger::Log("Creating editor windows", "window", CRITICAL);
filesystem = new FileSystemUI(this);
@@ -2111,12 +2113,12 @@ namespace Nuake {
}
if (ImGui::MenuItem("Save", "CTRL+S"))
{
Engine::GetProject()->Save();
Engine::GetCurrentScene()->Save();
PushCommand(SaveProjectCommand(Engine::GetProject()));
Selection = EditorSelection();
SetStatusMessage("Project saved.");
Selection = EditorSelection();
}
if (ImGui::MenuItem("Save as...", "CTRL+SHIFT+S"))
{
@@ -2455,6 +2457,11 @@ namespace Nuake {
return entityTypeName;
}
void EditorInterface::PushCommand(ICommand&& command)
{
mCommandBuffer->PushCommand(command);
}
bool EditorInterface::LoadProject(const std::string& projectPath)
{
FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath));

View File

@@ -6,12 +6,15 @@
#include <src/Vendors/imgui/ImGuizmo.h>
#include "src/Core/FileSystem.h"
#include "../Actions/EditorSelection.h"
#include "EditorSelectionPanel.h"
#include "WelcomeWindow.h"
#include "AudioWindow.h"
#include "../Windows/TrenchbroomConfiguratorWindow.h"
#include "../Commands/CommandBuffer.h"
#include "../Commands/ICommand.h"
using namespace NuakeEditor;
namespace Nuake
{
@@ -22,6 +25,7 @@ namespace Nuake
{
private:
Ref<Scene> SceneSnapshot;
NuakeEditor::CommandBuffer* mCommandBuffer;
bool m_DrawGrid = false;
bool m_DrawAxis = true;
@@ -52,7 +56,7 @@ namespace Nuake
EditorSelectionPanel SelectionPanel;
TrenchbroomConfiguratorWindow m_TrenchhbroomConfigurator;
EditorInterface();
EditorInterface(CommandBuffer& commandBuffer);
static ImFont* bigIconFont;
void BuildFonts();
@@ -76,5 +80,6 @@ namespace Nuake
private:
std::string GetEntityTypeName(const Entity& entity) const;
void PushCommand(ICommand&& command);
};
}