From a1fabc10623b9e9a4177e8e0344d5edccdcf60b7 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Mon, 18 Feb 2013 20:40:16 -0500 Subject: Make the tileset firstgid a Uint32. --- diff --git a/src/resources/map.c b/src/resources/map.c index 3fbf12e..0719a14 100644 --- a/src/resources/map.c +++ b/src/resources/map.c @@ -119,7 +119,7 @@ map_get(const char *path) } void -map_add_tileset(struct map *m, struct tileset *t, int firstgid) +map_add_tileset(struct map *m, struct tileset *t, Uint32 firstgid) { struct map_tileset *mts; @@ -345,7 +345,8 @@ tmx_map_el_start(void *pv, const char *name, const char **attr) xml_node_push(p, ts, tmx_tileset_el_start, tmx_tilesetemb_end, NULL); } - xml_get_int_attr(p, attr, "firstgid", &m->cur_ts_firstgid, 1); + xml_get_uint32_attr(p, attr, "firstgid", &m->cur_ts_firstgid, + 1); } else if (xml_check_tag(name, "layer")) { ly_name = NULL; xml_get_string_attr(p, attr, "name", &ly_name, 1); diff --git a/src/resources/map.h b/src/resources/map.h index 6d1d789..267eb30 100644 --- a/src/resources/map.h +++ b/src/resources/map.h @@ -32,7 +32,7 @@ struct tileset { }; struct map_tileset { struct tileset *tileset; - int firstgid; + Uint32 firstgid; struct map_tileset *next; }; struct layer { @@ -92,12 +92,12 @@ struct map { struct map_collision *collisions; struct map_exit *map_exits_head; struct map_exit *map_exits_tail; - int cur_ts_firstgid; + Uint32 cur_ts_firstgid; }; struct map *map_get(const char *path); void map_free(struct map *map); -void map_add_tileset(struct map *m, struct tileset *t, int firstgid); +void map_add_tileset(struct map *m, struct tileset *t, Uint32 firstgid); struct layer *map_get_layer(struct map *m, const char *name); void map_add_exit(struct map *m, struct map_exit *e); diff --git a/src/xml.c b/src/xml.c index 267b25e..b10b4c7 100644 --- a/src/xml.c +++ b/src/xml.c @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include "xml.h" #include "logging.h" @@ -35,6 +37,26 @@ xml_unexpected_end_tag(XML_Parser p, const char *found, const char *expected) } void +xml_get_uint32_attr(XML_Parser p, const char **attr, const char *name, + Uint32 *dest, int req) +{ + for (; attr[0] != NULL; attr += 2) { + if (strcmp(attr[0], name) == 0) { + if (sscanf(attr[1], "%" PRIu32, dest) == 1) { + return; + } else if (req) { + warn("Invalid \"%s\" attribute value", name); + XML_StopParser(p, XML_FALSE); + } + } + } + if (req) { + warn("Required attribute \"%s\" not found", name); + XML_StopParser(p, XML_FALSE); + } +} + +void xml_get_int_attr(XML_Parser p, const char **attr, const char *name, int *dest, int req) { diff --git a/src/xml.h b/src/xml.h index a863c9b..f3fc879 100644 --- a/src/xml.h +++ b/src/xml.h @@ -2,6 +2,7 @@ #define XML_H #include +#include extern inline int xml_check_tag(const char *found, const char *expected); extern inline void xml_unexpected_start_tag(XML_Parser p, const char *found, @@ -10,6 +11,8 @@ extern inline void xml_unexpected_end_tag(XML_Parser p, const char *found, const char *expected); void xml_get_int_attr(XML_Parser p, const char **attr, const char *name, int *dest, int req); +void xml_get_uint32_attr(XML_Parser p, const char **attr, const char *name, + Uint32 *dest, int req); void xml_get_string_attr(XML_Parser p, const char **attr, const char *name, char **dest, int req); void xml_node_push(XML_Parser p, void *data, -- cgit v0.9.1