summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-02-17 03:13:14 (EST)
committer P. J. McDermott <pjm@nac.net>2013-02-17 03:13:14 (EST)
commit3c09671866ff5131bcbb044b0df6326ff891fee6 (patch)
tree414b35520a2290d9facb769624947fc8611e05a6 /src
parentafaa1a637b8d139a556d3b1a0337f55a32d5e3b6 (diff)
downloadoverworld-rpg-3c09671866ff5131bcbb044b0df6326ff891fee6.zip
overworld-rpg-3c09671866ff5131bcbb044b0df6326ff891fee6.tar.gz
overworld-rpg-3c09671866ff5131bcbb044b0df6326ff891fee6.tar.bz2
Give each use of a tileset a unique firstgid.
Diffstat (limited to 'src')
-rw-r--r--src/main.c6
-rw-r--r--src/resources/map.c43
-rw-r--r--src/resources/map.h15
3 files changed, 42 insertions, 22 deletions
diff --git a/src/main.c b/src/main.c
index 0727d5b..abf515e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,7 +9,7 @@ main(void)
{
struct map *map;
struct image *img;
- struct tileset *ts;
+ struct map_tileset *ts;
SDL_Rect imgrect, surfacerect;
init();
@@ -17,11 +17,13 @@ main(void)
map = map_get("data/forest1.simple.tmx");
debug("Map dimensions: %dx%d", map->width, map->height);
for (ts = map->tilesets_head; ts != NULL; ts = ts->next) {
- debug("Tilesheet name: %s", ts->name);
+ debug("Tileset name: %s", ts->tileset->name);
+ debug("Tileset firstgid: %d", ts->firstgid);
}
img = img_png_get("../forest-6-layer-test_ground.png");
img_png_free(img);
+ quit(0);
return 0;
img = img_png_get("../forest-6-layer-test_ground.png");
img = img_png_get("../forest-6-layer-test_ground.png");
diff --git a/src/resources/map.c b/src/resources/map.c
index 67dbfd2..ea2144f 100644
--- a/src/resources/map.c
+++ b/src/resources/map.c
@@ -17,7 +17,7 @@ static void XMLCALL tmx_map_end(void *, const char *);
static void XMLCALL tmx_map_el_start(void *, const char *, const char **);
static void XMLCALL tmx_tileset_start(void *, const char *, const char **);
static void XMLCALL tmx_tileset_end(void *, const char *);
-static void XMLCALL tmx_tilesheetemb_end(void *, const char *);
+static void XMLCALL tmx_tilesetemb_end(void *, const char *);
static void XMLCALL tmx_tileset_el_start(void *, const char *, const char **);
static void XMLCALL tmx_image_end(void *, const char *);
static void XMLCALL tmx_unused_start(void *, const char *, const char **);
@@ -108,14 +108,25 @@ map_add_layer(struct map *m, struct layer *l)
}
void
-map_add_tileset(struct map *m, struct tileset *t)
+map_add_tileset(struct map *m, struct tileset *t, int firstgid)
{
+ struct map_tileset *mts;
+
+ mts = malloc(sizeof(*mts));
+ if (mts == NULL) {
+ return;
+ }
+
+ mts->tileset = t;
+ mts->firstgid = firstgid;
+ mts->next = NULL;
+
if (m->tilesets_head == NULL) {
- m->tilesets_head = t;
+ m->tilesets_head = mts;
} else {
- m->tilesets_tail->next = t;
+ m->tilesets_tail->next = mts;
}
- m->tilesets_tail = t;
+ m->tilesets_tail = mts;
}
static struct tileset *
@@ -227,6 +238,7 @@ static void XMLCALL
tmx_map_el_start(void *pv, const char *name, const char **attr)
{
XML_Parser p = (XML_Parser) pv;
+ struct map *m;
char *dirname;
char *source;
char *path;
@@ -238,11 +250,12 @@ tmx_map_el_start(void *pv, const char *name, const char **attr)
/* Not used by engine. */
xml_node_push(p, NULL, tmx_unused_start, tmx_unused_end, NULL);
} else if (xml_check_tag(name, "tileset")) {
- dirname = ((struct map *) xml_node_peek(p))->dirname;
+ m = xml_node_peek(p);
+ dirname = m->dirname;
source = NULL;
xml_get_string_attr(p, attr, "source", &source, 0);
if (source != NULL) {
- /* External tilesheet. */
+ /* External tileset. */
path = malloc(strlen(dirname) + strlen(source) + 2);
if (path == NULL) {
return;
@@ -251,9 +264,9 @@ tmx_map_el_start(void *pv, const char *name, const char **attr)
ts = tileset_get(path, dirname);
free(source);
xml_node_push(p, ts, tmx_invalid_start,
- tmx_tilesheetemb_end, NULL);
+ tmx_tilesetemb_end, NULL);
} else {
- /* Embedded tilesheet. */
+ /* Embedded tileset. */
ts = resource_alloc("internal", sizeof(*ts));
if (ts == NULL) {
return;
@@ -265,9 +278,9 @@ tmx_map_el_start(void *pv, const char *name, const char **attr)
xml_get_int_attr(p, attr, "tileheight", &ts->tileheight,
1);
xml_node_push(p, ts, tmx_tileset_el_start,
- tmx_tilesheetemb_end, NULL);
+ tmx_tilesetemb_end, NULL);
}
- xml_get_int_attr(p, attr, "firstgid", &ts->firstgid, 1);
+ xml_get_int_attr(p, attr, "firstgid", &m->cur_ts_firstgid, 1);
} else {
xml_unexpected_start_tag(p, name,
"properties, tileset, layer, or objectgroup");
@@ -309,16 +322,18 @@ tmx_tileset_end(void *pv, const char *name)
}
static void XMLCALL
-tmx_tilesheetemb_end(void *pv, const char *name)
+tmx_tilesetemb_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
struct tileset *ts;
+ struct map *m;
debug("</%s> (tileset)", name);
if (xml_check_tag(name, "tileset")) {
- ts = (struct tileset *) xml_node_pop(p);
- map_add_tileset((struct map *) xml_node_peek(p), ts);
+ ts = xml_node_pop(p);
+ m = xml_node_peek(p);
+ map_add_tileset(m, ts, m->cur_ts_firstgid);
} else {
xml_unexpected_end_tag(p, name, "tileset");
}
diff --git a/src/resources/map.h b/src/resources/map.h
index 673a01d..2926aa5 100644
--- a/src/resources/map.h
+++ b/src/resources/map.h
@@ -9,13 +9,15 @@
struct tileset {
struct resource res;
char *dirname;
- /* TODO: firstgid shouldn't apply to all uses of a tileset. */
- int firstgid;
char *name;
int tilewidth;
int tileheight;
struct image *image;
- struct tileset *next;
+};
+struct map_tileset {
+ struct tileset *tileset;
+ int firstgid;
+ struct map_tileset *next;
};
struct map {
struct resource res;
@@ -24,16 +26,17 @@ struct map {
int height;
int tilewidth;
int tileheight;
- struct tileset *tilesets_head;
- struct tileset *tilesets_tail;
+ struct map_tileset *tilesets_head;
+ struct map_tileset *tilesets_tail;
struct layer *layers_head;
struct layer *layers_tail;
Uint8 *collision;
+ int cur_ts_firstgid;
};
struct map *map_get(const char *path);
void map_free(struct map *map);
void map_add_layer(struct map *m, struct layer *l);
-void map_add_tileset(struct map *m, struct tileset *t);
+void map_add_tileset(struct map *m, struct tileset *t, int firstgid);
#endif