Game Programming Gems 7
Total Page:16
File Type:pdf, Size:1020Kb
Game Programming Gems 7 Edited by Scott Jacobs Charles River Media A part of Course Technology, Cengage Learning Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States Publisher and General Manager, © 2008 Course Technology, a part of Cengage Learning. Course Technology PTR: Stacy L. Hiquet Associate Director of Marketing: ALL RIGHTS RESERVED. No part of this work covered by the copyright Sarah Panella herein may be reproduced, transmitted, stored, or used in any form or by any means graphic, electronic, or mechanical, including but not limited to Heather Manager of Editorial Services: photocopying, recording, scanning, digitizing, taping, Web distribution, Talbot information networks, or information storage and retrieval systems, except Marketing Manager: Jordan Casey as permitted under Section 107 or 108 of the 1976 United States Copyright Senior Acquisitions Editor: Emi Smith Act, without the prior written permission of the publisher. Project/Copy Editor: Kezia Endsley CRM Editorial Services Coordinator: Jen Blaney For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 Interior Layout Tech: Judith Littlefield Cover Designer: Tyler Creative Services For permission to use material from this text or product, CD-ROM Producer: Brandon Penticuff submit all requests online at cengage.com/permissions Further permissions questions can be emailed to Valerie Haynes Perry Indexer: [email protected] Proofreader: Sue Boshers Library of Congress Control Number: 2007939358 ISBN-13: 978-1-58450-527-3 ISBN-10: 1-58450-527-3 eISBN-10: 1-30527-676-0 Course Technology 25 Thomson Place Boston, MA 02210 USA Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: international.cengage.com/region Cengage Learning products are represented in Canada by Nelson Education, Ltd. For your lifelong learning solutions, visit courseptr.com Visit our corporate website at cengage.com Printed in the United States of America 1 2 3 4 5 6 7 11 10 09 08 Contents Preface . ix About the Cover Image . xiii Acknowledgments . xv Contributor Bios . xvii SECTION 1 GENERAL PROGRAMMING . 1 Introduction . 3 Adam Lake, Graphics Software Architect 1.1 Efficient Cache Replacement Using the Age and Cost Metrics. 5 Colt “MainRoach” McAnlis, Microsoft Ensemble Studios 1.2 High Performance Heap Allocator . 15 Dimitar Lazarov, Luxoflux 1.3 Optical Flow for Video Games Played with Webcams . 25 Arnau Ramisa, Institut d’Investigació, en Intelligència Artificial Enric Vergara, GeoVirtual Enric Martí, Universitat Autónoma de Barcelona 1.4 Design and Implementation of a Multi-Platform Threading Engine . 35 Michael Ramsey 1.5 For Bees and Gamers: How to Handle Hexagonal Tiles . 47 Thomas Jahn, King Art Jörn Loviscach, Hochschule Bremen 1.6 A Sketch-Based Interface to Real-Time Strategy Games Based on a Cellular Automaton . 59 Carlos A. Dietrich, Luciana P. Nedel, João L. D. Comba 1.7 Foot Navigation Technique for First-Person Shooting Games. 69 Marcus Aurelius C. Farias, Daniela G. Trevisan, Luciana P. Nedel 1.8 Deferred Function Call Invocation System . 81 Mark Jawad, Nintendo of America Inc. 1.9 Multithread Job and Dependency System . 87 Julien Hamaide iii iv Contents 1.10 Advanced Debugging Techniques . 97 Martin Fleisz SECTION 2 MATH AND PHYSICS . 107 Introduction . 109 Graham Rhodes, Applied Research Associates, Inc. 2.1 Random Number Generation . 113 Chris Lomont 2.2 Fast Generic Ray Queries for Games. 127 Jacco Bikker, IGAD/NHTV University of Applied Sciences—Breda, The Netherlands 2.3 Fast Rigid-Body Collision Detection Using Farthest Feature Maps . 143 Rahul Sathe, Advanced Visual Computing, SSG, Intel Corp. Dillon Sharlet, University of Colorado at Boulder 2.4 Using Projective Space to Improve Precision of Geometric Computations . 153 Krzysztof Kluczek, Gda´nsk University of Technology 2.5 XenoCollide: Complex Collision Made Simple . 165 Gary Snethen, Crystal Dynamics 2.6 Efficient Collision Detection Using Transformation Semantics. 179 José Gilvan Rodrigues Maia, UFC Creto Augusto Vidal, UFC Joaquim Bento Cavalcante-Neto, UFC 2.7 Trigonometric Splines . 191 Tony Barrera, Barrera Kristiansen AB Anders Hast, Creative Media Lab, University of Gävle Ewert Bengtsson, Centre For Image Analysis, Uppsala University 2.8 Using Gaussian Randomness to Realistically Vary Projectile Paths . 199 Steve Rabin, Nintendo of America Inc. SECTION 3 AI . 205 Introduction . 207 Brian Schwab 3.1 Creating Interesting Agents with Behavior Cloning. 209 John Harger Nathan Fabian Contents v 3.2 Designing a Realistic and Unified Agent-Sensing Model. 217 Steve Rabin, Nintendo of America Inc. Michael Delp, WXP Inc. 3.3 Managing AI Algorithmic Complexity: Generic Programming Approach . 229 Iskander Umarov Anatoli Beliaev 3.4 All About Attitude: Building Blocks for Opinion, Reputation, and NPC Personalities . 249 Michael F. Lynch, Ph.D., Rensselaer Polytechnic Institute, Troy, NY 3.5 Understanding Intelligence in Games Using Player Traces and Interactive Player Graphs . 265 G. Michael Youngblood, UNC Charlotte Priyesh N. Dixit, UNC Charlotte 3.6 Goal-Oriented Plan Merging . 281 Michael Dawe 3.7 Beyond A*: IDA* and Fringe Search . 289 Robert Kirk DeLisle SECTION 4 AUDIO . 295 Introduction . 297 Alexander Brandon 4.1 Audio Signal Processing Using Programmable Graphics Hardware . 299 Mark France 4.2 MultiStream—The Art of Writing a Next-Gen Audio Engine. 305 Jason Page, Sony Computer Entertainment, Europe 4.3 Listen Carefully, You Probably Won’t Hear This Again . 321 Stephan Schütze 4.4 Real-Time Audio Effects Applied . 331 Ken Noland 4.5 Context-Driven, Layered Mixing . 341 Robert Sparks vi Contents SECTION 5 GRAPHICS. 349 Introduction . 351 Timothy E. Roden, Angelo State University 5.1 Advanced Particle Deposition . 353 Jeremy Hayes, Intel Corporation 5.2 Reducing Cumulative Errors in Skeletal Animations . 365 Bill Budge, Sony Entertainment of America 5.3 An Alternative Model for Shading of Diffuse Light for Rough Materials. 373 Tony Barrera, Barrera Kristiansen AB Anders Hast, Creative Media Lab, University of Gävle Ewert Bengtsson, Centre For Image Analysis, Uppsala University 5.4 High-Performance Subdivision Surfaces . 381 Chris Lomont 5.5 Animating Relief Impostors Using Radial Basis Functions Textures . 401 Vitor Fernando Pamplona, Instituto de Informática: UFRGS Manuel M. Oliveira, Instituto de Informática: UFRGS Luciana Porcher Nedel, Instituto de Informática: UFRGS 5.6 Clipmapping on SM1.1 and Higher . 413 Ben Garney 5.7 An Advanced Decal System . 423 Joris Mans Dmitry Andreev 5.8 Mapping Large Textures for Outdoor Terrain Rendering. 435 Antonio Seoane, Javier Taibo, Luis Hernández, and Alberto Jaspe, VideaLAB, University of La Coruña 5.9 Art-Based Rendering with Graftal Imposters. 447 Joshua A. Doss, Advanced Visual Computing, Intel Corporation 5.10 Cheap Talk: Dynamic Real-Time Lipsync. 455 Timothy E. Roden, Angelo State University SECTION 6 NETWORKING AND MULTIPLAYER . 463 Introduction . 465 Diana Stelmack Contents vii 6.1 High-Level Abstraction of Game World Synchronization . 467 Hyun-jik Baeb 6.2 Authentication for Online Games. 481 Jon Watte 6.3 Game Network Debugging with Smart Packet Sniffers . 491 David L. Koenig, The Whole Experience, Inc. SECTION 7 SCRIPTING AND DATA-DRIVEN SYSTEMS . 499 Introduction . 501 Scott Jacobs 7.1 Automatic Lua Binding System . 503 Julien Hamaide 7.2 Serializing C++ Objects Into a Database Using Introspection . 517 Joris Mans 7.3 Dataports . 535 Martin Linklater 7.4 Support Your Local Artist: Adding Shaders to Your Engine. 541 Curtiss Murphy, Alion Science and Technology 7.5 Dance with Python’s AST. 555 Zou Guangxian About the CD-ROM . 561 Index . 563 This page intentionally left blank Preface ix volumes of Game Programming Gems have preceded the edition now in your Shands. Useful, practical ideas and techniques have spilled out of each and every one of them. Referred to in online discussions, contemplated by inquisitive readers, and consulted by both amateur and professional game developers, I believe the previ- ous editions have contributed toward making the games we all play more innovative, entertaining, and satisfying. Significant efforts have been made so that this 7th volume continues this tradition. Passion for Game Development Game development is a fantastic endeavor of which to be a part. It can be a true mer- itocracy allowing passion and talent to shine. Degrees and experience can help get you in the door, but it often comes down to results. Is your code maintainable? Does its performance meet or exceed targets? Are the visuals and audio compelling? Is the gameplay fun? The challenge of excelling in these areas certainly contributes to the excitement of game development and I imagine is one of the motivations that inspired the authors of the following gems to share their ideas and experiences. I hope the same desires to excel have brought you to this book, as the intention of this volume and indeed the entire series is to provide tools and inspiration to do so. There are not many industries where passion for the work runs so high that work- ing professionals gather together with interested amateurs for weekend “jams” to do almost exactly what they just spent the previous five days doing. Maybe some of the lumberjack competitions I’ve seen on TV come close. But how many