From a14ad77a36c836fd3f6940eadeb8161e7ad02f92 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 25 Oct 2008 13:51:47 +0000 Subject: (svn r14528) -Codechange: cache the closest town for all road tiles instead of only roads owned by tiles. This replaces a O(n) search over all towns from the road's tileloop with a O(1) lookup (PhilSophus) --- src/town_gui.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/town_gui.cpp') diff --git a/src/town_gui.cpp b/src/town_gui.cpp index aee252892..48f8524b1 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -25,6 +25,7 @@ #include "tilehighlight_func.h" #include "string_func.h" #include "sortlist_type.h" +#include "road_cmd.h" #include "table/sprites.h" #include "table/strings.h" @@ -731,6 +732,7 @@ public: ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); } else { ScrollMainWindowToTile(t->xy); + InvalidateTownForRoadTile(); } } break; @@ -738,7 +740,11 @@ public: this->HandleButtonClick(TSEW_MANYRANDOMTOWNS); _generating_world = true; - if (!GenerateTowns()) ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); + if (!GenerateTowns()) { + ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0); + } else { + InvalidateTownForRoadTile(); + } _generating_world = false; break; @@ -783,4 +789,3 @@ void ShowBuildTownWindow() if (_game_mode != GM_EDITOR && !IsValidCompanyID(_current_company)) return; AllocateWindowDescFront(&_scen_edit_town_gen_desc, 0); } - -- cgit v1.2.3-54-g00ecf