Properly link flecs library
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#ifndef SIMPLE_MODULE_H
|
||||
#define SIMPLE_MODULE_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "simple_module/bake_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
namespace simple {
|
||||
|
||||
struct Position {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
struct Velocity {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
struct module {
|
||||
module(flecs::world& world); // Ctor that loads the module
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
)
|
||||
(.)
|
||||
.|.
|
||||
| |
|
||||
_.--| |--._
|
||||
.-'; ;`-'& ; `&.
|
||||
\ & ; & &_/
|
||||
|"""---...---"""|
|
||||
\ | | | | | | | /
|
||||
`---.|.|.|.---'
|
||||
|
||||
* This file is generated by bake.lang.c for your convenience. Headers of
|
||||
* dependencies will automatically show up in this file. Include bake_config.h
|
||||
* in your main project file. Do not edit! */
|
||||
|
||||
#ifndef SIMPLE_MODULE_BAKE_CONFIG_H
|
||||
#define SIMPLE_MODULE_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "simple_module",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
],
|
||||
"language": "c++",
|
||||
"public": false
|
||||
}
|
||||
}
|
||||
@@ -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