summaryrefslogtreecommitdiff
path: root/src/roadveh.h
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2011-01-21 17:35:17 +0000
committersmatz <smatz@openttd.org>2011-01-21 17:35:17 +0000
commit8b9f0d5adeb2ccacb30230907a2e11b2fe97d772 (patch)
tree2e9525fcfeb893ae72fa0673d2b27481849c2042 /src/roadveh.h
parente860075a16daf1194d5c7a859450dafb1da05490 (diff)
downloadopenttd-8b9f0d5adeb2ccacb30230907a2e11b2fe97d772.tar.xz
(svn r21883) -Codechange: make UpdateZPosition() faster by not calling GetSlopeZ() when not needed
Diffstat (limited to 'src/roadveh.h')
-rw-r--r--src/roadveh.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/roadveh.h b/src/roadveh.h
index c73575a13..e49badbec 100644
--- a/src/roadveh.h
+++ b/src/roadveh.h
@@ -262,6 +262,36 @@ protected: // These functions should not be called outside acceleration code.
return trackbits == TRACK_BIT_X || trackbits == TRACK_BIT_Y;
}
+
+ /**
+ * Road vehicles have to use GetSlopeZ() to compute their height
+ * if they are reversing because in that case, their direction
+ * is not parallel with the road. It is safe to return \c true
+ * even if it is not reversing.
+ * @return are we (possibly) reversing?
+ */
+ FORCEINLINE bool HasToUseGetSlopeZ()
+ {
+ const RoadVehicle *rv = this->First();
+
+ /* Check if this vehicle is in the same direction as the road under.
+ * We already know it has either GVF_GOINGUP_BIT or GVF_GOINGDOWN_BIT set. */
+
+ if (rv->state <= RVSB_TRACKDIR_MASK && IsReversingRoadTrackdir((Trackdir)rv->state)) {
+ /* If the first vehicle is reversing, this vehicle may be reversing too
+ * (especially if this is the first, and maybe the only, vehicle).*/
+ return true;
+ }
+
+ while (rv != this) {
+ /* If any previous vehicle has different direction,
+ * we may be in the middle of reversing. */
+ if (this->direction != rv->direction) return true;
+ rv = rv->Next();
+ }
+
+ return false;
+ }
};
#define FOR_ALL_ROADVEHICLES(var) FOR_ALL_VEHICLES_OF_TYPE(RoadVehicle, var)