changeset 11926:dd6202262c94 draft

(svn r16329) -Fix: possible desync when removing lots of towns in-game (not that we allow removing towns now, but better not have desync prone code lingering around)
author rubidium <rubidium@openttd.org>
date Sun, 17 May 2009 10:35:13 +0000
parents fa2b09b44490
children ce08eae88942
files src/saveload/misc_sl.cpp src/saveload/oldloader_sl.cpp src/saveload/town_sl.cpp src/town.h src/town_cmd.cpp
diffstat 5 files changed, 10 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/saveload/misc_sl.cpp
+++ b/src/saveload/misc_sl.cpp
@@ -68,14 +68,14 @@
 	SLE_CONDNULL(2, 0, 119),
 	    SLEG_VAR(_random.state[0],        SLE_UINT32),
 	    SLEG_VAR(_random.state[1],        SLE_UINT32),
-	SLEG_CONDVAR(_cur_town_ctr,           SLE_FILE_U8  | SLE_VAR_U32,  0, 9),
-	SLEG_CONDVAR(_cur_town_ctr,           SLE_UINT32,                 10, SL_MAX_VERSION),
+	SLE_CONDNULL(1,  0,   9),
+	SLE_CONDNULL(4, 10, 119),
 	    SLEG_VAR(_cur_company_tick_index, SLE_FILE_U8  | SLE_VAR_U32),
 	SLEG_CONDVAR(_next_competitor_start,  SLE_FILE_U16 | SLE_VAR_U32,  0, 108),
 	SLEG_CONDVAR(_next_competitor_start,  SLE_UINT32,                109, SL_MAX_VERSION),
 	    SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
 	SLEG_CONDVAR(_pause_mode,             SLE_UINT8,                   4, SL_MAX_VERSION),
-	SLEG_CONDVAR(_cur_town_iter,          SLE_UINT32,                 11, SL_MAX_VERSION),
+	SLE_CONDNULL(4, 10, 119),
 	    SLEG_END()
 };
 
--- a/src/saveload/oldloader_sl.cpp
+++ b/src/saveload/oldloader_sl.cpp
@@ -1583,7 +1583,6 @@
 }
 
 extern TileIndex _cur_tileloop_tile;
-static uint32 _old_cur_town_ctr;
 static const OldChunks main_chunk[] = {
 	OCL_ASSERT( OC_TTD, 0 ),
 	OCL_ASSERT( OC_TTO, 0 ),
@@ -1618,7 +1617,7 @@
 	OCL_ASSERT( OC_TTD, 0x4B26 ),
 	OCL_ASSERT( OC_TTO, 0x3A20 ),
 
-	OCL_VAR ( OC_UINT32,   1, &_old_cur_town_ctr ),
+	OCL_NULL( 4 ),              ///< town counter,  no longer in use
 	OCL_NULL( 2 ),              ///< timer_counter, no longer in use
 	OCL_NULL( 2 ),              ///< land_code,     no longer in use
 
@@ -1774,9 +1773,6 @@
 	/* Fix some general stuff */
 	_settings_game.game_creation.landscape = _settings_game.game_creation.landscape & 0xF;
 
-	/* Remap some pointers */
-	_cur_town_ctr      = RemapTownIndex(_old_cur_town_ctr);
-
 	/* Fix the game to be compatible with OpenTTD */
 	FixOldTowns();
 	FixOldVehicles();
@@ -1813,8 +1809,6 @@
 	_settings_game.game_creation.landscape = 0;
 	_trees_tick_ctr = 0xFF;
 
-	_cur_town_ctr = RemapTownIndex(_old_cur_town_ctr);
-
 	if (!FixTTOMapArray() || !FixTTOEngines()) {
 		DEBUG(oldloader, 0, "Conversion failed");
 		return false;
--- a/src/saveload/town_sl.cpp
+++ b/src/saveload/town_sl.cpp
@@ -189,11 +189,6 @@
 
 		_total_towns++;
 	}
-
-	/* This is to ensure all pointers are within the limits of
-	 *  the size of the TownPool */
-	if (_cur_town_ctr > GetMaxTownIndex())
-		_cur_town_ctr = 0;
 }
 
 extern const ChunkHandler _town_chunk_handlers[] = {
--- a/src/town.h
+++ b/src/town.h
@@ -341,8 +341,6 @@
 
 extern Town *_cleared_town;
 extern int _cleared_town_rating;
-extern uint32 _cur_town_ctr;
-extern uint32 _cur_town_iter;
 
 void ResetHouses();
 
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -683,17 +683,12 @@
 {
 	if (_game_mode == GM_EDITOR) return;
 
-	/* Make sure each town's tickhandler invocation frequency is about the
-	 * same - TOWN_GROWTH_FREQUENCY - independent on the number of towns. */
-	for (_cur_town_iter += GetMaxTownIndex() + 1;
-	     _cur_town_iter >= TOWN_GROWTH_FREQUENCY;
-	     _cur_town_iter -= TOWN_GROWTH_FREQUENCY) {
-		uint32 i = _cur_town_ctr;
-
-		if (++_cur_town_ctr > GetMaxTownIndex())
-			_cur_town_ctr = 0;
-
-		if (Town::IsValidID(i)) TownTickHandler(Town::Get(i));
+	Town *t;
+	FOR_ALL_TOWNS(t) {
+		/* Run town tick at regular intervals, but not all at once. */
+		if ((_tick_counter + t->index) % TOWN_GROWTH_FREQUENCY == 0) {
+			TownTickHandler(t);
+		}
 	}
 }
 
@@ -2877,8 +2872,6 @@
 		s->cargo_type = CT_INVALID;
 	}
 
-	_cur_town_ctr = 0;
-	_cur_town_iter = 0;
 	_total_towns = 0;
 }