Cache the result of GetImage() in Vehicle::UpdateViewport() where possible.
Sprite number is not cached if callback is made, or a variable access outside a whitelist occurs. Invalidate cached sprite number when direction or cargo changes, or vehicle is marked dirty.
This commit is contained in:
@@ -1638,6 +1638,8 @@ static void SwapTrainFlags(uint16 *swap_flag1, uint16 *swap_flag2)
|
||||
*/
|
||||
static void UpdateStatusAfterSwap(Train *v)
|
||||
{
|
||||
v->cur_image_valid_dir = INVALID_DIR;
|
||||
|
||||
/* Reverse the direction. */
|
||||
if (v->track != TRACK_BIT_DEPOT) v->direction = ReverseDir(v->direction);
|
||||
|
||||
@@ -3052,6 +3054,7 @@ void Train::MarkDirty()
|
||||
Train *v = this;
|
||||
do {
|
||||
v->colourmap = PAL_NONE;
|
||||
v->cur_image_valid_dir = INVALID_DIR;
|
||||
v->UpdateViewport(true, false);
|
||||
} while ((v = v->Next()) != NULL);
|
||||
|
||||
|
Reference in New Issue
Block a user