CSCE 552 Fall 2012 Language and Programming By Jijun Tang.

Slides:



Advertisements
Similar presentations
Written by: Dr. JJ Shepherd
Advertisements

Chapter 10 Introduction to Arrays
THQ/Gas Powered Games Supreme Commander and Supreme Commander: Forged Alliance Thread for Performance.
CSCE 590E Spring 2007 Game Programming By Jijun Tang.
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
How do games work? Game Workshop July 4, Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects.
Reza Gorgan Mohammadi AmirKabir University of Technology, Department of Computer Engineering & Information Technology Advanced design.
Chapter 3.3 Programming Fundamentals Languages Paradigms Basic Data Types Data Structures OO in Game Design Component Systems Design Patterns.
The Logic Machine We looked at programming at the high level and at the low level. The question now is: How can a physical computer be built to run a program?
CSCE 590E Spring 2007 Game Architecture and Math By Jijun Tang.
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.
Chapter 3.4 Programming Fundamentals. 2 Data Structures Arrays – Elements are adjacent in memory (great cache consistency) – They never grow or get reallocated.
Chapter 3.4 Game Architecture. Overall Architecture The code for modern games is highly complex With code bases exceeding a million lines of code, a well-defined.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
Chapter 26 Applying Gang of Four Design Patterns 1CS6359 Fall 2012 John Cole.
CHAPTER 17 Creating an Interactive 3D Environment © 2008 Cengage Learning EMEA.
File System. NET+OS 6 File System Architecture Design Goals File System Layer Design Storage Services Layer Design RAM Services Layer Design Flash Services.
Chapter Languages, Programming and Architecture.
CSE 381 – Advanced Game Programming 3D Game Architecture.
Design Patterns.
CSCE 552 Spring 2011 Math By Jijun Tang. Layered.
CSCE 552 Spring 2009 Programming Fundamentals By Jijun Tang.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
CHAPTER TEN AUTHORING.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
1 Web Based Programming Section 8 James King 12 August 2003.
Design Patterns CSCI 5801: Software Engineering. Design Patterns.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
Structural Design Patterns
Design Patterns CSIS 3701: Advanced Object Oriented Programming.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
Event Driven Programming Minus the GUI Plus a Robot By Charlie Vick.
July 28, 2015IAT 2651 Design Patterns. “Gang of Four” July 28, 2015IAT 2652.
CPSC 871 John D. McGregor Module 5 Session 1 Design Patterns.
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,
CSCE 552 Fall 2012 Language and Programming By Jijun Tang.
Programmeerimine Delphi keskkonnas MTAT Programmeerimine Delphi keskkonnas MTAT Jelena Zaitseva
Introduction to Interactive Media Interactive Media Tools: Authoring Applications.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
Games Development 1 Review / Revision CO2301 Games Development 1 Semester 2.
CS 210 Final Review November 28, CS 210 Adapter Pattern.
Game Programming Patterns Game Loop From the book by Robert Nystrom
CSCE 552 Spring 2011 Math By Jijun Tang. Languages C/C++ Java Script: Flash, Python, LISP, etc. C# XNA for PC and Xbox.
Chapter 3: Introducing the UML
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it by creating a representative object.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Written by: Dr. JJ Shepherd
StarBuzz Coffee Recipe Boil some water Brew coffee in boiling water Pour coffee in cup Add sugar and milk Tea Recipe Boil some water Steep tea in boiling.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Slide 1 Chapter 8 Architectural Design. Slide 2 Topics covered l System structuring l Control models l Modular decomposition l Domain-specific architectures.
CSCE 552 Spring 2009 Game Architecture and Math By Jijun Tang.
CSCE 552 Spring 2011 Language and Programming By Jijun Tang.
Examples (D. Schmidt et al)
Language and Programming
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.
CS360 Windows Programming
Object Oriented Design Patterns - Structural Patterns
Introduction to Design Patterns
Informatics 122 Software Design II
CSCI1600: Embedded and Real Time Software
Games Development 1 Review / Revision
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
GoF Patterns Ch. 26.
Presentation transcript:

CSCE 552 Fall 2012 Language and Programming By Jijun Tang

Data Structures: Array Elements are adjacent in memory (great cache consistency)  Requires continuous memory space They never grow or get reallocated  Use dynamic incremental array concept  GCC has a remalloc function In C++ there's no check for going out of bounds  Use vector if possible  Keep in mind of checking boundaries Inserting and deleting elements in the middle is expensive

Lists

Hash Table

Stack/Queue/Priority Queue

Bit packing Fold all necessary data into a smaller number of bits Bool in C++ may use up to 4 bytes, thus is very expensive Very useful for storing boolean flags: pack 32 in an integer Possible to apply to numerical values if we can give up range or accuracy Very low level trick  Use shifts to handle the operation or use assembly  Only use when absolutely necessary

Bits

Inheritance Models “is-a” relationship Extends behavior of existing classes by making minor changes Do not overuse, if possible, use component systerm UML diagram representing inheritance

Component Systems Component system organization

Factory Pattern

Singleton Implements a single instance of a class with global point of creation and access For example, GUI Don't overuse it!!!

Adapter Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces Real interface

Observer Allows objects to be notified of specific events with minimal coupling to the source of the event Two parts  subject and observer

Composite Allow a group of objects to be treated as a single object Very useful for GUI elements, hierarchical objects, inventory systems, etc

Composite Pattern Example - I Add many more inherited classes

Game Architecture

Overall Architecture The code for modern games is highly complex  The Sims: 3 million lines of code  Xbox HD DVD player: 4.7 million lines  MS Train Simulator has 1GB installed, with only 10MB executable With code bases exceeding a million lines of code, a well-defined architecture is essential

Overall Architecture Main structure  Game-specific code  Game-engine code Both types of code are often split into modules, which can be static libraries, DLLs, or just subdirectories

Overall Architecture Architecture types  Ad-hoc (everything accesses everything)  Modular  DAG (directed acyclic graph)  Layered Options for integrating tools into the architecture  Separate code bases (if there's no need to share functionality)  Partial use of game-engine functionality  Full integration

Ad-hoc

Modular

DAG

Layered

Example

Overview: Initialization/Shutdown The initialization step prepares everything that is necessary to start a part of the game The shutdown step undoes everything the initialization step did, but in reverse order

Initialization/Shutdown Resource Acquisition Is Initialization  A useful rule to minimalize mismatch errors in the initialization and shutdown steps  Means that creating an object acquires and initializes all the necessary resources, and destroying it destroys and shuts down all those resources Optimizations  Fast shutdown  Warm reboot

Overview: Main Game Loop Games are driven by a game loop that performs a series of tasks every frame Some games have separate loops for the front and the game itself Other games have a unified main loop Must finish a loop within second

Tasks of Main Game Loop Handling time Gathering player input Networking Simulation Collision detection and response Object updates Rendering Other miscellaneous tasks

Sample Game Loop

private void GameLoop() { frameRate = game.FrameRate(); ticks = Environment.TickCount; lastTime = 0; if (ticks > lastTime + 16) { lastTime = ticks; switch (game.gameState) { case Game.GameStates.STATE_PLAY: game.playScreen.Draw(); break; case Game.GameStates.STATE_LOAD: game.loadScreen.Draw(); break; case Game.GameStates.STATE_PLAYING: doScrolling(); doHero(); doSide(); break; } game.Update(); Application.DoEvents(); } else { System.Threading.Thread.Sleep(1); } }

Main Game Loop Structure  Hard-coded loops  Multiple game loops: for each major game state  Consider steps as tasks to be iterated through Coupling  Can decouple the rendering step from simulation and update steps  Results in higher frame rate, smoother animation, and greater responsiveness  Implementation is tricky and can be error-prone

Execution Order of Main Loop Most of the time it doesn't matter In some situations, execution order is important Can help keep player interaction seamless Can maximize parallelism Exact ordering depends on hardware

static void Start(UserSettings settings, string[] args) { InitSimulator(settings, args); Simulator.Start(); Viewer = new Viewer3D(Simulator); Viewer.Run(); Simulator.Stop(); } [ThreadName( "Render" )] public void Run() { LoaderProcess = new LoaderProcess( this ); UpdaterProcess = new UpdaterProcess( this ); RenderProcess = new RenderProcess( this ); RenderProcess.Run(); }

static void Start(UserSettings settings, string[] args) { InitSimulator(settings, args); Simulator.Start(); Viewer = new Viewer3D(Simulator); Viewer.Run(); Simulator.Stop(); } [ThreadName( "Render" )] public void Run() { LoaderProcess = new LoaderProcess( this ); UpdaterProcess = new UpdaterProcess( this ); RenderProcess = new RenderProcess( this ); RenderProcess.Run(); }

public LoaderProcess(Viewer3D viewer) { Threaded = true; Viewer = viewer; if (Threaded) { State = new ProcessState("Loader"); Thread = new Thread(LoaderThread); Thread.Start(); }

[ThreadName("Loader")] void LoaderThread() { Profiler.SetThread(); while (Thread.CurrentThread.ThreadState == System.Threading.ThreadState.Running) { // Wait for a new Update() command State.WaitTillStarted(); try { if (!DoLoad()) return; } finally { State.SignalFinish(); }

public UpdaterProcess(Viewer3D viewer) { Threaded = System.Environment.ProcessorCount > 1; Viewer = viewer; if (Threaded) { State = new ProcessState("Updater"); Thread = new Thread(UpdaterThread); Thread.Start(); }

[ThreadName("Updater")] void UpdaterThread() { Profiler.SetThread(); while (Thread.CurrentThread.ThreadState == System.Threading.ThreadState.Running) { // Wait for a new Update() command State.WaitTillStarted(); try { if (!DoUpdate()) return; } finally { State.SignalFinish(); }

public UpdaterProcess(Viewer3D viewer) { Threaded = System.Environment.ProcessorCount > 1; Viewer = viewer; if (Threaded) { State = new ProcessState("Updater"); Thread = new Thread(UpdaterThread); Thread.Start(); }

[ThreadName("Updater")] void UpdaterThread() { Profiler.SetThread(); while (Thread.CurrentThread.ThreadState == System.Threading.ThreadState.Running) { // Wait for a new Update() command State.WaitTillStarted(); try { if (!DoUpdate()) return; } finally { State.SignalFinish(); }