Changeset - r12068:a96f28ffc328
[Not reviewed]
master
0 7 0
frosch - 15 years ago 2009-05-31 12:03:14
frosch@openttd.org
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
7 files changed with 44 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -373,6 +373,8 @@ CommandCost CmdBuildAircraft(TileIndex t
 
		v->vehicle_flags = 0;
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 

	
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		if (v->cargo_type != CT_PASSENGERS) {
 
			uint16 callback = CALLBACK_FAILED;
 

	
 
@@ -391,6 +393,8 @@ CommandCost CmdBuildAircraft(TileIndex t
 
			u->cargo_cap = 0;
 
		}
 

	
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		UpdateAircraftCache(v);
 

	
 
		VehicleMove(v, false);
 
@@ -566,6 +570,7 @@ CommandCost CmdRefitAircraft(TileIndex t
 
		v->cargo_type = new_cid;
 
		v->cargo_subtype = new_subtype;
 
		v->colourmap = PAL_NONE; // invalidate vehicle colour map
 
		v->InvalidateNewGRFCacheOfChain();
 
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
		InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
src/misc_cmd.cpp
Show inline comments
 
@@ -122,7 +122,7 @@ CommandCost CmdSetCompanyColour(TileInde
 
		/* Company colour data is indirectly cached. */
 
		Vehicle *v;
 
		FOR_ALL_VEHICLES(v) {
 
			if (v->owner == _current_company) v->vcache.cache_valid = 0;
 
			if (v->owner == _current_company) v->InvalidateNewGRFCache();
 
		}
 
	}
 
	return CommandCost();
src/newgrf_engine.cpp
Show inline comments
 
@@ -1098,7 +1098,9 @@ void TriggerVehicle(Vehicle *v, VehicleT
 
		VehicleEnteredDepotThisTick(v);
 
	}
 

	
 
	v->InvalidateNewGRFCacheOfChain();
 
	DoTriggerVehicle(v, trigger, 0, true);
 
	v->InvalidateNewGRFCacheOfChain();
 
}
 

	
 
/* Functions for changing the order of vehicle purchase lists
src/roadveh_cmd.cpp
Show inline comments
 
@@ -137,6 +137,8 @@ void RoadVehUpdateCache(RoadVehicle *v)
 
	assert(v->type == VEH_ROAD);
 
	assert(IsRoadVehFront(v));
 

	
 
	v->InvalidateNewGRFCacheOfChain();
 

	
 
	for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 
		/* Check the v->first cache. */
 
		assert(u->First() == v);
 
@@ -252,12 +254,15 @@ CommandCost CmdBuildRoadVeh(TileIndex ti
 
		v->cargo_cap = rvi->capacity;
 

	
 
		AddArticulatedParts(v, VEH_ROAD);
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		/* Call various callbacks after the whole consist has been constructed */
 
		for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
 
			u->rcache.cached_veh_length = GetRoadVehLength(u);
 
			/* Cargo capacity is zero if and only if the vehicle cannot carry anything */
 
			if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, 0x0F, u->cargo_cap);
 
			v->InvalidateNewGRFCache();
 
			u->InvalidateNewGRFCache();
 
		}
 

	
 
		VehicleMove(v, false);
src/ship_cmd.cpp
Show inline comments
 
@@ -814,8 +814,12 @@ CommandCost CmdBuildShip(TileIndex tile,
 
		v->vehicle_flags = 0;
 
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
 

	
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		v->cargo_cap = GetVehicleProperty(v, 0x0D, svi->capacity);
 

	
 
		v->InvalidateNewGRFCacheOfChain();
 

	
 
		VehicleMove(v, false);
 

	
 
		InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
 
@@ -948,6 +952,7 @@ CommandCost CmdRefitShip(TileIndex tile,
 
		v->cargo_type = new_cid;
 
		v->cargo_subtype = new_subtype;
 
		v->colourmap = PAL_NONE; // invalidate vehicle colour map
 
		v->InvalidateNewGRFCacheOfChain();
 
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 
		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
 
		InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
src/train_cmd.cpp
Show inline comments
 
@@ -241,13 +241,15 @@ void TrainConsistChanged(Train *v, bool 
 

	
 
		/* Set user defined data to its default value */
 
		u->tcache.user_def_data = rvi_u->user_def_data;
 
		u->vcache.cache_valid = 0;
 
		v->InvalidateNewGRFCache();
 
		u->InvalidateNewGRFCache();
 
	}
 

	
 
	for (Train *u = v; u != NULL; u = u->Next()) {
 
		/* Update user defined data (must be done before other properties) */
 
		u->tcache.user_def_data = GetVehicleProperty(u, 0x25, u->tcache.user_def_data);
 
		u->vcache.cache_valid = 0;
 
		v->InvalidateNewGRFCache();
 
		u->InvalidateNewGRFCache();
 
	}
 

	
 
	for (Train *u = v; u != NULL; u = u->Next()) {
 
@@ -333,7 +335,8 @@ void TrainConsistChanged(Train *v, bool 
 
		if (!same_length) u->tcache.cached_veh_length = veh_len;
 

	
 
		v->tcache.cached_total_length += u->tcache.cached_veh_length;
 
		u->vcache.cache_valid = 0;
 
		v->InvalidateNewGRFCache();
 
		u->InvalidateNewGRFCache();
 
	}
 

	
 
	/* store consist weight/max speed in cache */
src/vehicle_base.h
Show inline comments
 
@@ -246,6 +246,26 @@ public:
 
	virtual SpriteID GetImage(Direction direction) const { return 0; }
 

	
 
	/**
 
	 * Invalidates cached NewGRF variables
 
	 * @see InvalidateNewGRFCacheOfChain
 
	 */
 
	FORCEINLINE void InvalidateNewGRFCache()
 
	{
 
		this->vcache.cache_valid = 0;
 
	}
 

	
 
	/**
 
	 * Invalidates cached NewGRF variables of all vehicles in the chain (after the current vehicle)
 
	 * @see InvalidateNewGRFCache
 
	 */
 
	FORCEINLINE void InvalidateNewGRFCacheOfChain()
 
	{
 
		for (Vehicle *u = this; u != NULL; u = u->Next()) {
 
			u->InvalidateNewGRFCache();
 
		}
 
	}
 

	
 
	/**
 
	 * Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
 
	 * @return the vehicle's speed
 
	 */
0 comments (0 inline, 0 general)