14 int tex_width, tex_height;
21 struct object *objlist;
28 struct object *objects;
31 void free_object(struct object *obj);
33 struct tilemaze *load_tilemaze(const char *fname)
37 if(!(tmz = calloc(sizeof *tmz, 1))) {
43 void destroy_tilemaze(struct tilemaze *tmz)
50 struct object *o = tmz->objects;
51 tmz->objects = tmz->objects->next;
61 void update_tilemaze(struct tilemaze *tmz)
65 void draw_tilemaze(struct tilemaze *tmz)
69 struct tile *load_tileset(const char *fname, int *count)
72 struct tile *tiles = 0, *tile;
73 struct ts_node *ts = 0, *node;
77 if(!(ts = ts_load(fname))) {
78 fprintf(stderr, "load_tileset: failed to load: %s\n", fname);
81 if(strcmp(ts->name, "tileset") != 0) {
82 fprintf(stderr, "load_tileset: %s is not a tileset file\n", fname);
86 if(!(tiles = dynarr_alloc(sizeof *tiles, 0))) {
87 fprintf(stderr, "load_tileset: failed to create tiles array\n");
91 node = ts->child_list;
93 if(strcmp(node->name, "tile") != 0) {
94 fprintf(stderr, "load_tileset: skipping unexpected node %s in %s\n", node->name, fname);
99 if(!(tile = malloc(sizeof *tile))) {
100 fprintf(stderr, "load_tileset: failed to allocate tile\n");
103 if(!(tile->name = malloc(strlen(node->name) + 1))) {
104 fprintf(stderr, "load_tileset: failed to allocate tile name\n");
108 strcpy(tile->name, node->name);
111 attr = node->attr_list;
114 if(strcmp(attr->name, "scn") == 0) {
116 if(!(obj = load_objlist(attr->value.str, &last))) {
120 last->next = tile->objlist;
132 for(i=0; i<dynarr_size(tiles); i++) {
134 obj = tiles[i].objlist;
136 struct object *tmp = obj;
143 if(ts) ts_free_tree(ts);
147 void free_object(struct object *obj)
153 destroy_mesh(&obj->mesh);