ayebear / es

An easy to use, high performance, C++14 "Entity Component System" library.
MIT License
12 stars 2 forks source link

begin/end functions for es::World #4

Closed Scipi closed 9 years ago

Scipi commented 9 years ago

es::World requires begin()/end() functions in order to work properly with ranged-based for loops. Currently, code such as this one taken from the system examples gives an error in VS2015:

for (auto& ent: world){
    auto pos = ent.get<Position>();
    auto vel = ent.get<Velocity>();
    if (pos && vel){
        pos->x += vel->x * dt;
        pos->y += vel->y * dt;
    }
}
ayebear commented 9 years ago

You can do world.query() for now, but I will add this soon.

ayebear commented 9 years ago

The readme was updated to use world.query(). Ideally this would work with begin()/end(), but the way the entities are internally stored makes this tricky. It would only be worth adding if there was a performance benefit. A new issue has been added for the performance aspect of this: #7