GithubHelp home page GithubHelp logo

ecs's Introduction

Overview

This repository hosts a single-include Entity Component System written in modern C++.

Example usage

auto registry = ecs::Registry{};

for (auto i = 0u; i < 10u; ++i)
{
    auto entity = registry.create_entity();
    registry.assign<Position>(entity, {0, 0});
    registry.assign<Velocity>(entity, {1, i});
}

auto view = registry.create_view<Position, Velocity>();
for (auto entity : registry.get(view))
{
    auto& pos = registry.get<Position>(entity);
    const auto vel = registry.get<Velocity>(entity);
    pos.x += vel.dx;
    pos.y += vel.dy;
}

An extended, compiling example is found in example.cpp.

Implementation overview

The maximum number of entities and component data types is static, but can be specified at compile time by setting ECS_MAX_ENTITY_COUNT and ECS_MAX_COMPONENT_COUNT before including the library.

Entities

Entities are stored as 32-bit unsigned integers in an std::array with skip values for faster iteration.

Components

Data types registered as components have an std::array the size of the entity pool pre-allocated for constant time access. The array entry associated with any specific entity is inaccessible until the corresponding component has been assigned to that entity. Accessing the component of an entity after it or its component has been removed throws a runtime error.

Views

Views are represented by 32-bit unsigned integers. Each view stores the identifiers of its entities in an std::unordered_set. The set is kept up-to-date in regard to assignments and removals of components on entities, meaning an identifier never decays.

Requirements

Compiles in C++14 or later. No external dependencies.

License

Released under the MIT License. See LICENSE for more information.

ecs's People

Contributors

maskhjarna avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.