gameplay programming in a rich and immersive open … · gameplay programming with emphasis on new...

51
BARTŁOMIEJ WASZAK GAMEPLAY PROGRAMMER AT UBISOFT QUÉBEC GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN WORLD Digital Dragons 2016, May 16-17 Cracow, Poland

Upload: others

Post on 29-Sep-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

BARTŁOMIEJ WASZAK

GAMEPLAY PROGRAMMER AT UBISOFT QUÉBEC

GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN WORLD Digital Dragons 2016, May 16-17Cracow, Poland

Page 2: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Assassin's Creed Syndicate

• Historical action-adventure game with open-world gameplay

• Platforms: PS4, XBox One, PC

• Ubisoft Quebec as a leading studio + 9 other Ubisoft studios

• XIX-th century Victorian Era London

• Massive simulation of the vehicles: carriages, trains and boats

• Programming languages: • C++

• Custom scripting language

Page 3: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 4: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 5: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Game object model

• Entity: main object represented in the world

• Entity: position + rotation, flags, components

• Components: configurable behaviours

• Example of entities: character, horse, street lamp, train's wagon, etc.

• Example of components: • Visual component

• Rigid Body component

• Behaviour (AI) component

• Skeleton component

Page 6: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

World structure

• World is a single object with added "world" components

• World components serve as managers for gameplay systems

• Examples of world components:• Railway System Component - trains

• Carriage Manager

• River System Component - boats

Page 7: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Map of London

Page 8: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Loading gridMap of London with loading grid

LoadingAdvisor & loadingAdvisor = CurrentWorld.GetLoadingAdvisor();bool isCellLoaded = loadingAdvisor.IsCellLoadedAtPosition( worldPosition );

Page 9: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 10: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

• Carriage is built from at least 3 entities:

• Carriage chassis (main body)

• Carriage tractor

• One entity representing each horse (1 or 2)

Carriage entities

ChassisHorse 1

Horse 2

Tractor

Page 11: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Carriage physics

• For physics engine, one dynamic rigid body is one entity

• Chassis – visuals + physics

• Tractor - no visual representation

• Horses - no physical simulation

• Hitch is modelled using constraints

Chassis dynamic

body

Tractordynamic

body

Hitch = physical constraint

Page 12: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Carriage-centric or entity-centric?

Existing code was entity-centric because character is one entity

More than one entity per carriage

A lot of redirections in the code

Page 13: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Traffic - streets of XIX-century London were full of carriages

Source: WikipediaSource: www.victorianlondon.org

Page 14: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Traffic system in the game

Page 15: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Traffic - spawning

• Spawning the entity has relatively high time cost

• Instead of spawning and despawning we use a pool of reusable entities

• The pool is small - around 20 carriages

• Spawning is replaced with reinitialization for gameplay logic

• We try to perform only one reinitialization per frame

• Requests are processed based on the distance from camera and priority

Page 16: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Traffic - simulation

512 simulated objects

20 carriages as entities Lightweight visual objects

Dynamic physics

Kinematic physics

Page 17: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 18: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Trains in the game

Page 19: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Railway system

Page 20: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Railway system

Bezier curves

Turnouts

Control points

Page 21: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

• Every wagon is entity

• Heavy usage of parenting mechanism

• High cost to update the hierarchy - trains are almost always in motion

• Optimizations:• Less frequent update based on the distance to the camera

• Move only visuals with predicted velocity

Train entities

Page 22: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Trains - physics

• Custom physically-basedsimulator

• Movable coupling chain drives movement for all wagons

• Collision tests between wagons

• Custom constraints solver for coupling chain

• Momentum transfers during train's start-up and full stop

Source: Wikipedia

Page 23: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 24: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Data-driven approach

• Designers control behaviours directly from the world editor

• Entities are created offline and loaded into the world

• Parameters can also be changed during the game's run-time

• Parameters represent directly values for member variables in C++:

float m_Speed;void SetSpeed(float NewSpeed);float GetSpeed();

Speed 11.3

Page 25: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Data-driven approach

• To create advanced behaviours we need more than simple linear dependencies

• We used curves instead of linear coefficients

• We've used a lot of curves for carriage's handling parameters

• We used it also for such behaviours like hit points

Page 26: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Data-driven approach

• Simple linear dependency vs. more complex curve:

Input: Collision amount Input: Collision amount

Output:Damagepoints

Output:Damagepoints

Page 27: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 28: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

State machines

• Simple concept used throughout the gameplay code

• Basic building block for gameplay and AI logic

• Internal scripting language supporting directly state machines

• Examples of state machines:• Human state machine

• Carriage state machine

• Horse state machine

• Gameplay programming means working a lot with state machines

Page 29: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

State machine structure

• States have constructor / destructor, enter / exit methods

• States can build hierarchies (substates)

• Exclusive states and additive states

• State machine is always in • one of the exclusive states

• and maybe in one or more of additive states

Page 30: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Horse state machine

Alive

Hitched Unhitched

Default

Pending deletion

Dead

Healthy Dying

Healthy

Dying

Audio and effects

Animationsquality

Active audio

Inactiveaudio

Page 31: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Flow in horse state machine

Alive

Hitched Unhitched

Default

Pending deletion

Dead

Healthy Dying

Healthy

Dying

Audio and effects

Animationsquality

Active audio

Inactiveaudio

ON_KILL()

ON_KILL()

ON_KILL()

Page 32: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Carriage state machine

Animationsfor

passengers

Audio and

Effects

Active

Damage

QueuedImpulses

RooftopEjection

Inactive

Ownership

Driver

Detached

HitchedKeyframed

Dynamic

Crashing

Page 33: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 34: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Real-time control parameters

• Data-driven control over the system through the set of simple parameters

• Parameters are using basic types like float, integer, enumeration, vector

• Examples: • Velocity, acceleration, emotional state (enumeration), impact direction

• Systems controlled through RTCPs: Animation, Audio and Special Effects

• Advantages:• Less coupled subsystems

• Simple interfaces - easy to control

• Easy to understand by non-programmers

Page 35: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Velocity as real-time control parameter

• Multiple behaviours for entities in the open-world game

• Different movement source: physics, animations, procedural

• Velocity - simple value, not so easy to calculate properly

• Solution: • External computation independent on movement source

• Velocity calculation is based only on position changes

• Will work even for the unknown future - any source of movement

Page 36: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Computation of velocity

p[0]

Velocity =

v[1] + v[2] + v[3] + v[4] + v[5] + v[6] + v[7] + v[8]

TotalTime

TotalDistance

TotalTimep[1]

p[2]

p[5]

p[4]

p[3]

p[6]

p[7]

where: v[i] = p[i] - p[i-1]

Velocity =

Page 37: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the
Page 38: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Animation system - layers

Real-time control parameters

Animation graph state machines

Animations

Final transformations for the bones

Artists

Programmers

Programmers (place for IK, etc.)

Page 39: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Animation logic

• Very common pattern with the coupling between the state machine code and animation's RTCPs:Alive_state{

enter_state{

m_Entity->GetAnimComponent()->SetControlParameter( GeneralStates_Alive, eRTCP.GeneralState );}

// … specific code for Alive state

exit_state{

m_Entity->GetAnimComponent()->SetControlParameter( GeneralStates_Default, eRTCP.GeneralState ); }

}

Page 40: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Horse animations

• Displacement: animation-driven vs. physics-driven

• The main character is animation-driven

• But horses are physics-driven

• Animation playback scaled with the current physical speed

• Different animations for speed ranges: walk, trot, gallop

• Hit reactions are additive animations

Page 41: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 42: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Event-driven gameplay logic

Entity A

Entity B

Entity C

Entity D

New event XChannel #1

Channel #2

New event Y

Page 43: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Event-driven gameplay logic

• Example of the event creation:

MyEventExplosion* newEvent = new MyEventExplosion;

newEvent->SetStrength( 4.0f );

SendEvent( channel, newEvent );

Page 44: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Receiving event from channel

• Method call upon receiving new event: OnExplosionEvent

• Can be called immediately or deferred

• Examples of events created in the game:• DestructibleHit

• RammingEvent

• CarriageTractorCollisionWithCharacter

Page 45: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 46: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Multithreaded environment

• Parallel update for carriages, horses and humans

Thread 1

Thread 2

Carriage A Horse A Human in carriage A

Carriage BHorse B Human #1 in

carriage BHuman #2 in carriage B

Page 47: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Presentation overview

Gameplay programming with emphasis on new vehicles' systems:• Object model and world structure• Vehicles as part of the game world

• Carriages• Trains

• Data-driven approach• State machines• Animation system and real-time control parameters• Event-driven gameplay logic• Multithreaded environment• Case study for the gameplay feature

Page 48: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the
Page 49: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

• What is happening in the gameplay code for this feature?

Decoupling train wagons

Detect coupling

chain

Wait for button

Transition to new statein

Human state machine

Send RTCPStart animation

Adjust player’s position and orientation

Page 50: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Decoupling train wagons

• What is happening in the gameplay code for this feature?

Audio and FX events

from animation

Callback in the code from

specific place in animation

Call ::Decouple() on wagon

Railway System Component splits

train into two groups

New event broadcasted:

WagonDetachEvent

Page 51: GAMEPLAY PROGRAMMING IN A RICH AND IMMERSIVE OPEN … · Gameplay programming with emphasis on new vehicles' systems: •Object model and world structure •Vehicles as part of the

Questions?

[email protected]

http://bwaszak.com

Thanks to:

Pierre Fortin, Dave Tremblay, James Carnahan, Matthieu Pierrot, Maxime Begin, Vincent Martineau, Martin Bedard, Marc Parenteau

and Leszek Godlewski.

Thank You!