From 22b285ffc4345bee05772509a60fb77fb90d16a0 Mon Sep 17 00:00:00 2001 From: Kirill Petrashin Date: Thu, 16 Apr 2026 23:02:27 +0300 Subject: Add pathfinding timing --- path.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'path.c') diff --git a/path.c b/path.c index 52f7291..7fcc73f 100644 --- a/path.c +++ b/path.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #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; } -- cgit v1.2.3