Mercurial > hg > openttd
changeset 12073:02d3a628e6db draft
(svn r16480) -Fix (r15617): Invalidate newgrf variable caches of more vehicles in more places. Esp. they were only invalidated for trains.
author | frosch <frosch@openttd.org> |
---|---|
date | Sun, 31 May 2009 12:03:14 +0000 |
parents | 3b2c0d71a279 |
children | 26d333fd6c15 |
files | src/aircraft_cmd.cpp src/misc_cmd.cpp src/newgrf_engine.cpp src/roadveh_cmd.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle_base.h |
diffstat | 7 files changed, 44 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -373,6 +373,8 @@ 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 @@ u->cargo_cap = 0; } + v->InvalidateNewGRFCacheOfChain(); + UpdateAircraftCache(v); VehicleMove(v, false); @@ -566,6 +570,7 @@ 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);
--- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -122,7 +122,7 @@ /* 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();
--- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -1098,7 +1098,9 @@ VehicleEnteredDepotThisTick(v); } + v->InvalidateNewGRFCacheOfChain(); DoTriggerVehicle(v, trigger, 0, true); + v->InvalidateNewGRFCacheOfChain(); } /* Functions for changing the order of vehicle purchase lists
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -137,6 +137,8 @@ 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 @@ 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);
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -814,8 +814,12 @@ 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 @@ 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);
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -241,13 +241,15 @@ /* 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 @@ 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 */
--- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -246,6 +246,26 @@ 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 */