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

View File

@@ -0,0 +1,12 @@
{
"id": "hierarchy",
"type": "application",
"value": {
"author": "Jane Doe",
"description": "A simple hello world flecs application",
"use": [
"flecs"
],
"language": "c++"
}
}

View File

@@ -0,0 +1,65 @@
#include <hierarchy.h>
#include <iostream>
struct Position {
double x, y;
};
struct Star { };
struct Planet { };
struct Moon { };
void iterate_tree(flecs::entity e, Position p_parent = {0, 0}) {
// Print hierarchical name of entity & the entity type
std::cout << e.path() << " [" << e.type().str() << "]\n";
// Get entity position
const Position *p = e.get<Position>();
// Calculate actual position
Position p_actual = {p->x + p_parent.x, p->y + p_parent.y};
std::cout << "{" << p_actual.x << ", " << p_actual.y << "}\n\n";
// Iterate children recursively
e.children([&](flecs::entity child) {
iterate_tree(child, p_actual);
});
}
int main(int, char *[]) {
flecs::world ecs;
// Create a simple hierarchy.
// Hierarchies use ECS relationships and the builtin flecs::ChildOf relationship to
// create entities as children of other entities.
flecs::entity sun = ecs.entity("Sun")
.add<Star>()
.set<Position>({1, 1});
ecs.entity("Mercury")
.child_of(sun) // Shortcut for add(flecs::ChildOf, sun)
.add<Planet>()
.set<Position>({1, 1});
ecs.entity("Venus")
.child_of(sun)
.add<Planet>()
.set<Position>({2, 2});
flecs::entity earth = ecs.entity("Earth")
.child_of(sun)
.add<Planet>()
.set<Position>({3, 3});
flecs::entity moon = ecs.entity("Moon")
.child_of(earth)
.add<Moon>()
.set<Position>({0.1, 0.1});
// Is the Moon a child of Earth?
std::cout << "Child of Earth? " << moon.has(flecs::ChildOf, earth) << "\n\n";
// Do a depth-first walk of the tree
iterate_tree(sun);
}