mapgen
This commit is contained in:
parent
f261269cb5
commit
82fce0b9d9
|
@ -261,6 +261,9 @@ int tile_cnt = 0;
|
|||
#define MAP_LINE_MAX 4096
|
||||
|
||||
|
||||
#define PHASE_MAPDATA 0
|
||||
#define PHASE_MAPSTRUCT 1
|
||||
|
||||
int map_phase;
|
||||
uint8_t map[MAP_SIZE_Y][MAP_SIZE_X];
|
||||
uint8_t map2[MAP_SIZE_Y][MAP_SIZE_X];
|
||||
|
@ -493,15 +496,15 @@ void clear_map(void)
|
|||
map_curr_line = 0;
|
||||
}
|
||||
|
||||
void write_map()
|
||||
void write_map(void)
|
||||
{
|
||||
int x, y;
|
||||
|
||||
if ( map_phase == 0 )
|
||||
if ( map_phase == PHASE_MAPDATA )
|
||||
{
|
||||
if ( out_fp != NULL )
|
||||
{
|
||||
fprintf(out_fp, "unsigned char map_%s[%ld] = ", map_name, map_height*map_width);
|
||||
fprintf(out_fp, "unsigned char map_%s[%ld] = \n", map_name, map_height*map_width);
|
||||
for( y = 0; y < map_height; y++ )
|
||||
{
|
||||
fprintf(out_fp, " \"");
|
||||
|
@ -515,6 +518,23 @@ void write_map()
|
|||
else
|
||||
fprintf(out_fp, ";\n");
|
||||
}
|
||||
fprintf(out_fp, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void write_map_struct(void)
|
||||
{
|
||||
if ( map_phase == PHASE_MAPSTRUCT )
|
||||
{
|
||||
if ( out_fp != NULL )
|
||||
{
|
||||
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, " },");
|
||||
fprintf(out_fp, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -523,6 +543,8 @@ void write_tga_map(const char *filename)
|
|||
{
|
||||
static u8g2_t u8g2;
|
||||
int x, y;
|
||||
if ( map_phase != PHASE_MAPDATA )
|
||||
return;
|
||||
|
||||
u8x8_tga_info.tile_width = map_width*2;
|
||||
u8x8_tga_info.tile_height = map_height*2;
|
||||
|
@ -678,9 +700,10 @@ int map_read_line(const char **s)
|
|||
if ( map_all_tiles() )
|
||||
{
|
||||
char buf[128];
|
||||
write_map("gm.c");
|
||||
write_map();
|
||||
sprintf(buf, "%s.tga", map_name);
|
||||
write_tga_map(buf);
|
||||
write_map_struct();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
@ -763,8 +786,21 @@ int main(int argc, char **argv)
|
|||
{
|
||||
out_fp = fopen(outfile, "w");
|
||||
printf("output file %s\n", outfile);
|
||||
fprintf(out_fp, "/* %s generated by mapgen, olikraus@gmail.com */\n", outfile);
|
||||
fprintf(out_fp, "\n");
|
||||
fprintf(out_fp, "#include \"map.h\"\n");
|
||||
fprintf(out_fp, "\n");
|
||||
}
|
||||
map_read_filename(filename, 0);
|
||||
map_read_filename(filename, PHASE_MAPDATA);
|
||||
if ( out_fp != NULL )
|
||||
{
|
||||
fprintf(out_fp, "map_t map_list[] = {\n");
|
||||
map_read_filename(filename, PHASE_MAPSTRUCT);
|
||||
fprintf(out_fp, "};\n");
|
||||
fprintf(out_fp, "\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ( out_fp != NULL )
|
||||
fclose(out_fp);
|
||||
|
|
Loading…
Reference in New Issue