void down_single_click_handler(ClickRecognizerRef recognizer, void *context) { // Generate new maze but don't solve it clear_solution(); clear_maze(); generate_maze(start_x, start_y); layer_mark_dirty(maze_layer); layer_mark_dirty(solution_layer); }
void select_single_click_handler(ClickRecognizerRef recognizer, void *context) { // Generate and Solve a new maze clear_solution(); clear_maze(); generate_maze(start_x, start_y); solve_maze(start_x, start_y); layer_mark_dirty(maze_layer); layer_mark_dirty(solution_layer); }
void parse(Maze *maze, Functions *functions, Memory *memory, const char *filename) { clear_maze(maze); zero(functions, Functions); maze->tree.bounds = (Rectangle){(V2){0, 0}, (V2){10000, 10000}}; u32 x = 0; u32 y = 0; u32 fd = open(filename, O_RDONLY); if (fd == -1) { printf("Failed to open file.\n"); exit(1); } struct stat sb; if (fstat(fd, &sb) == -1) { printf("Failed to open file.\n"); exit(1); } char *file = (char *)mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (file == MAP_FAILED) { printf("Failed to open file.\n"); exit(1); } char cell_str[2] = {}; char *f_ptr = file; char *f_end = f_ptr + sb.st_size; while (f_ptr < f_end) { cell_str[0] = f_ptr[0]; cell_str[1] = f_ptr[1]; Cell new_cell = {}; new_cell.type = CELL_NULL; f_ptr = parse_cell(maze, functions, cell_str, f_ptr, f_end, &new_cell); if (new_cell.type != CELL_NULL) { Cell *cell = get_cell(maze, x, y, memory); cell->type = new_cell.type; cell->pause = new_cell.pause; cell->function_index = new_cell.function_index; cell->name[0] = cell_str[0]; cell->name[1] = cell_str[1]; log_s(L_Parser, "%.2s ", cell_str); ++x; } else { if (cell_str[0] == '\n') { x = 0; ++y; log_s(L_Parser, "\n"); } f_ptr += 1; } } log_s(L_Parser, "\n"); if (munmap((void *)file, sb.st_size) != 0) { printf("Error unmapping file."); } if (close(fd) != 0) { printf("Error while closing file descriptor."); } }