Mercurial > hg > openttd
diff src/roadveh_cmd.cpp @ 7497:797ff0b0e0a5 draft
(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.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 30 Aug 2007 21:11:12 +0000 (2007-08-30) |
parents | 09743324277c |
children | 2250b8ea9466 |
line wrap: on
line diff
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -141,8 +141,8 @@ 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 @@ 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 @@ !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)) &&