changeset 11934:f65c82141aa9 draft

(svn r16337) -Codechange: remove pointless variable + wrapper function; having it return anything else than ORIGINAL_SAMPLE_COUNT is asking for NewGRFs failing to load (due to invalid sample index), thus desyncs
author rubidium <rubidium@openttd.org>
date Sun, 17 May 2009 14:57:14 +0000
parents 6734ebc1fa61
children afd8caa1ae0d
files src/newgrf.cpp src/newgrf_sound.cpp src/sound.cpp src/sound_func.h src/sound_type.h
diffstat 5 files changed, 7 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -2020,7 +2020,7 @@
 	}
 
 	for (int i = 0; i < numinfo; i++) {
-		uint sound = sid + i + _cur_grffile->sound_offset - GetNumOriginalSounds();
+		uint sound = sid + i + _cur_grffile->sound_offset - ORIGINAL_SAMPLE_COUNT;
 
 		if (sound >= GetNumSounds()) {
 			grfmsg(1, "SoundEffectChangeInfo: Sound %d not defined (max %d)", sound, GetNumSounds());
--- a/src/newgrf_sound.cpp
+++ b/src/newgrf_sound.cpp
@@ -60,7 +60,7 @@
 
 	callback = GetVehicleCallback(CBID_VEHICLE_SOUND_EFFECT, event, 0, v->engine_type, v);
 	if (callback == CALLBACK_FAILED) return false;
-	if (callback >= GetNumOriginalSounds()) callback += file->sound_offset - GetNumOriginalSounds();
+	if (callback >= ORIGINAL_SAMPLE_COUNT) callback += file->sound_offset - ORIGINAL_SAMPLE_COUNT;
 
 	if (callback < GetNumSounds()) SndPlayVehicleFx((SoundFx)callback, v);
 	return true;
@@ -68,7 +68,7 @@
 
 bool PlayTileSound(const GRFFile *file, uint16 sound_id, TileIndex tile)
 {
-	if (sound_id >= GetNumOriginalSounds()) sound_id += file->sound_offset - GetNumOriginalSounds();
+	if (sound_id >= ORIGINAL_SAMPLE_COUNT) sound_id += file->sound_offset - ORIGINAL_SAMPLE_COUNT;
 
 	if (sound_id < GetNumSounds()) {
 		SndPlayTileFx((SoundFx)sound_id, tile);
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -13,20 +13,15 @@
 #include "vehicle_base.h"
 #include "debug.h"
 
-static uint _file_count;
 static FileEntry *_files;
 MusicFileSettings msf;
 
 /* Number of levels of panning per side */
 #define PANNING_LEVELS 16
 
-/** The number of sounds in the original sample.cat */
-static const uint ORIGINAL_SAMPLE_COUNT = 73;
-
 static void OpenBankFile(const char *filename)
 {
 	FileEntry *fe = CallocT<FileEntry>(ORIGINAL_SAMPLE_COUNT);
-	_file_count = ORIGINAL_SAMPLE_COUNT;
 	_files = fe;
 
 	FioOpenFile(SOUND_SLOT, filename);
@@ -99,11 +94,6 @@
 	}
 }
 
-uint GetNumOriginalSounds()
-{
-	return _file_count;
-}
-
 static bool SetBankSource(MixerChannel *mc, const FileEntry *fe)
 {
 	assert(fe != NULL);
@@ -187,7 +177,7 @@
 
 void SndCopyToPool()
 {
-	for (uint i = 0; i < _file_count; i++) {
+	for (uint i = 0; i < ORIGINAL_SAMPLE_COUNT; i++) {
 		FileEntry *orig = &_files[_sound_idx[i]];
 		FileEntry *fe = AllocateFileEntry();
 
--- a/src/sound_func.h
+++ b/src/sound_func.h
@@ -12,7 +12,6 @@
 extern MusicFileSettings msf;
 
 bool SoundInitialize(const char *filename);
-uint GetNumOriginalSounds();
 
 void SndPlayTileFx(SoundFx sound, TileIndex tile);
 void SndPlayVehicleFx(SoundFx sound, const Vehicle *v);
--- a/src/sound_type.h
+++ b/src/sound_type.h
@@ -110,4 +110,7 @@
 template <> struct EnumPropsT<SoundFx> : MakeEnumPropsT<SoundFx, byte, SND_BEGIN, SND_END, SND_END> {};
 typedef TinyEnumT<SoundFx> SoundFxByte;
 
+/** The number of sounds in the original sample.cat */
+static const uint ORIGINAL_SAMPLE_COUNT = 73;
+
 #endif /* SOUND_TYPE_H */