Game Development Reference
In-Depth Information
established as the last executed command. In a redo operation, the Execute method
will be applied to the next command and set it as the last one executed.
What happens when a single user action results in the execution of several
commands? In this case it is mandatory to enclose all commands in a macro
command and put only the latter in the undo/redo stack. It should be noted that
to undo a macro command, you must execute undo operations in the contained
commands in reverse order.
13.4.2 Macro Commands
In the specific case discussed in this section, we define a macro as a command
that consists of several other commands. This might be a command to change the
material of an object, which can be a composition of the two commands that set the
object's color and texture. Another frequent example are commands that perform
operations on several items at the same time, for example, moving multiple selected
objects around on the map. The composite design pattern [Gamma et al. 95] is
usefulforimplementingthesecommands(see Figure13.6 ) .
Command
*
1
com m andList
for each (command in commandList)
{
MacroCommand
Execute()
command-> Execute();
}
Figure 13.6. Macro command model.
13.4.3 Preview
The preview mechanism is used to demonstrate the effect of a command without
actually executing it. A common example is the movement of an object in a 3D
scene by dragging it with the mouse. The command is not executed until the user
stops moving the mouse, but it is helpful to simulate the movement to show the
user the result of this motion as accurately as possible.
For the preview function, it is not a good idea to generate a command in response
to every event generated by the user (in the example of moving an object around,
there may be hundreds of mouse motion events in a single movement). This would
disable the undo/redo system due to the creation of a large sequence of commands
that represent small incremental changes.
 
Search WWH ::




Custom Search