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 BASICS_H
#define BASICS_H
/* This generated file contains includes for project dependencies */
#include "basics/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 BASICS_BAKE_CONFIG_H
#define BASICS_BAKE_CONFIG_H
/* Headers of public dependencies */
#include <flecs.h>
#endif

View File

@@ -0,0 +1,11 @@
{
"id": "basics",
"type": "application",
"value": {
"use": [
"flecs"
],
"language": "c++",
"public": false
}
}

View File

@@ -0,0 +1,65 @@
#include <basics.h>
#include <iostream>
struct Eats { };
struct Healthy { };
int main(int, char *[]) {
flecs::world ecs;
flecs::entity Apples = ecs.entity("Apples").add<Healthy>();
flecs::entity Salad = ecs.entity("Salad").add<Healthy>();
flecs::entity Burgers = ecs.entity("Burgers");
flecs::entity Pizza = ecs.entity("Pizza");
flecs::entity Chocolate = ecs.entity("Chocolate");
ecs.entity("Bob")
.add<Eats>(Apples)
.add<Eats>(Burgers)
.add<Eats>(Pizza);
ecs.entity("Alice")
.add<Eats>(Salad)
.add<Eats>(Chocolate)
.add<Eats>(Apples);
// Here we're creating a rule that in the query DSL would look like this:
// Eats($This, $Food), Healthy($Food)
//
// Rules are similar to queries, but support more advanced features. This
// example shows how the basics of how to use rules & variables.
flecs::rule<> r = ecs.rule_builder()
// Identifiers that start with _ are query variables. Query variables
// are like wildcards, but enforce that the entity substituted by the
// wildcard is the same across terms.
//
// For example, in this query it is not guaranteed that the entity
// substituted by the * for Eats is the same as for Healthy:
// (Eats, *), Healthy(*)
//
// By replacing * with _Food, both terms are constrained to use the
// same entity.
.with<Eats>("$Food")
.with<Healthy>().src("$Food")
.build();
// Lookup the index of the variable. This will let us quickly lookup its
// value while we're iterating.
int food_var = r.find_var("Food");
// Iterate the rule
r.each([&](flecs::iter& it, size_t index) {
std::cout
<< it.entity(index).name()
<< " eats " << it.get_var(food_var).name()
<< "\n";
});
// Rules need to be explicitly deleted.
r.destruct();
// Output:
// Bob eats Apples
// Alice eats Apples
// Alice eats Salad
}