static int load_tileset(struct level *lvl, struct ts_node *tsn)
{
- static const char *tile_types[] = {"empty", "straight", "corner", "door", 0};
+ static const char *tile_types[] = {
+ "open", "straight", "corner", "tee", "cross", "str2open", 0
+ };
int i;
char *path;
#define DEF_CELL_SIZE 3.0f
enum {
- TILE_EMPTY,
- TILE_STRAIGHT,
+ TILE_OPEN,
+ TILE_STR,
TILE_CORNER,
- TILE_DOOR
+ TILE_TEE,
+ TILE_CROSS,
+ TILE_STR2OPEN
};
enum {
struct tile {
char *name;
int type;
- struct scenefile scn;
struct tile *next;
};
float cell_size;
struct cell *cells;
- struct tile *tiles;
+ struct tileset *tset;
/* meshes owned by the level, constructed during geometry generation or
* loaded, excluding meshes in tiles scenefiles
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <alloca.h>
+#include "treestore.h"
+#include "tileset.h"
+#include "level.h"
+
+int load_tileset(struct tileset *tset, const char *fname)
+{
+ struct ts_node *ts, *node;
+ const char *str;
+ char *path;
+
+ if(!(ts = ts_load(fname))) {
+ fprintf(stderr, "failed to load tileset: %s\n", fname);
+ return -1;
+ }
+ if(strcmp(ts->name, "tileset") != 0) {
+ fprintf(stderr, "invalid or corrupted tileset file: %s\n", fname);
+ ts_free_tree(ts);
+ return -1;
+ }
+
+ if(!(str = ts_get_attr_str(ts, "file", 0))) {
+ fprintf(stderr, "tileset %s is missing the file attribute\n", fname);
+ ts_free_tree(ts);
+ return -1;
+ }
+ path = alloca(strlen(fname) + strlen(str) + 2);
+ path_dir(str, path);
+ combine_path(path, str, path);
+
+ if(load_scenefile(&tset->scn, path) == -1) {
+ fprintf(stderr, "tileset %s: failed to load scene file: %s\n", fname, path);
+ ts_free_tree(ts);
+ return -1;
+ }
+
+ tset->name = strdup(ts_get_attr_str(ts, "name", fname));
+}
--- /dev/null
+#ifndef TILESET_H_
+#define TILESET_H_
+
+#include "scenefile.h"
+
+struct tile;
+
+struct tileset {
+ const char *name;
+
+ struct scenefile scn; /* scene file containing tile geometry */
+ struct tile *tiles;
+};
+
+int load_tileset(struct tileset *tset, const char *fname);
+void destroy_tileset(struct tileset *tset);
+
+struct tileset *get_tileset(const char *name);
+
+#endif /* TILESET_H_ */
mkdir -p data/tex
+cp datasrc/test.tileset data
cp datasrc/test.lvl data
-cp datasrc/dwall1.obj data
-cp datasrc/dwall1.mtl data
+cp datasrc/walls.obj data
+cp datasrc/walls.mtl data
cp datasrc/tex/sfloor_norm.png data/tex
cp datasrc/tex/sfloor1b_diff.jpg data/tex
cp datasrc/tex/sfloor1b_spec.jpg data/tex