All Projects → BlackMATov → Ecs.hpp

BlackMATov / Ecs.hpp

Licence: mit
C++17 Entity Component System

Programming Languages

cpp
1120 projects
cpp14
131 projects

Projects that are alternatives of or similar to Ecs.hpp

Svelto.ecs
Svelto ECS C# Lightweight Data Oriented Entity Component System Framework
Stars: ✭ 605 (+2320%)
Mutual labels:  ecs, entity-component-system
Entt
Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more
Stars: ✭ 6,017 (+23968%)
Mutual labels:  ecs, entity-component-system
Shipyard
Entity Component System focused on usability and speed.
Stars: ✭ 247 (+888%)
Mutual labels:  ecs, entity-component-system
UnityDOTS-Thesis
Bachelor's degree thesis on Unity DOTS architecture
Stars: ✭ 14 (-44%)
Mutual labels:  ecs, entity-component-system
Etengine
Realtime 3D Game-Engine with a focus on space sim. Written in C++ 14
Stars: ✭ 408 (+1532%)
Mutual labels:  ecs, entity-component-system
IwEngine
This is an engine that I initially started building after taking a game coding class in high school. I didn't like Unity so tried to make something more code focused that was personally easier to use.
Stars: ✭ 97 (+288%)
Mutual labels:  ecs, entity-component-system
Ecs
LeoECS is a fast Entity Component System (ECS) Framework powered by C# with optional integration to Unity
Stars: ✭ 578 (+2212%)
Mutual labels:  ecs, entity-component-system
space
A SCI-FI community game server simulating space(ships). Built from the ground up to support moddable online action multiplayer and roleplay!
Stars: ✭ 25 (+0%)
Mutual labels:  ecs, entity-component-system
Entitas Csharp
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
Stars: ✭ 5,393 (+21472%)
Mutual labels:  ecs, entity-component-system
Godex
Godex is a Godot Engine ECS library.
Stars: ✭ 307 (+1128%)
Mutual labels:  ecs, entity-component-system
Rockgo
A developing game server framework,based on Entity Component System(ECS).
Stars: ✭ 532 (+2028%)
Mutual labels:  ecs, entity-component-system
Actors.unity
🚀Actors is a framework empowering developers to make better games faster on Unity.
Stars: ✭ 437 (+1648%)
Mutual labels:  ecs, entity-component-system
js13k-ecs
A 1kb entity component system, designed for Js13kGames
Stars: ✭ 76 (+204%)
Mutual labels:  ecs, entity-component-system
Fomalhaut
A clean, simple, c++14, Entity Component System like Overwatch ECS architecture
Stars: ✭ 29 (+16%)
Mutual labels:  ecs, entity-component-system
Usagi
A hierarchical component entity system based game engine
Stars: ✭ 44 (+76%)
Mutual labels:  ecs, entity-component-system
Defaultecs
Entity Component System framework aiming for syntax and usage simplicity with maximum performance for game development.
Stars: ✭ 286 (+1044%)
Mutual labels:  ecs, entity-component-system
ecs
A dependency free, lightweight, fast Entity-Component System (ECS) implementation in Swift
Stars: ✭ 79 (+216%)
Mutual labels:  ecs, entity-component-system
polymorph
A fast and frugal entity-component-system library with a focus on code generation and compile time optimisation.
Stars: ✭ 74 (+196%)
Mutual labels:  ecs, entity-component-system
Gdk For Unity
SpatialOS GDK for Unity
Stars: ✭ 296 (+1084%)
Mutual labels:  ecs, entity-component-system
Kengine
Entity-Component-System (ECS) with a focus on ease-of-use, runtime extensibility and compile-time type safety and clarity.
Stars: ✭ 417 (+1568%)
Mutual labels:  ecs, entity-component-system

ecs.hpp

C++17 Entity Component System

travis appveyor codecov language license paypal

Requirements

Installation

ecs.hpp is a header-only library. All you need to do is copy the headers files from headers directory into your project and include them:

#include "ecs.hpp/ecs.hpp"

Also, you can add the root repository directory to your cmake project:

add_subdirectory(external/ecs.hpp)
target_link_libraries(your_project_target ecs.hpp)

Basic usage

#include <ecs.hpp/ecs.hpp>
namespace ecs = ecs_hpp;

// events

struct update_event {
    float dt{};
};

struct render_event {
    std::string camera;
};

// components

struct movable {};
struct disabled {};

struct sprite {
    std::string name;
};

struct position {
    float x{};
    float y{};
};

struct velocity {
    float x{};
    float y{};
};

// systems

class gravity_system : public ecs::system<update_event> {
public:
    gravity_system(float gravity)
    : gravity_(gravity) {}

    void process(ecs::registry& world, const update_event& evt) override {
        world.for_each_component<velocity>(
        [this, &evt](ecs::entity, velocity& vel) {
            vel.x += gravity_ * evt.dt;
            vel.y += gravity_ * evt.dt;
        }, ecs::exists<movable>{} && !ecs::exists<disabled>{});
    }
private:
    float gravity_{};
};

class movement_system : public ecs::system<update_event> {
public:
    void process(ecs::registry& world, const update_event& evt) override {
        world.for_joined_components<position, velocity>(
        [&evt](ecs::entity, position& pos, const velocity& vel) {
            pos.x += vel.x * evt.dt;
            pos.y += vel.y * evt.dt;
        }, ecs::exists<movable>{} && !ecs::exists<disabled>{});
    }
};

class render_system : public ecs::system<render_event> {
public:
    void process(ecs::registry& world, const render_event& evt) override {
        world.for_joined_components<sprite, position>(
        [&evt](ecs::entity, const sprite& s, const position& p) {
            std::cout << "Render sprite:" << std::endl;
            std::cout << "--> pos: " << p.x << "," << p.y << std::endl;
            std::cout << "--> sprite: " << s.name << std::endl;
            std::cout << "--> camera: " << evt.camera << std::endl;
        }, !ecs::exists<disabled>{});
    }
};

// world

ecs::registry world;

struct physics_feature {};
world.assign_feature<physics_feature>()
    .add_system<movement_system>()
    .add_system<gravity_system>(9.8f);

struct rendering_feature {};
world.assign_feature<rendering_feature>()
    .add_system<render_system>();

// entities

auto entity_one = world.create_entity();
ecs::entity_filler(entity_one)
    .component<movable>()
    .component<sprite>("ship")
    .component<position>(4.f, 2.f)
    .component<velocity>(10.f, 20.f);

auto entity_two = world.create_entity();
ecs::entity_filler(entity_two)
    .component<movable>()
    .component<sprite>("player")
    .component<position>(4.f, 2.f)
    .component<velocity>(10.f, 20.f);

// processing

world.process_event(update_event{0.1f});
world.process_event(render_event{"main"});

License (MIT)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].