Changeset - r14798:e01f8ecb3ef8
[Not reviewed]
master
0 1 0
rubidium - 14 years ago 2010-03-13 14:58:37
rubidium@openttd.org
(svn r19398) -Codechange: move the desync cache checking code to its own function. Also make the drive through and cargo list checks only run when 'desync' debugging is enabled.
1 file changed with 37 insertions and 25 deletions:
0 comments (0 inline, 0 general)
src/openttd.cpp
Show inline comments
 
@@ -1082,31 +1082,18 @@ void SwitchToMode(SwitchMode new_mode)
 

	
 

	
 
/**
 
 * State controlling game loop.
 
 * The state must not be changed from anywhere but here.
 
 * That check is enforced in DoCommand.
 
 * Check the validity of some of the caches.
 
 * Especially in the sense of desyncs between
 
 * the cached value and what the value would
 
 * be when calculated from the 'base' data.
 
 */
 
void StateGameLoop()
 
static void CheckCaches()
 
{
 
	/* dont execute the state loop during pause */
 
	if (_pause_mode != PM_UNPAUSED) {
 
		CallWindowTickEvent();
 
		return;
 
	}
 
	if (IsGeneratingWorld()) return;
 
	/* Return here so it is easy to add checks that are run
 
	 * always to aid testing of caches. */
 
	if (_debug_desync_level > 1) return;
 

	
 
	ClearStorageChanges(false);
 

	
 
	if (_game_mode == GM_EDITOR) {
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		ClearStorageChanges(true);
 

	
 
		CallWindowTickEvent();
 
		NewsLoop();
 
	} else {
 
		/* Temporary strict checking of the road stop cache entries */
 
	/* Strict checking of the road stop cache entries */
 
		const RoadStop *rs;
 
		FOR_ALL_ROADSTOPS(rs) {
 
			if (IsStandardRoadStopTile(rs->xy)) continue;
 
@@ -1116,7 +1103,6 @@ void StateGameLoop()
 
			rs->GetEntry(DIAGDIR_NW)->CheckIntegrity(rs);
 
		}
 

	
 
		if (_debug_desync_level > 1) {
 
			Vehicle *v;
 
			FOR_ALL_VEHICLES(v) {
 
				if (v != v->First()) continue;
 
@@ -1168,10 +1154,8 @@ void StateGameLoop()
 
						break;
 
				}
 
			}
 
		}
 

	
 
		/* Check whether the caches are still valid */
 
		Vehicle *v;
 
		FOR_ALL_VEHICLES(v) {
 
			byte buff[sizeof(VehicleCargoList)];
 
			memcpy(buff, &v->cargo, sizeof(VehicleCargoList));
 
@@ -1188,6 +1172,34 @@ void StateGameLoop()
 
				assert(memcmp(&st->goods[c].cargo, buff, sizeof(StationCargoList)) == 0);
 
			}
 
		}
 
}
 

	
 
/**
 
 * State controlling game loop.
 
 * The state must not be changed from anywhere but here.
 
 * That check is enforced in DoCommand.
 
 */
 
void StateGameLoop()
 
{
 
	/* dont execute the state loop during pause */
 
	if (_pause_mode != PM_UNPAUSED) {
 
		CallWindowTickEvent();
 
		return;
 
	}
 
	if (IsGeneratingWorld()) return;
 

	
 
	ClearStorageChanges(false);
 

	
 
	if (_game_mode == GM_EDITOR) {
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		ClearStorageChanges(true);
 

	
 
		CallWindowTickEvent();
 
		NewsLoop();
 
	} else {
 
		CheckCaches();
 

	
 
		/* All these actions has to be done from OWNER_NONE
 
		 *  for multiplayer compatibility */
0 comments (0 inline, 0 general)