Properly link flecs library
This commit is contained in:
5
engine/libs/flecs/examples/c/reflection/units/.gitignore
vendored
Normal file
5
engine/libs/flecs/examples/c/reflection/units/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.bake_cache
|
||||
.DS_Store
|
||||
.vscode
|
||||
gcov
|
||||
bin
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"id": "units",
|
||||
"type": "application",
|
||||
"value": {
|
||||
"use": [
|
||||
"flecs"
|
||||
]
|
||||
}
|
||||
}
|
||||
71
engine/libs/flecs/examples/c/reflection/units/src/main.c
Normal file
71
engine/libs/flecs/examples/c/reflection/units/src/main.c
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <units.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct {
|
||||
double temperature;
|
||||
double pressure;
|
||||
double precipitation;
|
||||
} WeatherStation;
|
||||
|
||||
void print_value(ecs_world_t *world, const ecs_meta_cursor_t *cur) {
|
||||
// Get unit entity and component
|
||||
ecs_entity_t u = ecs_meta_get_unit(cur);
|
||||
const EcsUnit *u_data = ecs_get(world, u, EcsUnit);
|
||||
|
||||
// Print value with unit symbol
|
||||
printf("%s: %.1f %s\n", ecs_meta_get_member(cur), ecs_meta_get_float(cur),
|
||||
u_data->symbol);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
ecs_world_t *ecs = ecs_init_w_args(argc, argv);
|
||||
|
||||
// Import units module.
|
||||
ECS_IMPORT(ecs, FlecsUnits);
|
||||
|
||||
ECS_COMPONENT(ecs, WeatherStation);
|
||||
|
||||
// Register reflection data with units. This can improve the way information
|
||||
// is visualized in tools, such as the explorer.
|
||||
ecs_struct(ecs, {
|
||||
.entity = ecs_id(WeatherStation),
|
||||
.members = {
|
||||
{
|
||||
.name = "temperature",
|
||||
.type = ecs_id(ecs_f64_t),
|
||||
.unit = EcsCelsius
|
||||
},
|
||||
{
|
||||
.name = "pressure",
|
||||
.type = ecs_id(ecs_f64_t),
|
||||
.unit = EcsBar
|
||||
},
|
||||
{
|
||||
.name = "precipitation",
|
||||
.type = ecs_id(ecs_f64_t),
|
||||
.unit = EcsMilliMeters
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
ecs_entity_t e = ecs_set(ecs, 0, WeatherStation, {24, 1.2, 0.5});
|
||||
|
||||
// Use cursor API to print values with units
|
||||
WeatherStation *ptr = ecs_get_mut(ecs, e, WeatherStation);
|
||||
ecs_meta_cursor_t cur = ecs_meta_cursor(ecs, ecs_id(WeatherStation), ptr);
|
||||
|
||||
ecs_meta_push(&cur);
|
||||
print_value(ecs, &cur);
|
||||
ecs_meta_next(&cur);
|
||||
print_value(ecs, &cur);
|
||||
ecs_meta_next(&cur);
|
||||
print_value(ecs, &cur);
|
||||
ecs_meta_pop(&cur);
|
||||
|
||||
return ecs_fini(ecs);
|
||||
|
||||
// Output:
|
||||
// temperature: 24.0 °C
|
||||
// pressure: 1.2 bar
|
||||
// precipitation: 0.5 mm
|
||||
}
|
||||
Reference in New Issue
Block a user