summaryrefslogtreecommitdiff
path: root/src/material
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-02-11 19:46:23 -0600
committersanine <sanine.not@pm.me>2023-02-11 19:46:23 -0600
commit6722ef01e34f75bde72ba29e3279c0d1df030593 (patch)
tree1cb389a5af3c0aa4709def8a76c0628342c8aa7c /src/material
parent3b740d521a685fdc4f85d100447ff6d88c0b1d28 (diff)
add materials and images processingyacc-xml
Diffstat (limited to 'src/material')
-rw-r--r--src/material/CMakeLists.txt3
-rw-r--r--src/material/material.c77
-rw-r--r--src/material/material.h16
3 files changed, 96 insertions, 0 deletions
diff --git a/src/material/CMakeLists.txt b/src/material/CMakeLists.txt
new file mode 100644
index 0000000..b5941da
--- /dev/null
+++ b/src/material/CMakeLists.txt
@@ -0,0 +1,3 @@
+project(kalmia)
+
+target_sources(kalmia PUBLIC material.c)
diff --git a/src/material/material.c b/src/material/material.c
new file mode 100644
index 0000000..65e13d2
--- /dev/null
+++ b/src/material/material.c
@@ -0,0 +1,77 @@
+#include <kalmia.h>
+#include "util/util.h"
+#include "xml/xml.h"
+
+
+int kai_read_instance_effect(struct ka_instance_effect_t *dest, struct kai_tag_t *src)
+{
+ KAI_CHECK_TAG_TYPE("instance_effect");
+
+ char *url = kai_tag_attr_to_dup(src, "url");
+ if (url == NULL) { return -1; }
+
+ dest->sid = kai_tag_attr_to_dup(src, "sid");
+ dest->name = kai_tag_attr_to_dup(src, "name");
+ dest->url = url;
+
+ return 0;
+}
+
+void kai_release_instance_effect(struct ka_instance_effect_t i)
+{
+ free(i.sid);
+ free(i.name);
+ free(i.url);
+}
+
+
+int kai_read_material(struct ka_material_t *dest, struct kai_tag_t *src)
+{
+ KAI_CHECK_TAG_TYPE("material");
+
+ struct kai_tag_t *child = kai_tag_get_first_child_with_type(src, "instance_effect");
+ if (child == NULL) { return -1; }
+ int result = kai_read_instance_effect(&(dest->instance_effect), child);
+ if (result != 0) { return -1; }
+
+ dest->id = kai_tag_attr_to_dup(src, "id");
+ dest->name = kai_tag_attr_to_dup(src, "name");
+
+ return 0;
+}
+
+void kai_release_material(struct ka_material_t m)
+{
+ free(m.id);
+ free(m.name);
+ kai_release_instance_effect(m.instance_effect);
+}
+
+
+int kai_read_library_materials(struct ka_library_materials_t *dest, struct kai_tag_t *src)
+{
+ int result;
+ KAI_FILL_ARRAY_FROM_TAGS(
+ result,
+ dest->material, dest->material_count, struct ka_material_t,
+ src, "material",
+ kai_read_material, kai_release_material
+ );
+ if (result != 0) { return -1; }
+
+ dest->id = kai_tag_attr_to_dup(src, "id");
+ dest->name = kai_tag_attr_to_dup(src, "name");
+
+ return 0;
+}
+
+void kai_release_library_materials(struct ka_library_materials_t l)
+{
+ free(l.id);
+ free(l.name);
+ int i;
+ for (i=0; i<l.material_count; i++) {
+ kai_release_material(l.material[i]);
+ }
+ free(l.material);
+}
diff --git a/src/material/material.h b/src/material/material.h
new file mode 100644
index 0000000..f69f00b
--- /dev/null
+++ b/src/material/material.h
@@ -0,0 +1,16 @@
+#ifndef KALMIA_MATERIAL_H
+#define KALMIA_MATERIAL_H
+
+#include <kalmia.h>
+#include "xml/xml.h"
+
+int kai_read_instance_effect(struct ka_instance_effect_t *dest, struct kai_tag_t *src);
+void kai_release_instance_effect(struct ka_instance_effect_t i);
+
+int kai_read_material(struct ka_material_t *dest, struct kai_tag_t *src);
+void kai_release_material(struct ka_material_t m);
+
+int kai_read_library_materials(struct ka_library_materials_t *dest, struct kai_tag_t *src);
+void kai_release_library_materials(struct ka_library_materials_t l);
+
+#endif