summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-06-12 11:22:32 +0000
committerpeter1138 <peter1138@openttd.org>2007-06-12 11:22:32 +0000
commitce590b59f359b6ac8db7d29f0af6a885b63f53c0 (patch)
tree2318fb83c6ee94fe4c568067e21ff837afb6888b /src/train_cmd.cpp
parente5ea54fe222032dd61cd3c00c9cb98ed23a9b02e (diff)
downloadopenttd-ce590b59f359b6ac8db7d29f0af6a885b63f53c0.tar.xz
(svn r10111) -Codechange: Add new vehicle hash table for collision detection and finding vehicles on a tile. The hash area scanned is far smaller than the old hash table, which is now used for viewport updates only. This should give a significant performance improvement for games with many vehicles. (Based on work by 'B. N. SmatZ!' and 'madman2003')
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r--src/train_cmd.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 68be61c99..5f2073cf0 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2722,7 +2722,7 @@ static void CheckTrainCollision(Vehicle *v)
tcc.v_skip = v->next;
/* find colliding vehicle */
- Vehicle *realcoll = (Vehicle*)VehicleFromPos(TileVirtXY(v->x_pos, v->y_pos), &tcc, FindTrainCollideEnum);
+ Vehicle *realcoll = (Vehicle*)VehicleFromPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum);
if (realcoll == NULL) return;
Vehicle *coll = GetFirstVehicleInChain(realcoll);
@@ -2775,6 +2775,8 @@ static void TrainController(Vehicle *v, bool update_image)
/* For every vehicle after and including the given vehicle */
for (prev = GetPrevVehicleInChain(v); v != NULL; prev = v, v = v->next) {
+ DiagDirection enterdir = DIAGDIR_BEGIN;
+ bool update_signals = false;
BeginVehicleMove(v);
GetNewVehiclePosResult gp = GetNewVehiclePos(v);
@@ -2810,7 +2812,7 @@ static void TrainController(Vehicle *v, bool update_image)
/* Determine what direction we're entering the new tile from */
Direction dir = GetNewVehicleDirectionByTile(gp.new_tile, gp.old_tile);
- DiagDirection enterdir = DirToDiagDir(dir);
+ enterdir = DirToDiagDir(dir);
assert(IsValidDiagDirection(enterdir));
/* Get the status of the tracks in the new tile and mask
@@ -2917,11 +2919,9 @@ static void TrainController(Vehicle *v, bool update_image)
assert(v->u.rail.track);
}
- if (IsFrontEngine(v)) TrainMovedChangeSignals(gp.new_tile, enterdir);
-
- /* Signals can only change when the first
- * (above) or the last vehicle moves. */
- if (v->next == NULL) TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
+ /* We need to update signal status, but after the vehicle position hash
+ * has been updated by AfterSetTrainPos() */
+ update_signals = true;
if (prev == NULL) AffectSpeedByDirChange(v, chosen_dir);
@@ -2958,6 +2958,14 @@ static void TrainController(Vehicle *v, bool update_image)
/* This is the first vehicle in the train */
AffectSpeedByZChange(v, old_z);
}
+
+ if (update_signals) {
+ if (IsFrontEngine(v)) TrainMovedChangeSignals(gp.new_tile, enterdir);
+
+ /* Signals can only change when the first
+ * (above) or the last vehicle moves. */
+ if (v->next == NULL) TrainMovedChangeSignals(gp.old_tile, ReverseDiagDir(enterdir));
+ }
}
return;