Game Development Reference
In-Depth Information
Execute com m ands
Plugin
Host Application
Execute com m ands
Plugin
Execute com m ands
Figure 13.4. Commands can be invoked between system components without restriction.
command factory: access to these factories must be centralized in a global factory
based in the host application.
Plugins should be developed with the possibility to execute commands from
other components or to load other components. Consider the case in which our
game editor has a model editor and a material editor implemented each as separate
plugins. The model editor may desire to use the functionality of the material editor
to change the material of a particular model. In such a case, however, the model
editor may need to explicitly open the material editor before issuing any commands.
The follow code shows how this is done:
Command openMatEditor;
openMatEditor =
factory.CreateCommand("OpenMaterialEditor");
//if material editor is not installed the factory
//will fail to create the command returning null
if (openMatEditor != null)
{
openMatEditor.SetParam("MATERIAL",myMaterial);
openMatEditor.Execute();
}
Macro recording and batch execution. Since the commands use a common in-
terface and are created by means of their name, it is easy to generate command
execution scripts. This can be useful during the build process of the game or to
make batch changes to the content of the game. To save a script we can use, for
example, an XML file like Listing 13.1.
With the same philosophy, we can record the history of the commands that are
running on the editor. It is sucient that every command stores its name and the
information of its parameters at the moment of its execution. Keeping this kind of
 
Search WWH ::




Custom Search