1
0
Fork 0

(svn r24074) [1.2] -Backport from trunk:

- Fix: With certain versions of GCC and compiler flags the compiler could reorder some code badly causing the 32bpp depot flag not working [FS#5125] (r24063)
- Fix: Do not freeze aircraft mid-flight when skipping to an out-of-range destination [FS#5123] (r24060)
- Fix: Crash when timetabling a maximum travel speed of 0 [FS#5111] (r24053)
- Fix: [NewGRF] Imported GRF sounds were inserted into the wrong slots [FS#5107] (r24052)
- Fix: [NewGRF] Realsprites inside the action 11 block were not skipped correctly (r24050)
release/1.2
rubidium 2012-03-26 20:38:53 +00:00
parent 12fac2345e
commit 557be445af
6 changed files with 52 additions and 25 deletions

View File

@ -1894,7 +1894,7 @@ static bool AircraftEventHandler(Aircraft *v, int loop)
if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return true; if (v->current_order.IsType(OT_LOADING) || v->current_order.IsType(OT_LEAVESTATION)) return true;
if (v->state == FLYING) { if (v->state >= ENDTAKEOFF && v->state <= HELIENDLANDING) {
/* If we are flying, unconditionally clear the 'dest too far' state. */ /* If we are flying, unconditionally clear the 'dest too far' state. */
AircraftHandleDestTooFar(v, false); AircraftHandleDestTooFar(v, false);
} else if (v->acache.cached_max_range_sqr != 0) { } else if (v->acache.cached_max_range_sqr != 0) {

View File

@ -6688,13 +6688,12 @@ static void ParamSet(ByteReader *buf)
break; break;
case 0x9E: // Miscellaneous GRF features case 0x9E: // Miscellaneous GRF features
_misc_grf_features = res;
/* Set train list engine width */ /* Set train list engine width */
_cur.grffile->traininfo_vehicle_width = HasGrfMiscBit(GMB_TRAIN_WIDTH_32_PIXELS) ? VEHICLEINFO_FULL_VEHICLE_WIDTH : TRAININFO_DEFAULT_VEHICLE_WIDTH; _cur.grffile->traininfo_vehicle_width = HasBit(res, GMB_TRAIN_WIDTH_32_PIXELS) ? VEHICLEINFO_FULL_VEHICLE_WIDTH : TRAININFO_DEFAULT_VEHICLE_WIDTH;
/* Remove the local flags from the global flags */ /* Remove the local flags from the global flags */
ClrBit(_misc_grf_features, GMB_TRAIN_WIDTH_32_PIXELS); ClrBit(res, GMB_TRAIN_WIDTH_32_PIXELS);
_misc_grf_features = res;
break; break;
case 0x9F: // locale-dependent settings case 0x9F: // locale-dependent settings
@ -6874,10 +6873,13 @@ static void DefineGotoLabel(ByteReader *buf)
grfmsg(2, "DefineGotoLabel: GOTO target with label 0x%02X", label->label); grfmsg(2, "DefineGotoLabel: GOTO target with label 0x%02X", label->label);
} }
static void ImportGRFSound() /**
* Process a sound import from another GRF file.
* @param sound Destination for sound.
*/
static void ImportGRFSound(SoundEntry *sound)
{ {
const GRFFile *file; const GRFFile *file;
SoundEntry *sound = AllocateSound();
uint32 grfid = FioReadDword(); uint32 grfid = FioReadDword();
SoundID sound_id = FioReadWord(); SoundID sound_id = FioReadWord();
@ -6901,10 +6903,13 @@ static void ImportGRFSound()
sound->priority = 0; sound->priority = 0;
} }
static void LoadGRFSound(size_t offs) /**
* Load a sound from a file.
* @param offs File offset to read sound from.
* @param sound Destination for sound.
*/
static void LoadGRFSound(size_t offs, SoundEntry *sound)
{ {
SoundEntry *sound = AllocateSound();
/* Set default volume and priority */ /* Set default volume and priority */
sound->volume = 0x80; sound->volume = 0x80;
sound->priority = 0; sound->priority = 0;
@ -6925,15 +6930,24 @@ static void GRFSound(ByteReader *buf)
* W num Number of sound files that follow */ * W num Number of sound files that follow */
uint16 num = buf->ReadWord(); uint16 num = buf->ReadWord();
if (num == 0) return;
SoundEntry *sound;
if (_cur.grffile->sound_offset == 0) { if (_cur.grffile->sound_offset == 0) {
_cur.grffile->sound_offset = GetNumSounds(); _cur.grffile->sound_offset = GetNumSounds();
_cur.grffile->num_sounds = num; _cur.grffile->num_sounds = num;
sound = AllocateSound(num);
} else {
sound = GetSound(_cur.grffile->sound_offset);
} }
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
_cur.nfo_line++; _cur.nfo_line++;
/* Check whether the index is in range. This might happen if multiple action 11 are present.
* While this is invalid, we do not check for this. But we should prevent it from causing bigger trouble */
bool invalid = i >= _cur.grffile->num_sounds;
size_t offs = FioGetPos(); size_t offs = FioGetPos();
uint32 len = _cur.grf_container_ver >= 2 ? FioReadDword() : FioReadWord(); uint32 len = _cur.grf_container_ver >= 2 ? FioReadDword() : FioReadWord();
@ -6941,12 +6955,15 @@ static void GRFSound(ByteReader *buf)
if (_cur.grf_container_ver >= 2 && type == 0xFD) { if (_cur.grf_container_ver >= 2 && type == 0xFD) {
/* Reference to sprite section. */ /* Reference to sprite section. */
if (len != 4) { if (invalid) {
grfmsg(1, "GRFSound: Sound index out of range (multiple Action 11?)");
FioSkipBytes(len);
} else if (len != 4) {
grfmsg(1, "GRFSound: Invalid sprite section import"); grfmsg(1, "GRFSound: Invalid sprite section import");
FioSkipBytes(len); FioSkipBytes(len);
} else { } else {
uint32 id = FioReadDword(); uint32 id = FioReadDword();
if (_cur.stage == GLS_INIT) LoadGRFSound(GetGRFSpriteOffset(id)); if (_cur.stage == GLS_INIT) LoadGRFSound(GetGRFSpriteOffset(id), sound + i);
} }
continue; continue;
} }
@ -6954,10 +6971,15 @@ static void GRFSound(ByteReader *buf)
if (type != 0xFF) { if (type != 0xFF) {
grfmsg(1, "GRFSound: Unexpected RealSprite found, skipping"); grfmsg(1, "GRFSound: Unexpected RealSprite found, skipping");
FioSkipBytes(7); FioSkipBytes(7);
SkipSpriteData(type, num - 8); SkipSpriteData(type, len - 8);
continue; continue;
} }
if (invalid) {
grfmsg(1, "GRFSound: Sound index out of range (multiple Action 11?)");
FioSkipBytes(len);
}
byte action = FioReadByte(); byte action = FioReadByte();
switch (action) { switch (action) {
case 0xFF: case 0xFF:
@ -6966,7 +6988,7 @@ static void GRFSound(ByteReader *buf)
if (_cur.grf_container_ver >= 2) { if (_cur.grf_container_ver >= 2) {
grfmsg(1, "GRFSound: Inline sounds are not supported for container version >= 2"); grfmsg(1, "GRFSound: Inline sounds are not supported for container version >= 2");
} else { } else {
LoadGRFSound(offs); LoadGRFSound(offs, sound + i);
} }
} }
FioSkipBytes(len - 1); // <type> is not included in the length for pseudo-sprites. FioSkipBytes(len - 1); // <type> is not included in the length for pseudo-sprites.
@ -6977,7 +6999,7 @@ static void GRFSound(ByteReader *buf)
/* XXX 'Action 0xFE' isn't really specified. It is only mentioned for /* XXX 'Action 0xFE' isn't really specified. It is only mentioned for
* importing sounds, so this is probably all wrong... */ * importing sounds, so this is probably all wrong... */
if (FioReadByte() != 0) grfmsg(1, "GRFSound: Import type mismatch"); if (FioReadByte() != 0) grfmsg(1, "GRFSound: Import type mismatch");
ImportGRFSound(); ImportGRFSound(sound + i);
} else { } else {
FioSkipBytes(len - 1); FioSkipBytes(len - 1);
} }

View File

@ -22,11 +22,15 @@
static SmallVector<SoundEntry, 8> _sounds; static SmallVector<SoundEntry, 8> _sounds;
/* Allocate a new Sound */ /**
SoundEntry *AllocateSound() * Allocate sound slots.
* @param num Number of slots to allocate.
* @return First allocated slot.
*/
SoundEntry *AllocateSound(uint num)
{ {
SoundEntry *sound = _sounds.Append(); SoundEntry *sound = _sounds.Append(num);
MemSetT(sound, 0); MemSetT(sound, 0, num);
return sound; return sound;
} }

View File

@ -30,7 +30,7 @@ enum VehicleSoundEvent {
}; };
SoundEntry *AllocateSound(); SoundEntry *AllocateSound(uint num);
void InitializeSoundPool(); void InitializeSoundPool();
bool LoadNewGRFSound(SoundEntry *sound); bool LoadNewGRFSound(SoundEntry *sound);
SoundEntry *GetSound(SoundID sound_id); SoundEntry *GetSound(SoundID sound_id);

View File

@ -218,11 +218,11 @@ static const byte _sound_idx[] = {
void SndCopyToPool() void SndCopyToPool()
{ {
SoundEntry *sound = AllocateSound(ORIGINAL_SAMPLE_COUNT);
for (uint i = 0; i < ORIGINAL_SAMPLE_COUNT; i++) { for (uint i = 0; i < ORIGINAL_SAMPLE_COUNT; i++) {
SoundEntry *sound = AllocateSound(); sound[i] = _original_sounds[_sound_idx[i]];
*sound = _original_sounds[_sound_idx[i]]; sound[i].volume = _sound_base_vol[i];
sound->volume = _sound_base_vol[i]; sound[i].priority = 0;
sound->priority = 0;
} }
} }

View File

@ -118,6 +118,7 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
case MTF_TRAVEL_SPEED: case MTF_TRAVEL_SPEED:
max_speed = GB(p2, 0, 16); max_speed = GB(p2, 0, 16);
if (max_speed == 0) max_speed = UINT16_MAX; // Disable speed limit.
break; break;
default: default: