Game Architecture Inspired by Rabin ch 3 4
Game Architecture Inspired by Rabin ch. 3. 4 as hacked by Jeffery
Overall Architecture The code for modern games is highly complex With code bases exceeding a million lines of code, a well-defined architecture is essential 2
Overall Architecture Main structure Game-specific (“application”) code Game-engine (“library”) code • GDX, or Unicon, play this role. . . Both types of code are often split into modules, which can be static libraries, DLLs, subdirectories, packages. . . 3
Overall Architecture types Ad-hoc (everything accesses everything) Modular – ad hoc OOP DAG (directed acyclic graph) • Minimize coupling Layered • App, engine and system layers, ++? 4
Main Game Loop Performs a series of tasks every frame Some games use different main loops during different states/phases Some games de-couple the front end (display/UI) from the game itself – especially if online or using real AI 5
Overview: Main Game Loop Tasks Track/handle time Gather player input Network I/O (often: batched/buffered) Simulation Collision detection and response Object updates Rendering Other miscellaneous tasks 6
Overview: Main Game Loop Execution order Most of the time it doesn't matter In some situations, it is crucial Can help keep player interaction seamless Can maximize parallelism Exact ordering depends on hardware 7
Game Entities As we saw earlier. . . anything in a game world that can be interacted with a (self-contained) piece of logical interactive content only things we will interact with should become game entities 8
Game Entities Just declaring a variable for each one doesn't scale well, so. . . Organization Simple array or list Multiple databases! Logical tree Spatial database 9
Game Entities 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 frame 10
Game Entities Object creation Basic object factories Extensible object factories Using automatic registration Using explicit registration 11
Game Entities Level instantiation Loading a level involves loading both assets and the game state Create the game entities and set the correct state for them Using instance data vs. template data (flywheel design pattern) 12
Game Entities Identification Strings Pointers Unique IDs or handles 13
Game Entities Communication Simplest method is function calls Many games use a full messaging system Need to be careful about passing and allocating messages 14
- Slides: 14