summaryrefslogtreecommitdiff
path: root/src/vehicle.cpp
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2007-10-28 15:40:18 +0000
committerglx <glx@openttd.org>2007-10-28 15:40:18 +0000
commit4041d8108a4f5994c52af436b393faebdad3ae01 (patch)
tree09da5f37172fa5f54c8410e10e03bff557736bb8 /src/vehicle.cpp
parent18096c4e3c999a0cd994accaf03f08499daf5d65 (diff)
downloadopenttd-4041d8108a4f5994c52af436b393faebdad3ae01.tar.xz
(svn r11352) -Codechange: cache callback 2D result (vehicle color mapping) instead calling it every time the vehicle is drawn
Diffstat (limited to 'src/vehicle.cpp')
-rw-r--r--src/vehicle.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 28fb0e64c..86151e48a 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -274,6 +274,7 @@ Vehicle::Vehicle()
this->group_id = DEFAULT_GROUP;
this->fill_percent_te_id = INVALID_TE_ID;
this->first = this;
+ this->colormap = PAL_NONE;
}
/**
@@ -457,6 +458,12 @@ void ResetVehiclePosHash()
memset(_new_vehicle_position_hash, 0, sizeof(_new_vehicle_position_hash));
}
+void ResetVehicleColorMap()
+{
+ Vehicle *v;
+ FOR_ALL_VEHICLES(v) { v->colormap = PAL_NONE; }
+}
+
void InitializeVehicles()
{
_Vehicle_pool.CleanPool();
@@ -2607,7 +2614,10 @@ const Livery *GetEngineLivery(EngineID engine_type, PlayerID player, EngineID pa
static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, EngineID parent_engine_type, const Vehicle *v)
{
- SpriteID map = PAL_NONE;
+ SpriteID map = (v != NULL) ? v->colormap : PAL_NONE;
+
+ /* Return cached value if any */
+ if (map != PAL_NONE) return map;
/* Check if we should use the colour map callback */
if (HASBIT(EngInfo(engine_type)->callbackmask, CBM_VEHICLE_COLOUR_REMAP)) {
@@ -2618,7 +2628,11 @@ static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, Engine
map = GB(callback, 0, 14);
/* If bit 14 is set, then the company colours are applied to the
* map else it's returned as-is. */
- if (!HASBIT(callback, 14)) return map;
+ if (!HASBIT(callback, 14)) {
+ /* Update cache */
+ if (v != NULL) ((Vehicle*)v)->colormap = map;
+ return map;
+ }
}
}
@@ -2631,6 +2645,8 @@ static SpriteID GetEngineColourMap(EngineID engine_type, PlayerID player, Engine
map += livery->colour1;
if (twocc) map += livery->colour2 * 16;
+ /* Update cache */
+ if (v != NULL) ((Vehicle*)v)->colormap = map;
return map;
}