Game Engine Architecture

(Ben Green) #1
727

// Construct vehicle-specific components.
m_pChassis = new Chassis(*this,
*m_pAnimController);
m_pEngine = new Engine(*this);

}

~Vehicle()
{
// Only need to destroy vehicle-specific
// components, as GameObject cleans up the
// standard components for us.
delete m_pChassis;
delete m_pEngine;
}
};

14.2.1.5. Generic Components


Another more-fl exible (but also trickier to implement) alternative is to provide
the root game object class with a generic linked list of components. The com-
ponents in such a design usually all derive from a common base class—this
allows us to iterate over the linked list and perform polymorphic operations,
such as asking each component what type it is or passing an event to each
component in turn for possible handling. This design allows the root game
object class to be largely oblivious to the component types that are available
and thereby permits new types of components to be created without modify-
ing the game object class in many cases. It also allows a particular game object
to contain an arbitrary number of instances of each type of component. (The


GameObject

Transform

MeshInstance

AnimationController
RigidBody

+GetType()
+IsType()
+ReceiveEvent()
+Update()

Component

1*

Asterisk indicates zero
or more instances
(e.g., linked list).

Figure 14.9. A linked list of components can provide fl exibility by allowing the hub game ob-
ject to be unaware of the details of any particular component.


14.2. Runtime Object Model Architectures

Free download pdf