Upload
trandan
View
216
Download
1
Embed Size (px)
Citation preview
gamedesigninitiativeat cornell university
the
Take Away for Today
� Sensing as the primary bottleneck� Why is sensing so problematic?� What types of things can we do to improve it?
� Optimized sense computation� Can we improve sense computation performance?� Can we share sensing between NPCs?
� Sense event matching� What are events and how are they represented?� What is the advantage of an event system?
Sensing & Perception2
gamedesigninitiativeat cornell university
the
� Sense: � Perceive the world� Reading the game state� Example: enemy near?
� Think: � Choose an action � Often merged with sense� Example: fight or flee
� Act: � Update the state� Simple and fast� Example: reduce health
Sensing & Perception3
Review: Sense-Think-Act
?
gamedesigninitiativeat cornell university
the
� Sensing may be slow!� Consider all objects
� Example: morale� n knights, n skeletons� Knights fear skeletons� Proportional to # seen
� Count skeletons in view� O(n) to count skeletons� O(n2) for all units
Recall: Sensing Performance
Time per tick
3 units
2 units
1 unit
Sensing & Perception4
gamedesigninitiativeat cornell university
the
� Sensing may be slow!� Consider all objects
� Example: morale� n knights, n skeletons� Knights fear skeletons� Proportional to # seen
� Count skeletons in view� O(n) to count skeletons� O(n2) for all units
Recall: Sensing Performance
Time per tick
3 units
2 units
1 unit
Sensing & Perception5
gamedesigninitiativeat cornell university
the
� Idea taken from databases� Unordered set of information� Combine into single value� Used in statistical analysis� Examples: sum, avg, mode
� Decomposable Aggregates� Split the set up into subsets� Aggregate on each subset� Combine values from subsets� Only for some aggregates
6
10
5
7
9
7
3
9
Sensing & Perception6
Aggregation
gamedesigninitiativeat cornell university
the
� Idea taken from databases� Unordered set of information� Combine into single value� Used in statistical analysis� Examples: sum, avg, mode
� Decomposable Aggregates� Split the set up into subsets� Aggregate on each subset� Combine values from subsets� Only for some aggregates
6
10
5
7
9
7
3
9
Sensing & Perception7
Aggregation
avg = 8(16,2)
avg = 6(12,2)
avg = 8(16,2)
avg = 6(12,2)
gamedesigninitiativeat cornell university
the
� Idea taken from databases� Unordered set of information� Combine into single value� Used in statistical analysis� Examples: sum, avg, mode
� Decomposable Aggregates� Split the set up into subsets� Aggregate on each subset� Combine values from subsets� Only for some aggregates
6
10
5
7
9
7
3
9
Sensing & Perception8
Aggregation
avg = 8(16,2)
avg = 6(12,2)
avg = 8(16,2)
avg = 6(12,2)
avg = 7(28,4)
avg = 7(28,4)
gamedesigninitiativeat cornell university
the
� Idea taken from databases� Unordered set of information� Combine into single value� Used in statistical analysis� Examples: sum, avg, mode
� Decomposable Aggregates� Split the set up into subsets� Aggregate on each subset� Combine values from subsets� Only for some aggregates
6
10
5
7
9
7
3
9
Sensing & Perception9
Aggregation
avg = 8(16,2)
avg = 6(12,2)
avg = 8(16,2)
avg = 6(12,2)
avg = 7(28,4)
avg = 7(28,4)
avg = 7(56,8)
gamedesigninitiativeat cornell university
the
� Idea taken from databases� Unordered set of information� Combine into single value� Used in statistical analysis� Examples: sum, avg, mode
� Decomposable Aggregates� Split the set up into subsets� Aggregate on each subset� Combine values from subsets� Only for some aggregates
6
10
5
7
9
7
3
9
Sensing & Perception10
Aggregation
avg = 8(16,2)
avg = 6(12,2)
avg = 8(16,2)
avg = 6(12,2)
avg = 7(28,4)
avg = 7(28,4)
avg = 7(56,8)
gamedesigninitiativeat cornell university
the
AI and Aggregation Trees
Numberof Allies
Numberof Enemies
My HealthProximityto Leader
Strengthof Allies
Strengthof Enemies
Proximityto Base
Slide courtesy of Dave Mark
Sensing & Perception11
gamedesigninitiativeat cornell university
the
AI and Aggregation Trees
Numberof Allies
Numberof Enemies
My HealthProximityto Leader
Strengthof Allies
Strengthof Enemies
Allied Strength Enemy Strength
Proximityto Base
Slide courtesy of Dave Mark
Sensing & Perception12
gamedesigninitiativeat cornell university
the
AI and Aggregation Trees
Numberof Allies
Numberof Enemies
Threat Ratio
My HealthProximityto Leader
Strengthof Allies
Strengthof Enemies
Allied Strength Enemy Strength
Proximityto Base
Slide courtesy of Dave Mark
Sensing & Perception13
gamedesigninitiativeat cornell university
the
AI and Aggregation Trees
Numberof Allies
Numberof Enemies
Threat Ratio
My HealthProximityto Leader
Strengthof Allies
Strengthof Enemies
Allied Strength Enemy Strength
Proximityto Base
Urgency
Slide courtesy of Dave Mark
Sensing & Perception14
gamedesigninitiativeat cornell university
the
AI and Aggregation Trees
Numberof Allies
Numberof Enemies
Threat Ratio
My HealthProximityto Leader
Strengthof Allies
Strengthof Enemies
Allied Strength Enemy Strength
My Morale
Proximityto Base
Urgency
Slide courtesy of Dave Mark
Sensing & Perception15
gamedesigninitiativeat cornell university
the
AI and Aggregation Trees
Numberof Allies
Numberof Enemies
Threat Ratio
My HealthProximityto Leader
Strengthof Allies
Strengthof Enemies
Allied Strength Enemy Strength
My Morale
Retreat %
Proximityto Base
Urgency
Slide courtesy of Dave Mark
Sensing & Perception16
gamedesigninitiativeat cornell university
the
AI and Aggregation Trees
Numberof Allies
Numberof Enemies
Threat Ratio
My HealthProximityto Leader
Strengthof Allies
Strengthof Enemies
Allied Strength Enemy Strength
My Morale
Retreat %
Proximityto BaseUrgency
Slide courtesy of Dave Mark
Computable independentof the NPC
Sensing & Perception17
gamedesigninitiativeat cornell university
the
� “Invisible NPC”� Assigned to NPC Group� Performs all thinking� NPCs just follow orders
� Applications� Protecting special units� Flanking� Covering fire� Leapfrogging advance
Thinking and Acting18
Related Approach: Tactical Managers
NPC NPC NPC NPC
TacticalManager
gamedesigninitiativeat cornell university
the
Thinking and Acting19
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting20
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting21
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting22
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting23
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting24
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting25
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting26
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Thinking and Acting27
Protecting Special Units
Slide courtesy of Dave Mark
gamedesigninitiativeat cornell university
the
Normal Sensing
� Loop over all NPCs
� Check what NPC senses
Sensing & Perception28
Performance: Loop Inversion
Inverted Sensing
� Loop over sensations
� Send these to each NPC
NPCLoop
SenseLoop
sound1
sound2
sight1
sight1
gamedesigninitiativeat cornell university
the
Normal Sensing
� Loop over all NPCs
� Check what NPC senses
Sensing & Perception29
Performance: Loop Inversion
Inverted Sensing
� Loop over sensations
� Send these to each NPC
NPCLoop
SenseLoop
sound1
sound2
sight1
sight1
gamedesigninitiativeat cornell university
the
� Event: encoded sense data� Tagged with sense type � Information self-contained� O(n) data is aggregated� O(1) to combine w/ NPC
� Sensing is event matching� Each event has a type� NPCs “register” for a type� Send NPC registered events� Check if event is relevant
Sensing & Perception30
Sense Events
Pre-aggregated
gamedesigninitiativeat cornell university
the
Sensing & Perception31
Sense Event Matching
Event Handler
Register eventsof interest
Gam
e Loop
sound
sightsound
soundsmell
gamedesigninitiativeat cornell university
the
Sensing & Perception32
Sense Event Matching
Event Handler
Notify of anymatching events
Check for anymatching events
Gam
e Loop
gamedesigninitiativeat cornell university
the
MessageDispatcher
� Send with dispatchMessage� delay (0 if immediate)� sender (can be null)� target (null for subscribers)� type (user defined int code)� data (object, like Box2D)
� Subscribe with addListener� NPC to receive message� Type (int) to subscribe to
Sensing & Perception33
Event Handling in LibGDX
Telegram
� Stores the event message� Entries of dispatchMessage� Except for the delay value� Preaggregated sense in data
� Received by Telegraph � Interface for the receiver� Implemented by the NPC� One method: handleMessage
gamedesigninitiativeat cornell university
the
MessageDispatcher
� Send with dispatchMessage� delay (0 if immediate)� sender (can be null)� target (null for subscribers)� type (user defined int code)� data (object, like Box2D)
� Subscribe with addListener� NPC to receive message� Type (int) to subscribe to
Sensing & Perception34
Event Handling in LibGDX
Telegram
� Stores the event message� Entries of dispatchMessage� Except for the delay value� Preaggregated sense in data
� Received by Telegraph � Interface for the receiver� Implemented by the NPC� One method: handleMessage
gamedesigninitiativeat cornell university
the
Thinking and Acting35
Recall: S-T-A Architecture
Actor1
GameState
Actor1Controller
Actor2
Actor2Controller
ComputeSensing
gamedesigninitiativeat cornell university
the
Thinking and Acting36
Recall: S-T-A Architecture
Actor1
GameState
Actor1Controller
Actor2
Actor2Controller
ComputeSensing
gamedesigninitiativeat cornell university
the
Thinking and Acting37
Recall: S-T-A Architecture
Actor1
GameState
Actor1Controller
Actor2
Actor2Controller
ComputeThinking
gamedesigninitiativeat cornell university
the
Sensing: Perception Groups
� Vision: limited field of view� Gives exact object location, information � Limited by obstacles and range� Little information (motion) at periphery
� Sound: omni-directional� Gives direction & distances� Requires you track the “sounds” actions make
� Smell: omni-directional� No direction or distance; proximity only� Requires you track the “smells” actions make
Sensing & Perception38
gamedesigninitiativeat cornell university
the
Sensing & Perception41
Line-of-Sight in Thief
FocusedView
Long Distance
Short DistancePeripheral
Vision
gamedesigninitiativeat cornell university
the
Sensing & Perception42
Line-of-Sight in Thief
FocusedView
Long Distance
Short DistancePeripheral
Vision
MotionDetection
gamedesigninitiativeat cornell university
the
� “Easier” than vision� Primarily distance-based� Decays probabilistically� Tag with level of interest
� Sounds can be blocked� Not same as line-of-sight� Use alternate level map� Or tag your visible map
� Not physically realistic� Echoes? Reflections
Sensing & Perception43
Sounds in Thief
gamedesigninitiativeat cornell university
the
� “Easier” than vision� Primarily distance-based� Decays probabilistically� Tag with level of interest
� Sounds can be blocked� Not same as line-of-sight� Use alternate level map� Or tag your visible map
� Not physically realistic� Echoes? Reflections
Sensing & Perception44
Sounds in Thief
gamedesigninitiativeat cornell university
the
� Sounds are general purpose� Resuable framework� Code is lightweight� Encodes other senses
� Example: Smell� Treated as “pseudo-sound”� Generate like any sound
� Again, ignores other factors� Wind direction� Masking smells
Sensing & Perception45
Sounds in Thief
* sniff *
* sniff *
gamedesigninitiativeat cornell university
the
Lightweight
Sensing & Perception46
Custom Data in Events
Heavyweight
Memory
Target
ThiefExposed
Memory
Target
ThiefExposed
Reference to target
Copy oftarget
gamedesigninitiativeat cornell university
the
Lightweight
� Advantages� Fast to create event� No additional memory
� Disadvantages� Must be used immediately� Lost over frame boundary
� Ideal for fast decisions
Sensing & Perception47
Custom Data in Events
Heavyweight
� Advantages� Can persist past frame� Can retain as memory
� Disadvantages� Must allocate memory� Object ownership is tricky
� Ideal for communication
gamedesigninitiativeat cornell university
the
Sensing & Perception49
Communicating Senses
First HandLOS
Sight & Sound
gamedesigninitiativeat cornell university
the
Sensing & Perception50
Communicating Senses
First HandLOS
Sight & Sound
First HandLOS
Sight & Sound
gamedesigninitiativeat cornell university
the
Sensing & Perception51
Communicating Senses
First HandLOS
Sight & SoundSecond Hand
Sight & Sound
First HandLOS
Sight & Sound
gamedesigninitiativeat cornell university
the
Sensing & Perception52
Communicating Senses
First HandLOS
Sight & SoundSecond Hand
Sight & Sound
First HandLOS
Sight & Sound
?
gamedesigninitiativeat cornell university
the
Sensing & Perception53
Alertness: Active Senses
First HandLOS
Sight & SoundSecond Hand
Sight & Sound
First HandLOS
Sight & Sound
High Alert
gamedesigninitiativeat cornell university
the
Sensing & Perception54
Alertness: Active Senses
First HandLOS
Sight & SoundSecond Hand
Sight & Sound
First HandLOS
Sight & Sound
High AlertMedium Alert
gamedesigninitiativeat cornell university
the
Sensing & Perception55
Alertness: Active Senses
First HandLOS
Sight & SoundSecond Hand
Sight & Sound
First HandLOS
Sight & Sound
High AlertMedium Alert
High Alert
First HandSound
gamedesigninitiativeat cornell university
the
Sensing & Perception56
Alertness: Active Senses
First HandLOS
Sight & SoundSecond Hand
Sight & Sound
First HandLOS
Sight & Sound
High AlertMedium Alert
High Alert
gamedesigninitiativeat cornell university
the
Sensing & Perception57
Alertness: Active Senses
First HandLOS
Sight & SoundSecond Hand
Sight & Sound
First HandLOS
Sight & Sound
High AlertMedium Alert
High Alert
First HandSound
gamedesigninitiativeat cornell university
the
� Restrict to nearby NPCs� Have detection range
� Limits events sensed
� Easy to combine with event matching system
� Works in both directions � Nimbus: “can see” radius
� Aura: “can be seen” radius
� Area of interest management
Sensing & Perception58
Spatial Optimizations
gamedesigninitiativeat cornell university
the
� Restrict to nearby NPCs� Have detection range
� Limits events sensed
� Easy to combine with event matching system
� Works in both directions � Nimbus: “can see” radius
� Aura: “can be seen” radius
� Area of interest management
Sensing & Perception59
Spatial Optimizations
gamedesigninitiativeat cornell university
the
� Restrict to nearby NPCs� Have detection range
� Limits events sensed
� Easy to combine with event matching system
� Works in both directions � Nimbus: “can see” radius
� Aura: “can be seen” radius
� Area of interest management
Sensing & Perception60
Spatial Optimizations
gamedesigninitiativeat cornell university
the
Lighting Movement Exposure
Visibility
Viewcone
Sound System
Sound Queue
Non-specific Spatial Events
ListenLook
Sense PulseReceiver
Ramp UpDelay
Cool-downCapacitor
Inter-AgentCommunication
Inter-AgentObservation
ViewconeSelector
Position
Game Mechanics and Configuration
Sense Links61
Thief: Sense Events and Aggregation
gamedesigninitiativeat cornell university
the
Summary
� Sensing is the most expensive part of AI� Each character “looks” at every object in game� Often leads to O(n2) behavior (bad!)
� Can optimize sense gathering� Aggregation is amenable to parallelization� Can piggyback some data onto pathfinding
� Event matching inverts the sensing problem� Creation of sense makes a data event� Forward event to “relevant” NPCs
Sensing & Perception62