diff --git a/rpg/level14.c b/rpg/level14.c index 70454e0..fcd0658 100644 --- a/rpg/level14.c +++ b/rpg/level14.c @@ -27,4 +27,5 @@ LOAD_DYN(get_tile_by_tag) LOAD_DYN(grid_pos) LOAD_DYN(door) + return 0; } diff --git a/rpg/level14.c b/rpg/level14.c index 70454e0..fcd0658 100644 --- a/rpg/level14.c +++ b/rpg/level14.c @@ -27,4 +27,5 @@ LOAD_DYN(get_tile_by_tag) LOAD_DYN(grid_pos) LOAD_DYN(door) + return 0; } diff --git a/rpg/level14_2.c b/rpg/level14_2.c index ed86468..1a96b0e 100644 --- a/rpg/level14_2.c +++ b/rpg/level14_2.c @@ -27,4 +27,5 @@ LOAD_DYN(get_tile_by_tag) LOAD_DYN(grid_pos) LOAD_DYN(door) + return 0; } diff --git a/rpg/level14.c b/rpg/level14.c index 70454e0..fcd0658 100644 --- a/rpg/level14.c +++ b/rpg/level14.c @@ -27,4 +27,5 @@ LOAD_DYN(get_tile_by_tag) LOAD_DYN(grid_pos) LOAD_DYN(door) + return 0; } diff --git a/rpg/level14_2.c b/rpg/level14_2.c index ed86468..1a96b0e 100644 --- a/rpg/level14_2.c +++ b/rpg/level14_2.c @@ -27,4 +27,5 @@ LOAD_DYN(get_tile_by_tag) LOAD_DYN(grid_pos) LOAD_DYN(door) + return 0; } diff --git a/rpg/rpg.c b/rpg/rpg.c index a72832d..279e5fa 100644 --- a/rpg/rpg.c +++ b/rpg/rpg.c @@ -18,7 +18,7 @@ typedef struct { - char* tile; + char tile[12]; pbm_t* pbm; uint8_t flags; } bg_t; @@ -38,6 +38,18 @@ struct hashmap_s tile_tags; +dir_entry_t* rootDir; +size_t rootDirSize; +bool in_root_dir(char* f) +{ + for (int i = 0; i < rootDirSize; i++) + { + // + 1 to skip the opening / + if (strcmp(rootDir[i].name, f + 1) == 0) return true; + } + return false; +} + ent_t player; @@ -62,6 +74,11 @@ } __EXPORT__ int setup(int a) { + rootDir = f_list("/", &rootDirSize); + for (int i = 0; i < rootDirSize; i++) + { + printf2("/%s : %d\n", rootDir[i].name, rootDir[i].type); + } hashmap_create(32, &tile_tags); player.graphic = f_bitmap("/player.pbm"); @@ -113,8 +130,15 @@ bool load_level(char* level_name) { + unsigned long now = micros(); + unsigned long start = now; + unsigned long then = now; + printf3("load_level at %lu\n", now); unload_level(); + + then = now; now = micros(); printf2("unload_level() finished at %lu DLT: %lu\n", now, now - then); + memset(grid, 0, sizeof(grid)); char filename[100]; @@ -127,6 +151,7 @@ printf("Couldn't find level: %s\n", filename); return false; } + then = now; now = micros(); printf2("load_level() f_contents() finished at %lu DLT: %lu\n", now, now - then); reset_parse = true; @@ -177,36 +202,77 @@ bool found = false; char f[100]; sprintf(f, "/%s.pbm", tile_def[1]); - pbm_t* n = f_bitmap(f); + now = micros(); + pbm_t* n = in_root_dir(f) ? f_bitmap(f) : NULL; + unsigned long then2 = now; now = micros(); printf2(" load_level() f_bitmap(%s) finished at %lu DLT: %lu\n", f, now, now - then2); if (n) { found = true; - bg_t b = { tile_def[0], n, flags }; - bg[num_bg++] = b; + bg_t b; + strcpy(b.tile, tile_def[0]); + b.pbm = n; + b.flags = flags; + bg[num_bg] = b; + num_bg++; printf("Tile %s registered as word %s\n", f, tile_def[0]); } else { - int i = 1; - sprintf(f, "/%s%d.pbm", tile_def[1], i); - while (n = f_bitmap(f)) + sprintf(f, "/%s.pbp", tile_def[1]); + now = micros(); + size_t count = 0; + pbm_t** ns = in_root_dir(f) ? f_bitmaps_packed(f, &count) : NULL; + then2 = now; now = micros(); printf2(" load_level() f_bitmaps_packed(%s) (%d bitmaps) finished at %lu DLT: %lu\n", f, count, now, now - then2); + if (count > 0) { found = true; - - char name[10]; - sprintf(name, "%s%d", tile_def[0], i); + for (int i = 0; i < count; i++) + { + char name[10]; + sprintf(name, "%s%d", tile_def[0], i + 1); - bg_t b = { malloc(strlen(name) + 1), n, flags }; - strcpy(b.tile, name); - bg[num_bg++] = b; + bg_t b; + strcpy(b.tile, name); + b.pbm = ns[i]; + b.flags = flags; + bg[num_bg] = b; + num_bg++; - printf("Tile %s registered as word %s\n", f, name); - - i++; + printf("Tile %s(%d) registered as word %s\n", f, i, name); + } + free(ns); + } + else + { + int i = 1; sprintf(f, "/%s%d.pbm", tile_def[1], i); + now = micros(); + while (n = (in_root_dir(f) ? f_bitmap(f) : NULL)) + { + then2 = now; now = micros(); printf2(" load_level() f_bitmap(%s) finished at %lu DLT: %lu\n", f, now, now - then2); + found = true; + + char name[10]; + sprintf(name, "%s%d", tile_def[0], i); + + + bg_t b; + strcpy(b.tile, name); + b.pbm = n; + b.flags = flags; + bg[num_bg] = b; + num_bg++; + + printf("Tile %s registered as word %s\n", f, name); + + i++; + sprintf(f, "/%s%d.pbm", tile_def[1], i); + + now = micros(); + } } } @@ -231,6 +297,8 @@ } } + then = now; now = micros(); printf2("load_level() parsed tile defs finished at %lu DLT: %lu\n", now, now - then); + int gx = 0; int gy = 0; while (true) @@ -330,8 +398,10 @@ } } + then = now; now = micros(); printf2("load_level() parse grid finished at %lu DLT: %lu\n", now, now - then); + sprintf(filename, "/%s.bin", level_name); - level_code = f_code(filename); + level_code = in_root_dir(filename) ? f_code(filename) : NULL; if (level_code) { @@ -340,6 +410,8 @@ LOAD_DYN(level_update) } + then = now; now = micros(); printf3("load_level() f_code() finished at %lu DLT: %lu, total: %lu\n", now, now - then, now - start); + reset_pos(&player, 0, 0); return 0; @@ -427,6 +499,24 @@ { float t = ms / 1000.0f; + if (nextLevel[0] != 0) + { + load_level(nextLevel); + if (nextLevelTag[0] != 0) + { + grid_t* find = get_tile_by_tag(nextLevelTag); + if (find) + { + int target_gx, target_gy; + grid_pos(find, &target_gx, &target_gy); + reset_pos(&player, target_gx * GRID, target_gy * GRID); + } + } + nextLevel[0] = 0; + nextLevelTag[0] = 0; + } + + if (button_down(DPAD_RIGHT)) player.x += t * speed; if (button_down(DPAD_LEFT)) player.x -= t * speed; if (button_down(DPAD_DOWN)) player.y += t * speed; @@ -438,7 +528,7 @@ if (level_update) level_update(t); in_door = false; - d_clear(); + d_clearMem(); for (int i = 0; i < COLS; i++) { @@ -489,24 +579,6 @@ } } - if (nextLevel[0] != 0) - { - unload_level(); - load_level(nextLevel); - if (nextLevelTag[0] != 0) - { - grid_t* find = get_tile_by_tag(nextLevelTag); - if (find) - { - int target_gx, target_gy; - grid_pos(find, &target_gx, &target_gy); - reset_pos(&player, target_gx * GRID, target_gy * GRID); - } - } - nextLevel[0] = 0; - nextLevelTag[0] = 0; - } - return 0; } @@ -579,34 +651,34 @@ { int testX = ox_i < x_i ? ox_i + 1 : ox_i - 1; bool test = r_free(testX + 1, oy_i + 1, GRID - 2, GRID - 2); - if (move_debug) printf("testX: %d => %d\n", testX, test); + if (debug) printf("testX: %d => %d\n", testX, test); if (test) { ox_i = testX; if (ox_i == x_i) goX = false; - if (move_debug) printf("ox_i = %d, goX = %d\n", ox_i, goX); + if (debug) printf("ox_i = %d, goX = %d\n", ox_i, goX); } else { goX = false; - if (move_debug) printf("goX = false\n"); + if (debug) printf("goX = false\n"); } } if (goY) { int testY = oy_i < y_i ? oy_i + 1 : oy_i - 1; bool test = r_free(ox_i + 1, testY + 1, GRID - 2, GRID - 2); - if (move_debug) printf("testY: %d => %d\n", testY, test); + if (debug) printf("testY: %d => %d\n", testY, test); if (test) { oy_i = testY; if (oy_i == y_i) goY = false; - if (move_debug) printf("oy_i = %d, goY = %d\n", oy_i, goY); + if (debug) printf("oy_i = %d, goY = %d\n", oy_i, goY); } else { goY = false; - if (move_debug) printf("goY = false\n"); + if (debug) printf("goY = false\n"); } } }