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,16 @@
#ifndef MONITOR_H
#define MONITOR_H
/* This generated file contains includes for project dependencies */
#include "monitor/bake_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -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 MONITOR_BAKE_CONFIG_H
#define MONITOR_BAKE_CONFIG_H
/* Headers of public dependencies */
#include <flecs.h>
#endif

View File

@@ -0,0 +1,10 @@
{
"id": "monitor",
"type": "application",
"value": {
"use": [
"flecs"
],
"public": false
}
}

View File

@@ -0,0 +1,67 @@
#include <monitor.h>
#include <stdio.h>
// A monitor observer triggers when an entity starts/stop matching the observer
// filter. The observer communicates whether an entity is "entering/leaving" the
// monitor by setting ecs_iter_t::event to EcsOnAdd (for entering) or
// EcsOnRemove (for leaving).
//
// To specify that an observer is a monitor observer, the EcsMonitor tag must be
// provided as event. No additional event kinds should be provided for a monitor
// observer.
typedef struct {
double x, y;
} Position, Velocity;
void Observer(ecs_iter_t *it) {
ecs_world_t *ecs = it->world;
ecs_entity_t event = it->event;
ecs_entity_t event_id = it->event_id;
for (int i = 0; i < it->count; i ++) {
ecs_entity_t e = it->entities[i];
if (event == EcsOnAdd) {
printf(" - Enter: %s: %s\n",
ecs_get_name(ecs, event_id),
ecs_get_name(ecs, e));
} else if (event == EcsOnRemove) {
printf(" - Leave: %s: %s\n",
ecs_get_name(ecs, event_id),
ecs_get_name(ecs, e));
}
}
}
int main(int argc, char *argv[]) {
ecs_world_t *ecs = ecs_init_w_args(argc, argv);
ECS_COMPONENT(ecs, Position);
ECS_COMPONENT(ecs, Velocity);
ecs_observer(ecs, {
.filter = { .terms = {{ .id = ecs_id(Position) }, { .id = ecs_id(Velocity) }}},
.events = { EcsMonitor }, // Monitor entities entering/leaving the query
.callback = Observer,
});
// Create entity
ecs_entity_t e = ecs_new_entity(ecs, "e");
// This does not yet trigger the monitor, as the entity does not yet match.
ecs_set(ecs, e, Position, {10, 20});
// This triggers the monitor with EcsOnAdd, as the entity now matches.
ecs_set(ecs, e, Velocity, {1, 2});
// This triggers the monitor with EcsOnRemove, as the entity no longer matches.
ecs_remove(ecs, e, Position);
ecs_fini(ecs);
// Output
// - Enter: Velocity: e
// - Leave: Position: e
}