From 250361975fc81ca01d96f615ed1226641887c305 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Thu, 16 May 2024 20:33:22 +0200 Subject: improve pathfinding --- src/pathfinding.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/pathfinding.c') diff --git a/src/pathfinding.c b/src/pathfinding.c index 05acad7..77572ed 100644 --- a/src/pathfinding.c +++ b/src/pathfinding.c @@ -11,6 +11,7 @@ bool can_walk_at(float x, float y) object o = loaded_map.objects[i]; if (!o.active) continue; if (!o.collision) continue; + if (o.type == OBJECT_ZOMBIE_SPAWNER) continue; if (x >= o.position.x && x < o.position.x + o.size.x && y >= o.position.y && y < o.position.y + o.size.y) return false; } return true; @@ -61,7 +62,9 @@ bool find_path_to(vec2f start_pos, vec2f end_pos, array *to_fill, pathfinding_re //Pop current off open array, add to closed array list_push(&closed_array, (uint8_t*)current_node); - if (closed_array.count > 1000) return false; + if (closed_array.count > 400) { + return false; + } if (open_array.count > 1000) return false; // Found the goal @@ -277,8 +280,26 @@ void* pathfinding_thread(void *args) { pathfinding_request* request = *(pathfinding_request**)array_at(&global_pathfinding_queue, 0); array_remove_at(&global_pathfinding_queue, 0); + + #ifdef DEBUG_PATHFINDING + // Register request for debugging purposes + int req_index = 0; + for (int i = 0; i < SERVER_PATHFINDING_THREADS; i++) + { + if (!active_requests[i].active) + { + req_index = i; + break; + } + } + active_requests[req_index] = *request; + #endif + mutex_unlock(&global_pathfinding_queue.mutex); find_path_to(request->start, request->end, request->to_fill, request); + #ifdef DEBUG_PATHFINDING + active_requests[req_index].active = 0; + #endif } else { -- cgit v1.2.3-70-g09d2