Chapter 3.6 Game Architecture
Download
Report
Transcript Chapter 3.6 Game Architecture
Chapter 3.4
Game Architecture
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 code
Game-engine code
Both types of code are often split into
modules, which can be static libraries, DLLs,
or just subdirectories
3
Overall Architecture
Architecture types
Ad-hoc (everything accesses everything)
Modular
DAG (directed acyclic graph)
Layered
4
Overall Architecture
Options for integrating tools into the
architecture
Separate code bases (if there's no need to
share functionality)
Partial use of game-engine functionality
Full integration
5
Overview:
Initialization/Shutdown
The initialization step prepares
everything that is necessary to start a
part of the game
The shutdown step undoes everything
the initialization step did, but in reverse
order
6
Overview:
Initialization/Shutdown
Resource Acquisition Is Initialization
A useful rule to minimalize mismatch errors
in the initialization and shutdown steps
Means that creating an object acquires and
initializes all the necessary resources, and
destroying it destroys and shuts down all
those resources
7
Overview:
Initialization/Shutdown
Optimizations
Fast shutdown
Warm reboot
8
Overview:
Main Game Loop
Games are driven by a game loop that
performs a series of tasks every frame
Some games have separate loops for the
front and and the game itself
Other games have a unified main loop
9
Overview:
Main Game Loop
Tasks
Handling time
Gathering player input
Networking
Simulation
Collision detection and response
Object updates
Rendering
Other miscellaneous tasks
10
Overview:
Main Game Loop
Structure
Hard-coded loops
Multiple game loops
For each major game state
Consider steps as tasks to be iterated
through
11
Overview:
Main Game Loop
Coupling
Can decouple the rendering step from
simulation and update steps
Results in higher frame rate, smoother
animation, and greater responsiveness
Implementation is tricky and can be errorprone
12
Overview:
Main Game Loop
Execution order
Most of the time it doesn't matter
In some situations, execution order is
important
Can help keep player interaction seamless
Can maximize parallelism
Exact ordering depends on hardware
13
Game Entities
What 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 entities
14
Game Entities
Organization
Simple list
Multiple databases
Logical tree
Spatial database
15
Game Entities
Updating
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
16
Game Entities
Object creation
Basic object factories
Extensible object factories
Using automatic registration
Using explicit registration
17
Game Entities
Level 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 data
18
Game Entities
Identification
Strings
Pointers
Unique IDs or handles
19
Game Entities
Communication
Simplest method is function calls
Many games use a full messaging system
Need to be careful about passing and
allocating messages
20