Lecture_003

Components

Component of Modern Game: game objects

Game objects have properties (variables) and behavior (functions)

Instead of using inheritance, we use component based game objects

Instead of using inheritance, we use component based game objects

Component of Drone

Component of Drone

Component Code Example

Component Code Example

Component in Commercial Game Engine

Component in Commercial Game Engine

Note that UObject is not game object, but a wrapper on C's object.

Ticking

Ticking

Ticking

There are two types of ticking.

  1. tick logic
  2. tick render

They are usually asynchronous and can be spread to more than two threads.

Component-based ticking is more efficient than object-based ticking. Batch processing preserves locality.

Component-based ticking is more efficient than object-based ticking. Batch processing preserves locality.

Interaction Between Game Objects

Traditionally, we code interaction within game objects to search for related game objects and call game objects functions.

Hard-coded solution to game object interaction

Hard-coded solution to game object interaction

But event-based interactions are easier to code with.

Event-based Game Object interaction

Event-based Game Object interaction

Event in Commercial Game Engine

Event in Commercial Game Engine

Scene Management

However, if event is sent to every game objects, then the cost is high.

Reducing the cost by only send events to nearby game objects in the same grid.

Reducing the cost by only send events to nearby game objects in the same grid.

However, if the grid is crowded, then the cost is still high.

Octree Division

Octree Division

Basic Octree: for static objects, it is fine. However, for moving objects, editing tree structure based on movement is less costly than generating octree for each frame from scratch.

Basic Octree: for static objects, it is fine. However, for moving objects, editing tree structure based on movement is less costly than generating octree for each frame from scratch.

Bounding Volume Hierarchies: merging bounding box of objects.

You need to choose a scene management method that is suit to your game. For enclosed scene with minimal objects that can move, BSP or Potentially Visible Sets (PVS) would be good. However, BVH has low cost and is more suited for moving scenes.

Different Division Methods

Different Division Methods

The Problem with Ticking

Problem with Ticking: dependency feedback loop

Problem with Ticking: dependency feedback loop

Imagine a situration: in one tick

  1. your keyboard input triggers an animation of a character
  2. the character triggers physics
  3. the physics will again affect the animation

One way physics can interact with animation is that we blend physical impact (slam face) with animated impact so that the interaction looks natural.

In above example, the animation will change multiple time in one tick.

The order of ticks matters! Imagine a situration: using event system, in the same tick, a character is shot by a bullet and the character is healed by his teammate. Since those two events were sent in the same tick, it is ambiguous whether after the tick, the character is alive. If we only process event in order of reception time, then deterministic input (sending the command in the same tick) can result nondeterministic result (died or alive).

pre-tick, post-tick is used to solve the order of events.

Recursive dependency will result in game lag within one or two ticks.

Things to keep in mind in design:

When a tick takes too long to compute:

  1. only tick essential stuff first that can affect screen largely (such as movement)
  2. tick 2 ticks at once without user input (dangerous)
  3. optimize your code to interleave calculations from a tick to other ticks (like massive explosion)

Logic will run 1 tick ahead. Swaping frame buffer delays the display another tick... So we need to optimize how many ticks has passed from input to screen outcome. There are many tricks to put into minimize tick delay to optimize hitfeel.

Table of Content