Elevate Engine
1
Loading...
Searching...
No Matches
Command.cpp
Go to the documentation of this file.
1
#include "
Command.h
"
2
#include <format>
3
#include <
ElevateEngine/Core/Log.h
>
4
5
void
Elevate::CommandManager::ExecuteStack
()
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
16
void
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
31
void
Elevate::CommandManager::Undo
()
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
50
void
Elevate::CommandManager::Redo
()
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
}
Command.h
Log.h
Elevate::CommandManager::Undo
void Undo()
Definition
Command.cpp:31
Elevate::CommandManager::ExecuteStack
void ExecuteStack()
Definition
Command.cpp:5
Elevate::CommandManager::Execute
void Execute(std::unique_ptr< Command > command)
Definition
Command.cpp:16
Elevate::CommandManager::Redo
void Redo()
Definition
Command.cpp:50
ElevateEngine
src
ElevateEngine
Core
Command.cpp
Generated by
1.9.8