summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2007-12-15 23:11:18 +0000
committersmatz <smatz@openttd.org>2007-12-15 23:11:18 +0000
commitacf6e08f7840c9b6b89bd6e758972bf2bea29c5f (patch)
tree8577a9e0a6fc5a9738a729065c3218757a625053
parentcbcfcb3bf4fe5e438598859ec71bfb28bf391f09 (diff)
downloadopenttd-acf6e08f7840c9b6b89bd6e758972bf2bea29c5f.tar.xz
(svn r11642) -Codechange: VehicleFromPos does check for v->tile == tile, so remove useless checks
-rw-r--r--src/rail_cmd.cpp41
-rw-r--r--src/road_cmd.cpp2
-rw-r--r--src/roadveh_cmd.cpp2
-rw-r--r--src/station_cmd.cpp2
-rw-r--r--src/train_cmd.cpp23
-rw-r--r--src/tunnelbridge_cmd.cpp8
-rw-r--r--src/vehicle.cpp30
7 files changed, 32 insertions, 76 deletions
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 8596bc8be..b29f63538 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -82,21 +82,14 @@ const byte _track_sloped_sprites[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;
+ TrackBits rail_bits = *(TrackBits *)data;
- if (v->tile != info->tile || v->type != VEH_TRAIN) return NULL;
- if (v->z_pos > info->z) return NULL;
+ if (v->type != VEH_TRAIN) return NULL;
- if ((v->u.rail.track != info->rail_bits) && !TracksOverlap(v->u.rail.track | info->rail_bits)) 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 void *EnsureNoTrainOnTrackProc(Vehicle *v, void *data)
*/
static bool EnsureNoTrainOnTrack(TileIndex tile, Track track)
{
- TrainOnTrackData info;
-
- info.tile = tile;
- info.z = GetTileMaxZ(tile);
- info.rail_bits = TrackToTrackBits(track);
+ TrackBits rail_bits = TrackToTrackBits(track);
- return VehicleFromPos(tile, &info, EnsureNoTrainOnTrackProc) == NULL;
+ return VehicleFromPos(tile, &rail_bits, &EnsureNoTrainOnTrackProc) == NULL;
}
static bool CheckTrackCombination(TileIndex tile, TrackBits to_build, uint flags)
@@ -1160,7 +1149,7 @@ void *UpdateTrainPowerProc(Vehicle *v, void *data)
{
/* 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 @@ static CommandCost DoConvertRail(TileIndex tile, RailType totype, bool exec)
}
/* 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 @@ static bool SetSignalsEnumProc(TileIndex tile, void* data, Trackdir trackdir, ui
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 @@ static bool SignalVehicleCheck(TileIndex tile, uint track)
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;
}
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index f527a970e..b3b38e02c 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -619,7 +619,7 @@ CommandCost DoConvertStreetRail(TileIndex tile, RailType totype, bool exec)
SetRailType(tile, totype);
MarkTileDirtyByTile(tile);
YapfNotifyTrackLayoutChange(tile, FindFirstTrack(GetCrossingRailBits(tile)));
- VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
+ VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
}
return CommandCost(RailConvertCost(GetRailType(tile), totype));
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 78ca24de9..7ce4a9c7a 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -1015,7 +1015,7 @@ static void* EnumFindVehToOvertake(Vehicle* v, void* data)
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;
}
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index dabb64646..0e189bd05 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1306,7 +1306,7 @@ CommandCost DoConvertStationRail(TileIndex tile, RailType totype, bool exec)
SetRailType(tile, totype);
MarkTileDirtyByTile(tile);
YapfNotifyTrackLayoutChange(tile, GetRailStationTrack(tile));
- VehicleFromPos(tile, &tile, UpdateTrainPowerProc);
+ VehicleFromPos(tile, NULL, &UpdateTrainPowerProc);
}
return CommandCost(RailConvertCost(GetRailType(tile), totype));
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 7c1f488cd..8264b0fa3 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1528,15 +1528,15 @@ static void ReverseTrainSwapVeh(Vehicle *v, int l, int r)
/* 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 @@ static void CheckTrainCollision(Vehicle *v)
SndPlayVehicleFx(SND_13_BIG_CRASH, v);
}
-struct VehicleAtSignalData {
- TileIndex tile;
- Direction direction;
-};
-
static void *CheckVehicleAtSignal(Vehicle *v, void *data)
{
- const VehicleAtSignalData* vasd = (VehicleAtSignalData*)data;
+ Direction dir = *(Direction*)data;
- if (v->type == VEH_TRAIN && IsFrontEngine(v) && v->tile == vasd->tile) {
- DirDiff diff = ChangeDirDiff(DirDifference(v->direction, vasd->direction), DIRDIFF_90RIGHT);
+ 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 @@ static void TrainController(Vehicle *v, bool update_image)
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;
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index 008f8a1fa..272d1bca6 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -721,8 +721,8 @@ CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec
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 @@ CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bool exec
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
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 8074a08b4..7b9c8bc9c 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -120,10 +120,10 @@ StringID VehicleInTheWayErrMsg(const Vehicle* v)
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data)
{
- const TileInfo *ti = (const TileInfo*)data;
+ byte z = *(byte*)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;
+ 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 @@ static void *EnsureNoVehicleProcZ(Vehicle *v, void *data)
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 @@ Vehicle *FindVehicleBetween(TileIndex from, TileIndex to, byte z, bool without_c
}
-/** 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 @@ static void *GetVehicleTunnelBridgeProc(Vehicle *v, void *data)
*/
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);
}