From bb22f72ad9dc4ed37c7868e512b6498ae5bdc12e Mon Sep 17 00:00:00 2001 From: matthijs Date: Fri, 15 Apr 2005 15:28:01 +0000 Subject: [PATCH] (svn r2204) - Add: [NPF] NPF now has a maximum number of nodes it will search. The default value is 5000 for now, which is an educated guess. Probably needs some finetuning. Hopefully this "feature" can be removed later on, when more sophisticated means of limiting the pathfinder have been implemented. This should make ships and larger networks playable for now, though. --- npf.c | 5 ++++- settings.c | 3 +++ variables.h | 12 +++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/npf.c b/npf.c index c7bfb0c685..63f43ecfd7 100644 --- a/npf.c +++ b/npf.c @@ -785,7 +785,10 @@ void InitializeNPF(void) init_AyStar(&_npf_aystar, NPFHash, NPF_HASH_SIZE); _npf_aystar.loops_per_tick = 0; _npf_aystar.max_path_cost = 0; - _npf_aystar.max_search_nodes = 0; + //_npf_aystar.max_search_nodes = 0; + /* We will limit the number of nodes for now, until we have a better + * solution to really fix performance */ + _npf_aystar.max_search_nodes = _patches.npf_max_search_nodes; #if 0 init_AyStar(&_train_find_station, NTPHash, 1024); init_AyStar(&_train_find_depot, NTPHash, 1024); diff --git a/settings.c b/settings.c index 02085cb963..0c285a2c07 100644 --- a/settings.c +++ b/settings.c @@ -926,6 +926,9 @@ const SettingDesc patch_settings[] = { /* New Path Finding */ {"new_pathfinding_all", SDT_BOOL, (void*)false, &_patches.new_pathfinding_all, NULL}, + /* The maximum number of nodes to search */ + {"npf_max_search_nodes", SDT_UINT32, (void*)10000, &_patches.npf_max_search_nodes, NULL}, + /* When a red signal is encountered, a small detour can be made around * it. This specifically occurs when a track is doubled, in which case * the detour is typically 2 tiles. It is also often used at station diff --git a/variables.h b/variables.h index 32432f28d0..5a705214f3 100644 --- a/variables.h +++ b/variables.h @@ -192,9 +192,19 @@ typedef struct Patches { byte drag_signals_density; // many signals density bool ainew_active; // Is the new AI active? - /* New Path Finding */ + /* + * New Path Finding + */ bool new_pathfinding_all; /* Use the newest pathfinding algorithm for all */ + /** + * The maximum amount of search nodes a single NPF run should take. This + * limit should make sure performance stays at acceptable levels at the cost + * of not being perfect anymore. This will probably be fixed in a more + * sophisticated way sometime soon + */ + uint32 npf_max_search_nodes; + uint32 npf_rail_firstred_penalty; /* The penalty for when the first signal is red (and it is not an exit or combo signal) */ uint32 npf_rail_firstred_exit_penalty; /* The penalty for when the first signal is red (and it is an exit or combo signal) */ uint32 npf_rail_lastred_penalty; /* The penalty for when the last signal is red */