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 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,12 @@
{
"id": "basics",
"type": "application",
"value": {
"author": "Jane Doe",
"description": "A simple hello world flecs application",
"use": [
"flecs"
],
"language": "c++"
}
}

View File

@@ -0,0 +1,70 @@
#include <basics.h>
#include <iostream>
struct Position {
double x, y;
};
struct Velocity {
double x, y;
};
int main(int, char *[]) {
flecs::world ecs;
// Create a query for Position, Velocity. Queries are the fastest way to
// iterate entities as they cache results.
flecs::query<Position, const Velocity> q = ecs.query<Position, const Velocity>();
// Create a few test entities for a Position, Velocity query
ecs.entity("e1")
.set<Position>({10, 20})
.set<Velocity>({1, 2});
ecs.entity("e2")
.set<Position>({10, 20})
.set<Velocity>({3, 4});
// This entity will not match as it does not have Position, Velocity
ecs.entity("e3")
.set<Position>({10, 20});
// The next lines show the different ways in which a query can be iterated.
// Note how the 'const' qualifier matches the query template arguments.
// The each() function iterates each entity individually and accepts an
// entity argument plus arguments for each query component:
q.each([](flecs::entity e, Position& p, const Velocity& v) {
p.x += v.x;
p.y += v.y;
std::cout << e.name() << ": {" << p.x << ", " << p.y << "}\n";
});
// You can omit the flecs::entity argument if it's not needed:
q.each([](Position& p, const Velocity& v) {
p.x += v.x;
p.y += v.y;
std::cout << "{" << p.x << ", " << p.y << "}\n";
});
// Each also accepts flecs::iter + index (for the iterated entity) arguemnts
// currently being iterated. A flecs::iter has lots of information on what
// is being iterated, which is demonstrated in the "iter" example.
q.each([](flecs::iter& it, size_t i, Position& p, const Velocity& v) {
p.x += v.x;
p.y += v.y;
std::cout << it.entity(i).name() << ": {" << p.x << ", " << p.y << "}\n";
});
// Iter is a bit more verbose, but allows for more control over how entities
// are iterated as it provides multiple entities in the same callback.
q.iter([](flecs::iter& it, Position *p, const Velocity *v) {
for (auto i : it) {
p[i].x += v[i].x;
p[i].y += v[i].y;
std::cout << it.entity(i).name() <<
": {" << p[i].x << ", " << p[i].y << "}\n";
}
});
}