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 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,11 @@
{
"id": "basics",
"type": "application",
"value": {
"use": [
"flecs"
],
"language": "c++",
"public": false
}
}

View File

@@ -0,0 +1,56 @@
#include <basics.h>
#include <iostream>
// Prefabs are entities that can be used as templates for other entities. They
// are created with a builtin Prefab tag, which by default excludes them from
// queries and systems.
//
// Prefab instances are entities that have an IsA relationship to the prefab.
// The IsA relationship causes instances to inherit the components from the
// prefab. By default all instances for a prefab share its components.
//
// Inherited components save memory as they only need to be stored once for all
// prefab instances. They also speed up the creation of prefabs, as inherited
// components don't need to be copied to the instances.
//
// To get a private copy of a component, an instance can add it which is called
// an override. Overrides can be manual (by using add) or automatic (see the
// auto_override example).
//
// If a prefab has children, adding the IsA relationship instantiates the prefab
// children for the instance (see hierarchy example).
struct Defense {
double value;
};
int main() {
flecs::world ecs;
// Create a SpaceShip prefab with a Defense component.
flecs::entity SpaceShip = ecs.prefab("SpaceShip")
.set<Defense>({ 50 });
// Create a prefab instance
flecs::entity inst = ecs.entity("my_spaceship").is_a(SpaceShip);
// Because of the IsA relationship, the instance now shares the Defense
// component with the prefab, and can be retrieved as a regular component:
const Defense *d_inst = inst.get<Defense>();
std::cout << "defense: " << d_inst->value << "\n";
// Because the component is shared, changing the value on the prefab will
// also change the value for the instance:
SpaceShip.set<Defense>({ 100 });
std::cout << "defense after set: " << d_inst->value << "\n";
// Prefab components can be iterated like regular components:
ecs.each([](flecs::entity e, Defense& d) {
std::cout << e.path() << ": " << d.value << "\n";
});
// Output:
// defense: 50
// defense after set: 100
// ::my_spaceship: 100
}