Santo)
GAME
PROGRAMMING
64 2 TeContents
FOFrEWOrd. 2. cee xi
Preface... ccc te ee eee xv
About the Cover Image ......... wee eee eee eee » XXi
Contributor BiOS .. 1... ee xxii
SECTION 1 GENERAL PROGRAMMING ........00 0000 ne eenuneunnas 1
Introduction... 0... 0002: c eee ee eee 22s d
Adam Lake, Intel Software Solutions Group
1.1 Lock-Free Algorithms .......0.0000 cee eee eee cee 5
Loby Jones, Microsoft
1.2 Utilizing Multicore Processors with OpenMP .......... weueneeea WL
Pete lsensee, Microsoft Corporation
1.3 Computer Vision in Games Using the OpenCV Library ...........: 25
Arnau Ramisa, Institut d'Investigacié en Intelligencia Artificial
Enric Vergara, Universitat Politécnica de Catalunya
Enric Martt, Universitat Auténoma de Barcelona
1.4 Geographic Grid Registration of Game Objects. .......02000 220002 O9
Roger Smith, Modelbenders, LLC
1.5 BSP Techniques. .......... ween ween wee ee tees 49
Octavian Marius Chincisan, Freelancer
1.6 Closest-String Matching Algorithm .........2 00000 ence ene 69
James Boer, ArenaNet
1.7 Using CppUnit To Implement Unit Testing ......0 002 eee eee eee 79
Blake Madden, Oleander Solutions
1.8 Fingerprinting Pre-Release Builds To Deter and Detect Piracy. ..... 97
Steve Rabin, Nintendo of America, Incorporated
1.9 Faster File Loading with Access-Based File Reordering.......... 103
David L. Koenig, Touchdown Entertainment, Incorporated
1.10 Stay in the Game: Asset Hotloading for Fast Iteration. ... . see eeee 109
Noel Llopis and Charles Nicholson, High Moon Studiosvi
SECTION 2 MATHEMATICS AND PHYSICS .......... wena oun e ee 117
Introduction .....000n eee eee eee ewe ee 119
Jim Van Verth, Red Storm Entertainment, Inc.
2.1 Floating-Point Tricks ......00 0c eee eee 121
Chris Lomont, Cybernet Systems Corporation
2.2 GPU Computation in Projective Space Using
Homogeneous Coordinates ...... 000: cece eee eee eens VOD
Vaclav Skala, University of West Bohemia
2.3 Solving Systems of Linear Equations Using the Cross Product. .... 149
Anders Hast, University of Gévle
2.4 Sequence Indexing for Game Development ..... ee ee 161
Palem GopalaKrishna, Indian Institute of Technology
2.5 Exact Buoyancy for Polyhedra.......02.0000u0eus eee eee ees 175
Erin Catto, Crystal Dynamics
2.6 Real-Time Particle-Based Fluid Simulation with
Rigid Body Interaction. .......... ween een en nen wen an ennenae 189
Takashi Amada, Sony Computer Entertainment, Inc.
SECTION 3 ARTIFICIAL INTELLIGENCE. ........000cuae
Introduction... 0... 0. eee 209
Brian Schwab, Sony Computer Entertainment of America
3.1 Applying Model-Based Decision-Making Methods to Games:
Applying the Locust Al Engine to Quake® HD... cece QI
Armand Prieditis and Mukesh Dulal, Lookahead Desicions Incorporated
3.2 Achieving Coordination with Autonomous NPCs........0000008: 223
Diego Garcés, FX Interactive
3.3 Behavior-Based Robotic Architectures for Games ...... .
Hugo Pinto and Luis Otavio Alvares
3.4 Constructing a Goal-Oriented Robot for Unreal Tournament
Using Fuzzy Sensors, Finite-State Machines, and
Extended Behavior Networks. ......000c0neennenennenen neon 245
Hugo Pinto and Luis Otavio AlvaresContents vii
EEL EEE ESTED AEE BLEED T EDEL EAE EAP AER TED NEE CARE AU AEE OSSD ASA MAPA E00 PDTC HAE DRONE DED OOOO CDS MASAI GARD RFX ETH CDOWI GON MOREE A reason ae aD Manan donee stneNMAA{RtuILonémconce
3.5 A Goal-Oriented Unreal Bot: Building a Game Agent with
Goal-Oriented Behavior and Simple Personality Using
Extended Behavior Networks. ........0000cneueunauunruneeas 259
Hugo Pinto and Luis Otavio Alvares
3.6 Short-Term Memory Modeling Using a Support Vector Machine. . . . 273
Julien Hamaide, Elsewhere Entertainment
3.7 Using the Quantified Judgment Model for Engagement Analysis . . . 283
Michael Ramsey
3.8 Designing a Multilayer, Pluggable Al Engine ....... wees 291
Sébastien Schertenleib, Swiss Federal Institute of Technology
3.9 A Fuzzy-Control Approach to Managing Scene Complexity........ 307
Gabriyel Wong and Jialiang Wang, Nanyang Technological University
SECTION 4 SCRIPTING AND DATA-DRIVEN SYSTEMS .............317
Introduction. .........: Chee eens meee 21.319
Graham Rhodes, Applied Research Associates, Incorporated
4.1 Scripting Language Survey ........0000eeeeueee ween eee 323
Diego Garcés, FX Interactive
4.2 Binding C/C++ Objects to Lua... ee ee es 341
Waldemar Celes, PUC-Rtio
Luiz Henrique de Figueiredo, IMPA
Roberto Terusalimschy, PUC-Rio
4.3 Programming Advanced Control Mechanisms with
Lua Coroutines .......00enncuee wee eee wenenaue 357
Luiz Henrique de Figueiredo, IMPA
Waldemar Celes, PUC-Rio
Roberto Ierusalimschy, PUC-Rio
4.4 Managing High-Level Script Execution Within
Multithreaded Environments.........0c0000nceuuaas senneaat Olt
Sébastien Schertenleib, Swiss Federal Institute of Technology
4.5 Exposing Actor Properties Using Nonintrusive Proxies .......... 383
Matthew Campbell and Curtiss Murphy, BMH Associates, Incorporated
4.6 Game Object Component System .........002000ees ween nnnee 393
Chris Stoy, Red Storm Entertainmentviii
Contents
pamnnssnaiesgaLuenaerueiorcARsians cn mnRLesaLnaoeanetoRi RES Cacia ESCA oR SORie ER ArRMeO MRL ORME 0 PK OOK COON CORCORAN AP ABSA A SES ABBE MMAR HEE DOD COIL OX ENCODERS Ine AAA i MALANAATA AA ARAMA SARA HE ASABE AHEAD EAMES CEA HE SELLA ADL BEE
SECTION 5 GRAPHICS. ............. wee eee 405
5.1
§.2
5.3
5.4
5.5
5.6
5.7
5.8
5.9
Introduction. .......0000nneae eee ee 407
Paul Rowan, Rho, Incorporated
Synthesis of Realistic Idle Motion for
Interactive CharacterS.....0 000 c see eee eee ees 409
Arjan Egges, Thomas Di Giacomo, and
Nadia Magnenat-Thalmann; MIRALab, University of Geneva
Spatial Partitioning Using an Adaptive Binary Tree. ..........005.5 423
Martin Fleisz
Enhanced Object Culling with (Almost) Oriented Bounding Boxes . . 437
Ben St. John, Siemens
Skin Splitting for Optimal Rendering............0000000eenuee 449
Dominic Filion
GPU Terrain Rendering .....0 000 c cece eee eee 461
Harald Vistnes
interactive Fluid Dynamics and Rendering on the GPU........... 473
Frank Luna
Fast Per-Pixel Lighting with Many Lights ...........000000008: 489
Frank Puig Placeres, University of Informatic Sciences, Cuba
Rendering Road Signs Sharply ........02000 cee eee nee »».. 501
Jorn Loviscach, University of Applied Sciences
Practical Sky Rendering for Games.........0000 cnn eeu aeuaaes 517
Aurelio Reis, Raven Software
High Dynamic Range Rendering Using
OpenGL Frame Buffer Objects..........-. wee ee 529
Allen Sherrod, Ultimate Game Programming
SECTION 6 AUDIO... . wc ec eee et OOE
6.1
Introduction 2... cece cee ees seen ee OOD
Alexander Brandon, Midway Home Entertainment
Real-Time Sound Generation from Deformable Meshes.........: 541
Marg Singer, Red Storm EntertainmentContents ix
SAR YL DONORS EHH greece RVR DOMED BE reer ar AR AO OES CENT Sob AML MEE ROAR pina ta SL ORE DEDS IL EDO br Hea MRIEPA rH Sa Ef REDD CoOL EO HOON COMED OUTER Eten
6.2 A Lightweight Generator for Real-Time Sound Effects ........... 549
Frank Luchs, Visiomedia, Ltd.
6.3 Real-Time Mixing Busses ........2 000 e eee n eee 555
James Boer, ArenaNet
6.4 Potentially Audible Sets. ..... 0.02 cc nce cence nena 561
Dominic Filion
6.5 A Cheap Doppler Effect... 1.0... 0000 cee eee ee 573
Julien Hamaide, Elsewhere Entertainment
6.6 Faking Real-Time DSP Effects. ...... 2.002002 eee enema ee 583
Robert Sparks, Radical Entertainment
SECTION 7 NETWORK AND MULTIPLAYER ........0000000nue »... 589
Introduction... . ccc cee eee 591
Scott Jacobs, Virtual Heroes
7.1 Dynamically Adaptive Streaming of 3D Data for
Animated Characters. ......0000 0c e eee een 593
Thomas Di Giacomo, HyungSeok Kim, Stephane Garchery,
and Nadia Magnenat-Thalmann, MIRALab, C.U.1.; University of Geneva, and
Chris Joslin, School of Information Technology, Carleton University, Ottawa
7.2 Complex Systems-Based High-Level Architecture for
Massively Multiplayer Games ......-..2 20000 nsec eee 607
Viknashvaran Narayanasamy, Kok-Wai Wong, and Chun Che Fung,
Murdoch University
7.3 Generating Globally Unique Identifiers for Game Objects......... 623
Yongha Kim, Nexon Corporation
7.4 Massively Multiplayer Online Prototype Utilizing
Second Life for Game Concept Prototyping ........00000n0nuee 629
Peter A. Smith, University of Central Florida
7.5 Reliable Peer-to-Peer Gaming Connections Penetrating NAT...... 641
Larry Shi
About the CD-ROM ... ccc eee 651The Importance of Tool
Foreword
Mark DeLoura
[email protected]
elcome to Game Programming Gems 6. This sixth volume of the Game Program-
ming Gems series has been explicitly designed with your current challenges in
mind. As this series has grown, so have the demands on game programmers. With
team sizes constantly expanding, developers are finding themselves pushed to become
increasingly specialized. This makes it important to have cutting-edge material in
your specialization at your fingertips, as well as resources at your disposal that you can
call upon in case you need to work outside your area of expertise. I hope that in these
instances you will turn to Game Programming Gems.
Since we're at the sixth book in the series, let’s take a moment to think about what
has come before. Examining the material in the previous Gems volumes gives us an
interesting historical perspective; the issues that were most pressing during the cre-
ation of the original Gems volume in the year 2000 now seem substantially less trou-
blesome. Implementing advanced shader effects, integrating real-time physics into
game design, synchronizing multiplayer networked games, and finding artist- and
designer-friendly scripting languages are all prominent issues that we now need to
confront.
But the biggest issue facing all of us now is cost. The next generation of machines is
upon us—PlayStation® 3, Xbox® 360, Nintendo® Revolution®, multicore PCs—and
with the new capabilities come some new challenges. Our players will expect higher-
fidelity models and animations, fancier physics and graphics effects, and more-intelligent
Al. In order to create these, we'll build up our teams and lengthen our schedules, and
ultimately spend a lot more money. If we can’t increase the price of games (please, no!)
or increase our market size (please, yes!) we'll be more pressed than ever to deliver com-
pelling experiences on time and on a budget. Crunch time, here we come!
Making the technology we develop easily accessible to the rest of our team has
become one of the most important things we do as game programmers. After all,
what’ the use of having that fancy shader that we stayed up all night writing if our
artists cant figure out how to use it? While it’s true that our team sizes are growing
xix ef Oreword
quickly, most of the growth comes from the increasing number of artists. So if we can
make their lives easier by making some simple tools, our games will not only likely
wind up looking better, they will also be produced more quickly and inexpensively as
well—all good things!
Fortunately in this platform-transition period, reusing tools is much easier than
reusing engine technology. The front-end interface of a tool can remain relatively
unchanged, while the underpinnings and output of the tool are altered to suit the new
target. This makes tools one of the easiest things to amortize the cost of, since they
can largely be reused for multiple titles or multiple teams over time.
Having tools available at the beginning of the development process for pre-
production and early production work is very helpful, and practically de rigueur now
in order to save time on the development schedule. Unfortunately at this time, we're
seeing a reduction in the number of tools available on the middleware market. So if
you don’t already have your own tools, what should you do? Increasingly, studios are
banding together into larger development groups or being bought out by publishers,
and for them, the logical choice is the creation of a central technology group.
Collaboration
fhe ia RR a eee aah Nar hoe i SAGO 20 aot eA Bria a Ror Seis a ea SMR ot aie er pate a lena Miao aretha apn beth porate ome ee eo coe A i ee eee
The thought of trying to convince many studios to work together on sharing com-
mon technology and to rely on others is not something most of us relish. But with our
costs spiraling upward, distributing the development cost of a piece of technology
across multiple platforms and titles is a smart decision. Frankly, some of the larger
projects recently have become so expensive that they've gone from amortizing their
cost across multiple platforms to amortizing them across multiple future sequels! The
development costs are so expensive, this might be the only way they'll ever turn a
profit. How else could one justify these huge expenditures, if not by seeking to estab-
lish a strong brand and then reusing the tools and technology across multiple games
in a franchise? It seems crazy, but with a large risk comes the possibility of a large
reward.
Another kind of collaboration that is increasingly useful involves globalizing your
development. By turning to studios in regions that haven't previously been consid-
ered—such as Eastern Europe, China, and India—publishers and developers in
Europe, North America, and Japan have discovered new ways to keep their costs
down. Producers are learning to pull together resources for a game from locations
around the globe, and having solid tools to rely on becomes extremely important in
this scenario.
Parallelization
SRS: a BEES RSI Ba HSS NA ES SA EH CS BRE RS GB SY CRATERS MERTENS an SEU te OR aa Hae eR aR tt A re Hae aa eg Be Ee er RS See ere aA
As console developers move onto the next series of machines, they're facing a new
challenge: parallelizing their game engine. PC developers have a little more time
before they're pushed in this direction, as well. The upcoming multicore systemsForeword xiii
seontcceinestsatieetitHiiag engocnatoo katt se PTH OT ROI OMS OOH CEE HOES ELH ze ARASH ELENLDOACERESE ENDED! OSE crt ony nen A ACO HR ya ah SUNCOM GOIN nl LO AK RCRD Pr co RCO RAPE ne ARCO CK GOIN PRED DPR ol END GRO NCONOO EPROP i HTNDA UBC UDSUO EC it ROE OHO RN ROE either HEAD
require serious study and creative new techniques in order to be fully taken advantage
of. While we've all gotten used to some parallelism (e.g., between the CPU and
GPU), these new machines are forcing us to think in new ways. How will we deal
with splitting our engine into many pieces that are easily parallelizable? Will we be
able to rely on compilers and other tools that make programming these multicore
machines easier, or will we have to create new tricks and techniques for maximizing
performance on parallel architectures, ourselves? It certainly won't be a boring time
for expert programmers.
One interesting side effect to the increasing complexity of dealing with the hard-
ware is a bifurcation of programming roles at larger development houses. Many teams
now have dedicated, platform-specific programmers who deal with interfacing the
game engine to the hardware, while the majority of their programmers write platform-
independent code. This never works quite as cleanly as it sounds, and with the differ-
ences between the various platforms, there’s definitely a lot of job security for the
low-level coders. But ultimately, this is yet another way costs can be kept down, since
some of the high-level programmers can then be less experienced and therefore less
expensive!
Acknowledgments
The Gems series provides an interesting glimpse into the recent evolution of technol-
ogy in the games industry. There are other resources that address technical issues, such
as Game Developer magazine, gamasutra.com, and the Journal of Game Development,
but none of them cover as much material, and that as thoroughly. Thanks to all of the
authors and editors who have contributed so much of their time and energy to the
series. If you haven't yet contributed your unique perspective to Gems, please consider
writing down some of your experiences to share in the future!
Finally, many thanks to Michael Dickheiser for being such a professional and
crafting Gems 6 with his tireless persistence. I think you'll find that Mike’s unique per-
spective has created a very valuable volume, and I hope that it finds a place of honor
on your bookshelf!Preface
Mike Dickheiser,
Applied Research Associates, Inc.
[email protected]
his series is no longer for game developers. Or rather, it’s no longer just for game
developers. The past several years have seen a rise in the related industries of
Game-Based Learning, Edutainment, and other “serious games.” Admittedly, this is
nothing new, and the buzz surrounding these developments has been steadily growing
ever louder. However, the activity in the last year or so must be described as nothing
less than an invasion.
Discovered
snipes eee EER ea rere une onaon on
Computer game engines and tools are drawing attention on a scale that probably
escapes most game developers too busy to look up from their coffee-stained key-
boards. As someone who has recently left the industry to explore the other side, I can
vouch for the fact that many, many eyes are looking eagerly at what this industry has
produced. New companies are sprouting up everywhere like mushrooms after the
rain. Focused entirely on the use of game technology for the creation of commercial
and military training environments and simulations, they are coming en masse to
claim their stake in the New World.
But it’s not just industry that’s moving in. The academic world is paying greater
attention to our efforts as well. ’m not talking about computer game schools and
courses—those are exciting developments that deserve their own discussion. I’m talk-
ing about the use of licensed game technology in extremely sophisticated, cutting-edge
research. A brief inspection of the activities in progress at many major universities
will reveal the use of our best engines as out-of-the-box tools for exploring human-
computer interaction, cognitive modeling, intelligent agents, interactive narrative,
auditory pathology, motor skill therapy, human information processing... the list
goes on and on.
XV