runs with wrong geometry
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 25 Sep 2021 07:16:15 +0000 (10:16 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sat, 25 Sep 2021 07:16:15 +0000 (10:16 +0300)
src/level.c
src/tileset.c

index 6867e64..6e65785 100644 (file)
@@ -40,6 +40,7 @@ int load_level(struct level *lvl, const char *fname)
        struct cell *cell;
        float *vecptr;
        const char *str;
+       char *tset_path;
 
        if(!(ts = ts_load(fname))) {
                fprintf(stderr, "failed to load level: %s\n", fname);
@@ -63,9 +64,7 @@ int load_level(struct level *lvl, const char *fname)
 
        lvl->fname = strdup(fname);
        if((lvl->dirname = malloc(strlen(fname) + 1))) {
-#ifndef LEVEL_EDITOR
                path_dir(lvl->fname, lvl->dirname);
-#endif
        }
 
        lvl->cell_size = ts_get_attr_num(ts, "cellsize", DEF_CELL_SIZE);
@@ -76,7 +75,9 @@ int load_level(struct level *lvl, const char *fname)
        }
 
        if((str = ts_get_attr_str(ts, "tileset", 0))) {
-               lvl->tset = get_tileset(str);
+               tset_path = alloca(strlen(str) + strlen(lvl->dirname) + 2);
+               combine_path(lvl->dirname, str, tset_path);
+               lvl->tset = get_tileset(tset_path);
        }
 
        iter = ts->child_list;
@@ -115,8 +116,9 @@ int load_level(struct level *lvl, const char *fname)
                                tiletype = detect_cell_tile(lvl, j, i, &cell->tilerot);
                        }
 
-                       cell->tile = get_tile(lvl->tset, tiletype);
-
+                       if(lvl->tset) {
+                               cell->tile = get_tile(lvl->tset, tiletype);
+                       }
                        cell++;
                }
        }
index 240b17f..7be9c15 100644 (file)
@@ -14,7 +14,7 @@ static struct tileset *tset_list;
 int load_tileset(struct tileset *tset, const char *fname)
 {
        struct ts_node *ts, *node, *iter;
-       const char *str;
+       const char *str, *prefix;
        char *path;
        struct mesh *mesh;
        struct tile *tile;
@@ -37,7 +37,7 @@ int load_tileset(struct tileset *tset, const char *fname)
                return -1;
        }
        path = alloca(strlen(fname) + strlen(str) + 2);
-       path_dir(str, path);
+       path_dir(fname, path);
        combine_path(path, str, path);
 
        if(load_scenefile(&tset->scn, path) == -1) {
@@ -50,16 +50,20 @@ int load_tileset(struct tileset *tset, const char *fname)
        tset->name = strdup(ts_get_attr_str(ts, "name", fname));
 
        iter = ts->child_list;
-       while(node) {
+       while(iter) {
                node = iter;
                iter = iter->next;
                if(strcmp(node->name, "tile") == 0) {
-                       if(!(str = ts_get_attr_str(node, "prefix", 0))) {
+                       if(!(prefix = ts_get_attr_str(node, "prefix", 0))) {
                                continue;
                        }
 
-                       if((type = tile_type(ts_get_attr_str(node, "type", 0))) == -1) {
-                               fprintf(stderr, "load_tileset: missing or invalid tile type\n");
+                       if(!(str = ts_get_attr_str(node, "type", 0))) {
+                               fprintf(stderr, "load_tileset: missing tile type\n");
+                               continue;
+                       }
+                       if((type = tile_type(str)) == -1) {
+                               fprintf(stderr, "load_tileset: invalid tile type: %s\n", str);
                                continue;
                        }
 
@@ -78,7 +82,7 @@ int load_tileset(struct tileset *tset, const char *fname)
 
                        mesh = tset->scn.meshlist;
                        while(mesh) {
-                               if(match_prefix(mesh->name, str)) {
+                               if(mesh->name && match_prefix(mesh->name, prefix)) {
                                        if(vec) {
                                                xform_mesh(mesh, xform);
                                        }
@@ -86,6 +90,9 @@ int load_tileset(struct tileset *tset, const char *fname)
                                }
                                mesh = mesh->next;
                        }
+
+                       tile->next = tset->tiles;
+                       tset->tiles = tile;
                }
        }