parent
b8a0d9bbd1
commit
a3eaf78fd3
@ -0,0 +1,10 @@ |
||||
[wrap-git] |
||||
url = https://github.com/SanderMertens/flecs.git |
||||
revision = v4.0.2 |
||||
depth = 1 |
||||
method = cmake |
||||
# patch_filename = |
||||
# patch_hash = |
||||
|
||||
[provide] |
||||
flecs = flecs_dep |
@ -0,0 +1,10 @@ |
||||
#include "rand.hpp" |
||||
|
||||
std::random_device RNG; |
||||
std::mt19937 GENERATOR(RNG()); |
||||
|
||||
int Random::rand_int(int from, int to) { |
||||
std::uniform_int_distribution<int> rand(from, to); |
||||
|
||||
return rand(GENERATOR); |
||||
} |
@ -0,0 +1,6 @@ |
||||
#pragma once |
||||
#include <random> |
||||
|
||||
namespace Random { |
||||
int rand_int(int from, int to); |
||||
} |
@ -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(); |
||||
} |
Loading…
Reference in new issue