I'm a gameplay programmer
focused on developing
engaging and unique experiences!

My Resume Learn more

Entity-Component-System (ECS) : A Data-Oriented Gameplay Framework in C++ - Part 1

Introduction

One of the most recent architectural patterns to come out of the game development industry is the Entity-Component-System (ECS) with naming akin to the Model-View-Controller (MVC) pattern found in the software industry. This hints that ECS helps with separation of concerns while developing a game project.

While there's already been several articles written about ECS, I'd like to examine and implement this pattern from a data-oriented design perspective. This comes at a time where game engine giants like Unity are adopting the ECS approach for very impressive run-time demonstrations.

Something to note is that ECS is different than the Component pattern that is largely found in most Unity and Unreal projects prior to Unity's unveiling of their ECS implementation. Most of those projects lack the decoupling of the System from the Entity and Component to make it a true ECS.

What is ECS?

ECS is an architectural pattern that has you spread out your gameplay implementation across Entities, Components, and Systems. By doing this, your game can better utilize data-oriented design principles and also become more encapsulated than if an object-oriented approach was taken.

The three parts that make up an ECS can be described as:

Entities

General purpose objects that are tracked with a unique ID. They represent all the actors that make up your game.

Components

Containers of data that can be attached to an entity. These contain minimal if any logic relating to the data.

Systems

Global managers of a set of entities that have a certain component. This is where the core logic on the components happen that you normally wouldn't find separated in current Unity and Unreal gameplay implementations.

Features

The features of my ECS implementation will be focused on data-oriented design principles. These include:

Locality of Reference

By separating out gameplay implementation into discrete pieces of entities, components, and systems, data can be stored with locality of reference in mind to minimize cache misses.

Binary Files

Defining entities and components will happen in human-readable files that will be built out into binary files during compilation. This maintains a focus on data that can be quickly loaded for use while being easily editable by humans.

Platform Independent Interface

While I'll mainly be targeting Windows with this implementation, it will have a platform independent interface that can be extended with more platform-specific implementations if necessary. This will allow ease of integration into other projects.

Implementation Overview

Interfaces

The main interfaces for this ECS implementation will include:

  • Entity Interface
  • Component Interface
  • System Interface

Managers

Along with those, managers will be created for each type of interface:

  • Entity Manager
  • Component Manager
  • System Manager

Files

Finally, a method to load human-readable files for entity and component set up will be needed to build out binary files for run-time. This will take form as a:

  • EntityComponentLoader
  • EntityComponentBuilder

Components

At the end of this, I'll be setting up a Mesh/Effect component and system so we can visually see the entire workflow of utilizing the ECS in gameplay implementation.

No Comments Yet.

Leave a comment