Properly link flecs library
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include <simple_module.h>
|
||||
#include <iostream>
|
||||
|
||||
int main(int, char *[]) {
|
||||
flecs::world ecs;
|
||||
|
||||
ecs.import<simple::module>();
|
||||
|
||||
// Create system that uses component from module
|
||||
ecs.system<const simple::Position>("PrintPosition")
|
||||
.each([](const simple::Position& p) {
|
||||
std::cout << "p = {" << p.x << ", " << p.y << "} (system)\n";
|
||||
});
|
||||
|
||||
// Create entity with imported components
|
||||
flecs::entity e = ecs.entity()
|
||||
.set<simple::Position>({10, 20})
|
||||
.set<simple::Velocity>({1, 1});
|
||||
|
||||
// Call progress which runs imported Move system
|
||||
ecs.progress();
|
||||
|
||||
// Use component from module in operation
|
||||
e.get([](const simple::Position& p) {
|
||||
std::cout << "p = {" << p.x << ", " << p.y << "} (get)\n";
|
||||
});
|
||||
|
||||
// Output:
|
||||
// p = {11.000000, 22.000000} (system)
|
||||
// p = {11.000000, 22.000000} (get)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#include <simple_module.h>
|
||||
|
||||
namespace simple {
|
||||
|
||||
module::module(flecs::world& ecs) {
|
||||
// Register module with world. The module entity will be created with the
|
||||
// same hierarchy as the C++ namespaces (e.g. simple.module)
|
||||
ecs.module<module>();
|
||||
|
||||
// All contents of the module are created inside the module's namespace, so
|
||||
// the Position component will be created as simple.module.Position
|
||||
|
||||
// Component registration is optional, however by registering components
|
||||
// inside the module constructor, they will be created inside the scope
|
||||
// of the module.
|
||||
ecs.component<Position>();
|
||||
ecs.component<Velocity>();
|
||||
|
||||
ecs.system<Position, const Velocity>("Move")
|
||||
.each([](Position& p, const Velocity& v) {
|
||||
p.x += v.x;
|
||||
p.y += v.y;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user