From 4627d6c939b3b2d8153aca18f633a2580ecab028 Mon Sep 17 00:00:00 2001 From: pelya Date: Sun, 15 Jun 2014 23:18:37 +0300 Subject: [PATCH] Fixed game crash when two vehicles crash --- src/blitter/16bpp_base.hpp | 23 ++++++++++++++++++++--- src/blitter/16bpp_simple.cpp | 12 ++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/blitter/16bpp_base.hpp b/src/blitter/16bpp_base.hpp index e7a5b5e7a9..c4d63b0bd4 100644 --- a/src/blitter/16bpp_base.hpp +++ b/src/blitter/16bpp_base.hpp @@ -163,9 +163,9 @@ public: */ static inline Colour16 MakeGrey(Colour16 colour) { - uint r = colour.r; - uint g = colour.g; - uint b = colour.b; + uint8 r = colour.r; + uint8 g = colour.g; + uint8 b = colour.b; /* To avoid doubles and stuff, multiple it with a total of 65536 (16bits), then * divide by it to normalize the value to a byte again. See heightmap.cpp for @@ -175,6 +175,23 @@ public: return To16(grey, grey, grey); } + /** + * Make a colour dark grey, for specialized 32bpp remapping. + * @param r red component + * @param g green component + * @param b blue component + * @return the brightness value of the new colour, now dark grey. + */ + static inline uint8 MakeDark(Colour16 colour) + { + uint8 r = colour.r; + uint8 g = colour.g; + uint8 b = colour.b; + + /* Magic-numbers are ~66% of those used in MakeGrey() */ + return (((r << 3) * 13063) + ((g << 2) * 25647) + ((b << 3) * 4981)) / 65536; + } + enum { DEFAULT_BRIGHTNESS = 8 }; /** diff --git a/src/blitter/16bpp_simple.cpp b/src/blitter/16bpp_simple.cpp index 36f90f17b6..675b58b87d 100644 --- a/src/blitter/16bpp_simple.cpp +++ b/src/blitter/16bpp_simple.cpp @@ -46,6 +46,17 @@ void Blitter_16bppSimple::Draw(const Blitter::BlitterParams *bp, ZoomLevel zoom) } break; + case BM_CRASH_REMAP: + if (src->m == 0) { + if (src->a != 0) { + uint8 g = MakeDark(src->c); + *dst = ComposeColourRGBA(g, g, g, src->a, *dst); + } + } else { + if (bp->remap[src->m] != 0) *dst = ComposeColourPA(AdjustBrightness(LookupColourInPalette(bp->remap[src->m]), src->v), src->a, *dst); + } + break; + case BM_TRANSPARENT: /* TODO -- We make an assumption here that the remap in fact is transparency, not some colour. * This is never a problem with the code we produce, but newgrfs can make it fail... or at least: @@ -72,6 +83,7 @@ void Blitter_16bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo case BM_NORMAL: Draw (bp, zoom); return; case BM_COLOUR_REMAP: Draw(bp, zoom); return; case BM_TRANSPARENT: Draw (bp, zoom); return; + case BM_CRASH_REMAP: Draw (bp, zoom); return; } }