2.1. T HE G AME L OOP Central game update and render processes.

Slides:



Advertisements
Similar presentations
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Advertisements

Game Programming Patterns Game Loop
4.3. S OUND Use of sound within games. In lecture exploration of answers to frequently asked student questions.
Prof. Srinidhi Varadarajan Director Center for High-End Computing Systems.
THQ/Gas Powered Games Supreme Commander and Supreme Commander: Forged Alliance Thread for Performance.
3.3. G AME I NPUT Handling input within games. In lecture exploration of answers to frequently asked student questions.
How do games work? Game Workshop July 4, Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects.
Game Design and Programming. Objectives Classify the games How games are design How games are implemented What are the main components of a game engine.
SCA Introduction to Multimedia
CISC 879 : Software Support for Multicore Architectures John Cavazos Dept of Computer & Information Sciences University of Delaware
Games Development Practices Semester 2 Overview CO2301 Games Development 1 Week 14.
AGD: 5. Game Arch.1 Objective o to discuss some of the main game architecture elements, rendering, and the game loop Animation and Games Development.
CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA.
Gearbox Software PRODUCTION PIPELINE – JOBS TITLES – JOB DESCRIPTIONS.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
1 CS101 Introduction to Computing Lecture 19 Programming Languages.
PacMan by Midway, released 1980 CSE 380 – Computer Game Programming Real-Time Game Architecture.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CSE 381 – Advanced Game Programming 3D Game Architecture.
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
An Introduction to Software Architecture
Computer Graphics Graphics Hardware
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
CS101 Introduction to Computing Lecture Programming Languages.
Developing the Game User Interface (UI) Lesson 5.
Microsoft Tech Days 2012 Cheezia: Developing a Windows Phone XNA Game Rodrigo Barretto Software Engineer - MCPD on Windows Phone
Java Threads 11 Threading and Concurrent Programming in Java Introduction and Definitions D.W. Denbo Introduction and Definitions D.W. Denbo.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Operating-System Structures System Components Operating System Services.
Reference: Ian Sommerville, Chap 15  Systems which monitor and control their environment.  Sometimes associated with hardware devices ◦ Sensors: Collect.
3.2. G RAPHICS I Alpha blending within games. An exploration of the use of alpha blending within games.
Games Development 2 Concurrent Programming CO3301 Week 9.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Ahmed Saker Indie Game Developer
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Game Creation in XNA CS470 Final Project Chris Ragland.
Reference: The Game Loop Animation / Game loop 1. Update variables 2. [Get input from the user] (GameLoop only) 3. Draw (using variables)
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
2.3. A RCHITECTURAL D ESIGN I Example approach for game screen management.
Introduction to Interactive Media Interactive Media Tools: Authoring Applications.
Stored Programs In today’s lesson, we will look at: what we mean by a stored program computer how computers store and run programs what we mean by the.
Game Programming Patterns Game Loop From the book by Robert Nystrom
Intermediate 2 Computing Unit 2 - Software Development.
Concurrency Properties. Correctness In sequential programs, rerunning a program with the same input will always give the same result, so it makes sense.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Game program main loop.
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 –
Motivates, interests and engages. Teaches problem solving skills. Allows for creativity and imagination. Demonstrates project design. Encourages teamwork.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Starting Out with Games & Graphics in C++ Tony Gaddis Chapter 8 The.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
5.3. S ECTION R OUNDUP Exploration of project hand-in and section roundup.
6/27/20161 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
Computer Graphics Graphics Hardware
Sound Music & Sound Effects.
Background on the need for Synchronization
Lecture 21 Concurrency Introduction
Alpha blending within games
2.2. Architectural Design I
Game Loop Update & Draw.
3D Game Development Time and game loop Jernej Vičič.
2.3. Architectural Design I
Background and Motivation
Grades.
Central game update and render processes
Title of Project Joseph Hallahan Computer Systems Lab
Programming with Shared Memory Specifying parallelism
Use of sound within games
Presentation transcript:

2.1. T HE G AME L OOP Central game update and render processes

Identifying commonality between different game types

Select one of the shown genre of game (assuming a 2D game). Think about the game in terms of how it looks, the features that it has, the things that it does. Try to identify common aspects that most games in the genre will share in terms of features and behaviour. Start 10 mins9 mins8 mins7 mins6 mins5 mins4 mins3 mins2 mins 1 min 30 secFinished Easy: Hard: Puzzle game Adventure game Racing game Platform game Rhythm game

Things most 2D game have... Front-end (titles, menus) Assets Graphical assets (animations, backgrounds) Sound assets (sfx, background music) Objects In-game objects (sprites, platforms, etc.) HUD objects (score, lives, time, etc.) Object Containers Levels, Areas, Maps Input Events {other things as needed} Things most 2D games do... Once per game/per level Load assets Construct objects Populate containers Lots of times / second Consider input events Update objects Draw graphics Consider sounds {other things as needed} Note: There is no correct answer. Each model will impose a certain set of assumptions, suiting some types of game but not others.

Game Container construct { Build objects() } update { Update objects() } draw { Draw objects() } object Game Object construct { Load assets() Build containers() } Game Engine run { loop { Update active layers() Draw visible layers() } Game consists of objects (player, collectables, score, etc.). Assets are loaded at runtime and can be managed via an asset manager Input events may be ‘consumed’ by the main game loop, layers and/or objects Objects reside within a container (front-end, game level, config screen, etc.) Asset Manager Input Events There may be separate update/draw management for game containers

The central mechanism to evolve and render game objects

Timers ● Most games require a timer to manage the game loop ● Early games used the machine as the timer ○ the update/render loop would run as fast as possible (tied to processor speed) ○ used as typically no spare CPU resource and common platform hardware ○ Approach does not scale to varied platforms or increased hardware capabilities

Early Approaches ● Early solution was to use a fixed frame rate as the timer (with one update/render tick every frame) set up fixed rate ticker ( 30/s ) when( tick event ) { update() render() } while( running ) { record tStart update() render() record tEnd if( tEnd-tStart < tickPeriod ) wait( tickPeriod – (tEnd-tStart)) } Why is this problematic? ● UPS reduced if update and draw take too long ● game runs slower, not just displayed with lower FPS

Assume you have access to the following methods ● update() – update all game objects ● render() – draw all game objects ● time() – get the current time (ms) ● sleep(ms) – sleep for specified number of ms And the following constraint and target: ● ups –number of update/s (constraint) ● fps – equal to ups (target) Develop an algorithm that adapts to different update and render loads. Hint: The fps should be reduced to ensure the ups remain on target. Optional: Produce an algorithm that compensates for timing/sleep inaccuracies (see SleepTimerTest in the Java Code Repository) Start 10 mins9 mins8 mins7 mins6 mins5 mins4 mins3 mins2 mins 1 min 30 secFinished

while( running ) { tBefore = time() update() render() tAfter = time() sleepTime = updatePeriod - (tAfter - tBefore) - overTime if( sleepTime > 0 ) { sleep( sleepTime) overTime = time() - tAfter - sleepTime } else { timeBeyondPeriod = timeBeyondPeriod - sleepTime overTime = 0 while( timeBeyondPeriod > updatePeriod ) { update() timeBeyondPeriod = - updatePeriod }}}}}} updatePeriod = 1000 / UPS timeBeyondPeriod = 0 overTime = 0 Period Loop 1 Loop 2 s o r u Period Loop n Loop m

● Previous slide can be viewed as a form of semi-decoupling ● The AI (update) runs at a fixed rate as before, but the frame (draw) rate just runs as fast as it possibly can (however, no real point running faster than the update loop).

● “Full” decoupling runs the update loop as fast as possible ● A variable interval duration and delta (change) value are used: ○ on faster machines more AI ticks/s with a smaller delta value ○ on slower machines ticks take longer and the delta value will be larger

Issues and aspects you should consider as part of your game loop

When designing game objects decouple the update and render behaviours. Ask two separate questions: ‘how will I update this’ and ‘how will I draw this’ e.g. for an animation, select the animation to be display in the update phase and render it in the draw phase The draw phase should not change the game state (i.e. properties, etc. of objects, it should simply visualise the game state)

XNA provides good control over how the update/draw loop performs For Java: explore game.engine.GameEngine.run() GraphicsDeviceManager class SynchronizeWithVerticalRetrace property – get/set if the maximum draw rate will be limited by the screen refresh rate Game class IsFixedTimeStep property – controls if a fixed update time should be used TargetElapsedTime property – get/set the target fixed time step duration GameTime class Has methods to determine the actual ellapsed time (needed if not using a fixed time step) IsRunningSlowly property – true if the target fixed update time step cannot be obtained

The update/draw game loop increasingly involves aspects of concurrency In the most basic sense, the CPU/GPU run in parallel, i.e. CPU tells GPU what to render and lets it get on with it Aside: The graphics pipeline can be stalled (forcing the CPU to wait for the GPU to ‘catch-up’) in various situations (sometimes unavoidable, e.g. getting render target data) Multi-core CPUs, e.g. current gen consoles, PCs, etc. can have numerous concurrent update threads. This will likely require synchronization.

To do: Finalise initial game idea, team/no-team, development language Read section to be completed in Project Development Report Think about game idea in terms of game objects, layers, updating, drawing Today we explored: Core game components and actions The update / draw loop and the different ways of managing time Things to keep in mind about the update / draw loop