3 #include "server/schematic.h"
4 #include "server/server_node.h"
7 void schematic_load(List *schematic, const char *path, SchematicMapping *mappings, size_t num_mappings)
11 FILE *file = fopen(path, "r");
13 fprintf(stderr, "[warning] failed to open schematic %s\n", path);
22 // getline is POSIX 2008, so we can use it
23 while ((length = getline(&line, &siz, file)) > 0) {
29 SchematicNode *node = malloc(sizeof *node);
32 if (sscanf(line, "%d %d %d %2x%2x%2x",
33 &node->pos.x, &node->pos.z, &node->pos.y,
34 &color.x, &color.y, &color.z) != 6) {
35 fprintf(stderr, "[warning] syntax error in schematic %s in line %d: %s\n",
41 SchematicMapping *mapping = NULL;
42 for (size_t i = 0; i < num_mappings; i++)
43 if (v3s32_equals(color, mappings[i].color)) {
44 mapping = &mappings[i];
49 fprintf(stderr, "[warning] color not mapped to node in schematic %s in line %d: %02x%02x%02x\n",
50 path, count, color.x, color.y, color.z);
55 node->node = mapping->use_color
56 ? server_node_create_color(mapping->type, (v3f32) {
60 }) : server_node_create(mapping->type);
62 list_apd(schematic, node);
71 void schematic_place(List *schematic, v3s32 pos, TerrainGenStage tgs, List *changed_chunks)
73 LIST_ITERATE(schematic, list_node) {
74 SchematicNode *node = list_node->dat;
76 server_terrain_gen_node(
77 v3s32_add(pos, node->pos),
78 server_node_copy(node->node),
83 static void delete_schematic_node(SchematicNode *node)
85 server_node_delete(&node->node);
89 void schematic_delete(List *schematic)
91 list_clr(schematic, &delete_schematic_node, NULL, NULL);