Giter Site home page Giter Site logo

macsummer / ecs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pvigier/ecs

0.0 0.0 1.0 70 KB

A simple and easy to use entity-component-system C++ library

Home Page: https://pvigier.github.io/2019/07/07/entity-component-system-part1.html

License: MIT License

CMake 4.61% C++ 95.39%

ecs's Introduction

ecs

Build Status codecov

ecs is the entity-component-system library I have created for my game Vagabond.

ecs aims to be:

  • easy to use
  • fast
  • lightweight
  • header only
  • implemented with modern C++ features (C++17)

Example

Firstly, you should define some components:

struct Position : public Component<Position>
{
    float x;
    float y;
};

struct Velocity : public Component<Velocity>
{
    float x;
    float y;
};

A component of type T must inherit Component<T>.

Now, let us create an entity manager:

auto manager = EntityManager();

Next, let us create an entity with both components:

auto entity = manager.createEntity();
manager.addComponent<Position>(entity);
manager.addComponent<Velocity>(entity);

Finally, we can use getEntitySet to query all entities that have both components and update their positions:

auto dt = 1.0f / 60.0f;
for (auto [entity, components] : manager.getEntitySet<Position, Velocity>())
{
    auto [position, velocity] = components;
    // Update the position
    position.x += velocity.x * dt;
    position.y += velocity.y * dt;
}

It is that easy!

If you want more examples, look at the examples folder.

Documentation

I have written several articles on my blog describing the design of the library. They are available here.

Otherwise, just look at the EntityManager.h file, it is simple to understand.

License

Distributed under the MIT License.

ecs's People

Contributors

pvigier avatar

Forkers

rhinewg

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.