mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r26541) [1.4] -Backport from trunk:
- Fix: Prevent comparing to NULL when strndup could not allocate memory (r26476) - Fix: Potentially undefined shifts in NewGRF code (r26475) - Fix: Make sure there is no uninitialised sprite data (r26473) - Fix: Draw text shadow for ellipses (r26467) - Fix: Add special handling for PALETTE_CRASH to work for non-8bpp-mapped sprites (r26463)
This commit is contained in:
parent
be4eae9456
commit
34bff06d8a
|
@ -33,12 +33,13 @@ No suitable AI can be found
|
|||
If you have no AIs and an AI is started the so-called 'dummy' AI will
|
||||
be loaded. This AI does nothing but writing a message on the AI debug
|
||||
window and showing a red warning. There are basically two solutions
|
||||
for this problem: you must change the settings so no AI is started,
|
||||
this is done in the difficulty settings window. The other solution is
|
||||
acquiring (downloading) some AI. The easiest way to do this is via
|
||||
the "Check Online Content" button in the main (intro) menu or via
|
||||
"AI Settings" -> "Select AI" -> "Check Online Content" which is also
|
||||
accessed via the main menu.
|
||||
for this problem: Either you set the number of AI players to 0 so that
|
||||
no AI is started. You find that setting at the top of the window in the
|
||||
"AI / Game Scripts Settings" window.
|
||||
The other solution is acquiring (downloading) some AI. The easiest way
|
||||
to do this is via the "Check Online Content" button in the main (intro)
|
||||
menu or directly in the "AI / Game Scripts Settings" dialogue via the
|
||||
"Check Online Content" button.
|
||||
|
||||
After a while of playing, colours get corrupted
|
||||
In Windows 7 the background slideshow corrupts the colour mapping of
|
||||
|
|
|
@ -133,6 +133,46 @@ inline void Blitter_32bppAnim::Draw(const Blitter::BlitterParams *bp, ZoomLevel
|
|||
}
|
||||
break;
|
||||
|
||||
case BM_CRASH_REMAP:
|
||||
if (src_px->a == 255) {
|
||||
do {
|
||||
uint m = *src_n;
|
||||
if (m == 0) {
|
||||
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
|
||||
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
|
||||
*anim = 0;
|
||||
} else {
|
||||
uint r = remap[GB(m, 0, 8)];
|
||||
*anim = r | (m & 0xFF00);
|
||||
if (r != 0) *dst = this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8));
|
||||
}
|
||||
anim++;
|
||||
dst++;
|
||||
src_px++;
|
||||
src_n++;
|
||||
} while (--n != 0);
|
||||
} else {
|
||||
do {
|
||||
uint m = *src_n;
|
||||
if (m == 0) {
|
||||
if (src_px->a != 0) {
|
||||
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
|
||||
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
|
||||
*anim = 0;
|
||||
}
|
||||
} else {
|
||||
uint r = remap[GB(m, 0, 8)];
|
||||
*anim = 0;
|
||||
if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)), src_px->a, *dst);
|
||||
}
|
||||
anim++;
|
||||
dst++;
|
||||
src_px++;
|
||||
src_n++;
|
||||
} while (--n != 0);
|
||||
}
|
||||
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:
|
||||
|
@ -208,6 +248,7 @@ void Blitter_32bppAnim::Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomL
|
|||
case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom); return;
|
||||
case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP>(bp, zoom); return;
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT> (bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP> (bp, zoom); return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -313,6 +313,25 @@ bmcr_alpha_blend_single:
|
|||
if (src[0].a) anim[0] = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case BM_CRASH_REMAP:
|
||||
for (uint x = (uint) bp->width; x > 0; x--) {
|
||||
if (src_mv->m == 0) {
|
||||
if (src->a != 0) {
|
||||
uint8 g = MakeDark(src->r, src->g, src->b);
|
||||
*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
|
||||
*anim = 0;
|
||||
}
|
||||
} else {
|
||||
uint r = remap[src_mv->m];
|
||||
if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), src_mv->v), src->a, *dst);
|
||||
}
|
||||
src_mv++;
|
||||
dst++;
|
||||
src++;
|
||||
anim++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
next_line:
|
||||
|
@ -373,6 +392,7 @@ bm_normal:
|
|||
}
|
||||
break;
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT, RM_NONE, BT_NONE, true, true>(bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, RM_NONE, BT_NONE, true, true>(bp, zoom); return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -112,6 +112,19 @@ public:
|
|||
return Colour(r * nom / denom, g * nom / denom, b * nom / denom);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(uint8 r, uint8 g, uint8 b)
|
||||
{
|
||||
/* Magic-numbers are ~66% of those used in MakeGrey() */
|
||||
return ((r * 13063) + (g * 25647) + (b * 4981)) / 65536;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a colour grey - based.
|
||||
* @param colour the colour to make grey.
|
||||
|
|
|
@ -141,6 +141,40 @@ inline void Blitter_32bppOptimized::Draw(const Blitter::BlitterParams *bp, ZoomL
|
|||
}
|
||||
break;
|
||||
|
||||
case BM_CRASH_REMAP:
|
||||
if (src_px->a == 255) {
|
||||
do {
|
||||
uint m = *src_n;
|
||||
if (m == 0) {
|
||||
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
|
||||
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
|
||||
} else {
|
||||
uint r = remap[GB(m, 0, 8)];
|
||||
if (r != 0) *dst = this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8));
|
||||
}
|
||||
dst++;
|
||||
src_px++;
|
||||
src_n++;
|
||||
} while (--n != 0);
|
||||
} else {
|
||||
do {
|
||||
uint m = *src_n;
|
||||
if (m == 0) {
|
||||
if (src_px->a != 0) {
|
||||
uint8 g = MakeDark(src_px->r, src_px->g, src_px->b);
|
||||
*dst = ComposeColourRGBA(g, g, g, src_px->a, *dst);
|
||||
}
|
||||
} else {
|
||||
uint r = remap[GB(m, 0, 8)];
|
||||
if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), GB(m, 8, 8)), src_px->a, *dst);
|
||||
}
|
||||
dst++;
|
||||
src_px++;
|
||||
src_n++;
|
||||
} while (--n != 0);
|
||||
}
|
||||
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:
|
||||
|
@ -204,6 +238,7 @@ void Blitter_32bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode,
|
|||
case BM_NORMAL: Draw<BM_NORMAL> (bp, zoom); return;
|
||||
case BM_COLOUR_REMAP: Draw<BM_COLOUR_REMAP>(bp, zoom); return;
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT> (bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP> (bp, zoom); return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,17 @@ void Blitter_32bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoo
|
|||
}
|
||||
break;
|
||||
|
||||
case BM_CRASH_REMAP:
|
||||
if (src->m == 0) {
|
||||
if (src->a != 0) {
|
||||
uint8 g = MakeDark(src->r, src->g, src->b);
|
||||
*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
|
||||
}
|
||||
} else {
|
||||
if (bp->remap[src->m] != 0) *dst = ComposeColourPA(this->AdjustBrightness(this->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:
|
||||
|
|
|
@ -36,6 +36,7 @@ Sprite *Blitter_32bppSSE_Base::Encode(const SpriteLoader::Sprite *sprite, Alloca
|
|||
|
||||
/* Calculate sizes and allocate. */
|
||||
SpriteData sd;
|
||||
memset(&sd, 0, sizeof(sd));
|
||||
uint all_sprites_size = 0;
|
||||
for (ZoomLevel z = zoom_min; z <= zoom_max; z++) {
|
||||
const SpriteLoader::Sprite *src_sprite = &sprite[z];
|
||||
|
|
|
@ -238,13 +238,13 @@ inline void Blitter_32bppSSE4::Draw(const Blitter::BlitterParams *bp, ZoomLevel
|
|||
for (int y = bp->height; y != 0; y--) {
|
||||
Colour *dst = dst_line;
|
||||
const Colour *src = src_rgba_line + META_LENGTH;
|
||||
if (mode == BM_COLOUR_REMAP) src_mv = src_mv_line;
|
||||
if (mode == BM_COLOUR_REMAP || mode == BM_CRASH_REMAP) src_mv = src_mv_line;
|
||||
|
||||
if (read_mode == RM_WITH_MARGIN) {
|
||||
assert(bt_last == BT_NONE); // or you must ensure block type is preserved
|
||||
src += src_rgba_line[0].data;
|
||||
dst += src_rgba_line[0].data;
|
||||
if (mode == BM_COLOUR_REMAP) src_mv += src_rgba_line[0].data;
|
||||
if (mode == BM_COLOUR_REMAP || mode == BM_CRASH_REMAP) src_mv += src_rgba_line[0].data;
|
||||
const int width_diff = si->sprite_width - bp->width;
|
||||
effective_width = bp->width - (int) src_rgba_line[0].data;
|
||||
const int delta_diff = (int) src_rgba_line[1].data - width_diff;
|
||||
|
@ -377,10 +377,27 @@ bmcr_alpha_blend_single:
|
|||
dst->data = _mm_cvtsi128_si32(DarkenTwoPixels(srcABCD, dstABCD, DARKEN_PARAM_1, DARKEN_PARAM_2));
|
||||
}
|
||||
break;
|
||||
|
||||
case BM_CRASH_REMAP:
|
||||
for (uint x = (uint) bp->width; x > 0; x--) {
|
||||
if (src_mv->m == 0) {
|
||||
if (src->a != 0) {
|
||||
uint8 g = MakeDark(src->r, src->g, src->b);
|
||||
*dst = ComposeColourRGBA(g, g, g, src->a, *dst);
|
||||
}
|
||||
} else {
|
||||
uint r = remap[src_mv->m];
|
||||
if (r != 0) *dst = ComposeColourPANoCheck(this->AdjustBrightness(this->LookupColourInPalette(r), src_mv->v), src->a, *dst);
|
||||
}
|
||||
src_mv++;
|
||||
dst++;
|
||||
src++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
next_line:
|
||||
if (mode == BM_COLOUR_REMAP) src_mv_line += si->sprite_width;
|
||||
if (mode == BM_COLOUR_REMAP || mode == BM_CRASH_REMAP) src_mv_line += si->sprite_width;
|
||||
src_rgba_line = (const Colour*) ((const byte*) src_rgba_line + si->sprite_line_size);
|
||||
dst_line += bp->pitch;
|
||||
}
|
||||
|
@ -429,6 +446,7 @@ bm_normal:
|
|||
Draw<BM_COLOUR_REMAP, RM_WITH_MARGIN, BT_NONE, true>(bp, zoom); return;
|
||||
}
|
||||
case BM_TRANSPARENT: Draw<BM_TRANSPARENT, RM_NONE, BT_NONE, true>(bp, zoom); return;
|
||||
case BM_CRASH_REMAP: Draw<BM_CRASH_REMAP, RM_NONE, BT_NONE, true>(bp, zoom); return;
|
||||
}
|
||||
}
|
||||
#endif /* FULL_ANIMATION */
|
||||
|
|
|
@ -83,7 +83,8 @@ void Blitter_8bppOptimized::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Z
|
|||
width -= pixels;
|
||||
|
||||
switch (mode) {
|
||||
case BM_COLOUR_REMAP: {
|
||||
case BM_COLOUR_REMAP:
|
||||
case BM_CRASH_REMAP: {
|
||||
const uint8 *remap = bp->remap;
|
||||
do {
|
||||
uint m = remap[*src];
|
||||
|
|
|
@ -37,6 +37,7 @@ void Blitter_8bppSimple::Draw(Blitter::BlitterParams *bp, BlitterMode mode, Zoom
|
|||
|
||||
switch (mode) {
|
||||
case BM_COLOUR_REMAP:
|
||||
case BM_CRASH_REMAP:
|
||||
colour = bp->remap[*src];
|
||||
break;
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ enum BlitterMode {
|
|||
BM_NORMAL, ///< Perform the simple blitting.
|
||||
BM_COLOUR_REMAP, ///< Perform a colour remapping.
|
||||
BM_TRANSPARENT, ///< Perform transparency colour remapping.
|
||||
BM_CRASH_REMAP, ///< Perform a crash remapping.
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
15
src/gfx.cpp
15
src/gfx.cpp
|
@ -418,19 +418,21 @@ static int DrawLayoutLine(const ParagraphLayouter::Line *line, int y, int left,
|
|||
NOT_REACHED();
|
||||
}
|
||||
|
||||
TextColour colour = TC_BLACK;
|
||||
bool draw_shadow = false;
|
||||
for (int run_index = 0; run_index < line->CountRuns(); run_index++) {
|
||||
const ParagraphLayouter::VisualRun *run = line->GetVisualRun(run_index);
|
||||
const Font *f = (const Font*)run->GetFont();
|
||||
|
||||
FontCache *fc = f->fc;
|
||||
TextColour colour = f->colour;
|
||||
colour = f->colour;
|
||||
SetColourRemap(colour);
|
||||
|
||||
DrawPixelInfo *dpi = _cur_dpi;
|
||||
int dpi_left = dpi->left;
|
||||
int dpi_right = dpi->left + dpi->width - 1;
|
||||
|
||||
bool draw_shadow = fc->GetDrawGlyphShadow() && colour != TC_BLACK;
|
||||
draw_shadow = fc->GetDrawGlyphShadow() && colour != TC_BLACK;
|
||||
|
||||
for (int i = 0; i < run->GetGlyphCount(); i++) {
|
||||
GlyphID glyph = run->GetGlyphs()[i];
|
||||
|
@ -461,6 +463,11 @@ static int DrawLayoutLine(const ParagraphLayouter::Line *line, int y, int left,
|
|||
if (truncation) {
|
||||
int x = (_current_text_dir == TD_RTL) ? left : (right - 3 * dot_width);
|
||||
for (int i = 0; i < 3; i++, x += dot_width) {
|
||||
if (draw_shadow) {
|
||||
SetColourRemap(TC_BLACK);
|
||||
GfxMainBlitter(dot_sprite, x + 1, y + 1, BM_COLOUR_REMAP);
|
||||
SetColourRemap(colour);
|
||||
}
|
||||
GfxMainBlitter(dot_sprite, x, y, BM_COLOUR_REMAP);
|
||||
}
|
||||
}
|
||||
|
@ -788,7 +795,7 @@ void DrawSpriteViewport(SpriteID img, PaletteID pal, int x, int y, const SubSpri
|
|||
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite);
|
||||
} else if (pal != PAL_NONE) {
|
||||
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
|
||||
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_COLOUR_REMAP, sub, real_sprite);
|
||||
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite);
|
||||
} else {
|
||||
GfxMainBlitterViewport(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite);
|
||||
}
|
||||
|
@ -811,7 +818,7 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub,
|
|||
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_TRANSPARENT, sub, real_sprite, zoom);
|
||||
} else if (pal != PAL_NONE) {
|
||||
_colour_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1;
|
||||
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_COLOUR_REMAP, sub, real_sprite, zoom);
|
||||
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, pal == PALETTE_CRASH ? BM_CRASH_REMAP : BM_COLOUR_REMAP, sub, real_sprite, zoom);
|
||||
} else {
|
||||
GfxMainBlitter(GetSprite(real_sprite, ST_NORMAL), x, y, BM_NORMAL, sub, real_sprite, zoom);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,8 @@ IniGroup::IniGroup(IniLoadFile *parent, const char *name, size_t len) : next(NUL
|
|||
if (len == 0) len = strlen(name);
|
||||
|
||||
this->name = strndup(name, len);
|
||||
if (this->name != NULL) str_validate(this->name, this->name + len);
|
||||
if (this->name == NULL) error("not enough memory to allocate group name");
|
||||
str_validate(this->name, this->name + len);
|
||||
|
||||
this->last_item = &this->item;
|
||||
*parent->last_group = this;
|
||||
|
|
|
@ -6736,7 +6736,7 @@ static void ParamSet(ByteReader *buf)
|
|||
if ((int32)src2 < 0) {
|
||||
res = src1 >> -(int32)src2;
|
||||
} else {
|
||||
res = src1 << src2;
|
||||
res = src1 << (src2 & 0x1F); // Same behaviour as in EvalAdjustT, mask 'value' to 5 bits, which should behave the same on all architectures.
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -6744,7 +6744,7 @@ static void ParamSet(ByteReader *buf)
|
|||
if ((int32)src2 < 0) {
|
||||
res = (int32)src1 >> -(int32)src2;
|
||||
} else {
|
||||
res = (int32)src1 << src2;
|
||||
res = (int32)src1 << (src2 & 0x1F); // Same behaviour as in EvalAdjustT, mask 'value' to 5 bits, which should behave the same on all architectures.
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -228,9 +228,9 @@ static U EvalAdjustT(const DeterministicSpriteGroupAdjust *adjust, ScopeResolver
|
|||
case DSGA_OP_ROR: return RotateRight(last_value, value);
|
||||
case DSGA_OP_SCMP: return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
|
||||
case DSGA_OP_UCMP: return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
|
||||
case DSGA_OP_SHL: return (U)last_value << ((U)value & 0x1F); // mask 'value' to 5 bits, which should behave the same on all architectures.
|
||||
case DSGA_OP_SHR: return (U)last_value >> ((U)value & 0x1F);
|
||||
case DSGA_OP_SAR: return (S)last_value >> ((U)value & 0x1F);
|
||||
case DSGA_OP_SHL: return (uint32)(U)last_value << ((U)value & 0x1F); // Same behaviour as in ParamSet, mask 'value' to 5 bits, which should behave the same on all architectures.
|
||||
case DSGA_OP_SHR: return (uint32)(U)last_value >> ((U)value & 0x1F);
|
||||
case DSGA_OP_SAR: return (int32)(S)last_value >> ((U)value & 0x1F);
|
||||
default: return value;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue