PacMan by Midway, released 1980 CSE 380 – Computer Game Programming Real-Time Game Architecture.

Slides:



Advertisements
Similar presentations
2000 Prentice Hall, Inc. All rights reserved. 1 Outline 3.1Introduction 3.2Game Loop Components 3.3How to Implement in C# 3.4Adding Image to XNA Project.
Advertisements

Game Programming Patterns Game Loop
Chapter Chapter 4. Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times.
Chapter 1 - An Introduction to Computers and Problem Solving
Network synchronization of Online Games Li, Zetan.
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.
Game Mathematics & Game State The Complexity of Games Expectations of Players Efficiency Game Mathematics o Collision Detection & Response o Object Overlap.
Computer Organization and Architecture
Pencilvania: Architecture Review Presenters: Christopher Buska (Art Director) Michael Gourlay (Developer) Alfred Sterphone, III (Project Manager) Special.
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.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
Games Development Practices Semester 2 Overview CO2301 Games Development 1 Week 14.
By Steven Taylor.  Basically a video game engine is a software system designed for the creation and development of video games.  There are many game.
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.
 Contents 1.Introduction about operating system. 2. What is 32 bit and 64 bit operating system. 3. File systems. 4. Minimum requirement for Windows 7.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Unit Six Assignment 1 Chris Boardley.
SOFTWARE.
Microsoft Visual Basic 2005 CHAPTER 1 Introduction to Visual Basic 2005 Programming.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Chapter Languages, Programming and Architecture.
Games Development 2 Entity / Architecture Review CO3301 Week
CSE 380 – Computer Game Programming AI & Collision Strategy Erin Catto’s Box2D.
Introduction 01_intro.ppt
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Hands-on Introduction to Visual Basic.NET Programming Right from the Start with Visual Basic.NET 1/e 6.
CSE 381 – Advanced Game Programming 3D Game Architecture.
Super Pong Andrew Dunsmore CSC436. Overview Purpose Design Specification Software Engineering.
CSE 380 – Computer Game Programming Render Threading Portal, by Valve,
TerraForm3D Plasma Works 3D Engine & USGS Terrain Modeler Heather Jeffcott Craig Post Deborah Lee.
CSE 380 – Computer Game Programming Sprite Animation
Town Defenders Strategy Game prepared by: Osama N
A Spring 2005 CS 426 Senior Project By Group 15 John Studebaker, Justin Gerthoffer, David Colborne CSE Dept., University of Nevada, Reno Advisors (CSE.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
INVITATION TO COMPUTER SCIENCE, JAVA VERSION, THIRD EDITION Chapter 6: An Introduction to System Software and Virtual Machines.
CHAPTER TWO INTRODUCTION TO VISUAL BASIC © Prepared By: Razif Razali 1.
XNA An Introduction. What XNA is… Microsoft® XNA™ is composed of industry- leading software, services, resources, and communities focused on enabling.
Programming Video Games
2.1. T HE G AME L OOP Central game update and render processes.
CSE 380 – Computer Game Programming GUIs for Games.
Reference: The Game Loop Animation / Game loop 1. Update variables 2. [Get input from the user] (GameLoop only) 3. Draw (using variables)
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,
11 General Game Programming Approach. The program is event-driven The program is event-driven –Messages = events –So as all windows system (for example.
CS324e - Elements of Graphics and Visualization Timing Framework.
Iteration 1 Looping Structures. Iteration 2 The Plan While not everyone understands: 1.Motivate loops 2.For loops 3.While loops 4.Do-while loops 5.Equivalence.
An operating system is the software that makes everything in the computer work together smoothly and efficiently. What is an Operating System?
Super Pong Andrew S. Dunsmore CSC436 August 2004.
Game Programming Patterns Game Loop From the book by Robert Nystrom
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS Game program main loop.
Dr Nick Mitchell (Room CM 224)
CompSci Introduction to Jam’s Video Game Package.
Introduction to Game Programming Pertemuan 11 Matakuliah: T0944-Game Design and Programming Tahun: 2010.
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 –
CompSci 44.1 Game Package Introduction to Jam’s Video Game Package.
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.
Introduction to Game Programming & Design III Lecture III.
(More) Event handling. Input and Windowed-OS’s Windowed OS’s (Windows, OSX, GUI-linux’s) send messages (events) when the user does something “on” the.
Understanding AI of 2 Player Games. Motivation Not much experience in AI (first AI project) and no specific interests/passion that I wanted to explore.
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
CST 1101 Problem Solving Using Computers
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.
Introduction to Visual Basic 2008 Programming
Game Loops + Part II Reference:
Hands-on Introduction to Visual Basic .NET
Cannon Game App Android How to Program
Game Loop Update & Draw.
An Introduction to Linux
Games Development 2 Entity / Architecture Review
Presentation transcript:

PacMan by Midway, released 1980 CSE 380 – Computer Game Programming Real-Time Game Architecture

Game-specific code vs. Game-engine code Try to make code that’s flexible, maintainable, reusable, etc. –some things may be common for all games rendering, collision detection, game loop, etc. –some things are game-specific game rules, event responses, etc. Game #1 - custom use Game #2 - custom use Game Framework - Game Loop - Timing - GUI - AI - Level loading - Physics

The Game Loop Games aim to run at consistent frame rates What’s a frame rate? –the average iterations through the game loop per second Typical Frame rates: –30 fps –50 fps –up to 100 fps

Simple game loop architecture Retrieve player input Main logic Collision Detection Game AI Physics Render next frame Exit to O/S Cleanup Deallocate Close files Exit to menu What’s missing?Timing Initialization Allocate memory Load levels … Start Display Menu GUI

Dynamic Game Objects Let’s address this early Some objects move –characters, missiles, vehicles, animals, etc. Why move an object? –player input –AI decisions –collisions/physics

Design Strategy We need a reliable, consistent approach to handle Dynamic objects Solution: velocities

Velocities In our games, all dynamic game objects (things that can move) will have x & y velocities

Each Frame 1. P rocess game input –if necessary change player state and velocities 2. Process game AI –if necessary change bot states and velocities 3. Process game physics –if necessary change object(s) states and velocities –for each collision we may need to correct velocities and positions 4. Update all dynamic object positions using velocities

The Game Loop Each frame: –get mouse input since last frame if mouse button clicked over button, execute response –get key input since last frame determine key, if necessary, execute response –perhaps update player state/velocity –perhaps update game state (i.e. move to quit game state) –for all bots, compute AI update bot states & velocities –for all dynamic objects, compute physics update velocities & positions for collisions –update all positions using remaining velocities –render game –calculate time of last game loop, clamp to desired frame rate

Game Program Complexity Game programs are some of the most complex applications –Basically they are ultra-high performance computer programs Real-time, multithreaded, intelligent simulations displaying 30 frames per second or more Speed is extremely important Experienced game programmers sometimes use a coding style that optimizes program execution speed Warning: Video game programming is 90 % data manipulation –Careful data structure (simple is usually better) –Very careful algorithm selection (efficient is better, duh!)

What do we need from Windows? a main method –WinMain for event driven applications a Window messages concerning events –WinProc tells us about important stuff easy ways of getting mouse & key input data –we’ll do this with Windows method, not DirectX We’ll do everything else in DirectX –including making buttons and other controls

This semester’s Game class Will the focal point It will have: –the game loop –the game state i.e. game in progress, paused, quitting, etc. –access to everything: GameDataLoader, GameGraphics, GameGUI, GameInput, GameOS, GameStateManager, etc.

What does a game state dictate? What to draw? –which Menu/GUI controls Is the game in progress? –if no, skip the game logic code How to respond to user input? –know which buttons are being clicked Let’s look at a simplified Game class

A little UML GameTimer -timerResolution:UINT -targetMillisPerFrame:DWORD -gameLoopStartTime:DWORD - … -*writer:TextFileWriter + resetTimer( ) + timeGameLoop( ) GameApp + $WinMain(… Game -$ gameIsActive:bool - *window:GameWindow - *timer:GameTimer + killGameApplication( ) + runGameLoop( ) GameWindow -windowHandle:HWND -wi:WINDOWINFO -applicationName:LPCWSTR -manageWindowsProc( ) -$ WinProc (…

A game as a series of steps – one option 1.Game Initialization 2.Main game loop a.Menu initialization b.Menu loop i.Get input ii.Render screen iii.Update menu state iv.Trigger game state changes c.Menu shutdown d.Level Initialization e.Level Game Loop i.Get input ii.Run AI iii.Collision detection/physics iv.Update game objects v.Render screen 1.Time loop 1.Level shutdown a.Game Shutdown

A game as a series of steps – another option 1.Game & Menu Initialization 2.Main game loop - Test Game State a.If Menu state: i.Get input ii.Process menu events – if start game level A.Change to Game state B.Load level a.If Level state i.Get Input ii.Process GUI events – if change levels/go to menu A.Change to Menu state or change level B.Unload current level C.Load level if necessary iii.Run AI iv.Collision detection/physics v.Update game objects – if change levels/go to menu 1.Change to Menu state or change level 2.Unload current level –Load level if necessary vi.Render screen i.Time loop A.Game Shutdown

What is timing? We don’t want our game loop to go too slow or too fast –different machines have different capabilities Solution: –time your game loop –synch games on all PCs –synch all behavior to time, not to frames How? –“throttle frames” using high-resolution timer –also called clamping –we must do this for good animation and movement

Timers Timers have varying resolutions. What’s that? –precision of time measurements Best we can hope for is 1 millisecond One option, Windows Multimedia Library timers

High Resolution Timers Steps for use 1.Setup timer a.Ask system what best resolution is –getMinSystemTimerResolution b.Setup timer requesting that resolution –timeBeginPeriod 2.Use timer once per frame 1.Calculate time elapsed 2.Calculate target time – actual time 3.If > 0, loop too fast, what should we do? 4.If < 0, loop too slow, what should we do?

Clamping a Loop Options: –inner loop until time is up –sleep (preferred) Note, some numbers in GameTimer don’t include the time we sleep –these start with “sleepless”

Compensating for a slow machine Options: –improve program performance (duh) “tighten up the graphics” –other than that: skip rendering interpolation –scale movements –scale animations live with it, make the player buy a new computer

void GameTimer::timeGameLoop() { gameLoopEndTime = timeGetTime(); loopTime = gameLoopEndTime - gameLoopStartTime; gameLoopStartTime = timeGetTime(); sleeplessLoopTime = gameLoopEndTime - sleeplessGameLoopStartTime; if (targetMillisPerFrame > sleeplessLoopTime) { sleepTime = targetMillisPerFrame - sleeplessLoopTime; Sleep(sleepTime); timeScaleFactor = 1; } else { sleepTime = 0; timeScaleFactor = ((float)TARGET_FPS)/((float)sleeplessLoopRate); } sleeplessGameLoopStartTime = timeGetTime(); loopCounter++; }

References Introduction to Game Development –Edited by Steve Rabin, Charles River Media