Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
CommandSystem.cpp
Go to the documentation of this file.
1/**
2 * @file CommandSystem.cpp
3 * @brief Implementation of Command System
4 * @author Olympe Engine
5 * @date 2026-02-18
6 */
7
8#include "CommandSystem.h"
9
10namespace Olympe {
11namespace NodeGraph {
12
13// ============================================================================
14// CommandStack Implementation
15// ============================================================================
16
17void CommandStack::ExecuteCommand(std::unique_ptr<ICommand> cmd)
18{
19 if (cmd == nullptr)
20 return;
21
22 cmd->Execute();
23
24 m_undoStack.push_back(std::move(cmd));
25
26 // Limit stack size
27 if (m_undoStack.size() > MAX_STACK_SIZE)
28 {
29 m_undoStack.erase(m_undoStack.begin());
30 }
31
32 // Clear redo stack when new command is executed
33 m_redoStack.clear();
34}
35
37{
38 if (!CanUndo())
39 return;
40
41 std::unique_ptr<ICommand> cmd = std::move(m_undoStack.back());
42 m_undoStack.pop_back();
43
44 cmd->Undo();
45
46 m_redoStack.push_back(std::move(cmd));
47}
48
50{
51 if (!CanRedo())
52 return;
53
54 std::unique_ptr<ICommand> cmd = std::move(m_redoStack.back());
55 m_redoStack.pop_back();
56
57 cmd->Execute();
58
59 m_undoStack.push_back(std::move(cmd));
60}
61
63{
64 return !m_undoStack.empty();
65}
66
68{
69 return !m_redoStack.empty();
70}
71
73{
74 if (m_undoStack.empty())
75 return "";
76
77 return m_undoStack.back()->GetDescription();
78}
79
81{
82 if (m_redoStack.empty())
83 return "";
84
85 return m_redoStack.back()->GetDescription();
86}
87
89{
90 m_undoStack.clear();
91 m_redoStack.clear();
92}
93
94} // namespace NodeGraph
95} // namespace Olympe
Command pattern for undo/redo operations.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
void Undo()
Undo the last command.
static const size_t MAX_STACK_SIZE
bool CanUndo() const
Check if undo is available.
void Clear()
Clear all commands.
std::vector< std::unique_ptr< ICommand > > m_redoStack
std::string GetUndoDescription() const
Get description of next undo command.
std::string GetRedoDescription() const
Get description of next redo command.
void Redo()
Redo the last undone command.
bool CanRedo() const
Check if redo is available.
void ExecuteCommand(std::unique_ptr< ICommand > cmd)
Execute a command and add to undo stack.
std::vector< std::unique_ptr< ICommand > > m_undoStack
< Provides AssetID and INVALID_ASSET_ID