15 int tex_width, tex_height;
22 struct object *objlist;
29 struct object *objects;
32 void free_object(struct object *obj);
34 struct tilemaze *load_tilemaze(const char *fname)
38 if(!(tmz = calloc(sizeof *tmz, 1))) {
44 void destroy_tilemaze(struct tilemaze *tmz)
51 struct object *o = tmz->objects;
52 tmz->objects = tmz->objects->next;
62 void update_tilemaze(struct tilemaze *tmz)
66 void draw_tilemaze(struct tilemaze *tmz)
70 struct tile *load_tileset(const char *fname, int *count)
73 struct tile *tiles = 0, *tile;
74 struct ts_node *ts = 0, *node;
78 if(!(ts = ts_load(fname))) {
79 fprintf(stderr, "load_tileset: failed to load: %s\n", fname);
82 if(strcmp(ts->name, "tileset") != 0) {
83 fprintf(stderr, "load_tileset: %s is not a tileset file\n", fname);
87 if(!(tiles = dynarr_alloc(sizeof *tiles, 0))) {
88 fprintf(stderr, "load_tileset: failed to create tiles array\n");
92 node = ts->child_list;
94 if(strcmp(node->name, "tile") != 0) {
95 fprintf(stderr, "load_tileset: skipping unexpected node %s in %s\n", node->name, fname);
100 if(!(tile = malloc(sizeof *tile))) {
101 fprintf(stderr, "load_tileset: failed to allocate tile\n");
104 if(!(tile->name = malloc(strlen(node->name) + 1))) {
105 fprintf(stderr, "load_tileset: failed to allocate tile name\n");
109 strcpy(tile->name, node->name);
112 attr = node->attr_list;
115 if(strcmp(attr->name, "scn") == 0) {
117 if(!(obj = load_objlist(attr->value.str, &last))) {
121 last->next = tile->objlist;
133 for(i=0; i<dynarr_size(tiles); i++) {
135 obj = tiles[i].objlist;
137 struct object *tmp = obj;
144 if(ts) ts_free_tree(ts);
148 void free_object(struct object *obj)
154 destroy_mesh(&obj->mesh);