Game Development Reference
In-Depth Information
case CID_EXIT_DESKTOP:
// exit to the desktop
break;
// etc. etc.
}
}
This is very similar to the way Windows sends messages from controls to windows
via the WM_COMMAND message, but simplified. The only problem with defining control
IDs in this manner is keeping them straight, especially if you create screen classes
that inherit from other screen classes, each with its own set of controls.
Flatten Your Screen Class Hierarchies
There
s almost no end to the religious arguments about creating new screens by
inheriting from existing screen classes. Object-oriented coding techniques make it
easy to extend one class into another, but there is a risk of confusion and error
when the new class is so different from the original that it might as well be a
completely new class. This is why it
'
s better to define functionality in terms of
interfaces and helper functions and flatten your class hierarchy into functional
nuggets. A deep inheritance tree complicates the problems of changing something
in a base class without adversely affecting many classes that inherit from it.
'
Measure Twice, Cut Once
Many game companies don
t consider UI to be a particularly complex system,
and thus it tends to be delegated to junior engineers. This is also why most UI
systems are generally very difficult to maintain. When I worked at Slipgate, we
were making an MMO game that had very hefty UI requirements, so they
assigned a very senior engineer to create a UI architecture. He created a
system called COG, which allowed people to trivially create UI elements,
piece them together, and allow the gameplay team to hook into UI events
for button presses. It
'
ve used. A single engineer was able
to prototype complex UI screens in a matter of days or even hours while the
same screen at another company might take five times as long (literally). This
just goes to show you that UI can easily be just as complex as any other
system. Make sure you think through your architecture before jumping in
there, and don
'
s the best system I
'
'
t underestimate the amount of work you
'
ll have to do.
Some games define controls in terms of text strings, assigning each control a unique
string. But there is a downside to using strings to identify controls
you have to do
multiple string compares every time a control sends a message to your string class.
You
ll learn about a more efficient and interesting solution for this problem in Chap-
ter 11,
'
'
Game Event Management.
It does make things easier to debug, but there
s
 
Search WWH ::




Custom Search