summaryrefslogtreecommitdiff
path: root/src/roadveh_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-30 21:11:12 +0000
committerrubidium <rubidium@openttd.org>2007-08-30 21:11:12 +0000
commitaba867d78dd52154bb7874a6998a3002dab57684 (patch)
treeb205fc9b323290f091d73bfe7f40c7ed002d44cc /src/roadveh_cmd.cpp
parent8a6cc3aa104b5f8631dcb74343dcd68ffa3308ec (diff)
downloadopenttd-aba867d78dd52154bb7874a6998a3002dab57684.tar.xz
(svn r11011) -Fix [FS#1129]: GetFirstVehicleInChain did change the game state while being marked const.
-Codechange: do not brute force determine the first vehicle in the chain or previous vehicle, but do it by properly accounting the previous and first pointers when updating the next pointer. This gives a performance increase of about 15% when there are a lot of vehicles in the game.
Diffstat (limited to 'src/roadveh_cmd.cpp')
-rw-r--r--src/roadveh_cmd.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index 53155c8a1..ccb0c6962 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -141,8 +141,8 @@ void RoadVehUpdateCache(Vehicle *v)
assert(IsRoadVehFront(v));
for (Vehicle *u = v; u != NULL; u = u->Next()) {
- /* Update the v->first cache. */
- if (u->first == NULL) u->first = v;
+ /* Check the v->first cache. */
+ assert(u->First() == v);
/* Update the 'first engine' */
u->u.road.first_engine = (v == u) ? INVALID_ENGINE : v->engine_type;
@@ -259,7 +259,6 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
- v->first = NULL;
v->cargo_cap = GetVehicleProperty(v, 0x0F, rvi->capacity);
AddArticulatedParts(vl, VEH_ROAD);
@@ -868,7 +867,7 @@ static void* EnumCheckRoadVehClose(Vehicle *v, void* data)
!v->IsInDepot() &&
myabs(v->z_pos - rvf->veh->z_pos) < 6 &&
v->direction == rvf->dir &&
- GetFirstVehicleInChain(rvf->veh) != GetFirstVehicleInChain(v) &&
+ rvf->veh->First() != v->First() &&
(dist_x[v->direction] >= 0 || (x_diff > dist_x[v->direction] && x_diff <= 0)) &&
(dist_x[v->direction] <= 0 || (x_diff < dist_x[v->direction] && x_diff >= 0)) &&
(dist_y[v->direction] >= 0 || (y_diff > dist_y[v->direction] && y_diff <= 0)) &&