From 615ac1cff825f0c45888e299b29a2962de5228ca Mon Sep 17 00:00:00 2001 From: mateoconlechuga Date: Thu, 24 Dec 2020 15:31:57 -0700 Subject: [PATCH] fix #69 --- src/convert.c | 1 + src/output-appvar.c | 27 ++++++++++----------------- src/output-c.c | 18 ++++++++---------- src/tileset.h | 1 + 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/convert.c b/src/convert.c index cd93338..7f708d7 100644 --- a/src/convert.c +++ b/src/convert.c @@ -412,6 +412,7 @@ int convert_tileset(convert_t *convert, tileset_t *tileset) } tileset->compressed = convert->compress != COMPRESS_NONE; + tileset->rlet = convert->style == CONVERT_STYLE_RLET; tileset_alloc_tiles(tileset); diff --git a/src/output-appvar.c b/src/output-appvar.c index 2d7d427..7272591 100644 --- a/src/output-appvar.c +++ b/src/output-appvar.c @@ -163,7 +163,7 @@ int output_appvar_header(output_t *output, appvar_t *appvar) } appvar->size += appvar->dataOffset; - + /* first entry is number of entries */ appvar_insert_entry(appvar, 0, numEntries - 1); @@ -468,20 +468,11 @@ static void output_appvar_c_include_file_converts(output_t *output, FILE *fdh, i image->name, *index); - if (image->rlet) - { - fprintf(fdh, "#define %s ((gfx_rletsprite_t*)%s_appvar[%d])\n", - image->name, - output->appvar.name, - *index); - } - else - { - fprintf(fdh, "#define %s ((gfx_sprite_t*)%s_appvar[%d])\n", - image->name, - output->appvar.name, - *index); - } + fprintf(fdh, "#define %s ((%s*)%s_appvar[%d])\n", + image->name, + image->rlet ? "gfx_rletsprite_t" : "gfx_sprite_t", + output->appvar.name, + *index); } *index = *index + 1; @@ -538,14 +529,16 @@ static void output_appvar_c_include_file_converts(output_t *output, FILE *fdh, i fprintf(fdh, "extern unsigned char *%s_tiles_data[%d];\n", tileset->image.name, tileset->numTiles); - fprintf(fdh, "#define %s_tiles ((gfx_sprite_t**)%s_tiles_data)\n", + fprintf(fdh, "#define %s_tiles ((%s**)%s_tiles_data)\n", tileset->image.name, + tileset->rlet ? "gfx_rletsprite_t" : "gfx_sprite_t", tileset->image.name); for (l = 0; l < tileset->numTiles; l++) { - fprintf(fdh, "#define %s_tile_%d ((gfx_sprite_t*)%s_tiles_data[%d])\n", + fprintf(fdh, "#define %s_tile_%d ((%s*)%s_tiles_data[%d])\n", tileset->image.name, l, + tileset->rlet ? "gfx_rletsprite_t" : "gfx_sprite_t", tileset->image.name, l); } diff --git a/src/output-c.c b/src/output-c.c index 9149f02..b4e5e13 100644 --- a/src/output-c.c +++ b/src/output-c.c @@ -104,14 +104,10 @@ int output_c_image(image_t *image) } else { - if (image->rlet) - { - fprintf(fdh, "#define %s ((gfx_rletsprite_t*)%s_data)\n", image->name, image->name); - } - else - { - fprintf(fdh, "#define %s ((gfx_sprite_t*)%s_data)\n", image->name, image->name); - } + fprintf(fdh, "#define %s ((%s*)%s_data)\n", + image->name, + image->rlet ? "gfx_rletsprite_t" : "gfx_sprite_t", + image->name); fprintf(fdh, "extern unsigned char %s_data[%d];\n", image->name, image->size); } @@ -203,9 +199,10 @@ int output_c_tileset(tileset_t *tileset) tileset->image.name, i, tile->size); - fprintf(fdh, "#define %s_tile_%d ((gfx_sprite_t*)%s_tile_%d_data)\n", + fprintf(fdh, "#define %s_tile_%d ((%s*)%s_tile_%d_data)\n", tileset->image.name, i, + tileset->rlet ? "gfx_rletsprite_t" : "gfx_sprite_t", tileset->image.name, i); } @@ -229,8 +226,9 @@ int output_c_tileset(tileset_t *tileset) tileset->image.name, tileset->numTiles); - fprintf(fdh, "#define %s_tiles ((gfx_sprite_t**)%s_tiles_data)\n", + fprintf(fdh, "#define %s_tiles ((%s**)%s_tiles_data)\n", tileset->image.name, + tileset->rlet ? "gfx_rletsprite_t" : "gfx_sprite_t", tileset->image.name); } } diff --git a/src/tileset.h b/src/tileset.h index 242d2a8..4329b9c 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -59,6 +59,7 @@ typedef struct /* set by convert */ bool compressed; + bool rlet; /* set by output */ int appvarIndex;