Game Development Reference
In-Depth Information
You can take this concept a step further and separate the code that chooses which
behavior to run next. Not only can you mix and match behaviors, but you can also
mix and match the transitions between those behaviors. Any of these components
can change without affecting any other component in your system. This is exactly
what I did on Drawn to Life for the enemy AI.
Another thing that often changes is your rendering system. We
'
ve chosen to use
Direct3D in this topic because of its accessibility, but that doesn
t
use OpenGL. In a real game engine, you typically have multiple build configurations
for different platforms, each with a different renderer. That ' s exactly what we did for
The Sims Medieval. It used DirectX for the PC build and OpenGL for the Mac build.
Learning to spot the things that are likely to change is something that comes with
experience. In general, any major system you build should be as decoupled as possi-
ble from every other major system. Interfaces, factories, and other techniques are the
tools to enable you to do this.
There is an amazing book called Design Patterns: Elements of Reusable Object-
Oriented Software by Erich Gamma et al., which I mentioned previously in this chap-
ter. Many of these design patterns, such as the Observer pattern and the Strategy pat-
tern, are aimed at decoupling different components in software. I highly recommend
that you check this topic out. It
'
t mean you can
'
'
s one of those topics that should be on every pro-
grammer ' s bookshelf.
Use Streams to Initialize Objects
Any persistent object in your game should implement a method that takes a stream
as a parameter and reads the stream to initialize the object. If the game is loaded
from a file, objects can use the stream as a source of parameters. Here
'
s an example
to consider:
class AnimationPath
{
public:
AnimationPath();
Initialize (std::vector<AnimationPathPoint> const & srcPath);
Initialize (InputStream & stream);
//Of course, lots more code follows.
};
This class has a default constructor and two ways to initialize it. The first is through a
classic parameter list, in this case, a list of AnimationPathPoint s. The second
initializes the class through a stream object. This is cool because you can initialize
 
 
Search WWH ::




Custom Search