Properly link flecs library
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#ifndef UNITS_H
|
||||
#define UNITS_H
|
||||
|
||||
/* This generated file contains includes for project dependencies */
|
||||
#include "units/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 UNITS_BAKE_CONFIG_H
|
||||
#define UNITS_BAKE_CONFIG_H
|
||||
|
||||
/* Headers of public dependencies */
|
||||
#include <flecs.h>
|
||||
|
||||
#endif
|
||||
|
||||
11
engine/libs/flecs/examples/cpp/reflection/units/project.json
Normal file
11
engine/libs/flecs/examples/cpp/reflection/units/project.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"id": "units",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
],
|
||||
"language": "c++",
|
||||
"public": false
|
||||
}
|
||||
}
|
||||
50
engine/libs/flecs/examples/cpp/reflection/units/src/main.cpp
Normal file
50
engine/libs/flecs/examples/cpp/reflection/units/src/main.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <units.h>
|
||||
#include <iostream>
|
||||
|
||||
struct WeatherStation {
|
||||
double temperature;
|
||||
double pressure;
|
||||
double precipitation;
|
||||
};
|
||||
|
||||
void print_value(const flecs::cursor& cur) {
|
||||
// Get unit entity and component
|
||||
flecs::entity u = cur.get_unit();
|
||||
const flecs::Unit *u_data = u.get<flecs::Unit>();
|
||||
|
||||
// Print value with unit symbol
|
||||
std::cout << cur.get_member() << ": " << cur.get_float()
|
||||
<< " " << u_data->symbol << "\n";
|
||||
}
|
||||
|
||||
int main(int, char *[]) {
|
||||
flecs::world ecs;
|
||||
|
||||
// Import units module.
|
||||
ecs.import<flecs::units>();
|
||||
|
||||
// Register reflection data with units. This can improve the way information
|
||||
// is visualized in tools, such as the explorer.
|
||||
ecs.component<WeatherStation>()
|
||||
.member<double, flecs::units::temperature::Celsius>("temperature")
|
||||
.member<double, flecs::units::pressure::Bar>("pressure")
|
||||
.member<double, flecs::units::length::MilliMeters>("precipitation");
|
||||
|
||||
flecs::entity e = ecs.entity().set<WeatherStation>({24, 1.2, 0.5});
|
||||
|
||||
// Use cursor API to print values with units
|
||||
WeatherStation *ptr = e.get_mut<WeatherStation>();
|
||||
flecs::cursor cur = ecs.cursor<WeatherStation>(ptr);
|
||||
cur.push();
|
||||
print_value(cur);
|
||||
cur.next();
|
||||
print_value(cur);
|
||||
cur.next();
|
||||
print_value(cur);
|
||||
cur.pop();
|
||||
|
||||
// Output:
|
||||
// temperature: 24 °C
|
||||
// pressure: 1.2 bar
|
||||
// precipitation: 0.5 mm
|
||||
}
|
||||
Reference in New Issue
Block a user