Brought in FLECS to play with, tomorrow we learn it.

This commit is contained in:
Zed A. Shaw 2024-10-05 18:15:14 -04:00
parent b8a0d9bbd1
commit a3eaf78fd3
7 changed files with 76 additions and 5 deletions

39
scratchpad/flecs.cpp Normal file
View file

@ -0,0 +1,39 @@
#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();
}