The next little game in the series where I make a fancy rogue game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
roguish/scratchpad/flecs.cpp

40 lines
978 B

#include <flecs.h>
#include <iostream>
struct Position {
double x, y;
};
struct Velocity {
double x, y;
};
int main() {
flecs::world ecs;
// Create a system for Position, Velocity. Systems are like queries (see
// queries) with a function that can be ran or scheduled (see pipeline).
flecs::system s = ecs.system<Position, const Velocity>()
.each([](flecs::entity e, Position& p, const Velocity& v) {
p.x += v.x;
p.y += v.y;
std::cerr << e.name() << ": {" << p.x << ", " << p.y << "}\n";
});
// Create a few test entities for a Position, Velocity query
ecs.entity("e1")
.set<Position>({10, 20})
.set<Velocity>({1, 2});
ecs.entity("e2")
.set<Position>({10, 20})
.set<Velocity>({3, 4});
// This entity will not match as it does not have Position, Velocity
ecs.entity("e3")
.set<Position>({10, 20});
// Run the system
s.run();
}