Game Loops CIS 580 - Fundamentals of Game Programming Hangman - - PowerPoint PPT Presentation

game loops
SMART_READER_LITE
LIVE PREVIEW

Game Loops CIS 580 - Fundamentals of Game Programming Hangman - - PowerPoint PPT Presentation

Game Loops CIS 580 - Fundamentals of Game Programming Hangman Game Phases Game Loop Turn-based vs. Real-Time Turn-Based Real-Time Fixed-Timestep vs. Variable Timestep Example - Ballistic Motion x (delta t/timestep) Hybrid Game Loop


slide-1
SLIDE 1

Game Loops

CIS 580 - Fundamentals of Game Programming

slide-2
SLIDE 2

Hangman

slide-3
SLIDE 3

Game Phases

slide-4
SLIDE 4

Game Loop

slide-5
SLIDE 5

Turn-based vs. Real-Time

slide-6
SLIDE 6

Turn-Based

slide-7
SLIDE 7

Real-Time

slide-8
SLIDE 8

Fixed-Timestep vs. Variable Timestep

slide-9
SLIDE 9

Example - Ballistic Motion

slide-10
SLIDE 10

Hybrid Game Loop

x (delta t/timestep)

slide-11
SLIDE 11

Variable update/render Game Loop

Every Nth loop Every Nth loop

slide-12
SLIDE 12

Coding Game Loops

slide-13
SLIDE 13

setTimeout game loop

function loop() { setTimeout( loop, 16.666); // Asyncronous processInput(); update(); render(); } // 0.016666s = 1/60s setTimeout( loop, 16.666);

slide-14
SLIDE 14

setInterval game loop

function loop() { processInput(); update(); render(); } // 0.016666s = 1/60s var loopHandle = setInterval( loop, 16.666);

slide-15
SLIDE 15

recursive game loop

function loop() { processInput(); update(); render(); loop(); }

slide-16
SLIDE 16
slide-17
SLIDE 17

Simple request animation frame game loop

function loop(timestamp) { processInput(); update(); render(); requestAnimationFrame(loop); } requestAnimationFrame(loop);

slide-18
SLIDE 18

“Variable”-rate setTimeout game loop

var start = null; function loop(timestamp) { var progress; if (start === null) start = timestamp; progress = timestamp - start; processInput(); update(progress); render(progress); requestAnimationFrame(loop); } requestAnimationFrame(loop);

slide-19
SLIDE 19

Fixed Timestep setTimeout game loop

var start = null; var timestep = 16.6666; // 0.016666s = 1/60s function loop(timestamp) { var progress; if (start === null) start = timestamp; progress = timestamp - start; processInput(); while(progress > timestep) { update(progress); progress -= timestep; start += timestep; } render(progress); requestAnimationFrame(loop); } requestAnimationFrame(loop);

slide-20
SLIDE 20

request animation frame polyfill