kubo scene file schema

This commit is contained in:
Luka Jankovic 2025-07-25 14:05:17 +02:00
parent 156b962300
commit 8554b33cd6
4 changed files with 42 additions and 34 deletions

View file

@ -1,8 +0,0 @@
name: Fibonacci
data:
- [1.0, 0.5]
- [1.0, 0.5]
- [2.0, 0.5]
- [3.0, 0.5]
- [5.0, 0.5]
- [8.0, 0.5]

View file

@ -7,16 +7,20 @@ void kubo_file_parse(char *file_name) {
.log_level = CYAML_LOG_WARNING,
};
struct numbers *n;
struct kubo_file_scene *n;
cyaml_err_t err = cyaml_load_file(file_name, &config, &top_schema, (cyaml_data_t **)&n, NULL);
cyaml_err_t err = cyaml_load_file(file_name, &config, &top_schema,
(cyaml_data_t **)&n, NULL);
if (err != CYAML_OK) {
printf("cyaml err\n");
}
printf("%s:\n", n->name);
for (unsigned i = 0; i < n->data_count; i++) {
printf(" - %f:%f\n", n->data[i][0], n->data[i][1]);
for (unsigned i = 0; i < n->walls_count; i++) {
printf("wall:\n");
for (unsigned j = 0; j < n->walls[i].vertices_count; j++) {
printf("\t%f:%f\n", n->walls[i].vertices[j][0],
n->walls[i].vertices[j][1]);
}
}
err = cyaml_free(&config, &top_schema, n, 0);

View file

@ -24,40 +24,42 @@
#include <stdio.h>
typedef float kubo_file_vertex[2];
//
// struct kubo_file_wall {
// kubo_file_vertex *vertices;
// unsigned vertices_count;
// };
//
// struct kubo_file_scene {
// struct kubo_file_wall *walls;
// unsigned walls_count;
// };
struct numbers {
char *name;
kubo_file_vertex *data;
unsigned data_count;
struct kubo_file_wall {
kubo_file_vertex *vertices;
unsigned vertices_count;
};
struct kubo_file_scene {
struct kubo_file_wall *walls;
unsigned walls_count;
};
static const cyaml_schema_value_t float_entry = {
CYAML_VALUE_FLOAT(CYAML_FLAG_DEFAULT, float),
};
static const cyaml_schema_value_t data_entry = {
static const cyaml_schema_value_t vertex_entry = {
CYAML_VALUE_SEQUENCE_FIXED(CYAML_FLAG_DEFAULT, float, &float_entry, 2),
};
static const cyaml_schema_field_t top_mapping_schema[] = {
CYAML_FIELD_STRING_PTR("name", CYAML_FLAG_POINTER, struct numbers, name, 0,
CYAML_UNLIMITED),
CYAML_FIELD_SEQUENCE("data", CYAML_FLAG_POINTER, struct numbers, data,
&data_entry, 0, CYAML_UNLIMITED),
static const cyaml_schema_field_t wall_fields[] = {
CYAML_FIELD_SEQUENCE("vertices", CYAML_FLAG_POINTER, struct kubo_file_wall,
vertices, &vertex_entry, 0, CYAML_UNLIMITED),
CYAML_FIELD_END};
static const cyaml_schema_value_t wall_schema = {
CYAML_VALUE_MAPPING(CYAML_FLAG_DEFAULT, struct kubo_file_wall, wall_fields),
};
static const cyaml_schema_field_t scene_fields[] = {
CYAML_FIELD_SEQUENCE("walls", CYAML_FLAG_POINTER, struct kubo_file_scene,
walls, &wall_schema, 0, CYAML_UNLIMITED),
CYAML_FIELD_END};
static const cyaml_schema_value_t top_schema = {
CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct numbers, top_mapping_schema),
CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct kubo_file_scene,
scene_fields),
};
void kubo_file_parse(char *file_name);

10
scene.yaml Normal file
View file

@ -0,0 +1,10 @@
walls:
- vertices:
- [0.0, 1.0]
- [1.0, 2.0]
- vertices:
- [1.0, 3.0]
- [2.0, 1.0]
- vertices:
- [3.0, 5.0]
- [2.0, 1.0]