25static std::vector<SoundEntry> _sounds;
35 size_t pos = _sounds.size();
36 _sounds.insert(_sounds.end(), num,
SoundEntry());
41void InitializeSoundPool()
52 if (index >= _sounds.size())
return nullptr;
53 return &_sounds[index];
59 return (uint)_sounds.size();
70 if (sound.data ==
nullptr)
continue;
72 const auto &data = *sound.data;
73 bytes += data.capacity() *
sizeof(data[0]);
85 if (sound.file_offset == SIZE_MAX || sound.file ==
nullptr)
return false;
88 file.
SeekTo(sound.file_offset, SEEK_SET);
97 if (file.
ReadByte() != 0xFF)
return false;
98 if (file.
ReadByte() != 0xFF)
return false;
101 std::string name(name_len + 1,
'\0');
102 file.
ReadBlock(name.data(), name_len + 1);
105 if (name[name_len] !=
'\0') {
110 if (LoadSoundData(sound,
true, sound_id,
StrMakeValid(name)))
return true;
131 if (file ==
nullptr || sound_id >= file->num_sounds)
return INVALID_SOUND;
133 return file->sound_offset + sound_id;
151 if (file ==
nullptr)
return false;
163 if (callback == INVALID_SOUND)
return true;
165 assert(callback < GetNumSounds());
166 SndPlayVehicleFx(callback, v);
179 if (sound_id == INVALID_SOUND)
return;
181 assert(sound_id < GetNumSounds());
182 SndPlayTileFx(sound_id, tile);
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
A file from which bytes, words and double words are read in (potentially) a random order.
void ReadBlock(void *ptr, size_t size)
Read a block.
void SeekTo(size_t pos, int mode)
Seek in the current file.
uint8_t ReadByte()
Read a byte from the file.
const std::string & GetSimplifiedFilename() const
Get the simplified filename of the opened file.
uint32_t ReadDword()
Read a double word (32 bits) from the file (in low endian format).
uint16_t ReadWord()
Read a word (16 bits) from the file (in low endian format).
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Base for the NewGRF implementation.
@ CBID_VEHICLE_SOUND_EFFECT
Called to play a special sound effect.
@ CBM_VEHICLE_SOUND_EFFECT
Vehicle uses custom sound effects.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Functions for NewGRF engines.
SoundEntry * AllocateSound(uint num)
Allocate sound slots.
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
bool LoadNewGRFSound(SoundEntry &sound, SoundID sound_id)
Extract meta data from a NewGRF sound.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force)
Checks whether a NewGRF wants to play a different vehicle sound effect.
size_t GetSoundPoolAllocatedMemory()
Get size of memory allocated to sound effects.
SoundID GetNewGRFSoundID(const GRFFile *file, SoundID sound_id)
Resolve NewGRF sound ID.
Functions related to NewGRF provided sounds.
VehicleSoundEvent
Events at which a sound might be played.
Class related to random access to files.
A number of safeguards to prevent using unsafe methods.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
Functions related to sound.
static const uint ORIGINAL_SAMPLE_COUNT
The number of sounds in the original sample.cat.
Functions related to sound loaders.
Definition of base types and functions in a cross-platform compatible way.
static void StrMakeValid(T &dst, const char *str, const char *last, StringValidationSettings settings)
Copies the valid (UTF-8) characters from str up to last to the dst.
Functions related to low-level strings.
SoundSettings sound
sound effect settings
uint16_t callback_mask
Bitmask of vehicle callbacks that have to be called.
Dynamic data of a loaded NewGRF.
uint8_t grf_container_ver
NewGRF container version if the sound is from a NewGRF.
bool vehicle
Play vehicle sound effects.
EngineID engine_type
The type of engine used for this vehicle.
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
Base class for all vehicles.