diff --git a/data.yaml b/data.yaml deleted file mode 100644 index 232bbf7..0000000 --- a/data.yaml +++ /dev/null @@ -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] diff --git a/kubo_file.c b/kubo_file.c index 0612412..831a478 100644 --- a/kubo_file.c +++ b/kubo_file.c @@ -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); diff --git a/kubo_file.h b/kubo_file.h index eda042b..48e5bcc 100644 --- a/kubo_file.h +++ b/kubo_file.h @@ -24,40 +24,42 @@ #include 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); diff --git a/scene.yaml b/scene.yaml new file mode 100644 index 0000000..8959919 --- /dev/null +++ b/scene.yaml @@ -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]