Open 3D Engine EMotionFX Gem API Reference
24.09
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
|
#include <MCoreCommandManager.h>
Inherited by CommandSystem::CommandManager.
Classes | |
struct | CommandHistoryEntry |
Public Member Functions | |
CommandManager () | |
virtual | ~CommandManager () |
bool | ExecuteCommand (const char *command, AZStd::string &outCommandResult, bool addToHistory=true, Command **outExecutedCommand=nullptr, CommandLine *outExecutedParamters=nullptr, bool callFromCommandGroup=false, bool clearErrors=true, bool handleErrors=true) |
bool | ExecuteCommand (const AZStd::string &command, AZStd::string &outCommandResult, bool addToHistory=true, Command **outExecutedCommand=nullptr, CommandLine *outExecutedParamters=nullptr, bool callFromCommandGroup=false, bool clearErrors=true, bool handleErrors=true) |
bool | ExecuteCommand (Command *command, AZStd::string &outCommandResult, bool addToHistory=true, bool clearErrors=true, bool handleErrors=true, bool autoDeleteCommand=true) |
bool | ExecuteCommandInsideCommand (const char *command, AZStd::string &outCommandResult) |
bool | ExecuteCommandInsideCommand (const AZStd::string &command, AZStd::string &outCommandResult) |
bool | ExecuteCommandInsideCommand (Command *command, AZStd::string &outCommandResult) |
bool | ExecuteCommandOrAddToGroup (const AZStd::string &command, MCore::CommandGroup *commandGroup=nullptr, bool executeInsideCommand=false) |
bool | ExecuteCommandOrAddToGroup (Command *command, MCore::CommandGroup *commandGroup=nullptr, bool executeInsideCommand=false) |
bool | ExecuteCommandGroup (CommandGroup &commandGroup, AZStd::string &outCommandResult, bool addToHistory=true, bool clearErrors=true, bool handleErrors=true) |
bool | ExecuteCommandGroupInsideCommand (CommandGroup &commandGroup, AZStd::string &outCommandResult) |
bool | Undo (AZStd::string &outCommandResult) |
bool | Redo (AZStd::string &outCommandResult) |
bool | RegisterCommand (Command *command) |
void | LogCommandHistory () |
Command * | FindCommand (const AZStd::string &commandName) |
void | RemoveCallbacks () |
void | RegisterCallback (CommandManagerCallback *callback) |
void | RemoveCallback (CommandManagerCallback *callback, bool delFromMem=true) |
size_t | GetNumCallbacks () const |
CommandManagerCallback * | GetCallback (size_t index) |
void | SetMaxHistoryItems (size_t maxItems) |
size_t | GetMaxHistoryItems () const |
ptrdiff_t | GetHistoryIndex () const |
size_t | GetNumHistoryItems () const |
const CommandHistoryEntry & | GetHistoryItem (size_t index) const |
Command * | GetHistoryCommand (size_t historyIndex) |
void | ClearHistory () |
const CommandLine & | GetHistoryCommandLine (size_t historyIndex) const |
size_t | GetNumRegisteredCommands () const |
Command * | GetCommand (size_t index) |
void | RemoveCommandCallback (Command::Callback *callback, bool delFromMem) |
void | RemoveCommandCallback (const char *commandName, Command::Callback *callback, bool delFromMem) |
bool | RegisterCommandCallback (const char *commandName, Command::Callback *callback) |
template<typename T , typename... Args> | |
bool | RegisterCommandCallback (const char *commandName, AZStd::vector< Command::Callback * > &callbacks, Args... args) |
MCORE_INLINE void | AddError (const char *errorLine) |
MCORE_INLINE void | AddError (const AZStd::string &errorLine) |
bool | ShowErrorReport () |
bool | IsExecuting () const |
Protected Member Functions | |
bool | ExecuteCommand (Command *command, const CommandLine &commandLine, AZStd::string &outCommandResult, bool addToHistory, bool callFromCommandGroup, bool clearErrors, bool handleErrors, bool autoDeleteCommand) |
bool | ShouldDeleteCommand (Command *commandObject, bool commandExecutionResult, bool callFromCommandGroup, bool addToHistory) |
void | PushCommandHistory (Command *command, const CommandLine ¶meters) |
void | PushCommandHistory (CommandGroup *commandGroup) |
void | PopCommandHistory () |
void | ExecuteUndoCallbacks (Command *command, const CommandLine ¶meters, bool preUndo) |
void | ExecuteCommandCallbacks (Command *command, const CommandLine ¶meters, bool preCommand) |
Protected Attributes | |
AZStd::unordered_map< AZStd::string, Command * > | m_registeredCommands |
AZStd::vector< CommandHistoryEntry > | m_commandHistory |
AZStd::vector< CommandManagerCallback * > | m_callbacks |
AZStd::vector< AZStd::string > | m_errors |
AZStd::vector< Command * > | m_commands |
size_t | m_maxHistoryEntries |
ptrdiff_t | m_historyIndex |
size_t | m_totalNumHistoryItems |
int | m_commandsInExecution |
The command manager. This manager has a set of registered commands (MCore::Command) that can be executed and undo-ed and redo-ed through this manager. Also it keeps a command history. It also supports the usage of command groups, which batch sets of commands as single commands inside the command history.
MCore::CommandManager::CommandManager | ( | ) |
The default constructor.
|
virtual |
The destructor.
Reimplemented in CommandSystem::CommandManager.
|
inline |
Add error message to the internal callback based error handling system.
[in] | errorLine | The error line to add to the internal error handler. |
void MCore::CommandManager::ClearHistory | ( | ) |
Clear the history.
|
protected |
Internal method to execute a command.
command | The registered command object. | |
commandLine | The commandline object. | |
outCommandResult | The return/result value of the command. | |
[in] | callFromCommandGroup | True in case the command is called from a command group. False in case the command to be called is not part of a command group and called only by itself. |
addToHistory | When set to true it is being added to the command history. This is set to false when redoing a command. |
bool MCore::CommandManager::ExecuteCommand | ( | const char * | command, |
AZStd::string & | outCommandResult, | ||
bool | addToHistory = true , |
||
Command ** | outExecutedCommand = nullptr , |
||
CommandLine * | outExecutedParamters = nullptr , |
||
bool | callFromCommandGroup = false , |
||
bool | clearErrors = true , |
||
bool | handleErrors = true |
||
) |
Execute a command.
command | The command string including all arguments. | |
outCommandResult | The return/result value of the command. | |
addToHistory | When set to true it is being added to the command history and can be undone. | |
outExecutedCommand | This will contain the pointer to the command that was executed, or nullptr when no command was excuted. Please note that the pointer that will be stored in this parameter will be invalid when the command failed to execute. | |
outExecutedParamters | This will contain the command line parameter list of the executed command. | |
[in] | callFromCommandGroup | True in case the command is called from a command group. False in case the command to be called is not part of a command group and called only by itself. |
|
protected |
Will be internally called before and after executing a command.
command | The command which will get or got executed. |
parameters | The given command parameters. |
preCommand | Execute all pre-commant callbacks in case this parameter is true, execute all post-command callbacks elsewise. |
bool MCore::CommandManager::ExecuteCommandGroup | ( | CommandGroup & | commandGroup, |
AZStd::string & | outCommandResult, | ||
bool | addToHistory = true , |
||
bool | clearErrors = true , |
||
bool | handleErrors = true |
||
) |
Execute a command group. The group will contain a set of commands inside it which are seen as one command. This is useful when you want to for example execute 10 commands, but only show these 10 commands inside the command history as one grouped command. Undoing the group will undo all commands that are part of the group..
commandGroup | The command group to execute. |
outCommandResult | The result of the group execution. This generally contains the last successful or failed command status. |
addToHistory | Set to true when you want to add this group to the history. |
|
protected |
Will be internally called before and after undoing a command.
command | The command which will get or got executed. |
parameters | The given command parameters. |
preUndo | Execute all pre-undo callbacks in case this parameter is true, execute all post-undo callbacks elsewise. |
Command* MCore::CommandManager::FindCommand | ( | const AZStd::string & | commandName | ) |
Find the command in the hash table.
commandName | The name of the command. |
CommandManagerCallback* MCore::CommandManager::GetCallback | ( | size_t | index | ) |
Get a given callback.
index | The callback number to get, which must be in range of [0..GetNumCallbacks()-1]. |
Command* MCore::CommandManager::GetCommand | ( | size_t | index | ) |
Get a given registered command.
index | The command number, which must be in range of [0..GetNumRegisteredCommands()-1]. |
Command* MCore::CommandManager::GetHistoryCommand | ( | size_t | historyIndex | ) |
Get a given command from the command history.
historyIndex | The history index number, which must be in range of [0..GetNumHistoryItems()-1]. |
const CommandLine& MCore::CommandManager::GetHistoryCommandLine | ( | size_t | historyIndex | ) | const |
Get the command line for a given history item.
historyIndex | The history index number, which must be in range of [0..GetNumHistoryItems()-1]. |
ptrdiff_t MCore::CommandManager::GetHistoryIndex | ( | ) | const |
Get the current history index. This value will be in range of [0..GetMaxHistoryItems()-1].
size_t MCore::CommandManager::GetMaxHistoryItems | ( | ) | const |
Get the maximum number of history items that the manager will remember. On default this value is 100. This means it will remember the last 100 executed commands, which can then be undo-ed and redo-ed.
size_t MCore::CommandManager::GetNumCallbacks | ( | ) | const |
Get the number of registered callbacks.
size_t MCore::CommandManager::GetNumHistoryItems | ( | ) | const |
Get the number of history items stored. This is the number of executed commands that are stored in the history right now.
size_t MCore::CommandManager::GetNumRegisteredCommands | ( | ) | const |
Get the total number of registered commands.
|
inline |
Checks if there are commands currently being executed
void MCore::CommandManager::LogCommandHistory | ( | ) |
Debug function to log the current command history.
|
protected |
Pop a command history item from the stack. After this the command cannot be un- or redone.
|
protected |
Push a command to the command history stack . This method will be automatically called by the system when a command has been called but only if it is undoable.
command | The command instance that has been created at execution time. |
parameters | The command arguments. |
|
protected |
Add the given command group to the history.
commandGroup | The command group to add to the history. |
bool MCore::CommandManager::Redo | ( | AZStd::string & | outCommandResult | ) |
Redo the last command which has been undoed.
outCommandResult | The return/result value of the command. |
void MCore::CommandManager::RegisterCallback | ( | CommandManagerCallback * | callback | ) |
Register a callback. This increases the number returned by GetNumCallbacks().
callback | The callback to add to the list of registered callbacks. |
bool MCore::CommandManager::RegisterCommand | ( | Command * | command | ) |
Register a command to the command manager. Each command has to be registered using this function before using it. You can just new a command object when calling this function. The command manager will keep track of the used memory and will destroy it automatically. E.g. MCORE_COMMANDMANAGER.RegisterCommand( new CreateBoxCommand() );.
command | The command to register. |
bool MCore::CommandManager::RegisterCommandCallback | ( | const char * | commandName, |
Command::Callback * | callback | ||
) |
Register (add) a command callback to a given command with a given name.
commandName | The non-case-sensitive name of the command where we should add this callback to. |
callback | The callback to add to the given command. |
void MCore::CommandManager::RemoveCallback | ( | CommandManagerCallback * | callback, |
bool | delFromMem = true |
||
) |
Remove a given callback from the manager.
callback | The callback to remove. |
delFromMem | Set to true when you wish to also delete the callback object from memory. |
void MCore::CommandManager::RemoveCallbacks | ( | ) |
Remove and delete all callbacks from memory. Automatically called by the destructor.
void MCore::CommandManager::RemoveCommandCallback | ( | Command::Callback * | callback, |
bool | delFromMem | ||
) |
Remove a given command callback. This automatically finds the command where this callback has been added to and removes it from that.
callback | The callback to remove. |
delFromMem | When set to true, the specified callback will be deleted from memory as well (even when not registered at any of the commands). |
void MCore::CommandManager::RemoveCommandCallback | ( | const char * | commandName, |
Command::Callback * | callback, | ||
bool | delFromMem | ||
) |
Remove a given command callback from a given command with a given name.
commandName | The non-case-sentive name of the command to remove the callback from. |
callback | The callback to remove from the command with the specified name. |
delFromMem | When set to true, the specified callback will be deleted from memory as well (even when not registered at any of the commands). |
void MCore::CommandManager::SetMaxHistoryItems | ( | size_t | maxItems | ) |
Set the maximum number of history items that the manager should remember. On default this value is 100. This means it will remember the last 100 executed commands, which can then be undo-ed and redo-ed.
maxItems | The maximum number of items to remember. |
bool MCore::CommandManager::ShowErrorReport | ( | ) |
Checks if an error occurred and calls the error handling callbacks.
bool MCore::CommandManager::Undo | ( | AZStd::string & | outCommandResult | ) |
Undo the last executed command in the command history.
outCommandResult | The return/result value of the command. |
|
protected |
The command manager callbacks.
|
protected |
The command history stack for undo/redo functionality.
|
protected |
A flat array of registered commands, for easy traversal.
|
protected |
The number of commands currently in execution.
|
protected |
List of errors that happened during command execution.
|
protected |
The command history iterator. The current position in the undo/redo history.
|
protected |
The maximum remembered commands in the command history.
|
protected |
A hash table storing the command objects for fast command object access.
|
protected |
The number of history items since the application start. This number will neither change depending on the size of the history queue nor with undo/redo.