1. Trang chủ
  2. » Công Nghệ Thông Tin

Game programming tricks of the trade

1K 53 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 1.044
Dung lượng 10,4 MB

Nội dung

TeamLRN TeamLRN Game Programming Tricks of the Trade TeamLRN This page intentionally left blank TeamLRN Game Programming Tricks of the Trade Lorenzo D Phillips Jr., Editor André LaMothe, Series Editor TeamLRN © 2002 by Premier Press, a division of Course Technology All rights reserved No part of this book may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system without written permission from Premier Press, except for the inclusion of brief quotations in a review Premier Press, Inc is a registered trademark of Premier Press, Inc The Premier Press logo and related trade dress are trademarks of Premier Press, Inc and may not be used without written permission All other trademarks are the property of their respective owners Publisher: Stacy L Hiquet Marketing Manager: Heather Hurley Managing Editor: Sandy Doell Acquisitions Editor: Emi Smith Project Editor: Argosy Publishing Editorial Assistants: Margaret Bauer and Elizabeth Barrett Marketing Coordinator: Kelly Poffenbarger Technical Reviewer: André LaMothe Interior Layout: Argosy Publishing Cover Design: Mike Tanamachi CD-ROM Producer: Carson McGuire All trademarks are the property of their respective owners Important: Premier Press cannot provide software support Please contact the appropriate software manufacturer’s technical support line or Web site for assistance Premier Press and the author have attempted throughout this book to distinguish proprietary trademarks from descriptive terms by following the capitalization style used by the manufacturer Information contained in this book has been obtained by Premier Press from sources believed to be reliable However, because of the possibility of human or mechanical error by our sources, Premier Press, or others, the Publisher does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from use of such information Readers should be particularly aware of the fact that the Internet is an everchanging entity Some facts may have changed since this book went to press ISBN: 1-931841-69-1 Library of Congress Catalog Card Number: 2001099848 Printed in the United States of America 02 03 04 05 BA 10 Premier Press, a division of Course Technology 2645 Erie Avenue, Suite 41 Cincinnati, Ohio 45208 TeamLRN I dedicate this book to Sayun, Lorenzo IV, Tylen, and to the rest of my other family and friends —Lorenzo D Phillips, Jr TeamLRN Foreword I started programming games over 25 years ago, and although I have been on both sides of the business, that is, the development side and the business side, I can say wholeheartedly, I much prefer making games to selling them! The game business is like magic to me Although, I am practically as old as Yoda compared to many of the new young game programmers, all these years have clarified in my mind that I simply love making and playing games Video games are the most impressive artistic accomplishments of our generation They are the fusion of science, art, sound, music, and prose And the cool thing has been watching them grow from nothing to photo-real simulations that have you blinking your eyes saying, “that looks real!” I remember the very first game that I played—Pong Shortly after, I played Space War in an arcade in Oak Ridge Mall, San Jose, CA I was amazed by these games I couldn’t believe my eyes; it was like magic, but better, since it was real It was real, and I could learn how to it So I decided that I would spend my life learning how to it, and I have pretty much done that In my travels, I have met the most interesting people you can imagine, from Bill Gates to Steve Wozniak I had lunch with the guy who invented Defender, and sat in a dark room and talked about DOOM with John Carmack I can say without a doubt there’s nothing in the world I would rather And now with the turn of the century behind us, it’s up to you, the next generation of game developers, to take games to the places that we all dream about I admit I would much rather make games than write books, but writing books is much more constructive and more meaningful to me, personally, than writing games However, I am eager to start creating games as I did in the ’80s and early ’90s But, for now, I still have a few tricks up my sleeve, and this book is one of them When I first came up with the idea for a compilation book, the first comment to me was “the Game Programming Gems series is doing well, and in fact, you are one of the co-authors!” True, but this book is completely different Personally, I have never gotten that much out of books that have small 1- to 5-page articles I believe that a compilation book needs to have coherent and complete chapters wherein explain a topic to a point that the reader really learns how to it So, my goal was to have a TeamLRN Foreword compilation book with hefty 20- to 50-page chapters that are complete, more indepth, and written in tutorial style Additionally, I wanted a cohesive look and feel to them With all that said, this book hits the mark It’s the first in our series of compilation books, but I think that it more than delivers its weight in Pentiums There are some really interesting subjects covered in this book from advanced mathematics to scripting, as well as topics like OpenGL, 2D, Skyboxes, Optimizations techniques, Assembly Language, and so on Each topic is a complete treatise on the subject, not just introductions or little blurbs that leave you wondering Of course, the authors are to thank for the content, but Lorenzo Phillips, the managing editor of the book, is to thank for making this idea a reality If you’re reading this book and have worked on any kind of engineering job in your life, you will appreciate the incredible complexity of getting people to their jobs on time Now, try getting 15 to 20 people to all their jobs on time and it with consistency—that’s a miracle Lorenzo is really the person who I feel should get the most “props”—without his determination and hard work, this book would just be another idea and would never have come to fruition Lastly, as someone with experience in the trenches, and now that I have your attention, I would like to leave you with some real advice about making games—or making anything for that matter This stuff is hard—really hard If you are serious about it, then, as I have said many times, forget about having fun, forget about vacations, forget about that cute blonde next door—it’s not going to happen (especially the cute blonde) You simply don’t have time for anything, but work, work, and work Talk is cheap; don’t waste your time on web boards describing your newest game, engine, technology, whatever—spend your time making it! Remember, the few short moments of free time we have fade away all too quickly, and reality sets in All those things you wanted to do, thought you would do, never get done So while you have the chance, everything you can and finish it Whatever it is André LaMothe “Surrounded by 14 computers in his laboratory and one of them is getting impatient!” TeamLRN vii Acknowledgments Wow, my first book project is finally complete! There are so many people to thank that I hope I don’t forget anyone, but please know that if I forgot you, it was not intentional First and foremost, I have to thank my mother, Novella Phillips, for her guidance, love, and support and for keeping me out of harm’s way all these years I love you, Mom I’d like to thank my wife, Sayun Phillips, for her love, her support, and for growing with me over the years I thank you for making sure that I ate during those long stretches of no sleep and for the times when we just chilled out and played Tetris against each other I love you, babe I’d like to thank my sister, Sharnell Phillips, for being the greatest big sister a little brother could ever ask for I must thank the little people in my life (that is, the kids), starting with Lorenzo IV and Tylen, my two sons, for their unconditional love, Jordan and Shane for the endless hours of game play on the PCs and consoles, and Tessa for all of the laughter she provides on a daily basis To round out the family acknowledgements, I’d like to thank Joe and Kurt (my brothers-in-law), Su (my sister-in-law), and Myong (my mother-in-law), for being the best in-laws a man could hope for when two families are joined by marriage I have to thank my man André LaMothe for getting me involved in the game industry in the way I have always envisioned, for introducing me to book writing, for picking me to grow businesses with, and for simply being a great friend I’d like to thank Emi Smith and Morgan Halstead for putting up with me and my authors and for being such nice people to work with Emi, you have also grown into a good friend, and I know I still owe you a glass of wine –SMILE- I have to thank all of the authors because without them this book would not have been possible Thanks to all of you for your hard work and dedication to make the project a reality I hope the project has been enjoyable for each of you, and I would love to work with you all on future book projects Finally, I would like to thank all of the gamers around the world for sharing my love and passion for creating and playing games —Lorenzo D Phillips Jr TeamLRN 1002 Index info header, 255 loading, 254–259 pixel bits, 255 stride, 257 Block comments, 447 Booch, Grady, 20 bool, converting int to, 470 Boolean data type, 444–445 Boundary collision detection, 274 Bounding box collision See Rectangular area collision detection boundsCheck(), 272 Branches, 28 Branch instructions, 357–362, 424–425 Breakpoints, 930 Brute force, 150–152 Build and build numbers, 32–33 Bytecode, 339 byteSwap, 123 C CalculateFrustum(), 515–516, 528–529 Callback, 447 CallHost, 426, 429 Call stack, 446 canMove(), 270 CApplication, 56–58, 61–62, 65–68 Casting, 961–964 Catching performance data, 482–484 Category See Package diagrams CByteBlock, 477, 482 CDebug, 497 CD-ROM, contents of, 998–999 Celestial bodies, 673 CEventHandler, 58–60, 61, 62–63, 68–75 Change Control Board (CCB), Change Request (CR), CheckExtension(), 288 CheckLook(), 197, 198–199 Child trapping, 113 Circular buffers, 229, 240 Class definition, 98–100 Class diagrams, 23–25 Pong example, 38, 42–43 TeamLRN updating, 42–43 Class interaction diagrams (CIDs), 43–44 Clipper objects, 262 CLoadableObject, 476 closeGraphicSystem, 129, 135 CloseHandle, 460, 470 Clouds, 673 CMessageHandler, 60–63, 64–65, 96–97 COctree, 494–497 Code, stepping through, 932 CoInitialize(), 244 Collaboration diagrams, 26 Collision detection, 174 boundary, 274 rectangular area, 274–275 with sprites, 273–275 Color, OpenGL, 292–293 Comments, 338 block, 447 Commercial off-the-shelf (COTS) products, 13 Communication breakdowns, 17 Compilation See Compilers/compilation Compiled vertex arrays (CVAs), 296 Compilers/compilation branch instructions, 357–362 dealing with different, 123–124 instruction stream, 340, 341–344 label declarations, 357–362 label table, 340, 358–362 logo and usage information, printing, 374–377 memory references, 350–357 overview of, 340 program structure of compiler, 373–377 reasons for, 338–340 stacking, 352 string tables, 340, 344–350 summary of, 362–365 symbol table, 340, 352, 353–357 CompileSourceScript(), 377 Complex number theory addition/subtraction, 594–595 additive identity, 595 additive inverse, 595 defined, 592–594 Index division, 596–597 hyper, 599–607 multiplication, 595–596 multiplicative inverse, 597 norm of, 599 scalar multiplication/division, 594 as vectors, 598 Component assembly model, 11 Conceptual perspective, 24 Constants, 861 const_interator, 560 Constraints, 25 Constructor, 65–66 Constructors, widget, 94–95, 104–105 Continuous-level-of-detail (CLOD) algorithms, 166–167 Copy(), 560–561 C++, 172, 934 dynamic memory allocation, 939–942 exception handling, 950–959 inline functions, 935–936 keywords, 986 namespaces, 936–938 polymorphism and pure virtual functions, 942–950 runtime type identification, 962–964 style casting, 959–962 templates, 964–969 CProducerConsumerQueue, 471 CPropBags, 539–541, 543, 545 See also XML property bags CPropItem, 543 CPropString, 543, 545, 558–559 CQuadtree(), 632–633 CQuadtreeNode(), 634–636 CreateFile, 482 Create_From_SFP, 716–721 CreatNewNode(), 504, 505 CreateNode(), 496, 499–506, 510 CreateSemaphore, 469 CreateSoundBuffer, 230–231, 239–241 CreateThread, 458–459 CreateWindowClass, 69 Creation control flags, 230–231 CResourceLoader, 475–479 TeamLRN 1003 CResourceLoaderTask, 476, 477–478 Critical sections, 464–466 Cross-platform code abstraction layer, 126–135 derive layer, 135–137 planning for, 121–122 problems between platforms, 122–124 programming for multiple platforms, 124–126 why develop, 120–121 CSoundWAV, 235 C-style I/O, 147 CTERRAIN, 145–147 CTestApplication, 75–76, 77–78 CTestEventHandler, 76–77, 78–79, 113–114 CTestWidget, 114–117 CubeInFrustum(), 528 Cube maps, 668 Cubes, octree, 488 CWidget, 89 See also Widget(s) class definition, 98–100 implementation, 100–113 CWidget:: Display, 104, 106–107 HandleEvent, 104, 108–113 OnRedraw, 95, 104, 106 D Data chunk, 220 DBLT_KEYSRCOVERRIDE, 263–264 DDBLTFX, 263–264 DDBLT_WAIT, 263–264 DD_Draw_Text, 714–715 DD_Get_RGB_Format, 711–713 DD_Init, 706–710 ddsCaps, 261 DDSCAPS_SYSTEMMEMORY, 261 DDSCAPS_VIDEOMEMORY, 261 DD_Select_Font(), 886–887 DDSURFSCEDESC, 261 DD_UnSelect_Font(), 887–888 Debugging DevStudio, 929–932 1004 Index messages, 473, 475 Deep copy, 561 #define, 194, 201–203 DefWindowProc, 71 Degree of membership (DOM), 570, 571 DeleteCriticalSection, 466 Delimiters, 367 Dependencies, OpenGL, 286 Derived layer defined, 135 using, 135–137 Design phases, 13–14 transitions from analysis to, 41–42 dest, 551 Destroy, 95 Destroying semaphores, 470 DestroyOctree(), 496, 513–514 Destructors, widget, 94–95, 105–106 Development/construction phase, 14–15 Development Studio (DevStudio), 913–914 adding source-code files, 918–919 building and running programs, 929 compiler options, setting, 920–922 creating a project and workspace, 915–918 debugging, 929–932 help, accessing, 932 linking in DirectX libraries, 928–929 optimization level, setting, 923 runtime type identification, turning on, 924 search paths, 925–927 warning level, setting, 922–923 Diagrams, Unified Modeling Language activity, 27–29 categories of, 21 class, 23–25, 38, 42–43 interaction, 26–27, 43–44 packages/categories, 30–31, 36–37, 40–41 statechart, 29 use cases, 21–23, 33–36 DI_Init(), 732–734 DI_Init_Keyboard(), 734–736 DI_Read_Keyboard(), 737–738, 751 DirectDraw, 259–264 TeamLRN Direct Draw, connecting to, 704–705 Direct Draw library, 705–715 Directives, 337–338 DirectMusic, MIDI with, 243–252 DirectSound, 226–227 cooperation with other application processes, 228–229 DirectSoundCreate, 227 Direct3D, 127, 129, 130, 135 DirectX, 226–227 libraries, 928–929 DI_ShutDown(), 738–739 Dispatching, 113 Displaying widgets, 95, 106–107 DisplayLook(), 197–198, 199 DisplayRoom(), 186–187 DO-WHILE, 696–697 Draw_Bitmap(), 722–724 Draw_Captions(), 888–891 Draw Element Range, 293 Draw_Grid(), 806–810 Drawing octrees, 493–494, 511–513 sprites, 265–273 DrawOctree(), 496, 511–513, 527–528, 530 Draw_Shape(), 803–806, 880–885 DSBCAPS _CTRLFREQUENCY, 242–243 _CTRLPAN, 242 _CTRLVOLUME, 242 DSBFREQUENCY, 243 DSBLOCK_ENTIREBUFFER, 240 DSBLOCK_FROMWRITECURSOR, 240 DSBPLAY_LOOPING, 241 DSBUFFERDESC, 239 DSSCL _EXCLUSIVE, 228 _NORMAL, 228 _PRIORITY, 228, 229 _WRITEPRIMARY, 228, 229 dwAvgBytesPerSec, 219 DWORD, 458 dwSamplesPerSec, 219 dynamic_cast, 552, 559 Index E else if(), 197 Enemy block, adding, 181 section, 180–181, 208–209 EnterCriticalSection, 464, 465 Entry points, obtaining, 288–289 Enumerants, OpenGL, 285–286, 290 Equality operators, 543–544 Equates, 863–864 Error-handling functions, 377 Escape characters, 448–449 Event handlers, 103, 479 Exception handling, 952–961 Execute, 66–68 ExitOnError(), 377 Extensible Markup Language See XML F fdwSound, 221 fFloat, 343, 413 Field of view (FOV), camera, 490 FILE_FLAG_NO_BUFFERING flag, 482 FILE instance, 147 File I/O functions, 372–373 FilterEvent, 96 Floating-point operands, 342–343 Floating points, converting strings to, 551–552 Focus trapping, 113 Fog, 162–163 Forks, 28 Format chunk, 219 FOURCC, 233 Fowler, Martin, 24 FreeStringTable(), 346–347 Frustum culling, 514–518, 527–531, 651–652 description of, 490–492 planes, calculating, 519–527 planes, defined, 490 Functional baseline, creation of, 13 Functions, OpenGL, 285 obtaining entry points, 288–289 TeamLRN 1005 Fuzzy centroid, 589–591 Fuzzy logic associative matrices (FAM), 579–589 defined, 568 linguistic variables (FLV) and rules, 572–575 manifolds and membership, 575–579 MAX technique 586–587 standard set theory, 568–569 Fuzzy set theory, 570–572 fwrite(), 343 G Game development web sites, 988–989 Game engine, communication with, 425–432 Game_Init(), 725–728, 752–756 Game_Main(), 756–760, 811–819 Game_Shutdown(), 730–731 g_CriticalSection, 465–466 g_CurrentSubdivisions, 500 Get function, 551–552 GetApplication(), 65, 68 GetDataLength(), 239 GetFloatParam(), 430 GetHWND, 75 GetHINSTANCE, 65 GetInput(), 183–184, 189–191, 197 GetIntParam(), 430 GetLabelByIndex(), 424 getline(), 188 GetLookInfo(), 197, 198, 199–200 GetMasterWidget(), 114 GetMonsterInfo(), 205, 209 GetNewNodeCenter(), 507, 508 GetPlayerInfo(), 207 GetRetVal(), 427, 429 GetRoomInfo(), 187–189, 195, 199, 209 GetSceneDimensions(), 496, 497–499, 500 GetStringByIndex(), 430 GetStringParam(), 430 GetTickCount(), 739 GetWAVFormat, 239 gfxSystem, 135–137 g_lastchar, 462–463 1006 Index glFunctionName(), 285 glGetFenceNV(), 285 glGetString(), 285, 288 Globally unique identifiers (GUIDs), 226, 260 glSetFenceNV(), 285 glTestetFenceNV(), 285 g_MaxSubdivisions, 496, 500–501 g_MaxTriangles, 496, 501 GraphicSystem, 128–130 H Hamilton, William Rowan, 592 Hamiltonian Paths, 592 HandleEvent, 71–75 widget, 104, 108–113 HandleMessage, 64–65 Handle of a Device Context (HDC), 90, 104, 105 Hash, 541 Heap, 350 Height maps, 142–144 loading and unloading, 147–150 High-level design phase, 13–14 HINSTANCE, 68 HMMIO, 232, 233 Host API, 336–337 HostFunc, 428 HWND, 70, 71, 97 I iCurrInstr, 417 IDirectMusic, 243 IDirectMusicLoader, 244, 246–247 IDirectMusicPerformance, 243–244, 245 IDirectMusicPort, 244, 246 IDirectMusicSegment, 244 IDirectMusicSegmentState, 244 IDirectSound, 226 IDirectSoundBuffer, 226–227 IDirectSoundCapture, 227 IDirectSoundNotify, 227 #if defined directive, 124–125 IF-ELSE IF-ELSE, 696 TeamLRN ifstream, 184–185 iHeapIndex, 413, 418 iHeapOffsetIndex, 418 iHeapSize, 417 iInstrCount, 417 iInt, 413 iIsPaused, 417 iIsRunning, 417 Image subset, 293 Implementation perspective, 24 Include files, 858–859 Indirect static member accessors, 92–93 INFINITE, 460 Inheritance, 25 initGraphicSystem, 129, 135 InitializeCriticalSection, 466 Initialized data, 860–861 Initializing queues, 471–472 InitInstrList(), 406–407 Init_Menu(), 862–864 Init_Random(), 908 initSpriteData(), 268–270 InitStringTable(), 346 Init_Time(), 740–741 Inline functions, 935–936 Input focus/capture, 87–88 Input subsystem, 128 Installable client driver (ICD), 281, 282 instance, 551 Instruction pointer (IP), 411–412 Instruction stream, 340, 341–344, 417–419 int, converting to bool, 470 Integer operands, 342 Interaction diagrams, 26–27 updating, 43–44 InterlockedDecrement, 464 InterlockedIncrement, 464 Interpolation, 316–318 Intersections, quadtrees and finding, 641–644 int getSrcX(), 270 int getSrcY(), 271 iPauseEndTime, 417 IsCharDelimiter(), 367 IsCharIdent(), 367, 369 Index IsCharNumeric(), 366 IsCharWhitespace(), 366, 369 Is_Game_Won(), 898–899 IsStringFloat(), 371–372 IsStringIdent(), 369–370 IsStringInteger(), 370–371 IsStringWhitespace(), 369 Iterative model, 10–11 IUnknown, 226 J Jacobson, Ivar, 20 JGE, 425 Jmp, 424 Joins, 28 K key, 551 L Label declarations, 357–362 Label table, 340, 358–362, 419 LeaveCriticalSection, 464, 465 Lifeline, object, 26 Light, adding, 159–162 Line_Test(), 799–803, 892–896 Little-endian architectures, 122 LoadFromString, 555–558 Loading bitmaps, 254–259 property bags, 555–558 scripts, 417–419 Load_State(), 903–904 Load_WAV(), 835–846 Logo and usage information, printing, 374–377 long int, 470 section, 177–178, 196 Low-level design phase, 14 LPDIRECTSOUND, 227, 230, 245 LPDSBUFFERDESC, 230 LPVOID, 459 TeamLRN M Macros, 861 main(), 184–187, 203–205, 374–376 Maintenance phase, 16 Main Window Callback, 730–732 make_pair, 545, 551 MakeStringSafeForPropBag, 547–548 Mapping games, 176–177 Maps, STL, 977–983 Matrices, transposing, 295 maxcount, 472 MAX_LOOKS, 195, 196 m_bSubDivided, 496 m_Data, 477 Media control interface (MCI), 222–226 memcopy(), 510 Memory dynamic allocation, 939–943 references, 350–357 storing script in, 413–417 Menu system, 747–752 Merge(), 562–565 Merges, 28 Message handlers, 103 MessageID, 65 m_EverythingDoneEvent, 479 m_hbmOld, 93 m_hbmWidget, 93 m_hDC, 93 m_hWnd, 129 Microsoft See also Development Studio (DevStudio) Foundation Classes (MFC), 54, 918 OpenGL, 280–306 MIDI with DirectMusic, 243–252 file header, 220 playing, using Win32, 222–226 track chunks, 220–221 m_lstChildWidgets, 93 MMCKINFO, 232–233 MMIO (multimedia I/O), 231 _ALLOCBUFF, 233 1007 1008 Index commands and structures, 232–235 _FINDCHUNK, 234 _FINDLIST, 234 _FINDRIFF, 234 _READ, 233 _READWRITE, 233 using, to load WAV, 235–239 _WRITE, 233 mmioAscend, 233–234 mmioClose, 235 mmioDescend, 233–234 MMIOINFO, 232 mmioRead, 233–234 Mnemonic, 339 m_Object, 478 Monster block adding, 181 reading in, 205–206 Monster classes, adding, 201–203 Monsters, adding to room block, 180–181 move(), 270 Move(), 191–193 Move_Shape(), 790–798 Moving a character from room to room, 175–176 from room to room, 191–193 sprites, 265–273 Mov instruction, 405, 421–422, 423–424, 684 m_pParentWidget, 93 m_rcBounds, 93 m_TriangleCount, 496 Multimaps, STL, 541–542 Multimedia I/O See MMIO Multiple layers, creating, 672 Multiplicative inverse, 597, 606–607 Multisampling, 294 Multitasking, script, 445–447 Multitexturing, 294 Multithreads/multithreading advantages and disadvantages of, 457 atomic operations, 463 critical sections, 464–466 defined, 456–458 entry point, 456, 459 TeamLRN example, 481 handle, 460 producer/consumer problem, 466–475 queues, 471–475 race conditions, 461–463 resource loader, 475–479 secondary, 479–480 semaphores, 468–471 starting, 458–459 waiting for finish, 460–461 Music See Sound and music m_vCenter, 496, 498, 500 m_Width, 496, 498, 500 MyThreadProc, 458–459 N Names, OpenGL, 283 Namespaces, 936–938 Name strings, OpenGL, 285 New_Shape(), 768–772, 875–879 Nodes See Octrees; Quadtrees Nonstatic member accessors, 93–94, 102 Nonvalidating parser, 537–538 NormalizePlane(), 521, 523–524 Notification MCI, 225 widget, 86–87, 96–98 NVIDIA Corp., 282, 283, 284, 287, 297–298 O Object Constraint language (OCL), 25 Object lifeline, 26 Object Management Group (OMG), 20, 25 Object-oriented analysis (OOA), 41–42 Object-oriented design (OOD), 41–43, 45 Octrees code for, 494–497 defined, 486, 632 destroying, 513–514 drawing, 493–494, 511–513 end nodes, assigning vertices to, 510–511 frustum, 490–492 Index frustum culling, 514–518, 527–531 frustum planes, calculating, 519–527 how they work, 488–490 node center, getting a child, 508–509 nodes, creating, 500–506 nodes for recursion, setting up, 506–508 plane equation, 517–518 scene dimensions, obtaining, 497–499 subdividing, when to stop, 492–493 OnDestroy, 76–77, 79, 114 OnEvent, 71, 114 OnIdle, 62, 65, 75, 76 OnInit, 62, 65, 75, 76 OnKeyDown, 75, 76–77, 79 OnMessage, 62, 75, 76, 114 OnMouseMove, 75 OnPaint, 75, 114 OnRedraw, 95, 104, 106 OnTerminate, 62, 65, 75, 76 Opcodes, 339, 341–344, 415, 421–425 OpenFiles(), 376–377 OpenGL, 127, 130–137 Architectural Review Board (ARB), 281–282 headers and libraries, 280, 281–282 installable client driver (ICD), 281, 282 runtime, 281, 282 version 1.2, 292–293 version 1.3, 294–295 OpenGL extensions choosing, 298–299 demo of, 301–305 dependencies, 286 determining availability of, 288 documentation for, 286–287 enumerants, 285–286, 290 entry points, obtaining, 288–289 fences and ranges, 297 functions, 285 names, 283 name strings, 285 no support for, what to do, 300–301 prefixes, 283–284 role of, 282 shadows, 297–298 TeamLRN 1009 vertex and pixel shaders, 295–296 vertex arrays, compiled, 296 wgl, 296–297 Win32, 290–291 Operands, 342–344 Operation model, 1, 129 Operator= = method, 558–560 Outdoor images adding light, 159–162 base terrain class, 144–147 brute force, 150–152 fog, 162–163 height maps, 142–144, 147–150 resources on, 166–167 skyboxes, 163–165 textures, 153–158 OutputDebugString, 473 P Package diagrams, 30–31 Pong example, 36–37, 40–41 Package interaction diagrams (PIDs), 40–41, 44 PAPI_ENGINE, 320 Parent/child relationship, 60 Parsers, XML, 537–538 Parsing, 396–410 Particle engines billboarding, 314–316 defined, 309–314 designing, 318–324 interpolation and time-based movement, 316–318 Particle wrapper, designing, 325–326 pCollide function, 323 pcurValue, 123 pEmit function, 322 pFile, 343 pGravity function, 325 Pixel formats BGRA, 292 packed, 292 Pixel shaders, 295–296 Place_In_Grid(), 776–780 1010 Index Plane equation, 517–518 Play cursor, 229 Player classes, adding, 201–203 Player information adding, 181–182 reading in, 207 PlaySound(), 221, 831–833 pnewValue, 123 Pointers, 544 Polymorphism, 542, 543 C++, 942–950 pParamList, 430 Preprocessors, 447–448 Process_File_Menu(), 869–872 Process_Main_Menu(), 748–751, 865–869 Producer/consumer problem, 466–475 Program counter (PC), 411 Project startup phase, 12 Property bags See XML property bags ProtectedThreadProc, 464–465 Prototype model, 11 pszSound, 221, 222 PutTagIntoBag, 557–558 pVertex function, 322 Q Quadtrees AddFace(), 636–637, 638–642 applications, 651–652 building, 630–631, 636–638 cleaning up, 648–649 CQuadtree class, 632–633 CQuadtreeNode class, 634–636 defined, 627–628 demo, 653–655 design decisions, 649–651 finding an intersection, 641–644 parts of, 627–628 RayIntersectTraingle(), 644–648 Quaternions additive identity, 603 additive inverse, 603 applications of, 608–611 TeamLRN building a simple engine, 612–624 complex number theory, 592–599 conjugate, 605 defined, 592 hyper complex numbers, 599–607 mathematical operations using, 594–597, 602–605 multiplicative inverse, 606–607 norm of, 606 rotation, 608–611 Queues adding element to, 473 CProducerConsumerQueue, 471, 475 initializing, 471–472 removing element from, 474–475 shutting down, 475 Queuing tasks, 478 R Race conditions, 461–463 Random_Number(), 906–908 Rapid Application Development (RAD) See Application frameworks, building Rational Unified Process (RUP), 20 RAW format, 144 RayIntersectTraingle(), 644–648 ReadFile, 482 ReadingOpenTag, 556, 557 ReadingTagContents, 556, 557 Rectangular area collision detection, 274–275 rectAreaCheck(), 272 Reeves, William T., 309 Reference counting, 561 Regression testing, 15 Relative index, 353 ReleaseSemaphore, 470, 473 RemoveFromFront, 474, 475 render, 129, 135 RenderScene(), 528, 529 Replace, 548 Requirements Definition Document (RDD), 13 Requirements phase, 12–13 Requirements Traceability Matrix (RTM), 31–33 Rescaling, 293 Index ResolveMemoryOp(), 423 Resource Interchange File Format (RIFF), 218 Resource loader, 475–479 RestoreOrigFromSafeString, 548 Return address, 446 Return arrows, 26 ReturnValue, 417, 427, 430–432 RewindTokenStream(), 390, 397 Rooms See also Text adventure describing, 173–175 first room block, 173–175 moving a character from room to room, 175–176 use of term, 173 Rotate_Shape(), 782–790, 822–828 RTLMoveMemory(), 802 Rumbaugh, Jim, 20 Runtime environment, 410–413 Runtime type identification (RTTI), 544, 924, 962–964 S Save(), 543, 552, 553–554 Save_State(), 902–903 screenHeight, 129 Screen transitions, 847–856 screenWidth, 129 Scripting/script See also Compilers/compilation communication with game engine, 425–432 execution, 419–421 file I/O functions, 372–373 implementing opcodes, 421–425 library of string-handling functions, creating, 365–372 loading, 417–419 multitasking, 445–447 parsing, 396–410 reading instructions from external files, 449 role of, 330–331 runtime console, 435–443 runtime environment, 410–413 storing in memory, 413–417 TeamLRN timeslicing, 432–435 tokenization, 378–395 Scripting language arithmetic, 334–335 branching, 335–336 comments, 338 designing, 331–338 directives, 337–338 host API, 336–337 instructions, 332–333, 334–337 objectives, 333–334 string processing, 335 SearchingForOpenTag, 556, 557 Secondary sound buffers, 229, 241–243 Self-call arrows, 26 Semaphores, 461 creating, 469–470 defined, 468 destroying, 470 releasing/adding to, 470 subtracting from, 471 Sequence diagrams, 26 SetCooperativeLevel, 228 SetData, 547 setDir, 269 SetInstr(), 405 setScreenResolution, 130 SetWindowLong, 71 setXVel, 270 setYVel, 270 Shaders, pixel and vertex, 295–296 Shadows, 297–298 Shutdown_Menu(), 866–867 s_hWnd, 89, 90, 91, 92 Silicon Graphics (SGI), 281 sizeof(), 126 Skyboxes, 163–165 defined, 660 demo, 677 disabling states, 664 orienting, 662–663 rendering, 663–666 representing, 660–662 resources on, 678 1011 1012 Index restoring states, 664–665 sliding, 672 textures, generating, 672–676 texture states, 664–665 Skydomes creating, 667–668 defined, 667 rendering, 669 textures, 668 Skyplanes creating, 669–670 defined, 669 rendering, 670 Sleep(), 460 SLERP (spherical linear interpolation), 608 Sliding skyboxes, 672 Slope lighting, 159–162 s_lstDeleteList, 89, 92 s_lstMoveList, 89, 92 SND _ALIAS, 221 _ASYNC, 221–222 _FILENAME, 221 _LOOP, 222 _NODEFAULT, 221 _NOSTOP, 222 _PURGE, 222 _RESOURCE, 221 _SYNC, 221, 222 snprintf, 540 Software Configuration Management (SCM) concepts and functions, 6–8 defined, 4–5 future of, 19 history of, 5–6 importance of, 8–9, 17–18 web sites, 988 Software Development Life Cycle (SDLC) pitfalls, 16–17 models, 9–11 phases, 11–16 Sound and music checking play status, 250 cooperation with other application processes, TeamLRN 228–229 DirectSound, 226–227 DirectX, 226–227 loading a song, 247–249 MIDI, 220–221 MIDI with DirectMusic, 243–252 MMIO, 231, 232–235 MMIO to load WAV, 235–239 playing a song, 249 playing MIDI using Win32, 222–226 releasing a segment, 250–251 stopping a song, 250 WAV, 218–220, 231 Win32 API, 221–222 Sound buffers, 229–231, 239–243 Sound module, 828–835 Space partitioning See Octrees SPACE-TRIS, 687–694 See also Win32 ASM Spatial partitioning See also Quadtrees defined, 626, 628 forms of, 628–631 Specification perspective, 24 Spiral model, 10 s_pKeyboardFocus, 92 s_pMasterWidget, 91, 92 s_pMouseFocus, 92 s_pMouseHover, 89, 92 sprintf, 540 Sprites collision detection, 273–275 defined, 254 DirectDraw, 259–264 drawing and moving, 265–273 loading bitmaps, 254–259 resources on, 277 transparency, 264–265 Standard set theory, 568–569 Standard Template Library (STL) defined, 539, 972 list template, 90, 501, 635 maps, 977–983 multimaps, 541–542 Index queue object, 471 strings, 970–971 vectors, 467, 501, 972–977 Start_Time(), 741–743 State attribute, 39 Statechart diagrams, 29 State transition diagrams (STDs), 39–40 Static members, 57–58 accessors, 90–92, 101, 103 Static sound buffers, 229 Static window class member, 69 status command, 208 STL See Standard Template Library Stop_All_Sounds(), 833–835 Stop_Sound(), 832–833 str -LookArray, 195, 196–197, 198 -LookDescription, 198 -Temp, 188 use of, 184 Streaming operators, 541 Streaming sound buffers, 229 String-handling functions, creating a library of, 365–372 Strings processing, 335 retrieving, 550–551 STL, 970–971 tables, 340, 344–350, 419 stringstream, 540 Swimlanes, 28 switch block, 412, 421 Symbols ampersand, 546, 547 asterisks, 174, 179, 188, 200 brackets, 174, 179, 187, 200 chevrons/greater than and less than, 546, 547 percent operator, 197 pipe characters, 179, 199, 200, 401 property bags and translating, 546–548 streaming operators, 541 Symbol table, 340, 352, 353–357, 419 System architecture diagram, 13 System package diagram (SPD), 37 Systems Analysis Document (SAD), 13 TeamLRN 1013 sz, use of, 184 T Targas, 292 Tasks, 477–479 TASKSTATE_FAILED, 476 TASKSTATE_LOADED, 476 TASKSTATE_LOADING, 476 TASKSTATE_QUEUED, 476 Templates, C++, 964–969 Terminate(), 475 Terragen, 673–676 Terrain class, 144–147 Test_Collision(), 778–781 Testing phase, 15 Text adventure battle scenes, 182 collision detection, 174 defined, 170–171 describing a room, 173–175 help resources, 213, 215, 216 section, 177–178 mapping game, 176–177 monster/ememy block, adding, 181 monsters, adding to room block, 180–181 moving a character from room to room, 175–176 player information, adding, 181–182 room block, 173–175 view block, 178–179 Text adventure (version 1) game input, handling, 189–191 main(), 184–187 moving from room to room, 191–193 room block data, reading in, 187–189 room structure and defines, creating, 183–184 test run, 193–194 Text adventure (version 2) adding additions to room structure, 195 #define, 194 reading in new section, 195–197 view block, reading in, 199–200 view command, adding, 197–198 view keyword, determining valid, 198–199 1014 Index Text adventure (version 3) adding final additions to room structure, 203 adding more defines and monster/player classes, 201–203 battle code, writing, 210–212 future additions, 214–215 main(), finishing, 203–205 monster block, reading in, 205–206 player data, reading in, 207 room block reading in new section in, 208–209 status command, 208 summary and review, 212–213 Textures, 153–158 border clamp, 295 compression, 294 coordinate edge clamping, 293 cube map, 294 environment modes, 294–295 LOD control, 293 multi, 294 skyboxes and, 664–665, 672–672 skydomes and, 668 3D, 292 Thread See also Multithreads/multithreading defined, 456 3D Studio Max, 672 Time-based movement, 316–318 timeGetTime(), 740 Timeslicing, 432–435 timeToUpdateFrame(), 272 Tokenization, 378–395 parsing, 396–410 Tokenize, 541 Token stream, 396 Token types, 380–381 Track chunks, 220–221 Transition(), 848–850 Transparency color, 264 sprites and, 264–265 Transparent blit, 264–265 Trees See Quadtrees TrimWhitespace(), 367–369 TeamLRN Typedef, 125–126 U Unified Modeling Language (UML) activity diagrams, 27–29 class diagrams, 23–25, 38, 42–43 coding, 45 development of, 20 interaction diagrams, 26–27, 43–44 packages/categories, 30–31, 36–37, 40–41 refinement and iteration, 45 Requirements Traceability Matrix (RTM), 31–33 resources on, 46–47 role of, 21 statechart diagrams, 29 state transition diagrams, 39–40 transitions from analysis to design, 41–42 use cases, 21–23, 33–36 UnprotectedThreadProc, 462 Update, 95 updateFrame(), 272 Update_Shape(), 773–774 Usability plan, 13 Use case diagrams, 21–23 Pong example, 33–36 Use case scenarios, 22–23, 33 User Acceptance Testing (UAT), 15 User interfaces (UI) See also Widget(s) design considerations, 84 role of, 83–84 V Validating parser, 537 Variable declarations, forcing, 449–451 Variables external, for game, 859–860 memory references, 350–357 Vectors, STL, 972–977 Vertex arrays, 296 fence extension, 297 Index range extension, 297 Vertex shaders, 295–296 Video subsystem, 127 View block, 178–179 reading in, 199–200 View command, adding, 197–198 View keyword, determining valid, 198–199 VirtualAlloc, 482 VirtualFree, 482 Virtual functions C++, 942–950 table, 706 W WaitForMultipleObjects, 461, 471, 474 WaitForSingleObject, 460–461, 471 Wait_Time(), 743–746 WaitUntilFinished, 477 Watches, 930–931 Waterfall model, 9–10 WAV data chunk, 220 format chunk, 219 MMIO to load, 235–239 overview of, 218–219 reading, 231 WAVEFORMATEX, 231, 234, 235–239 wChannels, 219 Web sites, useful, 988–990 wFormatTag, 219 wgl extensions, description of, 296–297 wglGetExtensionsStringARB(), 290 wglGetExtensionsStringEXT(), 290 wglGetProcAddress(), 289, 290 WHILE, 697 While loop, 460, 479 White cursor, 229 Whitespace, 366, 367–369 Widget(s) appearance, 87 class definition, 98–100 constructors and destructors, 94–95, 104–106 displaying, 95 TeamLRN event/message handlers, 103 implementation, 100–113 indirect static member accessors, 92–93 input focus/capture, 87–88 master widget, constructing, 104 members, 88–90 nonmaster widget, constructing, 105 nonstatic member accessors, 93–94, 102 notification, 86–87, 96–98 receiving input, 95–96 static member accessors, 90–92, 101, 103 tree, 84–86 Z ordering, 86 WindowProc, 70–71 Windows WAV, 218–220 WinMain(), 68, 699–703 Win32 API, 221–222 extensions, 290–291 multithreading and, 458 playing MIDI using, 222–226 Win32 ASM ADD and SUB instructions, 684–685 bitmap library, writing, 715–725 code framework, 687–694 designing a game, 686–687 Direct Draw, connecting to, 704–705 Direct Draw library, 705–715 direct input, 732–739 game, creation of, 762–820 game code, 725–731 game loop, getting it running, 698–704 high-level syntax, 695–698 loading files, 835–847 menu system, 747–752 MOV instruction, 684 MUL and DIV instructions, 685–686 patterns and lookup table, 763–768 preview piece, 879–879 preview piece, drawing, 880–885 putting pieces together, 856–873 random numbers, obtaining, 905–908 reasons for, 683 rotation solution, 821–828 saving and storing games, 898–905 1015 1016 Index creation of, 539–541 data elements, adding, 545–546 data elements, getting, 550 data types, getting, 551–552 getting, 552 implementing, 542–544 loading, 555–558 merging, 562–565 nonstring elements, adding, 549 saving, 553–554 STL multimaps, 541–542 strings, getting, 550–551 testing for equality, 558–560 translating special characters, 546–548 scoring and levels, 891–897 screen transitions, 847–856 sound module, 828–835 text drawing, 885–891 timing and Windoze, 739–747 Wipe_Trans(), 850–855 WM_PAINT, 75 Words, 343 WriteLabelTableToExec(), 361–362 WriteStringTableToExec(), 348–349 X XML (eXtensible Markup Language) data file example, 538–539 defined, 537–538 parsers, 537–538 XML property bags adding, 549–550 copying one bag to another, 560–562 TeamLRN Z Z ordering, 86 ...TeamLRN Game Programming Tricks of the Trade TeamLRN This page intentionally left blank TeamLRN Game Programming Tricks of the Trade Lorenzo D Phillips Jr., Editor André LaMothe, Series Editor... without a doubt there’s nothing in the world I would rather And now with the turn of the century behind us, it’s up to you, the next generation of game developers, to take games to the places that... template of sorts, so that as you're reading each trick or tutorial you see a familiar structure rather than a smorgasbord of layouts Game Programming Tricks of the Trade fills a gap between the game

Ngày đăng: 23/10/2019, 16:43

TỪ KHÓA LIÊN QUAN