diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/newgrf_engine.cpp | 17 | ||||
-rw-r--r-- | src/newgrf_engine.h | 1 | ||||
-rw-r--r-- | src/train_cmd.cpp | 3 | ||||
-rw-r--r-- | src/vehicle.h | 3 |
4 files changed, 15 insertions, 9 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 4e72919cb..f7b6fd112 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -63,22 +63,22 @@ void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const SpriteGroup * memcpy(wo->train_id, train_id, trains); } -static const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byte overriding_engine) +const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byte overriding_engine) { const WagonOverrides *wos = &_engine_wagon_overrides[engine]; - int i; /* XXX: This could turn out to be a timesink on profiles. We could * always just dedicate 65535 bytes for an [engine][train] trampoline * for O(1). Or O(logMlogN) and searching binary tree or smt. like * that. --pasky */ - for (i = 0; i < wos->overrides_count; i++) { + for (int i = 0; i < wos->overrides_count; i++) { const WagonOverride *wo = &wos->overrides[i]; - int j; - for (j = 0; j < wo->trains; j++) { - if (wo->train_id[j] == overriding_engine && (wo->cargo == cargo || wo->cargo == CT_DEFAULT)) return wo->group; + if (wo->cargo != cargo && wo->cargo != CT_DEFAULT) continue; + + for (int j = 0; j < wo->trains; j++) { + if (wo->train_id[j] == overriding_engine) return wo->group; } } return NULL; @@ -850,8 +850,7 @@ static const SpriteGroup *GetVehicleSpriteGroup(EngineID engine, const Vehicle * cargo = v->cargo_type; if (v->type == VEH_TRAIN) { - group = GetWagonOverrideSpriteSet(engine, cargo, v->u.rail.first_engine); - + group = v->u.rail.cached_override; if (group != NULL) return group; } } @@ -912,7 +911,7 @@ SpriteID GetRotorOverrideSprite(EngineID engine, const Vehicle *v, bool info_vie bool UsesWagonOverride(const Vehicle* v) { assert(v->type == VEH_TRAIN); - return GetWagonOverrideSpriteSet(v->engine_type, v->cargo_type, v->u.rail.first_engine) != NULL; + return v->u.rail.cached_override != NULL; } /** diff --git a/src/newgrf_engine.h b/src/newgrf_engine.h index 812f30b43..e77cdac0f 100644 --- a/src/newgrf_engine.h +++ b/src/newgrf_engine.h @@ -14,6 +14,7 @@ extern int _traininfo_vehicle_width; void SetWagonOverrideSprites(EngineID engine, CargoID cargo, const struct SpriteGroup *group, byte *train_id, int trains); +const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, byte overriding_engine); void SetCustomEngineSprites(EngineID engine, byte cargo, const struct SpriteGroup *group); void SetRotorOverrideSprites(EngineID engine, const struct SpriteGroup *group); SpriteID GetCustomEngineSprite(EngineID engine, const Vehicle* v, Direction direction); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 7ed30d147..0b80bbb89 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -166,6 +166,9 @@ void TrainConsistChanged(Vehicle* v) if (IsTrainEngine(u)) first_engine = u->engine_type; + /* Cache wagon override sprite group. NULL is returned if there is none */ + u->u.rail.cached_override = GetWagonOverrideSpriteSet(u->engine_type, u->cargo_type, u->u.rail.first_engine); + if (rvi_u->visual_effect != 0) { u->u.rail.cached_vis_effect = rvi_u->visual_effect; } else { diff --git a/src/vehicle.h b/src/vehicle.h index 6fe8f5521..54f9da6ac 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -141,6 +141,9 @@ struct VehicleRail { /* Link between the two ends of a multiheaded engine */ Vehicle *other_multiheaded_part; + + /* Cached wagon override spritegroup */ + const struct SpriteGroup *cached_override; }; enum { |