Properly link flecs library
This commit is contained in:
16
engine/libs/flecs/examples/cpp/rules/basics/include/basics.h
Normal file
16
engine/libs/flecs/examples/cpp/rules/basics/include/basics.h
Normal 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
|
||||
|
||||
@@ -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
|
||||
|
||||
11
engine/libs/flecs/examples/cpp/rules/basics/project.json
Normal file
11
engine/libs/flecs/examples/cpp/rules/basics/project.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "basics",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
],
|
||||
"language": "c++",
|
||||
"public": false
|
||||
}
|
||||
}
|
||||
65
engine/libs/flecs/examples/cpp/rules/basics/src/main.cpp
Normal file
65
engine/libs/flecs/examples/cpp/rules/basics/src/main.cpp
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user