Changeset - r4130:f81353ba65a4
[Not reviewed]
master
0 1 0
KUDr - 18 years ago 2006-07-11 19:04:50
kudr@openttd.org
(svn r5483) -Fix: [YAPF] desync - for MP games invalidate YAPF cache on every tick to keep it exactly the same on server and clients (it doesn't fix the real source of the problem, but should solve it). Thanks TrueLight for hunting this bug.
1 file changed with 10 insertions and 0 deletions:
0 comments (0 inline, 0 general)
vehicle.c
Show inline comments
 
@@ -8,48 +8,50 @@
 
#include "spritecache.h"
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "functions.h"
 
#include "map.h"
 
#include "tile.h"
 
#include "vehicle.h"
 
#include "gfx.h"
 
#include "viewport.h"
 
#include "news.h"
 
#include "command.h"
 
#include "saveload.h"
 
#include "player.h"
 
#include "engine.h"
 
#include "sound.h"
 
#include "debug.h"
 
#include "vehicle_gui.h"
 
#include "depot.h"
 
#include "station.h"
 
#include "rail.h"
 
#include "train.h"
 
#include "industry_map.h"
 
#include "station_map.h"
 
#include "water_map.h"
 
#include "network.h"
 
#include "yapf/yapf.h"
 

	
 
#define INVALID_COORD (-0x8000)
 
#define GEN_HASH(x,y) (((x & 0x1F80)>>7) + ((y & 0xFC0)))
 

	
 
/*
 
 *	These command macros are used to call vehicle type specific commands with non type specific commands
 
 *	it should be used like: DoCommandP(x, y, p1, p2, flags, CMD_STARTSTOP_VEH(v->type))
 
 *	that line will start/stop a vehicle nomatter what type it is
 
 *	VEH_Train is used as an offset because the vehicle type values doesn't start with 0
 
 */
 

	
 
#define CMD_BUILD_VEH(x)		   _veh_build_proc_table[ x - VEH_Train]
 
#define CMD_SELL_VEH(x)				_veh_sell_proc_table[ x - VEH_Train]
 
#define CMD_REFIT_VEH(x)		   _veh_refit_proc_table[ x - VEH_Train]
 

	
 
static const uint32 _veh_build_proc_table[] = {
 
	CMD_BUILD_RAIL_VEHICLE,
 
	CMD_BUILD_ROAD_VEH,
 
	CMD_BUILD_SHIP,
 
	CMD_BUILD_AIRCRAFT,
 
};
 
static const uint32 _veh_sell_proc_table[] = {
 
	CMD_SELL_RAIL_WAGON,
 
	CMD_SELL_ROAD_VEH,
 
@@ -590,48 +592,56 @@ void VehicleEnteredDepotThisTick(Vehicle
 
	}
 

	
 
	if (_first_veh_in_depot_list == NULL) {
 
		_first_veh_in_depot_list = v;
 
	} else {
 
		Vehicle *w = _first_veh_in_depot_list;
 
		while (w->depot_list != NULL) w = w->depot_list;
 
		w->depot_list = v;
 
	}
 
}
 

	
 
static VehicleTickProc* _vehicle_tick_procs[] = {
 
	Train_Tick,
 
	RoadVeh_Tick,
 
	Ship_Tick,
 
	Aircraft_Tick,
 
	EffectVehicle_Tick,
 
	DisasterVehicle_Tick,
 
};
 

	
 
void CallVehicleTicks(void)
 
{
 
	Vehicle *v;
 

	
 
#ifdef ENABLE_NETWORK
 
	// hotfix for desync problem:
 
	//  for MP games invalidate the YAPF cache every tick to keep it exactly the same on the server and all clients
 
	if (_networking) {
 
		YapfNotifyTrackLayoutChange(0, 0);
 
	}
 
#endif //ENABLE_NETWORK
 

	
 
	_first_veh_in_depot_list = NULL;	// now we are sure it's initialized at the start of each tick
 

	
 
	FOR_ALL_VEHICLES(v) {
 
		if (v->type != 0) {
 
			_vehicle_tick_procs[v->type - 0x10](v);
 
		}
 
	}
 

	
 
	// now we handle all the vehicles that entered a depot this tick
 
	v = _first_veh_in_depot_list;
 
	while (v != NULL) {
 
		Vehicle *w = v->depot_list;
 
		v->depot_list = NULL;	// it should always be NULL at the end of each tick
 
		MaybeReplaceVehicle(v);
 
		v = w;
 
	}
 
}
 

	
 
static bool CanFillVehicle_FullLoadAny(Vehicle *v)
 
{
 
	uint32 full = 0, not_full = 0;
 

	
 
	//special handling of aircraft
 

	
0 comments (0 inline, 0 general)