From faa2783201d733973beaf3758acd1c9ea1fc031b Mon Sep 17 00:00:00 2001 From: olikraus Date: Fri, 14 Jul 2017 10:35:05 +0200 Subject: [PATCH] mapgen --- ChangeLog | 1 + sys/tga/mapgen/gm.map | 2 +- sys/tga/mapgen/map.h | 19 ++++++----- sys/tga/mapgen/mapgen.c | 71 ++++++++++++++++++++++++++++------------- 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0bce9d1..134e5d92 100644 --- a/ChangeLog +++ b/ChangeLog @@ -124,4 +124,5 @@ https://github.com/olikraus/u8g2 ChangeLog * Added support for MAX7219 (issue 280) * Performance optimization for SSD1322/25/27 (issue 302) * Support for 96x16 SSD1306 OLED (issue 295) + * Fixed OldStandard-Bold fonts (osb, issue 306) \ No newline at end of file diff --git a/sys/tga/mapgen/gm.map b/sys/tga/mapgen/gm.map index 73ae4aae..ab2c0f20 100644 --- a/sys/tga/mapgen/gm.map +++ b/sys/tga/mapgen/gm.map @@ -150,7 +150,7 @@ thing 'h $9c # chest thing 'H $92 # hut thing 'K $93 # kingdom -item normal_door $73 # $73 = door open +item normal_door $73 # $73 = door open itemkey normal_door 'x $72 # $72 = door closed iteminit normal_door diff --git a/sys/tga/mapgen/map.h b/sys/tga/mapgen/map.h index d1ad07a8..73634852 100644 --- a/sys/tga/mapgen/map.h +++ b/sys/tga/mapgen/map.h @@ -7,9 +7,20 @@ #include +struct _item_onmap_struct +{ + uint8_t x; + uint8_t y; + uint8_t template_index; + uint8_t option; +}; +typedef struct _item_onmap_struct item_onmap_t; + struct _map_struct { unsigned char *data; + item_onmap_t *onmap_list; + uint8_t onmap_cnt; uint8_t width; uint8_t height; }; @@ -25,14 +36,6 @@ struct _item_template_struct }; typedef struct _item_template_struct item_template_t; -struct _item_onmap_struct -{ - uint8_t x; - uint8_t y; - uint8_t template_index; - uint8_t option; -}; -struct _item_onmap_struct item_onmap_t; extern map_t map_list[]; diff --git a/sys/tga/mapgen/mapgen.c b/sys/tga/mapgen/mapgen.c index 176e6a7e..19f3da0d 100644 --- a/sys/tga/mapgen/mapgen.c +++ b/sys/tga/mapgen/mapgen.c @@ -252,8 +252,7 @@ struct tile_struct int ascii; int map_to; int condition[4]; - int item_index; /* reference into item_list */ - + int item_index; /* reference into item_list */ }; #define TILE_MAX 4096 struct tile_struct tile_list[TILE_MAX]; @@ -327,7 +326,7 @@ void item_write(FILE *fp) fprintf(fp, "item_template_t item_template_list[] = {\n"); for( i = 0; i < item_cnt;i++ ) { - fprintf(fp, " { %u, %u, %u}", item_list[i].init_proc, item_list[i].hit_proc, item_list[i].step_proc); + fprintf(fp, " { /* init= */ %u, /* hit= */%u, /* step= */ %u, /* fg= */ 0x%02x}", item_list[i].init_proc, item_list[i].hit_proc, item_list[i].step_proc, item_list[i].fg_tile); if ( i != item_cnt-1 ) fprintf(fp, ",\n"); else @@ -600,8 +599,10 @@ void write_map_struct(void) { fprintf(out_fp, " { "); fprintf(out_fp, "map_%s, ", map_name); - fprintf(out_fp, "%ld, ", map_width); - fprintf(out_fp, "%ld ", map_height); + fprintf(out_fp, "item_onmap_%s, ", map_name); + fprintf(out_fp, "ITEM_ONMAP_%s_CNT, ", map_name); + fprintf(out_fp, "/* width= */ %ld, ", map_width); + fprintf(out_fp, "/* height= */ %ld ", map_height); fprintf(out_fp, " },"); fprintf(out_fp, "\n"); } @@ -611,7 +612,8 @@ void write_map_struct(void) void write_tga_map(const char *filename) { static u8g2_t u8g2; - int x, y; + int x, y, i; + unsigned tile; if ( map_phase != PHASE_MAPDATA ) return; @@ -633,11 +635,20 @@ void write_tga_map(const char *filename) { for( x = 0; x < map_width; x++ ) { - /* - TODO: instead of outputing the char from the map, we should output the item if something is here at this position - */ + tile = map2[y][x]; + /* check if there is a fg_tile, if so, use that tile instead */ + for( i = 0; i < tile_cnt; i++ ) + { + if ( tile_list[i].item_index >= 0 ) + { + if ( tile_list[i].ascii == map[y][x] ) + { + tile = item_list[tile_list[i].item_index].fg_tile; + } + } + } - u8g2_DrawGlyph(&u8g2, x*16, y*16+16, map2[y][x]); + u8g2_DrawGlyph(&u8g2, x*16, y*16+16, tile); } } @@ -647,35 +658,48 @@ void write_tga_map(const char *filename) } -static void write_item_onmap() +static void write_item_onmap(void) { - int x, y; + int x, y, i; + int is_first = 1; + int cnt = 0; /* pseudo code: with all tiles on the map if the tile is connected to an item output an item onmap entry */ - if ( map_phase == PHASE_MAPSTRUCT ) + if ( map_phase == PHASE_MAPDATA ) { if ( out_fp != NULL ) { - fprintf(out_fp, "item_onmap_t item_onmap_list[] = {\n"); + fprintf(out_fp, "item_onmap_t item_onmap_%s[] = {\n", map_name); for( y = 0; y < map_height; y++ ) { for( x = 0; x < map_width; x++ ) { - fprintf(out_fp, " { "); - fprintf(out_fp, "map_%s, ", map_name); - fprintf(out_fp, "%ld, ", map_width); - fprintf(out_fp, "%ld ", map_height); - fprintf(out_fp, " },"); - + for( i = 0; i < tile_cnt; i++ ) + { + if ( tile_list[i].item_index >= 0 ) + { + if ( tile_list[i].ascii == map[y][x] ) + { + if ( is_first == 0 ) + { + fprintf(out_fp, ",\n"); + } + is_first = 0; + fprintf(out_fp, " "); + fprintf(out_fp, "{ /*x=*/ %d, /*y=*/ %d, /*idx=*/ %d, %d}", x, y, tile_list[i].item_index, 0); + cnt++; + } + } + } } } + fprintf(out_fp, "\n};\n"); + fprintf(out_fp, "#define ITEM_ONMAP_%s_CNT %d\n\n", map_name, cnt); - - fprintf(out_fp, "}\n\n"); } } } @@ -893,6 +917,7 @@ int map_read_line(const char **s) { char buf[128]; write_map(); + write_item_onmap(); sprintf(buf, "%s.tga", map_name); write_tga_map(buf); write_map_struct(); @@ -1006,6 +1031,8 @@ int main(int argc, char **argv) ugl_WriteBytecodeCArray(out_fp, "map_code"); + //write_item_onmap(); + item_write(out_fp); if ( out_fp != NULL )