Package com.j3d.engine.interact.macros
Class MacroRunner
java.lang.Object
com.j3d.engine.interact.macros.MacroRunner
- All Implemented Interfaces:
EventListener
A single-instantiated class with the purpose of running a single
Macro with many responsibilities
A typical flow is:
- Read one macro off the queue
- Execute it
- Repeat
Macro with an instruction type of InstructionType.COMMAND_EXEC, the executed command
might be stateful (implement SemiStatefulCommand), meaning it may have not finished synchronously. In that case the
order is as follows:
- Read one macro off the queue
- Execute it
-
Check if it was a command and it is stateful
-
If yes : Exit early and instead only continue if we receive the
EventType.STATEFUL_COMMAND_COMPLETEDevent fromCommandswhich denotes the command has completed, then repeat. - If no : Repeat as normal
-
If yes : Exit early and instead only continue if we receive the
This class can be accessed via MacroUtils however should only be sued by MacroCmd
(specifically its recording subcommand RunCmd)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ArrayDeque<MacroLine> The queue of instructionsprivate booleanWhether the macro should expect aEventType.STATEFUL_COMMAND_COMPLETEDevent to proceed execution.private SafeJLabelThe loglabel forRunCmdcallback errorsprivate MacroThe current macroprivate booleanWhether this macro is running or not -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcameraLine(String line) Parses and applies the camera movement. both position and rotationvoidclean()Cleans up all state to ensurerun(SafeJLabel, String)can be called for a new macro.private booleancommandLine(String line) Execute a given command-line by stealing what the command parser itself thinks the parsed arguments would be.booleanWhether the macro runner is itself running a macro or not<K> voidonEvent(EventType event, EventPayload<K> properties) Handles the event stuff of the macro.private voidpoll()Retrieves the head of the instruction set and attempts to execute it.booleanrun(SafeJLabel logLabel, String name) Attempts to run a given macro by name.private voidselectLine(String line) Parses and applies the selection
-
Field Details
-
macro
The current macro -
logLabel
The loglabel forRunCmdcallback errors -
deque
The queue of instructions -
running
private boolean runningWhether this macro is running or not -
expectEvent
private boolean expectEventWhether the macro should expect aEventType.STATEFUL_COMMAND_COMPLETEDevent to proceed execution.
-
-
Constructor Details
-
MacroRunner
MacroRunner()Package-private default constructor (OnlyMacroUtilscan instantiate it)
-
-
Method Details
-
run
Attempts to run a given macro by name. This serves as the start of running a macro and will run ther entire macro to completion.- Parameters:
logLabel- The log label for error purposesname- The name of the macro to run- Returns:
- boolean indicating whether the macro started running successfully.
-
clean
public void clean()Cleans up all state to ensurerun(SafeJLabel, String)can be called for a new macro. -
poll
private void poll()Retrieves the head of the instruction set and attempts to execute it. -
onEvent
Handles the event stuff of the macro. Specifically handlesEventType.STATEFUL_COMMAND_COMPLETEDonly ifexpectEventistrue- Specified by:
onEventin interfaceEventListener- Type Parameters:
K- The event emitter. In this case it would beCommands- Parameters:
event- The type of eventproperties- The given event payload
-
commandLine
Execute a given command-line by stealing what the command parser itself thinks the parsed arguments would be.- Parameters:
line- The input line- Returns:
- true indicating that the next macro instruction invocation can be polled via
poll()otherwise false indicating thatexpectEventis now true hence the next invocation will only happen once the event has been emitted. - See Also:
-
selectLine
Parses and applies the selection- Parameters:
line- The line input- See Also:
-
cameraLine
Parses and applies the camera movement. both position and rotation- Parameters:
line- the line- See Also:
-
isRunning
public boolean isRunning()Whether the macro runner is itself running a macro or not- Returns:
- true if it's running, false otherwise
-