Elevate Engine 1
Loading...
Searching...
No Matches
Command.cpp
Go to the documentation of this file.
1#include "Command.h"
2#include <format>
4
6{
7 while (!m_executeStack.empty())
8 {
9 EE_CORE_TRACE("ExecuteStack while loop iteration");
10 auto command = std::move(m_executeStack.top());
11 m_executeStack.pop();
12 Execute(std::move(command));
13 }
14}
15
16void Elevate::CommandManager::Execute(std::unique_ptr<Command> command)
17{
18 EE_CORE_TRACE("Execute");
19 command->Execute();
20
21 if (command->IsUndoable())
22 {
23 m_undoStack.push(std::move(command));
24
25 // Clear the redo stack with a swap trick (more safe with unique ptrs)
26 std::stack<std::unique_ptr<Command>> empty;
27 m_redoStack.swap(empty);
28 }
29}
30
32{
33 if (!m_undoStack.empty())
34 {
35 while (!m_undoStack.empty() && !m_undoStack.top()->IsUndoable())
36 {
37 m_undoStack.pop();
38 }
39
40 if (!m_undoStack.empty())
41 {
42 auto cmd = std::move(m_undoStack.top());
43 m_undoStack.pop();
44 cmd->Undo();
45 m_redoStack.push(std::move(cmd));
46 }
47 }
48}
49
51{
52 if (!m_redoStack.empty())
53 {
54 auto cmd = std::move(m_redoStack.top());
55 m_redoStack.pop();
56 PushCommand(std::move(cmd));
57 }
58}
void Execute(std::unique_ptr< Command > command)
Definition Command.cpp:16