Skip to content

A WIP, experimental header-only ECS framework. Written in C++20/17.

License

Notifications You must be signed in to change notification settings

pyrbin/realm.hpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

realm.hpp

A WIP, experimental header-only ECS framework. Written in C++20/17.

Table of Contents

Introduction

Goal of this project is to create a simple ECS (Entity Component System) framework in C++20/17 to increase my knowledge of modern C++/C++ toolchains, DoD patterns, parallelization and general game dev. This is an archetype-based ECS taking inspiration from Unity DOTS and smaller frameworks like legion, hecs, decs & entt.

The main focus is a clean & minimal API with acceptable performance, perfect aligned contiguous memory of components & easy parallelization of systems.

Project is currently very WIP and should not be used in anything serious.

Requires a C++20 compatible compiler.

Design

TODO

API

Components

Components are just simple structs of data. The only requirement is that they have to be default, move & copy constructible.

struct pos
{
    float x{0};
    float y{0};
}

Systems

Systems are defined by their update function where each argument is a component + access (const or not) they want to fetch.

struct example_system
{
    // Per entity
    void update(pos& p, const vel& v) const {
        // do system logic
    }
}

struct example_system_perchunk
{
    // You can use a single realm::view as an argument
    // to access components on a per-chunk basis
    void update(realm::view<pos, vel> view) const {
        for(auto [p, v] : view) {
            // do system logic
        }
    }
}

// Insert systems to a world
world.insert<example_system>();
world.insert<example_per_chunk>();

Example

struct pos
{
    float x{0};
    float y{0};
}

struct time
{
    float dt{1/60};
}

struct move_system
{
    void update(pos& p, const vel& v, const time& t) const {
        p.x += v.x * t.dt;
        p.y += v.y * t.dt;
    }
}


// Create a world with capacity of 1000 entities.
auto world = realm::world(1000);

// Create a singleton component
world.singleton<time>();

// Create entities of components pos & vel.
for(auto i{0}; i < 1000; i++) {
    auto entt = world.create<pos, vel>();
    world.set<vel>(entt, {10, 10});
}

// Insert move_system to the world
world.insert<move_system>();

// Update systems in parallel
world.update();

Benchmarks

TODO

TODO

  • See TODO file

Thanks

Thanks to the guides @skypjack on software for helping me understand the various concepts of an ECS implementation.

Videos & talks:

Developer


pyrbin

About

A WIP, experimental header-only ECS framework. Written in C++20/17.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published