Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung....

102
Game Programming Paradigms Michael Chung

Transcript of Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung....

Page 1: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Game Programming ParadigmsMichael Chung

Page 2: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.
Page 3: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.
Page 4: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.
Page 5: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.
Page 6: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

CS248, 10 years ago...

Page 7: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Goals

Page 8: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Goals1. High level tips for your project’s game architecture

Page 9: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Goals1. High level tips for your project’s game architecture

2. Some perspective on where Unity falls short

Page 10: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Outline1. Game loops and simulations2. Handling interactions3. Controls4. Entity component system

Page 11: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Outline1. Game loops and simulations2. Handling interactions3. Controls4. Entity component system

Page 12: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Game LoopGame loops handle all game simulation logic:

- Add / remove entities- Handle player inputs- Update game logic systems- Handle movement, physics and collisions- Generate state for the view layer

Page 13: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Game LoopGame loops decouple your simulation timeline from:

- User input- Processor speed

Page 14: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game Loop

https://docs.unity3d.com/Manual/ExecutionOrder.html

Page 15: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game LoopGame logic in Update()?

Worry less about view interpolation

Couples simulation frequency with rendering loop

Page 16: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game LoopGame logic in FixedUpdate()?

In sync with physics loop

Easier to reason with a discrete quantized timeline

Your views will be jittery if you don’t interpolate correctly

Page 17: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game LoopWhat about ordering of behavior within game loop?

Page 18: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game Loop

Page 19: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game Loop

Page 20: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game Loop

Page 21: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game LoopYou can order component priorities with a customized script execution order.

But that means you are defining one ordering for:

- Initialization- Updates- Teardown

Not always convenient:

- Hard to make sense of the merged ordering- Maybe you want different orderings

Page 22: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s Game LoopYou may also have cyclical dependencies between components during your initialization steps.

You could split components to solve this problem, but that may require you to update a lot of prefabs, and may increase coupling between components.

You could split initialization code between Awake() and Start(), but that’s really bad.

A good way to solve this problem is to separate your behaviors from your state, and not use Unity’s callbacks for most of your components.

Page 23: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

SimulationObject that encapsulates loop and state

Page 24: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

SimulationIn Unity, there is one simulation running at all times.

You have very little control over it:

- You can’t fast forward / rewind / replay- You can’t instantiate multiple simulations- You can’t differentiate initialization order from update order- You can’t define multiple initialization / update behaviors on the same

component

Page 25: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

SimulationYou can solve all of these problems by creating your own simulation class.

Page 26: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Multiple Simulations

Page 27: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Multiple Simulations

Page 28: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Outline1. Game loops and simulations2. Handling interactions3. Controls4. Entity component system

Page 29: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 30: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 31: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 32: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Slap!

Page 33: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 34: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 35: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 36: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 37: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 38: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 39: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 40: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 41: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction Resolution

Page 42: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Interaction ResolutionDo we care? Maybe.

- Turn based simulations- Competitive games- Consistently biased small advantages can add up

Page 43: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Double buffering

Page 44: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Double buffering

Page 45: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Double bufferingAfter swapping, instead of a buffer clear on the active buffer, we do a buffer copy.

The buffer copy can be unnecessarily expensive:

- Game states can be large- Usually only a small portion of the game state changes each tick

Potentially use this concept on pieces of state, or avoid it completely.

Page 46: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Message queues

Page 47: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Message queues

Page 48: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Message queues

Page 49: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Outline1. Game loops and simulations2. Handling interactions3. Controls4. Entity component system

Page 50: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls

Page 51: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - “Command” Pattern

Page 52: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - “Command” Pattern

Page 53: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - “Command” Pattern

Page 54: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input Handlers

Page 55: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input Handlers

Page 56: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input Handlers

Page 57: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with durationSome controls are kept activated.

For example, holding a button down for movement.

Page 58: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with durationCould try this:

- Activation command on key down- Deactivation command on key up

Page 59: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with durationCould try this:

- Activation command on key down- Deactivation command on key up

Couple problems:

- Callbacks may be missed- Conflicting controls could be a problem

Page 60: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with durationYou could poll the input state, and keep track of input handler activation.

Page 61: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with duration

Page 62: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with duration

Page 63: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with duration

Page 64: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with duration

Page 65: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with durationLet’s update our input handlers for “Jump” and “Fire”.

Page 66: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Input with durationNow add input handlers for moving left and right.

Page 67: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputsWhat about conflicting controls?

What happens when you press multiple buttons at the same time?

Page 68: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputs

Page 69: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputs

Page 70: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputs

Page 71: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputs

Page 72: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputs

Page 73: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputs

Page 74: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputsSometimes you want to handle only one input at a time out of a set of inputs.

Page 75: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputsSometimes you want to handle only one input at a time out of a set of inputs.

Priority of input may be based on various factors:

- How recent is the input?- What are the gameplay effects of the input?

Page 76: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputsSometimes you want to handle only one input at a time out of a set of inputs.

Priority of input may be based on various factors:

- How recent is the input?- What are the gameplay effects of the input?

Are these relationships gameplay rules, or input rules?

Page 77: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputsYou can use state machines, not only for animation, but also for gameplay logic.

In our movement system, you are either idle, moving left, or moving right.

Page 78: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputs

Page 79: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputsLet’s examine our movement code again.

Releasing one direction button could end movement in the opposite direction.

We don’t want that.

Page 80: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Controls - Simultaneous inputsInstead of requesting velocity modifications, we request state transitions.

Page 81: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Outline1. Game loops and simulations2. Handling interactions3. Controls4. Entity component system

Page 82: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Entity Component System (ECS)All interactive objects in your game are Entities.

Each Entity is associated with a collection of Components.

Plural quantities of certain types of Components may exist on an Entity.

Page 83: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Entity Component System (ECS)

Page 84: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Entity Component System (ECS)

Page 85: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Entity Component System (ECS)

Page 86: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s ECS

Page 87: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s ECS

Page 88: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s ECS

Page 89: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s ECSTwo problems with Unity’s ECS:

- No view / model separation- Probably not a huge problem for your final projects- Becomes a problem when you make a networked multiplayer game

Page 90: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Unity’s ECSTwo problems with Unity’s ECS:

- No view / model separation- Probably not a huge problem for your final projects- Becomes a problem when you make a networked multiplayer game

- No behavior / state separation- You can build this on top of Unity’s system, by creating your own simulation code

Page 91: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Behavior and State SeparationIt may help to separate behaviors from state.

Why?

- Behaviors need to be organized and ordered in the game loop, but state does not.- Modularization of behaviors is not clear if they are in the same class as the state.

Page 92: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Behavior and State Separation

Page 93: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Behavior and State Separation

Page 94: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Behavior and State Separation

Page 95: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Behavior and State Separation

Page 96: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Behavior and State Separation

Page 97: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Review

Page 98: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Review1. Game loops and simulations

a. Unity calls your code via callbacks, such as Awake(), Start(), FixedUpdate(), Update()b. You can customize the script execution order (be careful)c. Consider making a simulation class / component, to gain control

Page 99: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Review1. Game loops and simulations

a. Unity calls your code via callbacks, such as Awake(), Start(), FixedUpdate(), Update()b. You can customize the script execution order (be careful)c. Consider making a simulation class / component, to gain control

2. Handling interactionsa. Double bufferingb. Message queues

Page 100: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Review1. Game loops and simulations

a. Unity calls your code via callbacks, such as Awake(), Start(), FixedUpdate(), Update()b. You can customize the script execution order (be careful)c. Consider making a simulation class / component, to gain control

2. Handling interactionsa. Double bufferingb. Message queues

3. Controlsa. Commands and input handlersb. Resolve conflicts in your gameplay logic, possibly by using state machines

Page 101: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

Review1. Game loops and simulations

a. Unity calls your code via callbacks, such as Awake(), Start(), FixedUpdate(), Update()b. You can customize the script execution order (be careful)c. Consider making a simulation class / component, to gain control

2. Handling interactionsa. Double bufferingb. Message queues

3. Controlsa. Commands and input handlersb. Resolve conflicts in your gameplay logic, possibly by using state machines

4. Entity component systema. Unity’s ECS is very versatileb. You can write your own classes / components to extend it

i. View / model separationii. Behavior / state separation

Page 102: Game Programming Paradigms - Stanford University · Game Programming Paradigms Michael Chung. CS248, 10 years ago... Goals. Goals 1. High level tips for your project’s game architecture.

ContactHappy to provide help on final projects and career planning!

Reach out to me at [email protected]