1 / 10

UW Extension Certificate Program in Game Development 2 nd quarter: Advanced Graphics

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

Download Presentation

UW Extension Certificate Program in Game Development 2 nd quarter: Advanced Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UW ExtensionCertificate Program inGame Development 2nd quarter:Advanced Graphics Game program main loop

  2. Goals • Understand the structure of the game’s main loop • 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 Execution Data Render results

  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-gameplaysimulation 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 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

  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 8.33 ms Half the input sample rate Game reads button press 8.33 ms Simulation CPU budget Game simulation finishes 8.33 ms Render CPU budget Game sends frame to GPU 33.33 ms Half the max GPU queue GPU renders frame 8.33 ms Half the video frame rate Frame becomes visible

  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) { ProcessWindowsmessages(keepithappy) Readsimulationinputs time=GetTime(); while(time–startTime>frameTime) { startTime+=frameTime; Runsimulation } Renderframe((time–startTime)/frameTime) }

  10. Main loop – Variable-step simulation startTime=GetTime(); while(true) { ProcessWindowsmessages(keepithappy) Readsimulationinputs time=GetTime(); Runsimulation(time–startTime) startTime=time; Renderframe }

More Related