summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-07 15:00:47 +0000
committerbjarni <bjarni@openttd.org>2006-09-07 15:00:47 +0000
commit347a3f9a43f7264610973507e2067e6eaad6461e (patch)
tree9f55cbba5471d5308a4a8812a27abf7cdff225e4
parent782fe8b8f20319c25aeecc730ab33c9d81aeac4a (diff)
downloadopenttd-347a3f9a43f7264610973507e2067e6eaad6461e.tar.xz
(svn r6418) -Fix: [autoreplace] now multiheaded engines and other locomotives consisting of more than one unit will only be counted once
This also cleaned up the counting loop alot and it will also (hopefully) be faster (didn't benchmark it)
-rw-r--r--vehicle_gui.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/vehicle_gui.c b/vehicle_gui.c
index c12005693..1363ef649 100644
--- a/vehicle_gui.c
+++ b/vehicle_gui.c
@@ -773,19 +773,20 @@ static void ReplaceVehicleWndProc(Window *w, WindowEvent *e)
{
uint i;
const Vehicle *vehicle;
+ /* compiler optimisation tend to prefer to keep local variables in the registers instead of global ones,
+ * so we cache often used and unchanging variables in local variables to increase the loop speed */
+ const byte vehicle_type = w->window_number;
+ const PlayerID player = _local_player;
for (i = 0; i < lengthof(_player_num_engines); i++) {
_player_num_engines[i] = 0;
}
FOR_ALL_VEHICLES(vehicle) {
- if (vehicle->owner == _local_player) {
- if (vehicle->type == VEH_Aircraft && vehicle->subtype > 2) continue;
-
- // do not count the vehicles, that contains only 0 in all var
- if (vehicle->engine_type == 0 && vehicle->spritenum == 0) continue;
-
- if (vehicle->type != GetEngine(vehicle->engine_type)->type) continue;
-
+ if (vehicle->owner == player && vehicle->type == vehicle_type) {
+ if (vehicle_type == VEH_Aircraft && vehicle->subtype > 2) continue; // plane shadows and helicopter rotors
+ if (vehicle_type == VEH_Train && (
+ IsArticulatedPart(vehicle) || // tenders and other articulated parts
+ (IsMultiheaded(vehicle) && !IsTrainEngine(vehicle)))) continue; // rear parts of multiheaded engines
_player_num_engines[vehicle->engine_type]++;
}
}