1 / 74

Sim, Render, Repeat

Sim, Render, Repeat . An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour. March 23, 2006 . “Who?”. Introduction. Introduction: The Speakers. Technical directors at EA-Tiburon MS degrees 7+ years in the game industry Exposed to many games and architecture

thina
Download Presentation

Sim, Render, Repeat

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. Sim, Render, Repeat An Analysis of Game Loop Architectures Daniel Martin and Michael Balfour March 23, 2006

  2. “Who?” Introduction

  3. Introduction: The Speakers • Technical directors at EA-Tiburon • MS degrees • 7+ years in the game industry • Exposed to many games and architecture Also programmed on Apple ][’s and mainframes 

  4. Introduction: Motivation • Hidden complexities • Little coverage • Highest-level game architecture

  5. Introduction: Agenda • Definitions • Timeline • Architecture decisions • Case study • Questions Slides will be made available on the GDC website

  6. “What?” Game loop architectures defined

  7. Definition: Background • Source Code • Digger • Duke3D • Freespace2 • Harry Potter • Madden • Books • 3D Game Engine Architecture, First Edition • Core Techniques and Algorithms in Game Programming • Game Coding Complete, Second Edition • NASCAR • Popcap Engine • Quake2 • Unreal Tournament v432 • Wumpus

  8. Definition: Pseudocode pattern • GameLoop() • { • Startup(); • while (!done) • { • GetInput(); • Sim(); • Render(); • } • Shutdown(); • }

  9. Definition: Formal • Game Loop • A thread of execution consisting of • a startup phase, • a looping phase that processes inputs/outputs, • a shutdown phase. • We use “Game Loop” and “Loop” interchangeably

  10. “When?” Game Loop Timeline

  11. CRT Amusement Device Gun Fight Genesis MHz Barrier Noughts and Crosses Gypsy Juggler Saturn 1947: Cathode Ray Tube Amusement Device • First patented video game • Game: Fire a missile at a target • Hardware loop run by master clock 1950 1940 1960 1970 1980 1990 2000

  12. CRT Amusement Device Gun Fight Genesis MHz Barrier Noughts and Crosses Gypsy Juggler Saturn 1952: Noughts and Crosses • First software-based game • Game: Tic Tac Toe • Software loop 1950 1940 1960 1970 1980 1990 2000

  13. 1940-1970: Analysis • Game loops have existed for 50+ years • We still use the same game loop patterns today • Seems to be the most intuitive architecture for games • Hardware and software loops • Independently developed • Similar results

  14. CRT Amusement Device Gun Fight Genesis MHz Barrier Noughts and Crosses Gypsy Juggler Saturn 1975: Gun Fight • First CPU-based arcade video game • Game: Two players shoot at each other • Software Sim loop • Hardware Render and Audio loops 1950 1940 1960 1970 1980 1990 2000

  15. CRT Amusement Device Gun Fight Genesis MHz Barrier Noughts and Crosses Gypsy Juggler Saturn 1978: Gypsy Juggler • First multi-CPU game • Game: Move a gypsy and juggle eggs • Concurrent Software Sim/Audio loops • Two symmetric S2650 CPUs 1950 1940 1960 1970 1980 1990 2000

  16. 1970-1980: Analysis • Multi-CPU arcade games have existed for 28+ years • Multi-CPU common in arcade games • Typically 2-3 CPUs • Common use of specialized processors • Moved hardware Render/Audio Loops to software

  17. CRT Amusement Device Gun Fight Genesis MHz Barrier Noughts and Crosses Gypsy Juggler Saturn 1988: Genesis • First multi-CPU console • 68000 CPU for Sim/Render • Z80 CPU for Audio 1950 1940 1960 1970 1980 1990 2000

  18. CRT Amusement Device Gun Fight Genesis MHz Barrier Noughts and Crosses Gypsy Juggler Saturn 1994: Saturn • First symmetric Multi-CPU console • Two Hitachi RISC processors • 6 processors for video/sound/control 1950 1940 1960 1970 1980 1990 2000

  19. 1980-2000: Analysis • Multi-CPU Consoles have existed for 18+ years • Many consoles with asymmetric CPUs • Few consoles with symmetric CPUs • “One very fast central processor would be preferable… I think only one out of 100 programmers is good enough to get that kind of speed out of the Saturn.” – Yu Suzuki

  20. CRT Amusement Device Gun Fight Genesis MHz Barrier Noughts and Crosses Gypsy Juggler Saturn 2003: MHz Barrier 1950 1940 1960 1970 1980 1990 2000 CPU frequency 1995-2006 MHz Year

  21. 2000-2006: Analysis • Paradigm Shift • “The Free Lunch is Over” • Parallel by necessity • Legacy code won’t run magically faster • More performance requires mastering concurrency • Single CPU no longer the norm

  22. “How?” Game Loop Architecture Decisions

  23. Architecture: Game loop complexity Concurrency Coupling Time Complexity

  24. Architecture: Game loop complexity Concurrency Coupling Time Complexity

  25. Architecture: Time • Problem • Running smoothly in real-time • Solution • Frequency-Driven Game Loop • Divide time into discrete iterations • Attempt to run “fast enough” and “smooth enough” • Consequence • Each Loop iteration is a time slice

  26. Architecture: Time • Challenge • How to maintain a loop frequency with variable execution time • Factors • Performance • Tolerance • Architecture Decisions • Scheduling • Time Step • Determinism • Simplicity

  27. Scheduling Immediate Best-Fit Aligned Architecture: Time • Scheduling • Controls when a loop iteration starts

  28. Time Architecture: Legend • Time Axis • Real time • Ticks at desired frequency • Box • Loop iteration • Length is processing time • Arrows • Time step • Length is simulated time • Data • Data used by a loop

  29. Time Architecture: Time Scheduling • Description • “As fast as it can” • Factors + Performance - Tolerance Determinism + Simplicity Immediate Exact Faster Slower Varied

  30. Time Architecture: Example • Early adventure games Scheduling: Immediate while (1) { GetInput(); Sim(); Render(); }

  31. Time Architecture: Time Scheduling • Description • “Averaging” • Tries to • Maintain frequency • Start at exact times • Catch up • Factors + Performance + Tolerance Determinism - Simplicity Best-Fit Exact Faster Slower Varied

  32. Time Architecture: Time Scheduling • Description • “VSynced” • Factors - Performance - Tolerance Determinism + Simplicity Aligned Exact Faster Slower Varied

  33. Time Step None Fixed-Value Real-Time Architecture: Time • Time Step • Controls interpretation of time • “Simulated” time

  34. Time Architecture: Time Time Step • Description • Ignores time • Factors Performance Tolerance + Determinism + Simplicity None Exact Faster Slower Varied

  35. Time Architecture: Time Time Step • Description • Time step always constant • Factors Performance - Tolerance + Determinism - Simplicity Fixed-Value Exact Faster Slower Varied

  36. Time Architecture: Example • Deterministic real-time games Scheduling: Time Step: Best-Fit Fixed-Value const float TIMESTEP = 1 / 60.0f; while (1) { curTime = GetTime(); if ((curTime – lastTime) >= TIMESTEP) { Sim(TIMESTEP); lastTime = curTime; } }

  37. Time Architecture: Time Time Step • Description • Sim Time == Real Time • Factors Performance + Tolerance - Determinism - Simplicity Real-Time Exact Faster Slower Varied

  38. Architecture: Game Loop Complexity Concurrency Coupling Time Complexity

  39. Architecture: Coupling • Problem • Supporting systems at different frequencies • Solution • Multiple game loops • Consequence • Loop Coupling • Dependencies between every pair of loops

  40. Architecture: Coupling • Challenge • How to split code and data into multiple loops • Factors • Performance • Tolerance • Simplicity • Architecture Decisions • Frequency Coupling • Data Coupling • Video Modes • Memory • Scalability

  41. Frequency Equal Multiple Decoupled Architecture: Coupling • Frequency • How much a loop relies on another’s frequency

  42. Architecture: Coupling Frequency • Description • 1:1 • “Lockstep” • Factors - Video modes + Memory Performance - Tolerance - Scalability + Simplicity Equal Time (Loop 1) Time (Loop 2)

  43. Architecture: Coupling Frequency • Description • N:1 • Multiple of frequency • Sim @ 60 Hz • Render @ 30 Hz • Factors - Video modes + Memory Performance - Tolerance - Scalability + Simplicity Multiple Time (Loop 1) Time (Loop 2)

  44. Architecture: Coupling Frequency • Description • N:M • Two independent rates • Factors + Video modes - Memory Performance + Tolerance + Scalability - Simplicity Decoupled Time (Loop 1) Time (Loop 2)

  45. Architecture: Example Scheduling: Time Step: Frequency: Best-Fit Fixed-Value Decoupled Scheduling: Time Step: Frequency: Aligned Fixed-Value Decoupled • Decoupled Sim and Render loops while (1) { time = GetTime() if ((time – lastTime) >= SIM_STEP) { Sim(SIM_STEP); lastTime = time; } } while (1) { Render(RENDER_STEP); WaitForVSync(); }

  46. Data Coupling Tight Loose None Architecture: Coupling • Data Coupling • The amount and method of sharing data

  47. Architecture: Coupling Data Coupling • Description • Data structure reliance • Factors Video modes + Memory + Performance Tolerance - Scalability - Simplicity Tight

  48. Architecture: Coupling Data Coupling • Description • Formalized data passing • Factors Video modes - Memory - Performance Tolerance + Scalability + Simplicity Loose

  49. Architecture: Coupling Data Coupling • Description • Fully independent • No data passing • Factors Video modes + Memory + Performance Tolerance + Scalability + Simplicity None

  50. Architecture: Game loop complexity Concurrency Coupling Time Complexity

More Related