🌎

Object Model

Created
Tags

Overview

An object model is similar to a business model in a regular application.

In games, the object model is a representation of the elements that participate in the game world.

In some engines, the object model is restricted to the representation of visual objects in a scene.

Other engine adopt a broader object model in which any data can be represented.

Typically, a scene is built as an aggregation of game objects, or entities.

Editor and Runtime Models

Editor

Runtime


A one-to-one mapping between editor and runtime objects may not exist.

Models

Hierarchy System

In the hierarchy system, the typical object-oriented design (OOD) of modeling data is used with objects in an inheritance hierarchy.

At the root of the hierarchy, the entity type defines an abstract object.

Derived types define more specific objects with additional data and behaviors.

ℹ️Also called monolithic class hierarchy.

✔️Easy to map the concepts to a concrete hierarchy.

❌Poor flexibility.

❌Difficult to share functionality among objects.

❌Difficult to reason about the chain of hierarchy (ie Renderable derives from Animatable or the other way around).

❌Common functionality tends to move up the hierarchy (root objects contain too much functionality and knowledge of the hierarchy).

❌Problem of multiple inheritance: multiple copies of the base class, multiple virtual table pointers.

Examples

Component System

In the component-based architecture, the entity object is a container of components.

Components provide custom data and behaviors.

As an entity contains multiple components, sharing of functionality is easy.

Allowing components to reference each other makes communication easy.

✔️Easy to implement new behaviors.

✔️Easy to share functionality among objects.

❌Complex objects include many components and communication becomes difficult.

❌Implementation of behaviors is not efficient because of poor data locality.

Variants

Relashionship

Components

Examples

Hierarchy/Component Hybrid System

A hybrid of the hierarchy and component systems.

✔️Can specialize some concepts in dedicated objects.

❌Difficult to reason about the correct implementation (as a specialized object or a set of components).

Examples

Entity Component System

An entity component system (or ECS) is a data-oriented design (DOD).

An entity is a simulation object that lives in some kind of simulation world.

A component contains data of a certain type.

An entity contains multiple components.

A system is responsible for implementing the behavior of an entity containing a specific set of components.

A system perform the update of the simulation in the world.

The data layout of components is optimized by storing the component data in arrays, and identifying the relationship between entity and components using unique identifiers and hashed maps.

✔️Easy to share functionality among objects.

✔️Easy to optimized batch operations.

✔️Better performances with efficient memory layout and batching of operations.

❌Implementation of behaviors is harder to reason about.

Examples

Mix-in System

A mix-in system is property centric.

Multiple presets of data are defined and entities are created as a set of these presets.

Examples

Synchronization

Brute Force

Iterate over all the entities and copy their state.

Can be optimized with hierarchical dirty flags.

Callbacks

Call a callback whenever an entity is changed to copy its state.

Deferred

Put the changed entities in a list.

Process the list of changed entities and copy their state.