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;
int type;
float xform[16], *vec;
+ memset(tset, 0, sizeof *tset);
+
if(!(ts = ts_load(fname))) {
fprintf(stderr, "failed to load tileset: %s\n", fname);
return -1;
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) {
tset->fname = strdup(fname);
tset->name = strdup(ts_get_attr_str(ts, "name", fname));
+ tset->tile_size = ts_get_attr_num(ts, "tilesize", DEF_TILE_SIZE);
+
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;
}
cgm_midentity(xform);
if((vec = ts_get_attr_vec(node, "pos", 0))) {
- cgm_mtranslation(xform, vec[0], vec[1], vec[2]);
+ cgm_mtranslation(xform, -vec[0], -vec[1], -vec[2]);
}
init_meshgroup(&tile->mgrp);
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);
}
}
mesh = mesh->next;
}
+
+ tile->next = tset->tiles;
+ tset->tiles = tile;
}
}
int tile_type(const char *tstr)
{
static const char *typenames[] = {
- "open", "straight", "corner", "tee", "cross", "str2open", "stropen", 0
+ "open", "straight", "corner", "opencorner", "tee", "cross", "str2open", "stropen", 0
};
int i;