Download presentation
Presentation is loading. Please wait.
1
CSCE 590E Spring 2007 Game Architecture and Math By Jijun Tang
2
Announcements We will meet in 2A21 on Wednesday Please bring laptops (with mouse) on Wednesday Small game due Friday, March 9 th, 5:00pm Presentations start on Monday, March 5 th.
3
Game Design Presentation Two presentations, on March 5 th and March 7 th. March 5 th : Project Gnosis, Cheeze Puffs!, Team Swampus March 7 th : Space Banditos, Group E, Psychosoft Each has 20 minutes to present, 5 minutes to answer questions
4
Contents for the Presentation Description, specification, goals, game play System requirement, audience, rating Interface, input/output, interactions, cameras Premise/limitations/choices/resources Content designs, audio Level designs, flexibility Use case/UML (rough) Engines to use Version control/testing strategy Brief timeline (demo date is May 2 nd -9 th )
5
Logos-so-far
6
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
7
Lists
8
Hash Table
9
Stack/Queue/Priority Queue
10
Bits
11
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
12
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
13
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
14
Component Systems Component system organization
15
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
16
Singleton Implements a single instance of a class with global point of creation and access For example, GUI Don't overuse it!!!
17
Observer Allows objects to be notified of specific events with minimal coupling to the source of the event Two parts subject and observer
18
Composite Allow a group of objects to be treated as a single object Very useful for GUI elements, hierarchical objects, inventory systems, etc
19
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
20
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) 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)
21
Game Architecture
22
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
23
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
24
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
25
Ad-hoc
26
Modular
27
DAG
28
Layered
29
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
30
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
31
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 and the game itself Other games have a unified main loop
32
Tasks of Main Game Loop Handling time Gathering player input Networking Simulation Collision detection and response Object updates Rendering Other miscellaneous tasks
33
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
34
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
36
Sample Game Loop
37
Game Entities What are game entities? Basically anything in a game world that can be interacted with More precisely, a self-contained piece of logical interactive content Only things we will interact with should become game entities Organization Simple list Multiple databases Logical tree Spatial database
38
Creation and Updating Object creation Basic object factories Extensible object factories Using automatic registration Using explicit registration Updating Updating each entity once per frame can be too expensive Can use a tree structure to impose a hierarchy for updating Can use a priority queue to decide which entities to update every frame
39
Level Instantiation Loading a level involves loading both assets and the game state It is necessary to create the game entities and set the correct state for them Using instance data vs. template data
40
Identification and Communication Identification Strings Pointers Unique IDs or handles Communication Simplest method is function calls Many games use a full messaging system Need to be careful about passing and allocating messages
41
Math
42
Applied Trigonometry Trigonometric functions Defined using right triangle x y h
43
Applied Trigonometry Angles measured in radians Full circle contains 2 radians
44
Applied Trigonometry Sine and cosine used to decompose a point into horizontal and vertical components r cos r sin r x y
45
Trigonometry
46
Trigonometric identities
47
Inverse trigonometric functions Return angle for which sin, cos, or tan function produces a particular value If sin = z, then = sin -1 z If cos = z, then = cos -1 z If tan = z, then = tan -1 z
48
arcs
49
Applied Trigonometry Law of sines Law of cosines Reduces to Pythagorean theorem when = 90 degrees b a c
50
Vectors and Matrices Scalars represent quantities that can be described fully using one value Mass Time Distance Vectors describe a magnitude and direction together using multiple values
51
Vectors and Matrices Examples of vectors Difference between two points Magnitude is the distance between the points Direction points from one point to the other Velocity of a projectile Magnitude is the speed of the projectile Direction is the direction in which it ’ s traveling A force is applied along a direction
52
Vectors and Matrices Vectors can be visualized by an arrow The length represents the magnitude The arrowhead indicates the direction Multiplying a vector by a scalar changes the arrow ’ s length V 2V2V –V–V
53
Vectors and Matrices Two vectors V and W are added by placing the beginning of W at the end of V Subtraction reverses the second vector V W V + W V W V V – WV – W –W–W
54
Vectors and Matrices An n-dimensional vector V is represented by n components In three dimensions, the components are named x, y, and z Individual components are expressed using the name as a subscript:
55
Vectors and Matrices Vectors add and subtract componentwise
56
Vectors and Matrices The magnitude of an n-dimensional vector V is given by In three dimensions, this is
57
Vectors and Matrices A vector having a magnitude of 1 is called a unit vector Any vector V can be resized to unit length by dividing it by its magnitude: This process is called normalization
58
Vectors and Matrices A matrix is a rectangular array of numbers arranged as rows and columns A matrix having n rows and m columns is an n m matrix At the right, M is a 2 3 matrix If n = m, the matrix is a square matrix
59
Vectors and Matrices The entry of a matrix M in the i-th row and j-th column is denoted M ij For example,
60
Vectors and Matrices The transpose of a matrix M is denoted M T and has its rows and columns exchanged:
61
Vectors and Matrices An n-dimensional vector V can be thought of as an n 1 column matrix: Or a 1 n row matrix:
62
Vectors and Matrices Product of two matrices A and B Number of columns of A must equal number of rows of B Entries of the product are given by If A is a n m matrix, and B is an m p matrix, then AB is an n p matrix
63
Vectors and Matrices Example matrix product
64
Vectors and Matrices Matrices are used to transform vectors from one coordinate system to another In three dimensions, the product of a matrix and a column vector looks like:
65
Identity Matrix I n For any n n matrix M, the product with the identity matrix is M itself I n M = M MI n = M
66
Invertible An n n matrix M is invertible if there exists another matrix G such that The inverse of M is denoted M -1
67
Properties of Inverse Not every matrix has an inverse A noninvertible matrix is called singular Whether a matrix is invertible can be determined by calculating a scalar quantity called the determinant
68
Determinant The determinant of a square matrix M is denoted det M or |M| A matrix is invertible if its determinant is not zero For a 2 2 matrix,
69
Determinant The determinant of a 3 3 matrix is
70
Inverse Explicit formulas exist for matrix inverses These are good for small matrices, but other methods are generally used for larger matrices In computer graphics, we are usually dealing with 2 2, 3 3, and a special form of 4 4 matrices
71
Vectors and Matrices The inverse of a 2 2 matrix M is The inverse of a 3 3 matrix M is
72
Vectors and Matrices A special type of 4 4 matrix used in computer graphics looks like R is a 3 3 rotation matrix, and T is a translation vector
73
Vectors and Matrices The inverse of this 4 4 matrix is
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.