summaryrefslogtreecommitdiff
path: root/src/geometry
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-07 17:52:17 -0600
committersanine <sanine.not@pm.me>2023-02-07 17:52:17 -0600
commit79f4b0d33cbb490f957d081bd7c8bc97bd4c689c (patch)
treebe04a0dd98ca341a46bd65cf400a20e1c66f3563 /src/geometry
parentf547164540f4ac7f8436fef8e981b1fef503f08c (diff)
fix parser using REJECT so that example works
Diffstat (limited to 'src/geometry')
-rw-r--r--src/geometry/geometry.c51
-rw-r--r--src/geometry/geometry.h3
2 files changed, 54 insertions, 0 deletions
diff --git a/src/geometry/geometry.c b/src/geometry/geometry.c
index 25b899b..7d2e6c2 100644
--- a/src/geometry/geometry.c
+++ b/src/geometry/geometry.c
@@ -470,3 +470,54 @@ void kai_release_geometry(struct ka_geometry_t g)
free(g.name);
kai_release_mesh(g.mesh);
}
+
+
+int kai_read_library_geometries(struct ka_library_geometries_t *dest, struct kai_tag_t *src)
+{
+ CHECK_TAG_TYPE("library_geometries");
+
+ dest->id = kai_tag_attr_to_dup(src, "id");
+ dest->name = kai_tag_attr_to_dup(src, "name");
+
+ struct kai_tag_t *child;
+ unsigned int geometry_count = 0;
+ FOR_CHILD_OF_TYPE(src, child, "geometry") { geometry_count += 1; }
+
+ dest->geometry = kai_alloc(
+ geometry_count * sizeof(struct ka_geometry_t),
+ "library_geometries geometry array"
+ );
+ if (dest->geometry == NULL) {
+ free(dest->id);
+ free(dest->name);
+ return -1;
+ }
+
+ int i=0;
+ FOR_CHILD_OF_TYPE(src, child, "geometry") {
+ int result = kai_read_geometry(dest->geometry + i, child);
+ if (result != 0) {
+ dest->geometry_count = i;
+ kai_release_library_geometries(*dest);
+ return -1;
+ }
+ i += 1;
+ }
+ dest->geometry_count = geometry_count;
+
+ return 0;
+}
+
+void kai_release_library_geometries(struct ka_library_geometries_t l)
+{
+ free(l.id);
+ free(l.name);
+
+ int i;
+ for (i=0; i<l.geometry_count; i++) {
+ kai_release_geometry(l.geometry[i]);
+ }
+ free(l.geometry);
+}
+
+
diff --git a/src/geometry/geometry.h b/src/geometry/geometry.h
index c00704f..eb0395f 100644
--- a/src/geometry/geometry.h
+++ b/src/geometry/geometry.h
@@ -32,4 +32,7 @@ void kai_release_mesh(struct ka_mesh_t m);
int kai_read_geometry(struct ka_geometry_t *dest, struct kai_tag_t *src);
void kai_release_geometry(struct ka_geometry_t m);
+int kai_read_library_geometries(struct ka_library_geometries_t *dest, struct kai_tag_t *src);
+void kai_release_library_geometries(struct ka_library_geometries_t l);
+
#endif