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

View File

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

View File

@@ -0,0 +1,58 @@
#include <component_inheritance.h>
#include <iostream>
// This example shows how rules can be used to match simple inheritance trees.
struct Unit { };
struct CombatUnit : Unit { };
struct MeleeUnit : CombatUnit { };
struct RangedUnit : CombatUnit { };
struct Warrior : MeleeUnit { };
struct Wizard : RangedUnit { };
struct Marksman : RangedUnit { };
struct Builder : Unit { };
int main(int, char *[]) {
flecs::world ecs;
// Make the ECS aware of the inheritance relationships. Note that IsA
// relationship used here is the same as in the prefab example.
ecs.component<CombatUnit>().is_a<Unit>();
ecs.component<MeleeUnit>().is_a<CombatUnit>();
ecs.component<RangedUnit>().is_a<CombatUnit>();
ecs.component<Warrior>().is_a<MeleeUnit>();
ecs.component<Wizard>().is_a<RangedUnit>();
ecs.component<Marksman>().is_a<RangedUnit>();
ecs.component<Builder>().is_a<Unit>();
// Create a few units
ecs.entity("warrior_1").add<Warrior>();
ecs.entity("warrior_2").add<Warrior>();
ecs.entity("marksman_1").add<Marksman>();
ecs.entity("marksman_2").add<Marksman>();
ecs.entity("wizard_1").add<Wizard>();
ecs.entity("wizard_2").add<Wizard>();
ecs.entity("builder_1").add<Builder>();
ecs.entity("builder_2").add<Builder>();
// Create a rule to find all ranged units
flecs::rule<RangedUnit> r = ecs.rule<RangedUnit>();
// Iterate the rule
r.each([](flecs::entity e, RangedUnit) {
std::cout << "Unit " << e.name() << " found\n";
});
r.destruct();
// Output:
// Unit wizard_1 found
// Unit wizard_2 found
// Unit marksman_1 found
// Unit marksman_2 found
}