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,5 @@
.bake_cache
.DS_Store
.vscode
gcov
bin

View File

@@ -0,0 +1,16 @@
#ifndef FACTS_H
#define FACTS_H
/* This generated file contains includes for project dependencies */
#include "facts/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 FACTS_BAKE_CONFIG_H
#define FACTS_BAKE_CONFIG_H
/* Headers of public dependencies */
#include <flecs.h>
#endif

View File

@@ -0,0 +1,10 @@
{
"id": "facts",
"type": "application",
"value": {
"use": [
"flecs"
],
"language": "c++"
}
}

View File

@@ -0,0 +1,90 @@
#include <facts.h>
#include <iostream>
// This example shows how to use rules for testing facts. A fact is a query that
// has no variable elements. Consider a regular ECS query like this:
// Position, Velocity
//
// When written out in full, this query looks like:
// Position($This), Velocity($This)
//
// "This" is a (builtin) query variable that is unknown before we evaluate the
// query. Therefore this query does not test a fact, we can't know which values
// This will assume.
//
// An example of a fact-checking query is:
// IsA(Cat, Animal)
//
// This is a fact: the query has no elements that are unknown before evaluating
// the query. A rule that checks a fact does not return entities, but will
// instead return the reasons why a fact is true (if it is true).
struct Likes { };
int main(int, char *[]) {
flecs::world ecs;
flecs::entity bob = ecs.entity("Bob");
flecs::entity alice = ecs.entity("Alice");
flecs::entity jane = ecs.entity("Jane");
flecs::entity john = ecs.entity("John");
bob.add<Likes>(alice);
alice.add<Likes>(bob);
jane.add<Likes>(john);
john.add<Likes>(jane);
bob.add<Likes>(john); // bit of drama
// Create a rule that checks if two entities like each other. By itself this
// rule is not a fact, but we can use it to check facts by populating both
// of its variables.
//
// The equivalent query in the DSL is:
// Likes($X, $Y), Likes($Y, $X)
//
// Instead of using variables we could have created a rule that referred the
// entities directly, but then we would have to create a rule for each
// fact, vs reusing a single rule for multiple facts.
flecs::rule<> friends = ecs.rule_builder()
.with<Likes>("$Y").src("$X")
.with<Likes>("$X").src("$Y")
.build();
int x_var = friends.find_var("X");
int y_var = friends.find_var("Y");
// Check a few facts
std::cout << "Are Bob and Alice friends? " <<
(friends.iter()
.set_var(x_var, bob)
.set_var(y_var, alice)
.is_true() ? "Yes\n" : "No\n");
std::cout << "Are Bob and John friends? " <<
(friends.iter()
.set_var(x_var, bob)
.set_var(y_var, john)
.is_true() ? "Yes\n" : "No\n");
std::cout << "Are Jane and John friends? " <<
(friends.iter()
.set_var(x_var, jane)
.set_var(y_var, john)
.is_true() ? "Yes\n" : "No\n");
// It doesn't matter who we assign to X or Y. After the variables are
// substituted, either yields a fact that is true.
std::cout << "Are John and Jane friends? " <<
(friends.iter()
.set_var(x_var, john)
.set_var(y_var, jane)
.is_true() ? "Yes\n" : "No\n");
// Output
// Are Bob and Alice friends? Yes
// Are Bob and John friends? No
// Are Jane and John friends? Yes
// Are John and Jane friends? Yes
}