3D Game Development Time and game loop Jernej Vičič.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Yaron Doweck Yael Einziger Supervisor: Mike Sumszyk Spring 2011 Semester Project.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Mutual Exclusion.
Intertask Communication and Synchronization In this context, the terms “task” and “process” are used interchangeably.
MotoHawk Training Model-Based Design of Embedded Systems.
How do games work? Game Workshop July 4, Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects.
CHAPTER 1 Introduction to Game Development © 2008 Cengage Learning EMEA.
Chapter 3.6 Game Architecture. 2 Overall Architecture The code for modern games is highly complex With code bases exceeding a million lines of code, a.
Principle of Functional Verification Chapter 1~3 Presenter : Fu-Ching Yang.
Games Development Practices Semester 2 Overview CO2301 Games Development 1 Week 14.
CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA.
CSE 381 – Advanced Game Programming 3D Game Architecture.
15-740/ Oct. 17, 2012 Stefan Muller.  Problem: Software is buggy!  More specific problem: Want to make sure software doesn’t have bad property.
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
Concurrency, Mutual Exclusion and Synchronization.
CSE1GDT Gameplay Mechanics. Core Mechanics The exact definition of the gameplay rules –It doesn’t matter where these rules are, just that you know them!
2.1. T HE G AME L OOP Central game update and render processes.
Games Development Game Architecture: Entities CO2301 Games Development 1 Week 22.
Chapter 3.6 Game Architecture. 2 Overall Architecture The code for modern games is highly complex (can easily exceed 1M LOC) The larger your program,
Games Development 1 Review / Revision CO2301 Games Development 1 Semester 2.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Game program main loop.
Self-Adaptive Embedded Technologies for Pervasive Computing Architectures Self-Adaptive Networked Entities Concept, Implementations,
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE 498AL, University of Illinois, Urbana-Champaign 1 ECE 498AL Spring 2010 Lecture 13: Basic Parallel.
T HE G AME L OOP. A simple model How simply could we model a computer game? By separating the game in two parts: – the data inside the computer, and –
Image Processing A Study in Pixel Averaging Building a Resolution Pyramid With Parallel Computing Denise Runnels and Farnaz Zand.
Threaded Programming Lecture 1: Concepts. 2 Overview Shared memory systems Basic Concepts in Threaded Programming.
3/12/2013Computer Engg, IIT(BHU)1 CONCEPTS-1. Pipelining Pipelining is used to increase the speed of processing It uses temporal parallelism In pipelining,
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Parallel Computing Presented by Justin Reschke
Distributed Mutual Exclusion Synchronization in Distributed Systems Synchronization in distributed systems are often more difficult compared to synchronization.
Game Programming (Game Architecture)
Kai Li, Allen D. Malony, Sameer Shende, Robert Bell
CS703 - Advanced Operating Systems
REAL-TIME OPERATING SYSTEMS
Game Architecture Rabin is a good overview of everything to do with Games A lot of these slides come from the 1st edition CS 4455.
OVERVIEW Impact of Modelling and simulation in Mechatronics system
Tech.
Technologies Overview Media files, such as the sounds, are placed in the app’s resource folder res/raw. When an Activity is shut down, its Fragment.
ESE532: System-on-a-Chip Architecture
ECE 448 Lecture 6 Finite State Machines State Diagrams vs. Algorithmic State Machine (ASM) Charts.
COMP4211 : Advance Computer Architecture
Chapter 1: Introduction
RTS: Kernel Design and Cyclic Executives
Chapter 5 - Functions Outline 5.1 Introduction
CSCI1600: Embedded and Real Time Software
Superscalar Processors & VLIW Processors
World-Views of Simulation
Chapter 2: The Linux System Part 3
CIS 488/588 Bruce R. Maxim UM-Dearborn
RTS: Kernel Design and Cyclic Executives
Analysis models and design models
CPU scheduling decisions may take place when a process:
An Introduction to Software Architecture
Chapter I Introduction
RTS: Kernel Design and Cyclic Executives
Concurrency: Mutual Exclusion and Process Synchronization
Games Development Practices Semester 2 Overview
Direct Manipulation.
Multithreading Why & How.
Software Architecture
ECE 448 Lecture 6 Finite State Machines State Diagrams, State Tables, Algorithmic State Machine (ASM) Charts, and VHDL code ECE 448 – FPGA and ASIC Design.
Games Development Game Architecture: Entities
ECE 448 Lecture 6 Finite State Machines State Diagrams vs. Algorithmic State Machine (ASM) Charts.
WJEC GCSE Computer Science
Instruction Level Parallelism
CSCI1600: Embedded and Real Time Software
Games Development 1 Review / Revision
From Use Cases to Implementation
Presentation transcript:

3D Game Development Time and game loop Jernej Vičič

Overview (chapters in book: 7.1–7.5) rendering loop; game loop; architectural styles; abstract time plans; time and measuring. 3D Game Development, Jernej Vičič

Game loop a computer game is a real-time computer application, we use different types of time: real time (clock on the wall), time of the game (simulated time), local timetables (sound, animation time, ...), processor cycles (function time). game loop defines how these times are combined, this is how individual components are synchronized. 3D Game Development, Jernej Vičič

Game loop most of the components use local times, usually only three tasks run in parallel: HID input (interaction with the player), game logic (player status, world state, story), feedback (rendering, sound, HID output). technology restrictions: 1-4 (8) processors (maybe some more), limited memory, limited speed. 3D Game Development, Jernej Vičič

Game loop 3D Game Development, Jernej Vičič

Game loop - http://www.notebookcheck.net/ 3D Game Development, Jernej Vičič

Game loop – game logic game logic – analogy to business logic, recipe for updating: player status update: detect the player's input (HID), update the status of the player (observe the limits of the world); 3D Game Development, Jernej Vičič

Game loop – logika igre refresh world data: static elements: optimized by selecting the area of interest logic, elements controlled by the game logic (dynamic elements): sorted by relevance (LOD), update the status. elements managed by AI (complex behavior): aware of the internal state, decision making and enforcement of rules. 3D Game Development, Jernej Vičič

Rendering loop The illusion of movement is achieved with the high frequency of the rendering loop. while (!quit) { // fix the camera view according to input or path updateCamera(); // update scene graph (position/orientation of objects) updateSceneGraph(); // Render the scene in “Back Buffer” renderScene(); // swap “Back Buffer” and Front Bufferjem swapBuffers(); } 3D Game Development, Jernej Vičič

Game loop – real-time constraints we have to display graphics with at least 30 FPS (motion illusion), the frequency of other systems may vary: AI (~ 10), input (~ 40), sound (~ 50), stereovision (~ 60), physics (~ 100), haptic feedback (~ 3k), some need synchronization (physics and graphics), engine services all these subsystems: game loop calls the components in the right time. 3D Game Development, Jernej Vičič

Game loop – possible implementations coupled approach: update/render in one loop update render 3D Game Development, Jernej Vičič

Game loop – coupled approach primer (Pong): int main () { initGame(); // init while (true) { // game loop readHumanInterfaceDevices(); if (quitButtonPressed()) break; // end game loop movePaddles(); moveBall(); if (scored()) { updateScore(); resetBall(); } renderScore(); // render new state renderPaddles(); renderBall(); return 0; 3D Game Development, Jernej Vičič

Game loop – coupled approach advantages: both routines have the same priority, logic and presentation are united, shortcomings: the change in the complexity of one of the routines affects the another, we have no control over how often a routineis executed. 3D Game Development, Jernej Vičič

Game loop – possible implementations two threads with different frequencies: Engine update render 3D Game Development, Jernej Vičič

Game loop – združen pristop primer (Pong): Engine.cpp initGame(); // Set up initial configuration startUpdater(60); // Start the update loop (60 Hz) startRenderer(30); // Start the rendering loop (30 Hz) Update.cpp while (true) { // zanka Timer(60); readHumanInterfaceDevices(); if (quitButtonPressed()) exit(0); movePaddles(); moveBall(); if (scored()) { updateScore(); resetBall(); } Render.cpp while (true) { // zanka Timer(30); renderScore(); renderPaddles(); renderBall(); } 3D Game Development, Jernej Vičič

Game loop – dve niti z ločenima frekvencama pros: the rendering and update loops are performed at different frame rates, cons: not all the hardware is suitable for the implementation of threads (single-processor, timing problems), problems with synchronization (two threads access the same data). 3D Game Development, Jernej Vičič

Game loop – possible implementations one thread, open loop: render clock upodobitev 3D Game Development, Jernej Vičič

Game loop – one thread, open loop example (Pong): int main () { initGame(); float lastCall = getTime(); // internal computer clock while (true) { // Game loop if (getTime()-lastCall > 1/FREQ) {// timer readHumanInterfaceDevices(); if (quitButtonPressed()) break; movePaddles(); moveBall(); if (scored()) { updateScore(); resetBall(); } lastCall = getTime(); } // using MAX frequency for render renderScore(); renderPaddles(); renderBall(); return 0; 3D Game Development, Jernej Vičič

Game loop – one thread, open loop advantages: better control than one thread and simpler implementation than multiple threads (no synchronization), weaknesses: assumes that tick hours lasts 0 time, alt-tab destroys synchronization, does not allow higher frequency nests. 3D Game Development, Jernej Vičič

Game loop – possible implementations one thread, open loop, rendering and update is frequency dependent: Engine clock … clock update update render 3D Game Development, Jernej Vičič

Game loop – one loop, open loop primer (Pong): int main () { HID.setFrequency(20); Paddles.setFrequency(10); Ball.setFrequency(10); while (true) { // Zanka igre HID.update(); if (quitButtonPressed()) break; Paddles.update(); Ball.update(); if (scored()) { updateScore(); resetBall(); } lastCall = getTime(); // render frequency “as fast as possible” Score.render(); Paddles.render(); Ball.render(); return 0; 3D Game Development, Jernej Vičič

Game loop – one thread, open loop Advantages: allows separate frequencies for each entity in the game, the same mechanism can also be used for rendering, generic auto registration. Shortcomings: manually determine the frequency for each entity, we need an entry point for each update (the number can be high). 3D Game Development, Jernej Vičič

Game loop what we do if the time between two updates is much greater than the desired frequency: nothing (the game runs slower) (we are screwed), the update of the logic of the game should still take place in real time: ’visual gaps’ (poor man’s choice). 3D Game Development, Jernej Vičič

Game loop solution: speed up the update (if we can/know how) reduce the frequency (if it can be done - if it does not disturb), we use LoD for game logic (we are not dealing with all entities). 3D Game Development, Jernej Vičič

Game loop solution: speed up rendering: graphic LoD, reduce the resolution, reduce the number of effects, automatically with real-time profilers (detect and reduce accuracy - engine). 3D Game Development, Jernej Vičič

Threads and synchronization A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same time. a challenging task to ensure consistency, not all libraries and engines are thread-safe. Razvoj iger, Jernej Vičič

Threads and synchronization Which subsystem has thread control? Input Control (HiD), main engine, game logic, component that creates threads, ? 3D Game Development, Jernej Vičič

Threads and synchronization this is where we should go through paralle programming basics, let us assume that we already know the basics, still, have a look at: critical section, semaphore, mutex, conditional variables. 3D Game Development, Jernej Vičič