Giter VIP home page Giter VIP logo

ark's Introduction

ark is an entity component system focused on performance through data-oriented design, compile-time evaluation, and effortless parallelization. Currently written in C++20 and requires gcc 10 (or later) for concepts support.

Some notable features include:

  • Customizable component storage, similar to specs: https://github.com/amethyst/specs
    • unique self-defragmenting 'bucket array' component storage provided by default
  • Easy parallelization via behind-the-scenes thread pool
    • Entity level: for_each --> for_each_par
    • System level: run_systems_sequential --> run_systems_parallel
  • Concrete notion of a 'System' as a struct with specific typedefs and a 'run' method
  • Loose coupling.
    • Systems don't need to know about the entire 'World'.
    • System/World communication handled by a small number of 'handle' types in ark/system.hpp
    • Use of concepts over inheritance
  • No exceptions, no RTTI

Example

#include "ark/ark.hpp"

using namespace ark;

struct Velocity {
    float x = 0;
    float y = 0;
    using Storage = BucketArrayStorage<Velocity, 2000>;
};

struct Position {
    float x = 0;
    float y = 0;
    using Storage = BucketArrayStorage<Position, 2000>;

    inline void advance(float dt, const Velocity& v)
    {
        x += dt * v.x;
        y += dt * v.y;
    }
};

struct TestSystem {
    using Subscriptions = TypeList<Position, Velocity>;

    using SystemData = std::tuple<WriteComponent<Position>, ReadComponent<Velocity> >;

    static void run(FollowedEntities followed, SystemData data)
    {
        auto [position, velocity] = data;

        followed.for_each([&](const EntityID id) -> void {
            // we now use EntityId as an index into component storage
            position[id].advance(0.016, velocity[id]);
        });
    }
};

using GameComponents = TypeList<Position, Velocity>;
using GameSystems = TypeList<TestSystem>;
using GameWorld = World<GameComponents, GameSystems>;
using EntityCreator = EntityBuilder<GameComponents>;

int main()
{
    GameWorld world;

    world.build_entities([&](EntityCreator creator) {
        for (size_t i = 0; i < 500; i++) {
            creator.new_entity()
                .attach<Position>(Position{0.f, 0.f})
                .attach<Velocity>(Velocity{1.f, 1.f});
        }
    });

    for (size_t frame = 0; frame < 60; frame++) {
        world.run_systems_sequential<TestSystem>();
    }

    return 0;
}

Acknowledgements/Inspiration:

Jonathan Blow for his informative streams and the bucket array idea: https://www.youtube.com/watch?v=COQKyOCAxOQ

Casey Muratori for the Handmade Hero streams and inspiration to think more deeply about these problems: https://handmadehero.org/

Mike Acton for the famous talk you've probably already heard. If not: https://www.youtube.com/watch?v=rX0ItVEVjHc

Malte Skarupke for his great work on optimizing radix sort and open addressing hash tables. Check out his blog: https://probablydance.com/

Other ECS implementations:

ark's People

Contributors

zmeadows avatar

Stargazers

 avatar  avatar  avatar  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.