X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/a7875e0dd83390a47de359df1f33a017ecb3f065..05db94c84b6f7e4ee91fd67d6e1a8d97a2b97f2e:/badge/jumpnrun/levels.h?ds=sidebyside diff --git a/badge/jumpnrun/levels.h b/badge/jumpnrun/levels.h index 182cafd..c02ab97 100644 --- a/badge/jumpnrun/levels.h +++ b/badge/jumpnrun/levels.h @@ -10,16 +10,19 @@ #include #include +#define JUMPNRUN_PATH "/hackio" + typedef struct jumpnrun_level_header { - size_t tile_count; - size_t item_count; - size_t enemy_count; + uint16_t tile_count; + uint16_t item_count; + uint16_t enemy_count; } jumpnrun_level_header; typedef struct jumpnrun_level { jumpnrun_level_header header; vec2d start_pos; + uint8_t start_lives; jumpnrun_tile *tiles; jumpnrun_item *items; @@ -43,25 +46,25 @@ void jumpnrun_levels_dump(void); var.tiles = var ## _tiles; \ var.items = var ## _items; \ var.enemies = var ## _enemies; -#else +#else #ifdef __linux__ int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FILE *fd); int jumpnrun_load_level_from_file (jumpnrun_level *dest, FILE *fd); -#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ - memset(&(lv), 0, sizeof(lv)); \ - FILE *fd = fopen((lvname), "r"); \ - if(fd == NULL) return JUMPNRUN_ERROR; \ - int err = jumpnrun_load_level_header_from_file(&(lv), fd); \ - if(err != 0) { \ - fclose(fd); \ - return JUMPNRUN_ERROR; \ - } \ - JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ - err = jumpnrun_load_level_from_file(&(lv), fd); \ - fclose(fd); \ +#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ + memset(&(lv), 0, sizeof(lv)); \ + FILE *fd = fopen((lvname), "r"); \ + if(fd == NULL) return JUMPNRUN_ERROR; \ + int err = jumpnrun_load_level_header_from_file(&(lv), fd); \ + if(err != 0) { \ + fclose(fd); \ + return JUMPNRUN_ERROR; \ + } \ + JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ + err = jumpnrun_load_level_from_file(&(lv), fd); \ + fclose(fd); \ if(err != 0) return JUMPNRUN_ERROR; #else #include @@ -69,21 +72,22 @@ int jumpnrun_load_level_from_file (jumpnrun_level *dest, FILE *fd); int jumpnrun_load_level_header_from_file(jumpnrun_level *dest, FIL *fd); int jumpnrun_load_level_from_file (jumpnrun_level *dest, FIL *fd); -#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ - memset(&(lv), 0, sizeof(lv)); \ - FIL fd; \ - if(FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \ - return JUMPNRUN_ERROR; \ - } \ - if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \ - f_close(&fd); \ - return JUMPNRUN_ERROR; \ - } \ - JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ - int err = jumpnrun_load_level_from_file(&(lv), &fd); \ - f_close(&fd); \ - if(err != 0) { \ - return JUMPNRUN_ERROR; \ +#define JUMPNRUN_LEVEL_LOAD(lv, lvname) \ + memset(&(lv), 0, sizeof(lv)); \ + FIL fd; \ + if(FR_OK != f_chdir(JUMPNRUN_PATH) || \ + FR_OK != f_open(&fd, (lvname), FA_OPEN_EXISTING | FA_READ)) { \ + return JUMPNRUN_ERROR; \ + } \ + if(0 != jumpnrun_load_level_header_from_file(&(lv), &fd)) { \ + f_close(&fd); \ + return JUMPNRUN_ERROR; \ + } \ + JUMPNRUN_LEVEL_MAKE_SPACE(lv); \ + int err = jumpnrun_load_level_from_file(&(lv), &fd); \ + f_close(&fd); \ + if(err != 0) { \ + return JUMPNRUN_ERROR; \ } #endif