Properly link flecs library
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#ifndef PROPAGATE_H
|
||||
#define PROPAGATE_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "propagate/bake_config.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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 PROPAGATE_BAKE_CONFIG_H
|
||||
#define PROPAGATE_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "propagate",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
],
|
||||
"language": "c++",
|
||||
"public": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#include <propagate.h>
|
||||
#include <iostream>
|
||||
|
||||
// Events are propagated along relationship edges. This means that observers can
|
||||
// listen for events from a parent or prefab, like triggering when a component
|
||||
// inherited from a prefab was set.
|
||||
//
|
||||
// Event propagation happens automatically when an observer contains a filter
|
||||
// with the EcsUp flag set (indicating upwards traversal). Observers use the
|
||||
// same matching logic as queries: if a query with upwards traversal matches an
|
||||
// entity, so will an observer.
|
||||
//
|
||||
// Events are only propagated along traversable relationship edges.
|
||||
|
||||
struct Position {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
int main(int, char *[]) {
|
||||
flecs::world ecs;
|
||||
|
||||
// Create observer that listens for events from both self and parent
|
||||
ecs.observer<Position, Position>()
|
||||
.term_at(2).parent() // select 2nd Position from parent
|
||||
.event(flecs::OnSet)
|
||||
.each([](flecs::iter& it, size_t i, Position& p_self, Position& p_parent) {
|
||||
std::cout << " - " << it.event().name() << ": "
|
||||
<< it.event_id().str() << ": "
|
||||
<< it.entity(i).name() << ": "
|
||||
<< "self: {" << p_self.x << ", " << p_self.y << "}, "
|
||||
<< "parent: {" << p_parent.x << ", " << p_parent.y << "}\n";
|
||||
});
|
||||
|
||||
// Create entity and parent
|
||||
flecs::entity p = ecs.entity("p");
|
||||
flecs::entity e = ecs.entity("e").child_of(p);
|
||||
|
||||
// Set Position on entity. This doesn't trigger the observer yet, since the
|
||||
// parent doesn't have Position yet.
|
||||
e.set<Position>({10, 20});
|
||||
|
||||
// Set Position on parent. This event will be propagated and trigger the
|
||||
// observer, as the observer query now matches.
|
||||
p.set<Position>({1, 2});
|
||||
|
||||
// Output
|
||||
// - OnSet: Position: e: self: {10, 20}, parent: {1, 2}
|
||||
}
|
||||
Reference in New Issue
Block a user