CSCE 552 Spring 2009 Programming Fundamentals By Jijun Tang.

Slides:



Advertisements
Similar presentations
Memory Management Chapter 7.
Advertisements

Debugging Mohammad Zikky, M.T. 2 Debugging Introduction (1 of 2)  Debugging is methodical process for removing mistakes in a program  So important,
Chapter 10 Introduction to Arrays
Chapter 3.5 Debugging Games
CSCE 590E Spring 2007 Game Programming By Jijun Tang.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
2 Object-Oriented Analysis and Design with the Unified Process Objectives  Explain how statecharts can be used to describe system behaviors  Use statecharts.
How do games work? Game Workshop July 4, Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
Chapter 3.2 C++, Java, and Scripting Languages. 2 C++ C used to be the most popular language for games Today, C++ is the language of choice for game development.
Chapter 3.3 Programming Fundamentals Languages Paradigms Basic Data Types Data Structures OO in Game Design Component Systems Design Patterns.
CSCE 590E Spring 2007 Game Architecture and Math By Jijun Tang.
Chapter 3.2 C++, Java, and Scripting Languages “The major programming languages used in game development.”
Scripting Languages For Virtual Worlds. Outline Necessary Features Classes, Prototypes, and Mixins Static vs. Dynamic Typing Concurrency Versioning Distribution.
Satzinger, Jackson, and Burd Object-Orieneted Analysis & Design
Chapter 3.7 Memory and I/O Systems. 2 Memory Management Only applies to languages with explicit memory management (C or C++) Memory problems are one of.
Chapter 3.2 C++, Java, and Scripting Languages hacked by jeffery.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
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.
CIT241 Prerequisite Knowledge ◦ Variables ◦ Operators ◦ C++ Syntax ◦ Program Structure ◦ Classes  Basic Structure of a class  Concept of Data Hiding.
Chapter Languages, Programming and Architecture.
Games Development 2 Entity / Architecture Review CO3301 Week
Systems Analysis and Design in a Changing World, Fifth Edition
CSE 381 – Advanced Game Programming 3D Game Architecture.
Systems Analysis and Design in a Changing World, Fifth Edition
Systems Analysis and Design in a Changing World, Fifth Edition
Design Patterns.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
CSCE 552 Spring 2011 Math By Jijun Tang. Layered.
4/2/03I-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Software Architecture and Design Readings: Ambler, Chap. 7 (Sections to start.
CSCE 552 Spring 2009 Game Design III By Jijun Tang.
CSCE 552 Spring 2010 Language and Programming By Jijun Tang.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Object Oriented Design David Talby. Welcome! n Introduction n UML u Use Case Diagrams u Interaction Diagrams u Class Diagrams n Design Patterns u Composite.
Computing and SE II Chapter 9: Design Methods and Design Models Er-Yu Ding Software Institute, NJU.
“The perfect project plan is possible if one first documents a list of all the unknowns.” Bill Langley.
Data Structure & Algorithm
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
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,
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Learners Support Publications Object Oriented Programming.
CSCE 552 Fall 2012 Language and Programming By Jijun Tang.
08 - StructuralCSC4071 Structural Patterns concerned with how classes and objects are composed to form larger structures –Adapter interface converter Bridge.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Object-Oriented Programming Chapter Chapter
Games Development 1 Review / Revision CO2301 Games Development 1 Semester 2.
CSCE 552 Fall 2012 Language and Programming By Jijun Tang.
Introduction to OOP CPS235: Introduction.
STL CSSE 250 Susan Reeder. What is the STL? Standard Template Library Standard C++ Library is an extensible framework which contains components for Language.
CSCE 552 Spring 2011 Math By Jijun Tang. Languages C/C++ Java Script: Flash, Python, LISP, etc. C# XNA for PC and Xbox.
Next Back MAP MAP F-1 Management Information Systems for the Information Age Second Canadian Edition Copyright 2004 The McGraw-Hill Companies, Inc. All.
CSE 332: Design Patterns (Part II) Last Time: Part I, Familiar Design Patterns We’ve looked at patterns related to course material –Singleton: share a.
FILE SYSTEM IMPLEMENTATION 1. 2 File-System Structure File structure Logical storage unit Collection of related information File system resides on secondary.
CSCE 552 Spring 2009 Game Architecture and Math By Jijun Tang.
CSCE 552 Spring 2011 Language and Programming By Jijun Tang.
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.
Behavioral Design Patterns
Outline Chapter 2 (cont) OS Design OS structure
Informatics 122 Software Design II
Games Development Game Architecture: Entities
Games Development 2 Entity / Architecture Review
GoF Patterns Ch. 26.
Presentation transcript:

CSCE 552 Spring 2009 Programming Fundamentals By Jijun Tang

Homework #1 6 points, due on next Wednesday Turn in hard copy before the class Expected about 1 page Question: Review your popular games (2-3), including game description, features, strength and weakness, etc.

C++: Strengths Performance High-level, object-oriented C Heritage Libraries

C++: Weaknesses Too low-level Slow iteration Too complicated Lacking features

Java Performance Has typically been Java's weak point Has improved in the last few years: still not up to C++ level, but very close Uses Just-In-Time compiling and HotSpot optimizations Now has high-performance libraries Also has access to native functionality

Popular scripting languages Python Lua Other off-the-shelf options such as Ruby, Perl, Javascript Custom scripting languages  UnrealScript, QuakeC, NWNScript

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

List Very cheap to add/remove elements. Available in the STL (std::list) Every element is allocated separately, not placed contiguously in memory  Lots of little allocations  Bad cache awareness, but can use arrays to hold pre-allocated items Single/Double linked list

Lists

Dictionaries Maps a set of keys to some data. std::map, std::hash, etc Very fast access to data Perfect for mapping IDs to pointers, or resource handles to objects May waste space, need to design comparison operators

Hash Table

Others Stacks  First in, last out  std::stack adaptor in STL Queues  First in, first out  std::deque  Priority queue is useful in game to schedule events

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

Game Architecture and Math

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

Polymorphism The ability to refer to an object through a reference (or pointer) of the type of a parent class Key concept of object oriented design C++ implements it using virtual functions

Multiple Inheritance Allows a class to have more than one base class Derived class adopts characteristics of all parent classes Huge potential for problems (clashes, casting, dreaded diamond, etc) Multiple inheritance of abstract interfaces is much less error prone (virtual inheritance) Java has no multiple inheritance

Dreaded Diamond It is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A (and does not override the method), and B and C have overridden that method differently, then from which class does it inherit: B, or C?

Component Systems Component system organization

Object Factory Creates objects by name Pluggable factory allows for new object types to be registered at runtime Extremely useful in game development for passing messages, creating new objects, loading games, or instantiating new content after game ships

Factory Pattern

Simple Sample Factory - I

Simple Sample Factory - II

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

Singleton Example

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

Adapter Pattern

Adapter Example - I

Adapter Example - II

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

Observer Pattern

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

Composite Pattern Example - I Add many more inherited classes

The Five Step Debugging Process 1. Reproduce the problem consistently 2. Collect clues 3. Pinpoint the error 4. Repair the problem 5. Test the solution

Expert Debugging Tips Question assumptions Minimize interactions and interference Minimize randomness Break complex calculations into steps Check boundary conditions, use assertions Disrupt parallel computations Exploit tools in the debugger (VC is good, purify) Check code that has recently changed Explain the bug to someone else Debug with a partner (A second pair of eyes) Take a break from the problem Get outside help (call people)

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

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

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