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

View File

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

View File

@@ -0,0 +1,73 @@
#include <override.h>
#include <iostream>
// Overriding makes it possible for a prefab instance to obtain a private copy
// of an inherited component. To override a component the regular add operation
// is used. The overridden component will be initialized with the value of the
// inherited component.
//
// In some cases a prefab instance should always have a private copy of an
// inherited component. This can be achieved with an auto override which can be
// added to a prefab. Components with an auto override are automatically
// overridden when the prefab is instantiated.
struct Attack {
double value;
};
struct Defense {
double value;
};
struct Damage {
double value;
};
int main() {
flecs::world ecs;
// Attack and Damage are properties that can be shared across many
// spaceships. This saves memory, and speeds up prefab creation as we don't
// have to copy the values of Attack and Defense to private components.
flecs::entity SpaceShip = ecs.prefab("SpaceShip")
.set<Attack>({ 75 })
.set<Defense>({ 100 });
// Damage is a property that is private to a spaceship, so add an auto
// override for it. This ensures that each prefab instance will have a
// private copy of the component.
SpaceShip.set_override<Damage>({ 0 });
// Create a prefab instance.
flecs::entity inst = ecs.entity("my_spaceship").is_a(SpaceShip);
// The entity will now have a private copy of the Damage component, but not
// of the Attack and Defense components. We can see this when we look at the
// type of the instance:
std::cout << inst.type().str() << "\n";
// Even though Attack was not automatically overridden, we can always
// override it manually afterwards by adding it:
inst.add<Attack>();
// The Attack component now shows up in the entity type:
std::cout << inst.type().str() << "\n";
// We can get all components on the instance, regardless of whether they
// are overridden or not. Note that the overridden components (Attack and
// Damage) are initialized with the values from the prefab component:
const Attack *a = inst.get<Attack>();
const Defense *d = inst.get<Defense>();
const Damage *dmg = inst.get<Damage>();
std::cout << "attack: " << a->value << "\n";
std::cout << "defense: " << d->value << "\n";
std::cout << "damage: " << dmg->value << "\n";
// Output:
// Damage, (Identifier,Name), (IsA,SpaceShip)
// Attack, Damage, (Identifier,Name), (IsA,SpaceShip)
// attack: 75
// defense: 100
// damage: 0
}