entity
Entity/Component System for C++
User Manual

Preface


ECS for C++ For more information on what an ECS is, visit ECS on Wikipedia.

Development Status:

This code is alpha quality at best. Though it does contain a reasonable test suit, it's not been proven to be of use to any real systems as of yet. The being said, I believe the concept is solid and the library just needs refinement.

Installation


This library is currently header-only but depends on boost 1.55 or higher. The easiest installation is, if you use cmake, to auto configure it using my handy cmake tools. An example might look like this;

Download cmaketools to project folder

1 mkdir my_program
2 cd my_program
3 git clone https://github.com/cdglove/cmaketools contrib/cmaketools

Add the following to a CMakeLists.txt

1 include(contrib/cmaketools/external_git.cmake)
2 include(contrib/cmaketools/enable_cpp11.cmake)
3 
4 set(ENTITY_BUILD_TESTS OFF CACHE BOOL "Disable libentity tests" FORCE)
5 add_external_git_repo(
6  "https://github.com/cdglove/entity.git"
7  "master" # master breach at HEAD. Or a specific commit.
8  "contrib/entity")
9 find_package(entity)
10 
11 add_executable(my_executable main.cpp)
12 target_include_directories( my_executable PUBLIC ${ENTITY_INCLUDE_DIRS})
13 target_link_libraries( my_executable ${ENTITY_LIBRARIES})

That's all that's required. entity will autoconfigure itself and your project with the appropriate dependencies. To get started,

#include <entity/all.hpp>

or each individual file as necessary;

#include <entity/**/*.hpp>

Alternatively, you can get the source from the entity repository on github and then point your compiler at it via -I, /I, et al.

License


Most of the source code in this project are mine, and those are under the Boost Software License. Please see the attached LICENSE file for the licensing.

Supported Compilers


The code is known to work on the following compilers:

  • clang 3.4.0
  • GCC 4.9.0
  • MSVC 2015

What is entity?


entity implements an ECS system which is usually described as a method to compose object-like things from component-like things in a dynamic, yet typesafe fashion.

There are several other C++ ECS systems, but many of them suffer from some performance issues due to the cost of the entity carrying a list of type erased components. Fetching a component from the entity means walking a list fo see if such a type exists in the list. Because such system usually work based on types, this also means than an entity can only have one instance of each component type attached to it

To fix these two problems, entity takes a slightly different approach: nstead treating the entity as an object, it's actually just an id from which to retrieve and modify components from various pools. entity, therefore, simply coordinates the lifetime management of the entities and it's components while also providing algorithsm to assist in working with the system.

Why Use an ECS?

Flexibility

Inheritance is probably the most overused abstraction in C++ and indeed most modern languages. Despite the fact that most problems don't fit into such a nice hierarchy, most programmers reach for inheritance too soon when first building a new system resulting in overly rigid architcturses that are difficult to change.

An ECS on the otherhand is flexible and dynamic.

Performance

The virtual function mehanism implies heap allocated objects (or at least, pointers to objects). This in turn implies jumping around in memory a lot, which is hard on the CPU cache.

But, we like composability, so an ECS aims to fix offer that without the cache problem.

OOP vs. ECS

// Put sample OOP code here.

with

// Put sample ECS code here.