Scaling Computer Games To Epic Proportions Walker White Cornell - - PowerPoint PPT Presentation

scaling computer games to epic proportions
SMART_READER_LITE
LIVE PREVIEW

Scaling Computer Games To Epic Proportions Walker White Cornell - - PowerPoint PPT Presentation

Scaling Computer Games To Epic Proportions Walker White Cornell University Joint work with Al Demers, Johannes Gehrke, Christoph Koch, and Rajamohan Rajagopolan Computer Games $7B in sales in 2005 Outperforming the movie industry


slide-1
SLIDE 1

Walker White

Cornell University

Joint work with Al Demers, Johannes Gehrke, Christoph Koch, and Rajamohan Rajagopolan

Scaling Computer Games To Epic Proportions

slide-2
SLIDE 2

SIGMOD 2007 Scaling Games to Epic Proportions

Computer Games

 $7B in sales in 2005

 Outperforming the movie industry

 Unique challenges

 Virtual environments  High degree of interactivity

slide-3
SLIDE 3

SIGMOD 2007 Scaling Games to Epic Proportions

Game Design

 Game design brings together many disciplines

 Art, music, computer science, etc...

 Development brings together different skills:

 Programmers: Create the game engine

 Focus on technological development

 Designers: Create the game content

 Typically artistic content  But may include (programmed) character behavior

slide-4
SLIDE 4

SIGMOD 2007 Scaling Games to Epic Proportions

Data-Driven Game Design

 Today’s games are data-driven

 Game content is separated from game code

 Examples:

 Art and music kept in industry-standard file formats  Character data kept in XML or other data file formats  Character behavior specified through scripts

 Programmed via scripting language

slide-5
SLIDE 5

SIGMOD 2007 Scaling Games to Epic Proportions

Data-Driven Game Design

slide-6
SLIDE 6

SIGMOD 2007 Scaling Games to Epic Proportions

Advantages of Data-Driven Design

 Engine is reusable.

 Able to recoup R&D costs over several games.  Possible to license engine to other companies.

 Example: The Unreal engine

 Can extend the life span of the game

 Modder communities develop around the game

 Keep game fresh and new

 User-created content becoming very popular

slide-7
SLIDE 7

SIGMOD 2007 Scaling Games to Epic Proportions

Talk Outline

 Simulation Games  Scaling Games with SGL  Optimizing SGL  Experimental Evaluation

slide-8
SLIDE 8

SIGMOD 2007 Scaling Games to Epic Proportions

This Talk: Simulation Games

 What are simulation games?

 Characters can interact w/o player input  Non-Player Characters (NPCs): indirect control

 Example: Real-Time Strategy (RTS) games

 Troops move and fight in real time  Player control via limited number of commands  Player multitasks between large number of units

slide-9
SLIDE 9

SIGMOD 2007 Scaling Games to Epic Proportions

RTS Demonstration

slide-10
SLIDE 10

SIGMOD 2007 Scaling Games to Epic Proportions

Expressiveness vs. Performance

 Expressiveness: the range of behavior scriptable outside engine  As # of NPCs increases expressiveness decreases

 Neverwinter Nights

 Each NPC fully scriptable

 WarCraft III

 Script armies, not NPCs  Can only “fake” NPC control  Little NPC coordination

 Rome: Total War

 No individual control at all

Rome: Total War WarCraft III The Sims 2 Neverwinter Nights

Expressiveness Number of NPCs

Low High Low High

slide-11
SLIDE 11

SIGMOD 2007 Scaling Games to Epic Proportions

Expressiveness vs. Performance

Rome: Total War WarCraft III The Sims 2 Neverwinter Nights

Expressiveness Number of NPCs

Low High Low High Goal

 Expressiveness: the range of behavior scriptable outside engine  As # of NPCs increases expressiveness decreases

 Neverwinter Nights

 Each NPC fully scriptable

 WarCraft III

 Script armies, not NPCs  Can only “fake” NPC control  Little NPC coordination

 Rome: Total War

 No individual control at all

slide-12
SLIDE 12

SIGMOD 2007 Scaling Games to Epic Proportions

Why Is Scaling NPCs Hard?

Time per tick

3 units 2 units 1 unit

 Can be very expensive

 O(n) to process all units.  Observations may be O(n)

 Example: morale

 Units afraid of skeletons  Chance of running proportional to # of skeletons  O(n) to count skeletons  O(n2) to process all units.

slide-13
SLIDE 13

SIGMOD 2007 Scaling Games to Epic Proportions

Why Is Scaling NPCs Hard?

Time per tick

3 units 2 units 1 unit

 Can be very expensive

 O(n) to process all units.  Observations may be O(n)

 Example: morale

 Units afraid of skeletons  Chance of running proportional to # of skeletons  O(n) to count skeletons  O(n2) to process all units.

 Want computation close to graphics frame rate.

slide-14
SLIDE 14

SIGMOD 2007 Scaling Games to Epic Proportions

Talk Outline

 Simulation Games  Scaling Games with SGL  Optimizing SGL  Experimental Evaluation

slide-15
SLIDE 15

SIGMOD 2007 Scaling Games to Epic Proportions

Scaling Scripts to Many NPCs

 Idea: Use declarative language for scripts.  Analysis shows:

 Typically a set of if-then rules.  Iteration is restricted to:

 Computing an aggregate of a collection of objects.  Applying an update to the environment.  Processing an array of fixed size.

slide-16
SLIDE 16

SIGMOD 2007 Scaling Games to Epic Proportions

Talk Outline

 Simulation Games  Scaling Games with SGL

 Simulation == Queries and updates  The SGL Language

 Optimizing SGL  Experimental Evaluation

slide-17
SLIDE 17

SIGMOD 2007 Scaling Games to Epic Proportions

Inside the Simulation Engine

 Actions divided into “ticks”.  During a tick, each unit

  • 1. Reads the environment
  • 2. Determines its current action
  • 3. Performs action, creating one or more effects

 An effect may alter a unit’s own state (i.e. movement)  An effect may alter the state of others (i.e. damage)

slide-18
SLIDE 18

SIGMOD 2007 Scaling Games to Epic Proportions

Inside the Simulation Engine

 Actions divided into “ticks”.  During a tick, each unit

 Database queries

1 Reads the environment 2 Determines its current action

 Database updates

3 Performs action, creating one or more effects

slide-19
SLIDE 19

SIGMOD 2007 Scaling Games to Epic Proportions

The Environment Table

 The environment is a single table E.

 Each unit a row in the table.

 Schema is unit state and possible effects.

 Position: Unit state  Movement: Unit effect State Effect

1 3

  • 4

Doug

  • 1

Alice 2 3 10 2 Bob Move_y Move_x Pos_y Pos_x Name

slide-20
SLIDE 20

SIGMOD 2007 Scaling Games to Epic Proportions

Processing Effects

 At end of tick, effects update environment

 All effects are processed simultaneously  Have rules to combine effects

 Must be order independent  Currently games use aggregate functions  Examples: sum, product, min, max

 Combination is single effect, used for update

slide-21
SLIDE 21

SIGMOD 2007 Scaling Games to Epic Proportions

The Environment Table

 The environment is a single table E.

 Each unit a row in the table.

 Schema is unit state and possible effects.  Schema annotated to tell which is which.

 State subschema annotated by const.  Effects annotated by combination function.

 Examples: sum, min, max

slide-22
SLIDE 22

SIGMOD 2007 Scaling Games to Epic Proportions

Example Environment Table

E(keyconst, “Key”; used to identify unit. playerconst, Player controlling unit pos_xconst, Current x-position of unit pos_yconst, Current y-position of unit healthconst, Current health of unit move_xsum, Amount to move unit on x-axis move_ysum, Amount to move unit on y-axis damagesum, Amount of damage to do to unit heal_auramax Amount to heal unit ) STATE EFFECTS

slide-23
SLIDE 23

SIGMOD 2007 Scaling Games to Epic Proportions

Formal Processing Model

 Each unit performs a single action.

 A query that produces a set of effects.  Returns the subtable of affected units.

 Const attributes are unmodified.  Effect attributes modified with effect amounts.

 Effects of each action are combined.

 Produces a new table Eu of all updated units.

 Post-processing step updates state from effects.

 Produces the new table E for the next tick.

slide-24
SLIDE 24

SIGMOD 2007 Scaling Games to Epic Proportions

The Post-Processing Step

 Is just an SQL query!  Example:

SELECT u.key, u.player, u.pos_x + u.move_x * norm AS pos_x, u.pos_y + u.move_y * norm AS pos_y, u.health - u.damage + u.heal_aura AS u.health, FROM E u WHERE u.health > 0

slide-25
SLIDE 25

SIGMOD 2007 Scaling Games to Epic Proportions

Talk Outline

 Simulation Games  Scaling Games with SGL

 Simulation == Queries and updates  The SGL Language

 Optimizing SGL  Experimental Evaluation

slide-26
SLIDE 26

SIGMOD 2007 Scaling Games to Epic Proportions

Defining Actions: SGL

 Scalable Games Language

 Functional language

 Used to choose NPC actions

 Aggregate functions to perform observations

 Built-in or definable in SQL

 Action functions to produce effects

 Built-in or definable in SQL

slide-27
SLIDE 27

SIGMOD 2007 Scaling Games to Epic Proportions

Example SGL Script

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key){ perform FireAt(u,target_key); } } } }

slide-28
SLIDE 28

SIGMOD 2007 Scaling Games to Epic Proportions

Aggregate Function Definitions

function CountEnemiesInRange(u,range) returns SELECT Count(*) FROM E WHERE E.x >= u.pos_x - range AND E.x <= u.pos_x + range AND E.y >= u.pos_y - range AND E.y <= u.pos_y + range AND E.player <> u.player; function CentroidOfEnemyUnits(u,range) returns SELECT Avg(x) AS x, Avg(y) AS y FROM E WHERE E.x >= u.pos_x - range AND E.x <= u.pos_x + range AND E.y >= u.pos_y - range AND E.y <= u.pos_y + range AND E.player <> u.player;

slide-29
SLIDE 29

SIGMOD 2007 Scaling Games to Epic Proportions

Action Function Definitions

function MoveInDirection(u,x,y) returns SELECT e.key,e.player,e.pos_x,e.pos_y,e.health, x-e.pos_x AS move_x, y-e.pos_y as move_y, e.damage,e.heal_aura FROM E e WHERE e.key=u.key; function FireAt(u,target_key) returns SELECT e.key,e.player,e.pos_x,e.pos_y,e.health, e.move_x, e.move_y, e.damage+(_ARROW_HIT_DAMAGE - _ARMOR) * (Random(e,1) mod 2) as damage, e.heal_aura FROM E e WHERE e.key=target_key;

slide-30
SLIDE 30

SIGMOD 2007 Scaling Games to Epic Proportions

Advantage of this Model

 Units often perform a lot of shared computation.

 Example: Units all processing the same command  Optimize with set-at-time processing.

 Determine all effects with a single database query.  Apply all effects as single update at end of tick.

 Sometimes computation is only overlapping.

 Example: Counting number of skeletons.

 Units overlapping, not same, line-of-sight.

 Optimize with indexing techniques. Let’s now model a simulation using database techniques!

slide-31
SLIDE 31

SIGMOD 2007 Scaling Games to Epic Proportions

Talk Outline

 Simulation Games  Scaling Games with SGL  Optimizing SGL

 Set-at-a-time processing  Aggregate Indexing

 Experimental Evaluation

slide-32
SLIDE 32

SIGMOD 2007 Scaling Games to Epic Proportions

Combining Effects Together

 Combination operation ⊕.

 Operates on a set: ⊕ E  Merges rows of same “key” according to annotation.  Example:

 Gives formal definition for combining of effects.

4 Bob 2 2 Bob 1 3 Bob 1 DamageSum PlayerConst KeyConst 4 Bob 2 5 Bob 1 DamageSum PlayerConst KeyConst

=

slide-33
SLIDE 33

SIGMOD 2007 Scaling Games to Epic Proportions

Set-At-A-Time Processing

 Define [[f]]⊕ (E) = ⊕ (∪{[[f]]E(u) | u ∈ E})  Process an entire “tick” as [[main]]⊕(E)⊕E = ⊕ (∪ {[[main]]E (u) | u ∈ E})⊕E  Suggests set-processing semantics:

[[(let A := a) f ]]⊕(E) := [[f]]⊕(π,a() as A(E)) [[f1 ; f2]]⊕(E) := [[f1]]⊕(E) ⊕ [[f2]]⊕(E) [[if ϕ then f]]⊕(E) := [[f]]⊕(σϕ(Ε)) [[perform G]]⊕(E) := [[g]]⊕(E)

slide-34
SLIDE 34

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-35
SLIDE 35

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-36
SLIDE 36

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-37
SLIDE 37

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-38
SLIDE 38

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-39
SLIDE 39

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-40
SLIDE 40

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-41
SLIDE 41

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-42
SLIDE 42

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-43
SLIDE 43

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }

slide-44
SLIDE 44

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

slide-45
SLIDE 45

SIGMOD 2007 Scaling Games to Epic Proportions

Talk Outline

 Simulation Games  Scaling Games with SGL  Optimizing SGL

 Set-at-a-time processing  Aggregate Indexing

 Experimental Evaluation

slide-46
SLIDE 46

SIGMOD 2007 Scaling Games to Epic Proportions

Optimizing Aggregates

 The problem:

 Script associated with each NPC  Script performs aggregate computation

 Count number of skeletons  In our query plans: ,agg()(R)

 Compute for every unit in the environment

 O(n2) cost!

 But we “understand” the scripts!

 Compute common aggregate for query plan

slide-47
SLIDE 47

SIGMOD 2007 Scaling Games to Epic Proportions

Optimizing Aggregates (Contd.)

 The problem is actually a bit harder:

 Script associated with each NPC  Script performs aggregate computation that depends on the unit

 Count number of skeletons in my neighborhood  In our query plans: ,agg()(σϕ (R))

 Compute for every unit in the environment

 O(n2) cost!

 But we “understand” the scripts!

 Compute common aggregate for query plan

slide-48
SLIDE 48

SIGMOD 2007 Scaling Games to Epic Proportions

Solution: Aggregate Indexing

 Create an index to encode aggregates

 Replaces computation with index lookup  ,agg()(σϕ (R)) now index nested loops join

 Indices for all aggregates in Warcraft III

 See the paper for technical details  All indices are

 O(n logd n) to build  O(logd n) to look-up  where d depends on arity of ϕ

slide-49
SLIDE 49

SIGMOD 2007 Scaling Games to Epic Proportions

Indices in the Processing Model

 Construct all indices at beginning of tick

 O(n logd n) for each aggregate index

 Scripts are read only queries on indices

 Aggregates are index nested loops join  O(logd n) look-up for each unit  O(n logd n) costed for nested loops join

 Linear cost to post-process updates  Total cost for entire tick: O(n logd n)

slide-50
SLIDE 50

SIGMOD 2007 Scaling Games to Epic Proportions

Indices in the Processing Model

 Construct all indices at beginning of tick

 O(n logd n) for each aggregate index

 Scripts are read only queries on indices

 Aggregates are index nested loops join  O(logd n) look-up for each unit  O(n logd n) costed for nested loops join

 Linear cost to post-process updates  Total cost for entire tick: O(n logd n)

slide-51
SLIDE 51

SIGMOD 2007 Scaling Games to Epic Proportions

Talk Outline

 Simulation Games  Scaling Games with SGL  Optimizing SGL  Experimental Evaluation

slide-52
SLIDE 52

SIGMOD 2007 Scaling Games to Epic Proportions

Experimental Evaluation

 System is currently under construction  But performed an evaluation of the

  • ptimizations on a game simulation

 Do we really see n2 behavior in practice?  What about overhead of index construction?

slide-53
SLIDE 53

SIGMOD 2007 Scaling Games to Epic Proportions

Experimental Evaluation

 Combat simulation

 Three types of units: knights, healers, archers  Complex, but reasonable NPC behavior.

 Archers use knights as cover.

 Compute centroids of archers, knights, enemies.  Make sure in a line, with knights at center.

 Healers stay in between archers, knights.

 Spread out for maximum healing.

 Knights retreat to healers if too wounded.

 Uses d20 (D&D) mechanics for combat.

slide-54
SLIDE 54

SIGMOD 2007 Scaling Games to Epic Proportions

Experimental Design

 Number of NPCs vs. time for 500 clock ticks.  Pluggable simulation comparing query plans

1. Naive processing of aggregates. 2. Use of indexing techniques.

  • The factor d from indexing techniques is d=1.

 Performance is thus O(n log n) for each aggregate

 Hardware parameters:

 2Ghz Intel Core Duo running OS X in 1.5 GB RAM.  Compiled in C++ using GCC.

slide-55
SLIDE 55

SIGMOD 2007 Scaling Games to Epic Proportions

Experimental Results

slide-56
SLIDE 56

SIGMOD 2007 Scaling Games to Epic Proportions

Experimental Results

60 frames/s 10 frames/s

slide-57
SLIDE 57

SIGMOD 2007 Scaling Games to Epic Proportions

Future Work

 Working to implement SGL in XNA

 Microsoft’s new game development platform  Works on PC and XBox 360

 Lots of open problems:

 Query processing  Query optimization  Further indexing methods  Implementation

slide-58
SLIDE 58

SIGMOD 2007 Scaling Games to Epic Proportions

Final Words

 What was the success of databases?

 Declarative specification vs. procedural retrieval

 This is the same program for simulations

 Declarative behavior vs. procedural implementation

 Is a roadmap for multicore optimization

 Declarative languages are highly parallelizable  What other problems can we apply them to?

slide-59
SLIDE 59

Let’s Play!

Any questions?

slide-60
SLIDE 60

SIGMOD 2007 Scaling Games to Epic Proportions

Algebraic Optimization

main(u) { (let c = CountEnemiesInRange(u,u.range)) { if (c > u.morale) then (let away_vector = (u.posx, u.posy) - CentroidOfEnemyUnits(u,u.range)) { perform MoveInDirection(u,away_vector); } else if (c > 0) then { if (u.cooldown = 0) then (let target_key = getNearestEnemy(u).key) { perform FireAt(u,target_key); } } } }