Presentation is loading. Please wait.

Presentation is loading. Please wait.

UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Game program main loop.

Similar presentations


Presentation on theme: "UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Game program main loop."— Presentation transcript:

1 UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Game program main loop

2 Goals 1. Understand the structure of the game’s main loop 2. Know how the other components affect rendering

3 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 simulation Render results Execution Data

4 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

5 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

6 The input  Some input is used for the simulation  Shooting or jumping buttons  Some input is used only for rendering  Mouse cursor or 1 st 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

7 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 budget8.33 ms Render CPU budget8.33 ms Half the max GPU queue33.33 ms Half the video frame rate8.33 ms

8 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

9 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) }

10 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 }


Download ppt "UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Game program main loop."

Similar presentations


Ads by Google