This commit is contained in:
olikraus 2017-07-14 10:35:05 +02:00
parent 6efb5eba30
commit faa2783201
4 changed files with 62 additions and 31 deletions

View File

@ -124,4 +124,5 @@ https://github.com/olikraus/u8g2 ChangeLog
* Added support for MAX7219 (issue 280) * Added support for MAX7219 (issue 280)
* Performance optimization for SSD1322/25/27 (issue 302) * Performance optimization for SSD1322/25/27 (issue 302)
* Support for 96x16 SSD1306 OLED (issue 295) * Support for 96x16 SSD1306 OLED (issue 295)
* Fixed OldStandard-Bold fonts (osb, issue 306)

View File

@ -150,7 +150,7 @@ thing 'h $9c # chest
thing 'H $92 # hut thing 'H $92 # hut
thing 'K $93 # kingdom 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 itemkey normal_door 'x $72 # $72 = door closed
iteminit normal_door iteminit normal_door

View File

@ -7,9 +7,20 @@
#include <stdint.h> #include <stdint.h>
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 struct _map_struct
{ {
unsigned char *data; unsigned char *data;
item_onmap_t *onmap_list;
uint8_t onmap_cnt;
uint8_t width; uint8_t width;
uint8_t height; uint8_t height;
}; };
@ -25,14 +36,6 @@ struct _item_template_struct
}; };
typedef struct _item_template_struct item_template_t; 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[]; extern map_t map_list[];

View File

@ -252,8 +252,7 @@ struct tile_struct
int ascii; int ascii;
int map_to; int map_to;
int condition[4]; int condition[4];
int item_index; /* reference into item_list */ int item_index; /* reference into item_list */
}; };
#define TILE_MAX 4096 #define TILE_MAX 4096
struct tile_struct tile_list[TILE_MAX]; 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"); fprintf(fp, "item_template_t item_template_list[] = {\n");
for( i = 0; i < item_cnt;i++ ) 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 ) if ( i != item_cnt-1 )
fprintf(fp, ",\n"); fprintf(fp, ",\n");
else else
@ -600,8 +599,10 @@ void write_map_struct(void)
{ {
fprintf(out_fp, " { "); fprintf(out_fp, " { ");
fprintf(out_fp, "map_%s, ", map_name); fprintf(out_fp, "map_%s, ", map_name);
fprintf(out_fp, "%ld, ", map_width); fprintf(out_fp, "item_onmap_%s, ", map_name);
fprintf(out_fp, "%ld ", map_height); 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, " },");
fprintf(out_fp, "\n"); fprintf(out_fp, "\n");
} }
@ -611,7 +612,8 @@ void write_map_struct(void)
void write_tga_map(const char *filename) void write_tga_map(const char *filename)
{ {
static u8g2_t u8g2; static u8g2_t u8g2;
int x, y; int x, y, i;
unsigned tile;
if ( map_phase != PHASE_MAPDATA ) if ( map_phase != PHASE_MAPDATA )
return; return;
@ -633,11 +635,20 @@ void write_tga_map(const char *filename)
{ {
for( x = 0; x < map_width; x++ ) for( x = 0; x < map_width; x++ )
{ {
/* tile = map2[y][x];
TODO: instead of outputing the char from the map, we should output the item if something is here at this position /* 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: pseudo code:
with all tiles on the map with all tiles on the map
if the tile is connected to an item if the tile is connected to an item
output an item onmap entry output an item onmap entry
*/ */
if ( map_phase == PHASE_MAPSTRUCT ) if ( map_phase == PHASE_MAPDATA )
{ {
if ( out_fp != NULL ) 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( y = 0; y < map_height; y++ )
{ {
for( x = 0; x < map_width; x++ ) for( x = 0; x < map_width; x++ )
{ {
fprintf(out_fp, " { "); for( i = 0; i < tile_cnt; i++ )
fprintf(out_fp, "map_%s, ", map_name); {
fprintf(out_fp, "%ld, ", map_width); if ( tile_list[i].item_index >= 0 )
fprintf(out_fp, "%ld ", map_height); {
fprintf(out_fp, " },"); 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]; char buf[128];
write_map(); write_map();
write_item_onmap();
sprintf(buf, "%s.tga", map_name); sprintf(buf, "%s.tga", map_name);
write_tga_map(buf); write_tga_map(buf);
write_map_struct(); write_map_struct();
@ -1006,6 +1031,8 @@ int main(int argc, char **argv)
ugl_WriteBytecodeCArray(out_fp, "map_code"); ugl_WriteBytecodeCArray(out_fp, "map_code");
//write_item_onmap();
item_write(out_fp); item_write(out_fp);
if ( out_fp != NULL ) if ( out_fp != NULL )