Properly link flecs library

This commit is contained in:
2023-11-09 11:38:29 +01:00
parent dc585396c3
commit 8edcf9305c
1392 changed files with 390081 additions and 164 deletions

View File

@@ -0,0 +1,38 @@
#include <simple_module.h>
#include <stdio.h>
void PrintPosition(ecs_iter_t *it) {
Position *p = ecs_field(it, Position, 1);
for (int i = 0; i < it->count; i ++) {
printf("p = {%f, %f} (system)\n", p[i].x, p[i].y);
}
}
int main(int argc, char *argv[]) {
ecs_world_t *world = ecs_init_w_args(argc, argv);
// Import module which calls the SimpleModuleImport function
ECS_IMPORT(world, SimpleModule);
// Create system that uses component from module. Note how the component
// identifier is prefixed with the module.
ECS_SYSTEM(world, PrintPosition, EcsOnUpdate, simple.module.Position);
// Create entity with components imported from module
ecs_entity_t e = ecs_set(world, 0, Position, {10, 20});
ecs_set(world, e, Velocity, {1, 2});
// Call progress which runs imported Move system
ecs_progress(world, 0);
// Use component from module in operation
const Position *p = ecs_get(world, e, Position);
printf("p = {%f, %f} (get)\n", p->x, p->y);
return ecs_fini(world);
// Output:
// p = {11.000000, 22.000000} (system)
// p = {11.000000, 22.000000} (get)
}

View File

@@ -0,0 +1,28 @@
#include <simple_module.h>
ECS_COMPONENT_DECLARE(Position);
ECS_COMPONENT_DECLARE(Velocity);
void Move(ecs_iter_t *it) {
Position *p = ecs_field(it, Position, 1);
Velocity *v = ecs_field(it, Velocity, 2);
for (int i = 0; i < it->count; i ++) {
p[i].x += v[i].x;
p[i].y += v[i].y;
}
}
void SimpleModuleImport(ecs_world_t *world) {
// Create the module entity. The PascalCase module name is translated to a
// lower case path for the entity name, like "simple.module".
ECS_MODULE(world, SimpleModule);
// All contents of the module are created inside the module's namespace, so
// the Position component will be created as simple.module.Position
ECS_COMPONENT_DEFINE(world, Position);
ECS_COMPONENT_DEFINE(world, Velocity);
ECS_SYSTEM(world, Move, EcsOnUpdate, Position, Velocity);
}