Mercurial > hg > openttd
changeset 8081:97d86b93edda draft
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
author | smatz <smatz@openttd.org> |
---|---|
date | Sat, 15 Dec 2007 23:11:18 +0000 |
parents | dc4d4af342b4 |
children | 4540919ba965 |
files | src/rail_cmd.cpp src/road_cmd.cpp src/roadveh_cmd.cpp src/station_cmd.cpp src/train_cmd.cpp src/tunnelbridge_cmd.cpp src/vehicle.cpp |
diffstat | 7 files changed, 37 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -82,21 +82,14 @@ * 11uuuudd => rail depot */ -/** Struct used in EnsureNoTrainOnTrack() */ -struct TrainOnTrackData { - TileIndex tile; ///< tile to check - uint z; ///< tile max Z - TrackBits rail_bits; ///< trackbits of interest -}; static void *EnsureNoTrainOnTrackProc(Vehicle *v, void *data) { - const TrainOnTrackData *info = (const TrainOnTrackData *)data; - - if (v->tile != info->tile || v->type != VEH_TRAIN) return NULL; - if (v->z_pos > info->z) return NULL; - - if ((v->u.rail.track != info->rail_bits) && !TracksOverlap(v->u.rail.track | info->rail_bits)) return NULL; + TrackBits rail_bits = *(TrackBits *)data; + + if (v->type != VEH_TRAIN) return NULL; + + if ((v->u.rail.track != rail_bits) && !TracksOverlap(v->u.rail.track | rail_bits)) return NULL; _error_message = VehicleInTheWayErrMsg(v); return v; @@ -111,13 +104,9 @@ */ static bool EnsureNoTrainOnTrack(TileIndex tile, Track track) { - TrainOnTrackData info; - - info.tile = tile; - info.z = GetTileMaxZ(tile); - info.rail_bits = TrackToTrackBits(track); - - return VehicleFromPos(tile, &info, EnsureNoTrainOnTrackProc) == NULL; + TrackBits rail_bits = TrackToTrackBits(track); + + return VehicleFromPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc) == NULL; } static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags) @@ -1160,7 +1149,7 @@ { /* Similiar checks as in TrainPowerChanged() */ - if (v->type == VEH_TRAIN && v->tile == *(TileIndex*)data && !IsArticulatedPart(v)) { + if (v->type == VEH_TRAIN && !IsArticulatedPart(v)) { const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); if (GetVehicleProperty(v, 0x0B, rvi->power) != 0) TrainPowerChanged(v->First()); } @@ -1198,7 +1187,7 @@ } /* update power of train engines on this tile */ - VehicleFromPos(tile, &tile, UpdateTrainPowerProc); + VehicleFromPos(tile, NULL, &UpdateTrainPowerProc); } return CommandCost(RailConvertCost(GetRailType(tile), totype) * CountBits(GetTrackBits(tile))); @@ -1893,23 +1882,14 @@ return false; } -/* Struct to parse data from VehicleFromPos to SignalVehicleCheckProc */ -struct SignalVehicleCheckStruct { - TileIndex tile; - uint track; -}; - static void *SignalVehicleCheckProc(Vehicle *v, void *data) { - const SignalVehicleCheckStruct* dest = (SignalVehicleCheckStruct*)data; + uint track = *(uint*)data; if (v->type != VEH_TRAIN) return NULL; - /* Wrong tile, or no train? Not a match */ - if (v->tile != dest->tile) return NULL; - /* Are we on the same piece of track? */ - if (dest->track & v->u.rail.track * 0x101) return v; + if (track & v->u.rail.track * 0x101) return v; return NULL; } @@ -1922,8 +1902,7 @@ TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile); return GetVehicleTunnelBridge(tile, endtile) != NULL; } else { - SignalVehicleCheckStruct dest = {tile, track}; - return VehicleFromPos(tile, &dest, &SignalVehicleCheckProc) != NULL; + return VehicleFromPos(tile, &track, &SignalVehicleCheckProc) != NULL; } }
--- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -619,7 +619,7 @@ SetRailType(tile, totype); MarkTileDirtyByTile(tile); YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetCrossingRailBits(tile))); - VehicleFromPos(tile, &tile, UpdateTrainPowerProc); + VehicleFromPos(tile, NULL, &UpdateTrainPowerProc); } return CommandCost(RailConvertCost(GetRailType(tile), totype));
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1015,7 +1015,7 @@ const OvertakeData* od = (OvertakeData*)data; return - v->tile == od->tile && v->type == VEH_ROAD && v->First() == v && v != od->u && v != od->v ? + v->type == VEH_ROAD && v->First() == v && v != od->u && v != od->v ? v : NULL; }
--- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1306,7 +1306,7 @@ SetRailType(tile, totype); MarkTileDirtyByTile(tile); YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile)); - VehicleFromPos(tile, &tile, UpdateTrainPowerProc); + VehicleFromPos(tile, NULL, &UpdateTrainPowerProc); } return CommandCost(RailConvertCost(GetRailType(tile), totype));
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1528,15 +1528,15 @@ /* Check if the vehicle is a train and is on the tile we are testing */ static void *TestTrainOnCrossing(Vehicle *v, void *data) { - if (v->tile != *(const TileIndex*)data || v->type != VEH_TRAIN) return NULL; + if (v->type != VEH_TRAIN) return NULL; return v; } static void DisableTrainCrossing(TileIndex tile) { if (IsLevelCrossingTile(tile) && - VehicleFromPos(tile, &tile, TestTrainOnCrossing) == NULL && // empty? - IsCrossingBarred(tile)) { + IsCrossingBarred(tile) && + VehicleFromPos(tile, NULL, &TestTrainOnCrossing) == NULL) { // empty? UnbarCrossing(tile); MarkTileDirtyByTile(tile); } @@ -2798,17 +2798,12 @@ SndPlayVehicleFx(SND_13_BIG_CRASH, v); } -struct VehicleAtSignalData { - TileIndex tile; - Direction direction; -}; - static void *CheckVehicleAtSignal(Vehicle *v, void *data) { - const VehicleAtSignalData* vasd = (VehicleAtSignalData*)data; - - if (v->type == VEH_TRAIN && IsFrontEngine(v) && v->tile == vasd->tile) { - DirDiff diff = ChangeDirDiff(DirDifference(v->direction, vasd->direction), DIRDIFF_90RIGHT); + Direction dir = *(Direction*)data; + + if (v->type == VEH_TRAIN && IsFrontEngine(v)) { + DirDiff diff = ChangeDirDiff(DirDifference(v->direction, dir), DIRDIFF_90RIGHT); if (diff == DIRDIFF_90RIGHT || (v->cur_speed <= 5 && diff <= DIRDIFF_REVERSE)) return v; } @@ -2907,12 +2902,10 @@ v->progress = 255 - 10; if (++v->load_unload_time_rem < _patches.wait_twoway_signal * 73) { TileIndex o_tile = gp.new_tile + TileOffsByDiagDir(enterdir); - VehicleAtSignalData vasd; - vasd.tile = o_tile; - vasd.direction = ReverseDir(dir); + Direction rdir = ReverseDir(dir); /* check if a train is waiting on the other side */ - if (VehicleFromPos(o_tile, &vasd, CheckVehicleAtSignal) == NULL) return; + if (VehicleFromPos(o_tile, &rdir, &CheckVehicleAtSignal) == NULL) return; } } goto reverse_train_direction;
--- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -721,8 +721,8 @@ YapfNotifyTrackLayoutChange(tile, track); YapfNotifyTrackLayoutChange(endtile, track); - VehicleFromPos(tile, &tile, UpdateTrainPowerProc); - VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc); + VehicleFromPos(tile, NULL, &UpdateTrainPowerProc); + VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc); } return CommandCost((DistanceManhattan(tile, endtile) + 1) * RailConvertCost(GetRailType(tile), totype)); @@ -746,8 +746,8 @@ YapfNotifyTrackLayoutChange(tile, track); YapfNotifyTrackLayoutChange(endtile, track); - VehicleFromPos(tile, &tile, UpdateTrainPowerProc); - VehicleFromPos(endtile, &endtile, UpdateTrainPowerProc); + VehicleFromPos(tile, NULL, &UpdateTrainPowerProc); + VehicleFromPos(endtile, NULL, &UpdateTrainPowerProc); for (tile += delta; tile != endtile; tile += delta) { MarkTileDirtyByTile(tile); // TODO encapsulate this into a function
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -120,10 +120,10 @@ static void *EnsureNoVehicleProcZ(Vehicle *v, void *data) { - const TileInfo *ti = (const TileInfo*)data; - - if (v->tile != ti->tile || v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL; - if (v->z_pos > ti->z) return NULL; + byte z = *(byte*)data; + + if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL; + if (v->z_pos > z) return NULL; _error_message = VehicleInTheWayErrMsg(v); return v; @@ -131,12 +131,7 @@ Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z) { - TileInfo ti; - - ti.tile = tile; - ti.z = z; - - return (Vehicle*)VehicleFromPos(tile, &ti, EnsureNoVehicleProcZ); + return (Vehicle*)VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ); } bool EnsureNoVehicleOnGround(TileIndex tile) @@ -170,17 +165,10 @@ } -/** Struct used for GetVehicleTunnelBridge() */ -struct TunnelBridgeInfo { - TileIndex tile; ///< tile -}; - /** Procedure called for every vehicle found in tunnel/bridge in the hash map */ static void *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) { - TunnelBridgeInfo *tbi = (TunnelBridgeInfo*)data; - - if (v->tile != tbi->tile || (v->type != VEH_TRAIN && v->type != VEH_ROAD)) return NULL; + if (v->type != VEH_TRAIN && v->type != VEH_ROAD) return NULL; _error_message = VehicleInTheWayErrMsg(v); return v; @@ -194,14 +182,10 @@ */ Vehicle *GetVehicleTunnelBridge(TileIndex tile, TileIndex endtile) { - TunnelBridgeInfo tbi = {tile}; - - Vehicle *v = (Vehicle*)VehicleFromPos(tile, &tbi, &GetVehicleTunnelBridgeProc); + Vehicle *v = (Vehicle*)VehicleFromPos(tile, NULL, &GetVehicleTunnelBridgeProc); if (v != NULL) return v; - tbi.tile = endtile; - - return (Vehicle*)VehicleFromPos(endtile, &tbi, &GetVehicleTunnelBridgeProc); + return (Vehicle*)VehicleFromPos(endtile, NULL, &GetVehicleTunnelBridgeProc); }