Properly link flecs library
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#ifndef TWO_COMPONENTS_H
|
||||
#define TWO_COMPONENTS_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "two_components/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 TWO_COMPONENTS_BAKE_CONFIG_H
|
||||
#define TWO_COMPONENTS_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "two_components",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
],
|
||||
"language": "c++",
|
||||
"public": false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <two_components.h>
|
||||
#include <iostream>
|
||||
|
||||
// An observer can match multiple components/tags. Only entities that match the
|
||||
// entire observer filter will be forwarded to the callback. For example, an
|
||||
// observer for Position,Velocity won't match an entity that only has Position.
|
||||
|
||||
struct Position {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
struct Velocity {
|
||||
double x, y;
|
||||
};
|
||||
|
||||
int main(int, char *[]) {
|
||||
flecs::world ecs;
|
||||
|
||||
// Create observer for custom event
|
||||
ecs.observer<Position, Velocity>()
|
||||
.event(flecs::OnSet)
|
||||
.each([](flecs::iter& it, size_t i, Position& p, Velocity& v) {
|
||||
std::cout << " - " << it.event().name() << ": "
|
||||
<< it.event_id().str() << ": "
|
||||
<< it.entity(i).name() << ": "
|
||||
<< "p: {" << p.x << ", " << p.y << "} "
|
||||
<< "v: {" << v.x << ", " << v.y << "}\n";
|
||||
});
|
||||
|
||||
// Create entity, set Position (emits EcsOnSet, does not yet match observer)
|
||||
flecs::entity e = ecs.entity("e")
|
||||
.set<Position>({10, 20});
|
||||
|
||||
// Set Velocity (emits EcsOnSet, matches observer)
|
||||
e.set<Velocity>({1, 2});
|
||||
|
||||
// Output
|
||||
// - OnSet: Velocity: e: p: {10, 20} v: {1, 2}
|
||||
}
|
||||
Reference in New Issue
Block a user