Upload
tallulah-cote
View
26
Download
0
Embed Size (px)
DESCRIPTION
UW Extension Certificate Program in Game Development 2 nd quarter: Advanced Graphics. Game program main loop. Goals. Understand the structure of the game’s main loop Know how the other components affect rendering. The game’s main loop. Three things to do, periodically: Gather inputs - PowerPoint PPT Presentation
Citation preview
UW EXTENSION
CERTIFICATE PROGRAM INGAME DEVELOPMENT
2ND QUARTER:ADVANCED GRAPHICSGame program main loop
Goals
1. Understand the structure of the game’s main loop
2. Know how the other components affect rendering
The game’s main loop Three things to do, periodically:
Gather inputs Mouse, keyboard, game controller,
network Run the game simulation
Physics, AI, scripting, logic Return (render) results
Graphics, audio, force-feedback, network
Gather inputs
Game simulatio
n
Render results
Exe
cuti
on
Data
The game simulation The key, central part that makes gameplay work
If it doesn’t run, there’s no game Inputs and results are as loosely tied to it as possible
Multiple kinds: Constant vs. variable rate Deterministic vs. non-deterministic
Main graphics-related concern: Ensure none of the rendering affects the simulation Isolate… by all means necessary
Non-gameplay simulation tasks For instance, physics is part of the simulation But not all the physics!
Grenade bouncing off walls belongs in the simulation Sparks bouncing off walls don’t belong in the simulation
Eye candy only Also, sometimes rendering uses some simulation code
Local simulation, meant to predict or extrapolate Used to reduce perceived latency
The input Some input is used for the simulation
Shooting or jumping buttons Some input is used only for rendering
Mouse cursor or 1st person camera orientation Latency and granularity are two key concepts
here Low sampling rate: low granularity and higher latency Latency also affected by the structure of the code
Latency Time it takes for the player to see the
reaction to her actions It is a factor of many sequential events Some can be budgeted
Time it takes for the CPU or the GPU to render
Some can’t be controlled Video frame rate
Human beings can perceive latencies of 100 ms or more Some can detect much smaller latencies
Player presses button
Game reads button press
Game simulation finishes
Game sends frame to GPU
GPU renders frame
Half the input sample rate
Frame becomes visible
8.33 ms
Simulation CPU budget
8.33 ms
Render CPU budget8.33 ms
Half the max GPU queue
33.33 ms
Half the video frame rate
8.33 ms
The rendering Must aim for a constant, guaranteed framerate
At the screen’s refresh rate Budgeted for both: CPU and GPU Must be able to throttle back
If frames take too long to render or simulate Keep all animation running at the intended speed Less framerate: more choppiness, not slower
animation
Main loop – Constant-step simulation
startTime = GetTime();while (true){ Process Windows messages (keep it happy) Read simulation inputs time = GetTime(); while (time – startTime > frameTime) { startTime += frameTime; Run simulation } Render frame((time – startTime) / frameTime)}
Main loop – Variable-step simulation
startTime = GetTime();while (true){ Process Windows messages (keep it happy) Read simulation inputs time = GetTime(); Run simulation(time – startTime) startTime = time; Render frame}