Generative Design Patterns
Generative design patterns are a programming strategy where reusable
modules are used to generate code. The reusable modules are customized to each situation by allowing the programmer to enter
a suitable value for certain parameters. In this way, the same module may be used in many
different situations. Using generative design patterns makes
programming easier and more efficient.
When programming games or missions for games, people sometimes copy and paste code fragments and change their
parameters to get an effect similar to using generative design patterns. Generative design patterns have a few advantages
over simple copy and paste.
- The reusable components are clearly encapsulated and work independently from other code, meaning you do not need to worry about context
of where the code is coming from. There is always a possibility when copying and pasting code, that the code fragment requires code somewhere else in the program to work properly.
- For each GPD, you only need to input the parameters once. The
pattern puts them in all of the appropriate places. With copy and
paste, you need to modify the code yourself, creating the possibility for error.
- Generative design patterns are easily shared. The reusable modules
are presented as distinct units that work independently. With
generative design patterns it is not necessary to understand how the code
works in order to have it do what you want, so the modules can easily be used by people other than the original creator. To reuse code via copy and paste, you first
need to search through code and find the useful pieces.
Generative design patterns make coding accessible even to people without the background or experience to do it from scratch.
Domain experts with little knowledge of programming can get involved in the
development process more directly. By understanding the purpose of each module,
and making sure the appropriate parameters can be set, the experts can more
easily communicate their needs with the programmer. The generative design patterns make it
easier for the domain experts to understand what the code is doing, which makes
it easier for them to ensure the functionality they need is being implemented.
Magnetar XSG uses generative design patterns on multiple layers, that can be
mixed in different combinations to create the world, objects, behaviours, and plot that make up
a game or simulation scenario. This approach was inspired by ScriptEase, a generative
design pattern approach to creating role-playing games developed at the
University of Alberta. ScriptEase is based on the analysis of a popular Computer Role-playing game, Bioware's
Neverwinter Nights.
With multiple layers of generative design patterns, each
layer can be made up of pieces from the layers below it. The multiple layers in this approach include:
- The ontology. The ontology is the lowest layer, and consists of a dictionary of terms, their definitions and their relationships to each other.
- The atoms are the layer directly above the ontology. Atoms are small pieces of code that check the state
of the game or simulation and make changes accordingly.
- Behavior patterns. Atoms can be composed into
behaviour patterns, that represent common behaviours. These patterns describe how an object or character will act in certain situations.
- The prototypes describe a game entity and can be customized either by setting appropriate parameters or by extending the prototype.
The prototype includes a visual representation as well as the code that describes the prototype. A specific instance of a prototype can be a parameter passed to a behaviour pattern, and each prototype may have a number of behaviour patterns that describe its default behaviour.
Magnetar XSG is developed with each of the layers described above playing a role in creating a scene or scenario. The standard
describes the structure for each of the reusable pieces in the layers as well as the scene graph that integrates all these components to describe the scene.
Each layer is described by a metagraph that defines its structure and how that structure can be extended. Following the standard makes it easy to reuse pieces from
one game or simulation project to the next. The standards compliant pieces can be reused within projects and
across different projects.