Creating Your Building Blocks Modular Component AI Systems Brett - - PowerPoint PPT Presentation

creating your building blocks
SMART_READER_LITE
LIVE PREVIEW

Creating Your Building Blocks Modular Component AI Systems Brett - - PowerPoint PPT Presentation

Creating Your Building Blocks Modular Component AI Systems Brett Laming, Rockstar Leeds Joel McGinnis, CCP Alex Champandard, AiGameDev.com Overview 1. Brett Laming Component systems revisited 2. Joel McGinnis Behaviour


slide-1
SLIDE 1

Creating Your Building Blocks

Modular Component AI Systems

  • Brett Laming, Rockstar Leeds
  • Joel McGinnis, CCP
  • Alex Champandard, AiGameDev.com
slide-2
SLIDE 2

Overview

  • 1. Brett Laming
  • Component systems revisited
  • 2. Joel McGinnis
  • Behaviour and Design Patterns
  • 3. Alex Champandard
  • Performance and Multi-threading
slide-3
SLIDE 3

COMPONENT SYSTEMS REVISITED

Part 1. Brett Laming

slide-4
SLIDE 4

Component Systems

  • What are they?
  • No single definition
  • Potentially
  • Smart objects
  • COM
  • Game object / entity architectures
  • Plug-ins
  • Message based, data driven
  • Fairly certain class cOgre : class cMonster

is wrong

slide-5
SLIDE 5

Background

DEEP CLASS

class cThrowingKnife : public cRangedWeapon, public cMeleeWeapon

slide-6
SLIDE 6

Background

DEEP CLASS

class cWeapon : public cDynamicProp class cRangedWeapon : public cWeapon class cBow : public cRangedWeapon class cBallista : public cRangedWeapon, public cStaticProp, !public cDynamicProp

slide-7
SLIDE 7

Background

DEEP CLASS FAT CLASS

class cWeapon : public cGameObj { cGameObj* CreateAmmo(); // Reloading not for melee eState mState; eAttackMode mAttackMode; eAmmoType mAmmoType; // Ranged weapons only int mAmmoCount; };

slide-8
SLIDE 8

Background

DEEP CLASS FAT CLASS PLUGIN

slide-9
SLIDE 9

Background

DEEP CLASS FAT CLASS PLUGIN DATA DRIVEN

slide-10
SLIDE 10

Damned if you do…

  • Don’t believe it.
  • We get the problems
slide-11
SLIDE 11

Component

  • Broad Classification
  • Key Properties
  • Defined I/O
  • Interchangeable
slide-12
SLIDE 12

System

  • Organisation
  • Compartmentalization
slide-13
SLIDE 13

Reusable A.I.

  • Output  gameplay.
  • Input  gameplay world
  • Disciplined gameplay
  • Good organisation
  • Purposeful data
  • Sensible lifetimes
  • Good reusable A.I.

5 key levels of organisation

INHERITANCE

 Taxonomy  Component Name

STRUCTURE

 World Organisation  Parents – Children

DATA FLOW

 A.I.  Gameplay

COMPARTMENTALIZATION

 Data boundaries  Smart objects and DLC

PARALLELIZATION

 Homogenous  Batches / Jobs

slide-14
SLIDE 14

Inheritance

Object Base Classification Name

cGameObj cVehicle cCar cSeat cDrivingSeat cGunnerSeat cLiving cDog cArea cInterior cExterior cHuman cWeapon cPistol

Classification

  • RTTI queries
  • Ability to sort by class

Name

  • RTTI factory creation
  • Ability to serialise

Combined

  • Data driven approach
  • Shallow hierarchy
slide-15
SLIDE 15

RTTI Power

typedef int RttiType DECLARE_RTTI_TYPE IMPLEMENT_RTTI_META_BEGIN IMPLEMENT_RTTI_META_END RTTI_CLASSIFY_AND_ADD( mpSeat, cSeat, p_obj ); cWeapon *p_wep = DynamicCast<cWeapon*>(p_obj); cRegistry::Instance().Create( R_STR(“cColt45”) ); virtual void Serialise( cAttributeReader &rdr ); virtual void Serialise( cAttributeWriter &wtr ); rdr << PTR_IS_OWNED( mpSeats )

  • With a pre compile step, you can make it extremely efficient

indeed!

slide-16
SLIDE 16

Structure

  • Spatial
  • cGameObj
  • Reference frame
  • World transform
  • Functional
  • Composition
  • Aggregation
  • Dependency tracking
  • Conflict resolution
  • Job ordering

class cThing { RttiType mRTTI; }; class cGameObj : public cThing { public: private: cGameObj *mpParent; cGameObj *mpFirstChild; cGameObj *mpNextSibling; cMat4 mLocalTransform; };

slide-17
SLIDE 17

Structure & Inheritance

cWorld cWorldRegion cInterior cVehicle cCar cSeat cDrivingSeat cLiving* cHuman cSeat* cGunnerSeat cLiving* cHuman cWeapon* cLiving cDog cWorldRegion cInterior cWorldRegion cExterior cLiving cHuman cSkeleton cGameObject* cBrain cSensory cBrain cSensory cWeapon cPistol cTurret

slide-18
SLIDE 18

Data Flow

  • Data Flow
  • World State  A.I 

Gameplay  World State

  • Changes to structure
  • Not inside dt!
  • Upstream

 Message

  • Downstream

 Message

  • Changes to properties
  • Downstream

 Signalling

  • Upstream

 Signalling

  • Spatial Barrier  Message

cWorld cWorldRegion cInterior cVehicle cCar cSeat cDrivingSeat cLiving* cHuman cSeat* cGunnerSeat cLiving* cHuman cWeapon* cBrain cSensory cBrain cSensory cTurret cGameObj cBullet

slide-19
SLIDE 19

Compartmentalization

  • Smart Objects
  • Reconstructable by RTTI
  • Near free
  • Given good structure
  • External instructions
  • A.I., animation etc…
  • Carried by signalling

cVehicle cCar cSeat cDrivingSeat cLiving* cHuman cSeat* cGunnerSeat cLiving* cWeapon* cBrain cSensory cPhysics*

slide-20
SLIDE 20

Parallelization

  • The ideal…
  • … is still a way off
  • A.I./gameplay still parallelizes!
  • Even in game graphs!
  • Indirection
  • Aliasing
  • Candidates
  • Leaf output
  • animation, navigation,

component update

  • Leaf input
  • sensory info, blackboards, ray

tests

cInterior cInterior cSensory cSensory cLiving* cBrett cLiving* cAlex cLiving* cJoel

slide-21
SLIDE 21

All things being good…

cWorld cWorldRegion cInterior cVehicle cCar cSeat cDrivingSeat cLiving* cHuman cSeat* cGunnerSeat cLiving* cHuman cWeapon* cLiving cDog cWorldRegion cInterior cWorldRegion cExterior cLiving cHuman cSkeleton cGameObject* cBrain cSensory cBrain cSensory cWeapon cPistol

slide-22
SLIDE 22

Design Tricks 1

  • Remove temptation
  • Minimal data
  • Per frame  stack
  • Minimal lifetime
  • Use new/delete boundary!
  • Pools
  • Favour derivation
  • No equation contradiction
  • No duplicate data
  • Potential deep class problem?
  • Generalise

class cPhysicalProperties { public: inline float Volume() const; inline float Mass() const { return Volume() * mDensity; } inline float BoundsRadius() const; inline bool IsCarriable( cAABB grasp, float force ) const; inline bool IsThrowable( float force ) const; private: cAABB mBoundingBox; float mDensity; };

slide-23
SLIDE 23

Design Tricks 2

  • Locality of reference
  • Abstraction + composition
  • Placement new
  • Embedded lists
  • Pools
  • Minimise NULL checks
  • Non-virtual pathways
  • Use RTTI filtering
  • Many virtual pointers
  • Package once and carry

downstream

class cProjectile : public cGameObj { public: DECLARE_POOL( ... ); cProjectile() : mpPhysics( &mNullPhysics ) { } void SetGravity( ... ) { mpPhysics->Add( mGravity ); } private: iPhysics *mpPhysics; cGravity mGravity; static cDummyPhysics mNullPhysics; };

slide-24
SLIDE 24

Conclusions

  • Gameplay gives us fun buttons to press!
  • Tight game-play  Good, reusable A.I.
  • Think
  • Minimal classes
  • Data life time
  • Locality of reference
  • Use
  • Generalisation
  • RTTI
  • Placement new/delete
  • Pools
  • Nothing is really that un-surmountable!
slide-25
SLIDE 25

AI DESIGN PATTERNS

Part 2. Joel McGinnis

slide-26
SLIDE 26

What are the pressures?

  • Resources
  • Cycles
  • Memory
  • Design specificity
slide-27
SLIDE 27

CA for AI

  • Flexibility
  • Performance balancing
slide-28
SLIDE 28

Word of warning

  • Paradigm not

architecture

  • So we’ll be looking

at patterns

slide-29
SLIDE 29

TAKING IT APART

slide-30
SLIDE 30

Pattern

AIComponent “Where shall we put the data?” “Lets just put it on the AIComponent” “That seems like a bad idea, lets not do it”

(anti)

slide-31
SLIDE 31

So what do you have?

Behavior Tree Pathfinder Movement controller Target manager Perception Tracking

slide-32
SLIDE 32

What you consume

  • Focal point
  • Targetable object
  • Cover markup
  • Interaction point
  • Trigger volume
  • Granularity is

Good!

slide-33
SLIDE 33

Component matrix

Entities

Sniper Heavy Barrel Terminal

Behavior Tree

Tree component Tree component

Pathfinding

Component Component

Targeting system

Targeting Targeting Target Target Target Target

Movement Controller

Movement Movement

Cover

Cover Point

slide-34
SLIDE 34

PUTTING IT BACK TOGETHER

slide-35
SLIDE 35

Substitution

Behavior Tree Standard movement Perception Pathfinder Animation Targeting

slide-36
SLIDE 36

Substitution

Behavior Tree Standard movement Perception Pathfinder Animation Targeting Big creature movement

slide-37
SLIDE 37

Substitution

  • What did we gain?
  • Wasn't enough to

ship but...

  • Minimal investment
  • Nice prototype
  • Answered design

questions sooner

  • Required:
  • COM, signaling,

interface, messaging

  • Leverage hierarchy
  • OOP under the CA
slide-38
SLIDE 38

Find Via Registration

Target Selection Targetable

slide-39
SLIDE 39

Find Via Registration

Target Selection Targetable Targeting System

slide-40
SLIDE 40

Find Via Registration

Target Selection Targetable Targeting System

slide-41
SLIDE 41

Find Via Registration

  • What did we gain?
  • Reduced search

space

  • Scoping
  • Simplify

construction of behavior

  • Required:
  • Life-cycle

management

slide-42
SLIDE 42

Late construction of types

Target Selection Targetable

slide-43
SLIDE 43

Late construction of types

Target Selection Targetable

slide-44
SLIDE 44

Late construction of types

  • What did we gain?
  • The ability to

change our minds

  • Load balancing
  • Try it everywhere
  • Keep it where most

effective

  • Required:
  • Data driven(?)
  • Light weight
slide-45
SLIDE 45

Things to keep in mind

  • Simplest affordances – greatest benefit
  • Prefer small and light-weight CA
  • Lots of little components
slide-46
SLIDE 46

PERFORMANCE & MULTI-THREADING

Part 3. Alex Champandard

slide-47
SLIDE 47

You Must Be Wondering…

“How do you reconcile this modularity with high performance on all hardware?”

slide-48
SLIDE 48

Demo Interlude

  • Example Component
  • Influence Maps
  • Come back at 3:00 for details!
slide-49
SLIDE 49

High-Performance

  • Vectorization
  • Update 4x maps at a time with SIMD.
  • Parallelization
  • Run batches of 4x maps on multiple cores.
slide-50
SLIDE 50

The Solution

  • Build your Engine as modularly as Entities!
  • Physics, Sensory, Reasoning, Behavior,

Navigation, Locomotion, Animation.

  • Just assure the break-down is the same.
  • It opens up opportunities for optimization.
slide-51
SLIDE 51

Architecture

Entity 2 Entity 1 Engine Systems

Jobs

slide-52
SLIDE 52

BREAKDOWN

Section 2.

slide-53
SLIDE 53

Component: Configuration

# Threat Type, Influence HeavyEnemy = 4.0 RangedEnemy = 2.0 MeleeEnemy = 4.0 ScoutEnemy = 1.0

slide-54
SLIDE 54

Component: Interface

class ReasoningComponent { public: void setEntityThreat(EntityId, float threat); void setAreaThreat(AreaId, float threat); float getAreaThreat(AreaId) const; /* … */ };

slide-55
SLIDE 55

Component: Communication

class ReasoningComponent { public: void setEntityThreat(EntityId, float threat); void setAreaThreat(AreaId, float threat); float getAreaThreat(AreaId) const; /* … */ typedef Delegate<void (float)> ThreatObserver; void notifyThreatLevel(float threshold, ThreatObserver); };

slide-56
SLIDE 56

Component: Life-Cycle

  • Request new influence map on init().
  • Or when entering combat state.
  • Remove it on shutdown()
  • Or when going into wounded state.
slide-57
SLIDE 57

System: Batching & Prioritization

  • Don’t process individual requests…
  • Instead decides how to spawn jobs
  • Group maps updated at same frequencies.
  • Limit maximum number of jobs per frame.
slide-58
SLIDE 58

System: Memory Allocation

  • Manage memory for all influence maps.
  • Customize allocation:
  • Allocate 4x maps at a time!
  • Interleave the float values for SIMD.
slide-59
SLIDE 59

Jobs: Workload

  • Implemented using SSE, Altivec.
  • Process 4x maps at a time
  • Output
  • Influence Data
  • Input
  • Level Map
  • Parameters
slide-60
SLIDE 60

Jobs: Parallelism

  • Jobs are isolated from each other.
  • No communication or inter-dependencies.
  • Can run in parallel if necessary.
slide-61
SLIDE 61

SUMMARY

Section 3.

slide-62
SLIDE 62

Components

  • 1. Very lightweight
  • 2. Simple interface
  • 3. Handles events
  • 4. Data-driven
slide-63
SLIDE 63

Systems

  • 1. Memory Allocation
  • 2. Computation Limits
  • 3. Batching
  • 4. Prioritization
slide-64
SLIDE 64

Jobs

  • 1. Computationally heavy work
  • 2. Easily parallelizable code
  • 3. Clear interface w/ engine
slide-65
SLIDE 65

Creating Your Building Blocks

Modular Component AI Systems

  • Brett Laming, Rockstar Leeds
  • Joel McGinnis, CCP
  • Alex Champandard, AiGameDev.com