int can_start_procgen(int x, int y) { int cx = GEN_CHUNK_X_FOR_WORLD_X(x); int cy = GEN_CHUNK_Y_FOR_WORLD_Y(y); int slot_x = cx & (IN_PROGRESS_CACHE_SIZE-1); int slot_y = cy & (IN_PROGRESS_CACHE_SIZE-1); return !procgen_in_progress[slot_y][slot_x].in_use; }
int is_in_progress(int x, int y) { int cx = GEN_CHUNK_X_FOR_WORLD_X(x); int cy = GEN_CHUNK_Y_FOR_WORLD_Y(y); int slot_x = cx & (IN_PROGRESS_CACHE_SIZE-1); int slot_y = cy & (IN_PROGRESS_CACHE_SIZE-1); return procgen_in_progress[slot_y][slot_x].x == x && procgen_in_progress[slot_y][slot_x].y == y && procgen_in_progress[slot_y][slot_x].in_use; }
void end_procgen(int x, int y) { int cx = GEN_CHUNK_X_FOR_WORLD_X(x); int cy = GEN_CHUNK_Y_FOR_WORLD_Y(y); int slot_x = cx & (IN_PROGRESS_CACHE_SIZE-1); int slot_y = cy & (IN_PROGRESS_CACHE_SIZE-1); procgen_in_progress[slot_y][slot_x].x = x; procgen_in_progress[slot_y][slot_x].y = y; procgen_in_progress[slot_y][slot_x].in_use = false; }
gen_chunk_cache *get_gen_chunk_cache_for_coord(int x, int y) { int cx = GEN_CHUNK_X_FOR_WORLD_X(x); int cy = GEN_CHUNK_Y_FOR_WORLD_Y(y); gen_chunk_cache *gc = &gen_cache[cy & (GEN_CHUNK_CACHE_Y-1)][cx & (GEN_CHUNK_CACHE_X-1)]; if (gc->chunk_x == cx && gc->chunk_y == cy) { assert(gc->chunk != NULL); return gc; } else return NULL; }
gen_chunk_cache * put_chunk_in_cache(int x, int y, gen_chunk *gc) { int cx = GEN_CHUNK_X_FOR_WORLD_X(x); int cy = GEN_CHUNK_Y_FOR_WORLD_Y(y); int slot_x = cx & (GEN_CHUNK_CACHE_X-1); int slot_y = cy & (GEN_CHUNK_CACHE_Y-1); gen_chunk_cache *gcc = &gen_cache[slot_y][slot_x]; assert(gcc->chunk_x != x || gcc->chunk_y != y || gcc->chunk == NULL); if (gcc->chunk != NULL) free_gen_chunk(gcc); gcc->chunk_x = cx; gcc->chunk_y = cy; gcc->chunk = gc; return gcc; }