Chapter 3.2-3.7 Languages, Programming and Architecture“Core” languagesScripting LanguagesSlide 4Flash, Director, etc. (ch 3.3)Programming Fundamentals (ch 3.4)Debugging (ch 3.5)Adding Infrastructure to Assist in DebuggingPrevention of BugsGame ArchitectureOverall ArchitectureOverview: Initialization/ShutdownOverview: The Main LoopOverview: Main Game LoopSlide 15Slide 16Game EntitiesSlide 18Slide 19Slide 20Slide 21Memory ManagementSlide 23File I/OGame ResourcesSlide 26Slide 27Slide 28SerializationChapter 3.2-3.7Languages, Programming and ArchitectureCS 4455 2“Core” languagesC/C++: fast compiled languagesJava: getting better, still not there!–Niche games (web, slow-paced games, etc.)CS 4455 3Scripting LanguagesWhy use scripting languages?–Ease and speed of development–Short iteration time–Code becomes a game assetPopular scripting languages–Most common: Python, Lua–Other: Tcl, Ruby, Perl, Javascript, Scheme–Custom scripting languages•UnrealScript, QuakeC, NWNScriptCS 4455 4Scripting LanguagesKey issue–How will you use it?Speed only an issue if in main loop–Even then, perhaps not!Interactive runtime consoles–Extremely powerful for debugging–Esp. via network connectionCS 4455 5Flash, Director, etc. (ch 3.3)Self contained, interactive development environmentsIf they meet your game needs, they can’t be beat!Excellent for prototyping–Very commonly used in this wayCS 4455 6Programming Fundamentals (ch 3.4)Some ideas are reviewOthers may be newKey point–This is how engines are written!–Useful for writing your own games, vital for understanding existing tools!CS 4455 7Debugging (ch 3.5)Debugging RT interactive systems is HARD–Probe effects–Hard to reproduce errorsA great collection of debugging ideas and guidelines!–For more than just gamesCS 4455 8Adding Infrastructureto Assist in DebuggingInteractive shells–Alter game variables during gameplayVisual diagnostics–AI, entity stateLogging capability–With different “severity” levels, control via shellRecording and playback capability–Controllable global timeTrack memory allocation–(Return to this later)Print as much information as possible on a crashCS 4455 9Prevention of BugsSet compiler to highest warning levelSet compiler warnings to be errorsCompile on multiple compilersWrite your own memory managerUse asserts to verify assumptionsInitialize variables when they are declaredBracket loops and if statementsUse cognitively different variable namesAvoid identical code in multiple placesAvoid magic (hardcoded) numbersVerify code coverage when testingCS 4455 10Game ArchitectureThe code for modern games is highly complex–Code bases exceeding a million lines of codeMany commonly accepted approaches–Developed and proven over time–Ignore them at your peril!CS 4455 11Overall ArchitectureMain structure–Game-specific code–Game-engine codeArchitecture types–Ad-hoc (everything accesses everything)–Modular–DAG (directed acyclic graph)–LayeredCS 4455 12Overview: Initialization/ShutdownThe initialization step prepares everything that is necessary to start a part of the gameThe shutdown step undoes everything the initialization step did, but in reverse orderThis is IMPORTANT–Applies to main loop, down to individual stepsCS 4455 13Overview: The Main LoopAll interactive programs are driven by a loop that performs a series of tasks every frame–GUI, 3D, VR, Simulation–Games are no exceptionSeparate loops for the front end and the game itself, or unified main loop–Both work; a question of preference and styleCS 4455 14Overview: Main Game LoopTasks–Handling time–Gathering player input–Networking–Simulation–Collision detection and response–Object updates–Rendering–Other miscellaneous tasksCS 4455 15Overview: Main Game LoopCoupling–Can decouple the rendering step from simulation and update steps–Results in higher frame rate, smoother animation, and greater responsiveness•May be necessary for complex simulations–Implementation is tricky and can be error-proneCS 4455 16Overview: Main Game LoopExecution order–Can help keep player interaction seamless•Avoid “one frame behind” problems–Can maximize parallelism–Exact ordering depends on hardwareCS 4455 17Game EntitiesWhat are game entities?–Basically anything in a game world that can be interacted with–More precisely, a self-contained piece of logical interactive content–Only things we will interact with should become game entitiesCS 4455 18Game EntitiesOrganization–Simple list–Multiple databases–Logical tree–Spatial databaseCS 4455 19Game EntitiesUpdating–Updating each entity once per frame can be too expensive–Can use a tree structure to impose a hierarchy for updating–Can use a priority queue to decide which entities to update every frameCS 4455 20Game EntitiesObject creation–Basic object factories–Extensible object factories–Using automatic registration–Using explicit registrationIdentification (pointers vs. uids)Communication (messages)CS 4455 21Game EntitiesLevel instantiation–Loading a level involves loading both assets and the game state–It is necessary to create the game entities and set the correct state for them–Using instance data vs. template dataCS 4455 22Memory ManagementOnly applies to languages with explicit memory management (C or C++)Memory problems are one of the leading causes of bugs in programs–Or, “Reason 437 why I dislike C++”CS 4455 23Memory ManagementChapter gives lots of good advice on how to deal with memory and WHY–E.g., avoiding memory fragmentationCustom memory managers are great!For you, probably most important reasons: –Simple error-checking schemes–Debugging toolsCS 4455 24File I/OAs with memory, chapter gives lots of good advice on how to deal with loading things from disk–E.g., to avoid long load timesAside from efficiency, keeps things together!For you, probably not worth doingCS 4455 25Game ResourcesA game resource (or asset) is anything that gets loaded that could be shared by several parts of the game–A texture, an animation, a sound, etcWe want to load and share resources easilyThere will be many different types of resources in a gameCS 4455 26Game ResourcesResource manager–Uses registering object factory
View Full Document