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

View File

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

View File

@@ -0,0 +1,98 @@
#include <group_iter.h>
#include <iostream>
// A group iterator iterates over a single group of a grouped query (see the
// group_by example for more details). This can be useful when an application
// may need to match different entities based on the context of the game, such
// as editor mode, day/night, inside/outside or location in the world.
//
// One example is that of an open game which is divided up into world
// cells. Even though a world may contain many entities, only the entities in
// cells close to the player need to be processed.
//
// Instead of creating a cached query per world cell, which could be expensive
// as there are more caches to keep in sync, applications can create a single
// query grouped by world cell, and use group iterators to only iterate the
// necessary cells.
// A world cell relationship with four cells
struct WorldCell {};
struct Cell_0_0 {};
struct Cell_0_1 {};
struct Cell_1_0 {};
struct Cell_1_1 {};
// Npc tags
struct Npc {};
struct Merchant {};
struct Soldier {};
struct Beggar {};
struct Mage {};
int main() {
flecs::world ecs;
// Create npc's in world cell 0_0
ecs.entity().add<WorldCell, Cell_0_0>()
.add<Merchant>()
.add<Npc>();
ecs.entity().add<WorldCell, Cell_0_0>()
.add<Merchant>()
.add<Npc>();
// Create npc's in world cell 0_1
ecs.entity().add<WorldCell, Cell_0_1>()
.add<Beggar>()
.add<Npc>();
ecs.entity().add<WorldCell, Cell_0_1>()
.add<Soldier>()
.add<Npc>();
// Create npc's in world cell 1_0
ecs.entity().add<WorldCell, Cell_1_0>()
.add<Mage>()
.add<Npc>();
ecs.entity().add<WorldCell, Cell_1_0>()
.add<Beggar>()
.add<Npc>();
// Create npc's in world cell 1_1
ecs.entity().add<WorldCell, Cell_1_1>()
.add<Soldier>()
.add<Npc>();
flecs::query<Npc> q = ecs.query_builder<Npc>()
.group_by<WorldCell>()
.build();
// Iterate all tables
std::cout << "All tables:\n";
q.iter([&](flecs::iter& it) {
flecs::entity group = ecs.entity(it.group_id());
std::cout << " - group " << group.path() << ": table ["
<< it.table().str() << "]\n";
});
std::cout << "\n";
// Only iterate entities in cell 1_0
std::cout << "Tables for cell 1_0:\n";
q.iter().set_group<Cell_1_0>().iter([&](flecs::iter& it) {
flecs::entity group = ecs.entity(it.group_id());
std::cout << " - group " << group.path() << ": table ["
<< it.table().str() << "]\n";
});
// Output:
// All tables:
// - group ::Cell_0_0: table [Merchant, Npc, (WorldCell,Cell_0_0)]
// - group ::Cell_0_1: table [Npc, Beggar, (WorldCell,Cell_0_1)]
// - group ::Cell_0_1: table [Npc, Soldier, (WorldCell,Cell_0_1)]
// - group ::Cell_1_0: table [Npc, Mage, (WorldCell,Cell_1_0)]
// - group ::Cell_1_0: table [Npc, Beggar, (WorldCell,Cell_1_0)]
// - group ::Cell_1_1: table [Npc, Soldier, (WorldCell,Cell_1_1)]
//
// Tables for cell 1_0:
// - group ::Cell_1_0: table [Npc, Mage, (WorldCell,Cell_1_0)]
// - group ::Cell_1_0: table [Npc, Beggar, (WorldCell,Cell_1_0)]
}