diff options
| -rw-r--r-- | main.c | 8 | ||||
| -rw-r--r-- | path.c | 23 | ||||
| -rw-r--r-- | path.h | 2 |
3 files changed, 29 insertions, 4 deletions
@@ -23,11 +23,8 @@ - Clean up unused `#include`s - keybinding help screen - 'clean' rendering mode, without all the ugly shit - - time - Comments */ -/* FIXME: Costs are broken */ - void sigint_handler(int sig) { (void)sig; /* We know it's a SIGINT */ endwin(); @@ -144,7 +141,7 @@ int main(int argc, char **argv) { if (bmp_only) { map_to_bmp(map, width, height, start_pos, end_pos, path, visited, bmp_filename); - printf("Wrote the bmp to %s\n", bmp_filename); + printf("Wrote the bmp to %s. Pathfinding took %f seconds\n", bmp_filename, path_time); exit(0); } @@ -282,6 +279,9 @@ int main(int argc, char **argv) { path = path_func(dirs, map, cell_costs, width, height, start_pos, end_pos, visited, anim); } break; + case 't': + set_message("%f seconds", path_time); print_message(height); + break; case 'c': /* Load a cost file */ curs_set(2); /* Show the cursor */ @@ -3,6 +3,7 @@ #include <string.h> #include <curses.h> #include <math.h> +#include <time.h> #include <unistd.h> #include "path.h" @@ -13,6 +14,7 @@ #include "config.h" Path (*path_func)(int, Map, size_t **, size_t, size_t, Position, Position, char **, char) = &astar_path; +double path_time = 0; char anim_automatic = 0; @@ -124,6 +126,8 @@ int anim(Map map, size_t width, size_t height, Position start, Position end, Pos //} Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) { + clock_t tstart = clock(); + anim_automatic = 0; /* The function to use to find neighbours */ @@ -151,6 +155,10 @@ Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t if (cur.x == end.x && cur.y == end.y) { ppq_free(frontier); cost_free(cost_so_far, height); + + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; + return path; /* Found path */ } @@ -176,6 +184,8 @@ Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } } @@ -184,10 +194,14 @@ Path dijkstra_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim) { + clock_t tstart = clock(); + anim_automatic = 0; /* The function to use to find neighbours */ @@ -218,6 +232,10 @@ Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t hei if (cur.x == end.x && cur.y == end.y) { ppq_free(frontier); cost_free(cost_so_far, height); + + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; + return path; /* Found path */ } @@ -244,6 +262,8 @@ Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t hei path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } } @@ -252,6 +272,9 @@ Path astar_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t hei path_free(path, height); ppq_free(frontier); cost_free(cost_so_far, height); + + clock_t tend = clock(); + path_time = (tend - tstart) / (double)CLOCKS_PER_SEC; return NULL; } @@ -6,6 +6,8 @@ /* The currently chosen path func */ extern Path (*path_func)(int, Map, size_t **, size_t, size_t, Position, Position, char **, char); +/* Time it took to calculate a path */ +extern double path_time; /* dirs can be 4 or 8 to disallow or allow diagonal movement */ //Path breadth_first_search_path(int dirs, Map map, size_t **cell_costs, size_t width, size_t height, Position start, Position end, char **visited, char should_anim); |
