Game Development Reference
In-Depth Information
'
you
ve never seen it, just imagine an entire case of alphabet soup laid out on a recur-
sive grid. It
'
s gross.
The two methods,
VOnRestore()
and
VOnUpdate(),
simply traverse their children
nodes and recursively call the same methods. When you inherit from
SceneNode
and create a new object, don
s
VOnRestore()
or
VOnUpdate()
if you happen to overload them. If you fail to do this, your children
nodes won
'
t forget to call the base class
'
t get these calls. The
VOnRestore()
method is meant to re-create any
programmatically created data after it has been lost. This is a similar concept to the
section on lost 2D DirectDraw surfaces.
The
VOnUpdate()
method is meant to handle animations or anything else that is
meant to be decoupled from the rendering traversal. That
'
s why it is called with the
elapsed time, measured in milliseconds. You can use the elapsed time to make sure
animations or other movements happen at a consistent speed, regardless of computer
processing power. A faster CPU should always create a smoother animation, not nec-
essarily a faster one!
The
VPreRender()
method is meant to perform any task that must occur before
the render, such as setting render states. The
VIsVisible()
method performs a vis-
ibility test. The
VRender()
method does exactly what it advertises: it renders the
object. A recursive call to
VRenderChildren()
is made to traverse the scene
graph, performing all these actions for every node. The
VPostRender()
method is
meant to perform a postrendering action, such as restoring a render state to its origi-
nal value.
The
VAddChild()
method adds a child node. You
'
ll see different implementations
of this interface class add children in different ways. No, you shouldn
'
'
t attach a node
to itself; you
ll run out of stack space in your infinitely recursive scene graph before
you know what happened.
'
When I first designed the
ISceneNode
class and the implementation class you
'
ll see
in a few pages,
SceneNode
, the first attempt, loaded the class full of virtual accessor
methods:
VGetThis()
,
VGetThat()
, and
VGetTheOtherDamnThing()
. What I
really wanted was a structure of these properties and a single virtual accessor that
would give me read-only access to the data in that structure. The structure,
Scene-
NodeProperties
, is defined as follows:
typedef unsigned int ActorId;
class SceneNodeProperties