summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-02-19 22:44:38 (EST)
committer P. J. McDermott <pjm@nac.net>2013-02-19 22:44:38 (EST)
commit35226d81ac2db45ce514f07d9be60b1dee5d88fe (patch)
treea832d9ee8d8d733080407f23eac392525600771d
parent22357decdbdd612a00bcfa9291b767e6f068fd9f (diff)
downloadoverworld-rpg-35226d81ac2db45ce514f07d9be60b1dee5d88fe.zip
overworld-rpg-35226d81ac2db45ce514f07d9be60b1dee5d88fe.tar.gz
overworld-rpg-35226d81ac2db45ce514f07d9be60b1dee5d88fe.tar.bz2
Disable TMX parser debugging noise by default.
-rw-r--r--configure.ac20
-rw-r--r--src/compression.c7
-rw-r--r--src/resources/map.c63
3 files changed, 90 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 4a28c1c..6b735f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,26 @@ if test "x$GCC" = "xyes"; then
fi
AC_SUBST(GCC_CFLAGS)
+AC_ARG_ENABLE([debug-tmx],
+ [AC_HELP_STRING([--enable-debug-tmx],
+ [enable debug output from TMX parser])],
+ [enable_debug_tmx=yes],
+ [])
+if test "x$enable_debug_tmx" = "xyes"; then
+ AC_DEFINE([DEBUG_TMX], [1],
+ [Define to 1 to enable debug output from TMX parser])
+fi
+
+AC_ARG_ENABLE([debug-compression],
+ [AC_HELP_STRING([--enable-debug-compression],
+ [enable debug output from tile data inflation])],
+ [enable_debug_compression=yes],
+ [])
+if test "x$enable_debug_compression" = "xyes"; then
+ AC_DEFINE([DEBUG_COMPRESSION], [1],
+ [Define to 1 to enable debug output from tile data inflation])
+fi
+
AC_CONFIG_FILES([Makefile])
AC_CONFIG_HEADERS([config.h])
AC_OUTPUT()
diff --git a/src/compression.c b/src/compression.c
index 2dac4e5..b7c8307 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
+#include "../config.h"
#include "compression.h"
#include "logging.h"
@@ -48,13 +49,19 @@ decompress(char *src, size_t src_len, char *dest, size_t dest_len)
d_stream.next_out = (Bytef *) dest;
d_stream.avail_out = dest_len;
+#ifdef DEBUG_COMPRESSION
debug("Initializing inflation stream...");
+#endif
zlib_err(inflateInit2(&d_stream, 15 + 32));
+#ifdef DEBUG_COMPRESSION
debug("Inflating %d bytes into up to %d bytes...", src_len, dest_len);
+#endif
zlib_err(inflate(&d_stream, Z_NO_FLUSH));
+#ifdef DEBUG_COMPRESSION
debug("Ending inflation stream...");
+#endif
zlib_err(inflateEnd(&d_stream));
}
diff --git a/src/resources/map.c b/src/resources/map.c
index 6c96650..c6a62f4 100644
--- a/src/resources/map.c
+++ b/src/resources/map.c
@@ -3,6 +3,7 @@
#include <libgen.h>
#include <ctype.h>
#include <expat.h>
+#include "../../config.h"
#include "map.h"
#include "resource.h"
#include "../xml.h"
@@ -256,7 +257,9 @@ tmx_map_start(void *pv, const char *name, const char **attr)
XML_Parser p = (XML_Parser) pv;
struct map *m;
+#ifdef DEBUG_TMX
debug("<%s> (map)", name);
+#endif
if (xml_check_tag(name, "map")) {
m = xml_node_peek(p);
@@ -282,7 +285,9 @@ tmx_map_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("</%s> (map)", name);
+#endif
if (xml_check_tag(name, "map")) {
xml_node_pop(p);
@@ -303,7 +308,9 @@ tmx_map_el_start(void *pv, const char *name, const char **attr)
char *ly_name;
struct layer *ly;
+#ifdef DEBUG_TMX
debug("<%s> (map child)", name);
+#endif
m = xml_node_peek(p);
@@ -375,7 +382,9 @@ tmx_tileset_start(void *pv, const char *name, const char **attr)
XML_Parser p = (XML_Parser) pv;
struct tileset *ts;
+#ifdef DEBUG_TMX
debug("<%s> (external tileset)", name);
+#endif
if (xml_check_tag(name, "tileset")) {
ts = xml_node_peek(p);
@@ -399,7 +408,9 @@ tmx_tileset_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("</%s> (external tileset)", name);
+#endif
if (xml_check_tag(name, "tileset")) {
xml_node_pop(p);
@@ -415,7 +426,9 @@ tmx_tilesetemb_end(void *pv, const char *name)
struct tileset *ts;
struct map *m;
+#ifdef DEBUG_TMX
debug("</%s> (tileset)", name);
+#endif
if (xml_check_tag(name, "tileset")) {
ts = xml_node_pop(p);
@@ -436,7 +449,9 @@ tmx_tileset_el_start(void *pv, const char *name, const char **attr)
char *path;
struct image *img;
+#ifdef DEBUG_TMX
debug("<%s> (tileset child)", name);
+#endif
ts = xml_node_peek(p);
@@ -490,7 +505,9 @@ tmx_image_end(void *pv, const char *name)
struct image *img;
struct tileset *ts;
+#ifdef DEBUG_TMX
debug("</%s> (image)", name);
+#endif
if (xml_check_tag(name, "image")) {
img = (struct image *) xml_node_pop(p);
@@ -506,7 +523,9 @@ tmx_tile_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("</%s> (tile)", name);
+#endif
xml_node_pop(p);
@@ -522,7 +541,9 @@ tmx_tile_properties_start(void *pv, const char *name, const char **attr)
XML_Parser p = (XML_Parser) pv;
struct tileset *ts;
+#ifdef DEBUG_TMX
debug("<%s> (tile properties)", name);
+#endif
ts = xml_node_peek(p);
@@ -547,7 +568,9 @@ tmx_tile_property_start(void *pv, const char *name, const char **attr)
int coll_t, coll_r, coll_b, coll_l;
int n;
+#ifdef DEBUG_TMX
debug("<%s> (tile property)", name);
+#endif
ts = xml_node_peek(p);
@@ -579,7 +602,9 @@ tmx_layer_el_start(void *pv, const char *name, const char **attr)
XML_Parser p = (XML_Parser) pv;
struct layer *ly;
+#ifdef DEBUG_TMX
debug("<%s> (layer child)", name);
+#endif
ly = xml_node_peek(p);
@@ -604,7 +629,9 @@ tmx_layer_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("</%s> (layer)", name);
+#endif
if (xml_check_tag(name, "layer")) {
xml_node_pop(p);
@@ -624,29 +651,39 @@ tmx_data_end(void *pv, const char *name)
char *decomp_buf;
size_t i;
+#ifdef DEBUG_TMX
debug("</%s> (data)", name);
+#endif
ly = xml_node_peek(p);
if (xml_check_tag(name, "data")) {
decoded_len = strlen(ly->raw_data);
decomp_len = 4 * ly->map->width * ly->map->height;
+#ifdef DEBUG_TMX
debug("Expected map data size: %d", decomp_len);
+#endif
decoded_buf = malloc(decoded_len + 1);
if (decoded_buf == NULL) {
warn("Failed to allocate layer data buffer");
return;
}
if (strcmp(ly->encoding, "base64") == 0) {
+#ifdef DEBUG_TMX
debug("Decoding base 64 layer data...");
+#endif
base64_decode(ly->raw_data,
decoded_buf, decoded_len + 1);
}
if (ly->compression == NULL) {
+#ifdef DEBUG_TMX
debug("Layer data already decompressed");
+#endif
decomp_buf = decoded_buf;
} else if (strcmp(ly->compression, "zlib") == 0) {
+#ifdef DEBUG_TMX
debug("Decompressing layer data with zlib...");
+#endif
decomp_buf = malloc(decomp_len);
if (decomp_buf == NULL) {
warn("Failed to allocate layer data buffer");
@@ -656,7 +693,9 @@ tmx_data_end(void *pv, const char *name)
decomp_buf, decomp_len);
free(decoded_buf);
} else if (strcmp(ly->compression, "gzip") == 0) {
+#ifdef DEBUG_TMX
debug("Decompressing layer data with gzip...");
+#endif
decomp_buf = malloc(decomp_len);
if (decomp_buf == NULL) {
warn("Failed to allocate layer data buffer");
@@ -695,7 +734,9 @@ tmx_data_cdata(void *pv, const char *s, int len)
char *s_z;
char *s_z_trimmed, *s_z_trimmed_end;
+#ifdef DEBUG_TMX
debug("[CDATA]");
+#endif
ly = xml_node_peek(p);
@@ -728,7 +769,9 @@ tmx_objectgroup_el_start(void *pv, const char * name, const char **attr)
struct map_exit *e;
struct map_spawn *s;
+#ifdef DEBUG_TMX
debug("<%s> (objectgroup child)", name);
+#endif
m = xml_node_peek(p);
@@ -783,7 +826,9 @@ tmx_objectgroup_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("</%s> (objectgroup)", name);
+#endif
if (xml_check_tag(name, "objectgroup")) {
xml_node_pop(p);
@@ -798,7 +843,9 @@ tmx_object_exit_el_start(void *pv, const char * name, const char **attr)
XML_Parser p = (XML_Parser) pv;
struct map_exit *e;
+#ifdef DEBUG_TMX
debug("<%s> (object type=\"exit\" child)", name);
+#endif
e = xml_node_peek(p);
@@ -827,7 +874,9 @@ tmx_object_exit_end(void *pv, const char *name)
struct map_exit *e;
struct map *m;
+#ifdef DEBUG_TMX
debug("</%s> (object type=\"exit\")", name);
+#endif
if (xml_check_tag(name, "object")) {
e = xml_node_pop(p);
@@ -847,7 +896,9 @@ tmx_object_exit_property_start(void *pv, const char *name, const char **attr)
char *attr_value;
char *path;
+#ifdef DEBUG_TMX
debug("<%s> (object type=\"exit\" property)", name);
+#endif
e = xml_node_peek(p);
@@ -885,7 +936,9 @@ tmx_object_spawn_el_start(void *pv, const char * name, const char **attr)
XML_Parser p = (XML_Parser) pv;
struct map_spawn *s;
+#ifdef DEBUG_TMX
debug("<%s> (object type=\"spawn\" child)", name);
+#endif
s = xml_node_peek(p);
@@ -912,7 +965,9 @@ tmx_object_spawn_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("</%s> (object type=\"spawn\")", name);
+#endif
if (xml_check_tag(name, "object")) {
xml_node_pop(p);
@@ -926,7 +981,9 @@ tmx_unused_start(void *pv, const char *name, const char **attr)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("<%s> (unused)", name);
+#endif
/* Shut up, GCC. */
for (; *name != '\0'; ++name);
@@ -940,7 +997,9 @@ tmx_unused_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("</%s> (unused)", name);
+#endif
/* Shut up, GCC. */
for (; *name != '\0'; ++name);
@@ -953,7 +1012,9 @@ tmx_invalid_start(void *pv, const char *name, const char **attr)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("<%s> (invalid)", name);
+#endif
/* Shut up, GCC. */
for (; *attr != NULL; ++attr);
@@ -966,7 +1027,9 @@ tmx_invalid_end(void *pv, const char *name)
{
XML_Parser p = (XML_Parser) pv;
+#ifdef DEBUG_TMX
debug("<%s> (invalid)", name);
+#endif
xml_unexpected_end_tag(p, name, "");
}