csce 552 spring 2009 game design iii by jijun tang

50
CSCE 552 Spring 2009 Game Design III By Jijun Tang

Upload: angela-boyd

Post on 20-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSCE 552 Spring 2009 Game Design III By Jijun Tang

CSCE 552 Spring 2009

Game Design III

By Jijun Tang

Page 2: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Design Procedure

Waterfall method Development methodology Design and production are broken into phases

Iterative development Practice of producing things incrementally Refining and re-refining the product May iterate many cycles before get it right

Page 3: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Waterfall vs. Iterative

testing

Page 4: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Brainstorming Generating ideas without discrimination Evaluation after elaboration, can be

unfocused

Page 5: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Programming Teams

In the 1980s programmers developed the whole game (and did the art and sounds too!)

Now programmers write code to support designers and artists (content creators)

Page 6: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Different Programs

Game codeAnything related directly to the game

Game engineAny code that can be reused between

different games Tools

In house tools

Plug-ins for off-the-shelf tools

Page 7: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Methodologies

A methodology describes the procedures followed during development to create a game

Every company has a methodology (way of doing things), even if they don't explicitly think about it

Page 8: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Methodologies: Code and Fix

Unfortunately very common Little or no planning Always reacting to events Poor quality and unreliability of finished

product “Crunch” time normal

Page 9: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Methodologies: Waterfall

Very well-defined steps in development Lots of planning ahead of time Great for creating a detailed milestone

schedule Doesn't react well to changes Game development is too unpredictable

for this approach

Page 10: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Methodologies: Iterative

Multiple development cycles during a single project Each delivering a new set of functionality Refinements are needed

The game could ship at any moment Allows for planning but also for changes

Page 11: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Methodologies: Agile Methods

Deal with the unexpected Very short iterations: 2-3 weeks Iterate based on feedback of what was

learned so far Very good visibility of state of game Difficult for publishers or even

developers to adopt because it's relatively new

Page 12: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Make Coding Easier

Version control Coding standards Automated build Code review Unit testing and acceptance testing

Page 13: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Version Control

Recommended to use for team project Version control is

Database with all the files and history. Only way to work properly with a team. Branching and merging can be very useful Used for source code as well as game assets (text

and binary) Tools:

CVS is one of the most popular tool Source anywhere

Page 14: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Coding standards

Coding standards are Set of coding rules for the whole team to follow Improves readability and maintainability of the code Easier to work with other people's code They vary a lot from place to place

Some simple, some complex Get used to different styles

Sample standards can be found at: http://www.chris-lott.org/resources/cstyle/CppCodingStandard.html

Page 15: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Automated builds

Dedicated build server builds the game from scratch

Takes the source code and creates an executable

Also takes assets and builds them into game-specific format

Build must never break

Page 16: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Quality Control

Code reviews Knowing others will read the code will make coding

more carefully Another programmer reads over some code and

tries to find problems Sometimes done before code is committed to

version control Can be beneficial if done correctly

Follow coding standards, and put comments

Page 17: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Avoid Run-time Errors Run-time errors are hardest to trace and have the biggest

damage Initialize variables, use tools (Visual .Net is good at this), check

boundaries, etc. purify on Windows valgrind on Linux

Asserts and crashes Use asserts anytime the game could crash or something could go

very wrong An assert is a controlled crash in the debug version Much easier to debug and fix Happens right where the problem occurred Don't use them for things that a user could do

Open a non-existing file Press the wrong button

Page 18: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Leveraging Existing Code

A lot of code that games use is the same

It's a total waste of time to write it over and over

Instead, spend your time in what's going to make your game unique

Avoid Not Invented Here (NIH) syndrome!

Page 19: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Where Are Existing Codes Reuse code from previous project

Easier in a large company if you have an engine and tools group

Use freeware code and tools No support Make sure license allows it

Middleware Companies provide with components used in game

development physics, animation, graphics, etc

Commercial game engines You can license the whole engine and tools and a

single package Good if you're doing exactly that type of game

Page 20: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Platforms - PC

PCs Includes Windows, Linux, and Macs Can have very powerful hardware Easier to patch and allow for user content Need to support a wide range of hardware

and drivers Games need to play nice with other

programs and the operating system

Page 21: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Platforms –Game Console

Game consoles Current generation

PS2, Xbox, GameCube Fixed set of hardware – never changes Usually use custom APIs – not very mature They have very limited resources Currently much better sales than PC games

(although that changes over time)

Page 22: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Platforms

Handhelds and mobiles Extremely limited hardware (although

rapidly improving) Programming often done in lower-level

languages (C or even assembly) However, DS and PSP in C++

Much smaller projects, teams, and budgets Emerging market

Page 23: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Platforms – Online

Browser and downloadable games Small games – mostly 2D Need to be downloaded quickly Run on the PC itself (on any browser

usually)

Page 24: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Multiplatform Development

The closer the platforms, the easier the development

Use abstraction layers to hide platform-specific code, especially for GUI

Choice: Target the minimum common denominator for

platforms (easy, cheap) Or do the best you can in each platform (more

expensive and time consuming)

Page 25: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Languages

C/C++ Java Script: Flash, Python, LISP, etc. C# XNA for PC and Xbox

Page 26: CSCE 552 Spring 2009 Game Design III By Jijun Tang

C++

C used to be the most popular language for games

Today, C++ is the language of choice for game development

Page 27: CSCE 552 Spring 2009 Game Design III By Jijun Tang

C++: Strengths - I

Performance Control over low-level functionality (memory management,

etc) Can switch to assembly or C whenever necessary Good interface with OS, hardware, and other languages

High-level, object-oriented High-level language features are essential for making today's

complex games Has inheritance, polymorphism, templates, and exceptions Strongly typed, so it has improved reliability

Page 28: CSCE 552 Spring 2009 Game Design III By Jijun Tang

C++: Strengths - II

C Heritage C++ is the only high-level language that is

backwards-compatible with C Has APIs and compiler support in all platforms Easier transition for experienced programmers

Libraries STL (Standard Template Library)

Comprehensive set of standard libraries Boost: widely used library with wide variety of

functionality Many commercial C++ libraries also available

Page 29: CSCE 552 Spring 2009 Game Design III By Jijun Tang

C++: Weaknesses - I

Too low-level Still forces programmers to deal with low-level issues Too error-prone Attention to low-level details is overkill for high-level features

or tools Slow iteration

C++ is fully compiled into binary format from source code Compiling large numbers of files is very slow This will only become more of a problem as games become

more complex

Page 30: CSCE 552 Spring 2009 Game Design III By Jijun Tang

C++: Weaknesses - II

Too complicated Because of its C heritage, C++ is very

complicated Long learning curve to become competent

with the language Lacking features

No reflection or introspection features No method of object serialization No native support for message passing

Page 31: CSCE 552 Spring 2009 Game Design III By Jijun Tang

C++: When to Use It?

When performance is crucial If your current code base is mostly C and C++ If you have a lot of in-house expertise in C++ Avoid using it for high-level code, such as tools

Page 32: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Java for Game Development

Why use Java? It's a high-level OO language that

simplifies many C++ features Adds several useful high-level features Easy to develop for multiple platforms

because of intermediate bytecode Good library support

Page 33: CSCE 552 Spring 2009 Game Design III By Jijun Tang

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

Page 34: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Java Platforms

Well suited to downloadable and browser-based games

Dominates development on mobile and handheld platforms

Possible to use in full PC games, but more likely to be embedded into a game

Page 35: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Commercial Games using Java

Downloadable games like those from PopCap Games: Mummy Maze, etc

Online card games PC games using Java as a scripting

language: Vampire: The Masquerade, Star Wars Galaxies

PC games fully written in Java: You Don't Know Jack, Who Wants to Be a Millionaire

Page 36: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Scripting Languages

Why use scripting languages? Ease and speed of development Short iteration time Code becomes a game asset Offer additional features and are

customizable

Page 37: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Drawbacks of Scripting Languages

Slow performance Limited tool support Dynamic typing makes it difficult to catch

errors Awkward interface with the rest of the

game Difficult to implement well

Page 38: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Popular scripting languages

Python Lua Other off-the-shelf options such as

Ruby, Perl, Javascript Custom scripting languages

UnrealScript, QuakeC, NWNScript

Page 39: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Choose a Scripting Languages

Consider whether you need one at all What features do you need? What kind of performance do you need? What debugging facilities does the

language have? On what platforms does it need to run? What resources and expertise are

available?

Page 40: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Programming Fundamentals

Page 41: CSCE 552 Spring 2009 Game Design III 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

Page 42: CSCE 552 Spring 2009 Game Design III By Jijun Tang

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

Page 43: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Lists

Page 44: CSCE 552 Spring 2009 Game Design III By Jijun Tang

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

Page 45: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Hash Table

Page 46: CSCE 552 Spring 2009 Game Design III By Jijun Tang

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

Page 47: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Stack/Queue/Priority Queue

Page 48: CSCE 552 Spring 2009 Game Design III By Jijun Tang

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

Page 49: CSCE 552 Spring 2009 Game Design III By Jijun Tang

Bits

Page 50: CSCE 552 Spring 2009 Game Design III 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.