Game Development Reference
In-Depth Information
With this type of solution, each subsystem in your game would likely need this enu-
meration because each probably generates one or more of these events. In coding this
approach, you would need to have every system #include this enumeration. Then,
every time you add to it or change it, your entire game would need to be recompiled,
clearly a bad thing.
Build Times on Thief: Deadly Shadows
When I was working on Thief: Deadly Shadows at Ion Storm, we had a few
systems like this, including the event system. Each event type was defined in
a huge enumeration, and creating a new event or deleting a deprecated one
caused us to recompile everything, and I mean everything. Thief: Deadly
Shadows had nine build targets: PC Game, Xbox Game, and Editor, with
each having Debug, Profile, and Release build flavors. Even on a fast
desktop workstation, it would take us 15 minutes or more to build just one,
and building everything took more than an hour. Screams of anguish could
be heard when someone checked in one of these core header files without
sending a warning email with plenty of advance notice. The moment
someone had to get code off the Net, that person might as well go take a
prolonged break. Believe me, we didn
t want the break either because it
would just turn a 12-hour day into a 13-hour day.
'
Fortunately, there
s a better way to do this. Instead of creating a massive enumeration
in a core header file, you can create a bunch of GUIDs (globally unique identifiers)
for each event. These GUIDs are defined on the event itself so if something gets
added or removed, you only need to recompile the effected files. It ' s fast and saves
your team from the terrible monolithic enumeration that everyone has to reference.
You can create GUIDs in Visual Studio by going to the Tools menu and clicking on
Create GUID, which will bring up a dialog box with several new options. The one I
always choose is
'
Then you can press the Copy button,
which copies the GUID to your clipboard. When you paste this into your code or a
text file somewhere, you
DEFINE_GUID that(
).
'
ll get something like this:
// {6A873D78-508D-4AC0-AC79-1D73B3FF1A0A}
DEFINE_GUID(<<name>>,
0x6a873d78, 0x508d, 0x4ac0, 0xac, 0x79, 0x1d, 0x73, 0xb3, 0xff, 0x1a, 0xa);
Then grab the first number, 0x6a873d78 in this case, and use that as your 32-bit
GUID. Now you have an easy way to create as many event types as you want.
Here
'
s how to create events and data that can ride along with the event:
class IEventData
{
public:
 
Search WWH ::




Custom Search