(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)

This commit is contained in:
rubidium
2008-10-25 13:51:47 +00:00
parent 65e81d5e9b
commit 52ac592422
9 changed files with 64 additions and 10 deletions

View File

@@ -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<ScenarioEditorTownGenerationWindow>(&_scen_edit_town_gen_desc, 0);
}