OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
23 static std::vector<SoundEntry> _sounds;
33 size_t pos = _sounds.size();
34 _sounds.insert(_sounds.end(), num,
SoundEntry());
39 void InitializeSoundPool()
50 if (index >= _sounds.size())
return nullptr;
51 return &_sounds[index];
57 return (uint)_sounds.size();
68 if (sound->file_offset == SIZE_MAX || sound->file ==
nullptr)
return false;
71 file.
SeekTo(sound->file_offset, SEEK_SET);
80 if (file.
ReadByte() != 0xFF)
return false;
81 if (file.
ReadByte() != 0xFF)
return false;
84 char *name =
AllocaM(
char, name_len + 1);
88 if (name[name_len] != 0) {
101 uint header_size = 11;
103 if (total_size + name_len + header_size > num) {
113 while (total_size >= 8) {
117 if (total_size < size) {
126 if (size < 16 || file.
ReadWord() != 1) {
134 sound->bits_per_sample = file.
ReadWord();
141 sound->file_size = size;
142 sound->file_offset = file.
GetPos();
144 Debug(grf, 2,
"LoadNewGRFSound [{}]: channels {}, sample rate {}, bits per sample {}, length {}", file.
GetSimplifiedFilename(), sound->channels, sound->rate, sound->bits_per_sample, size);
175 if (file ==
nullptr || sound_id >= file->num_sounds)
return INVALID_SOUND;
177 return file->sound_offset + sound_id;
194 if (file ==
nullptr)
return false;
206 if (callback == INVALID_SOUND)
return true;
208 assert(callback < GetNumSounds());
209 SndPlayVehicleFx(callback, v);
222 if (sound_id == INVALID_SOUND)
return;
224 assert(sound_id < GetNumSounds());
225 SndPlayTileFx(sound_id, tile);
SoundEntry * AllocateSound(uint num)
Allocate sound slots.
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event)
Checks whether a NewGRF wants to play a different vehicle sound effect.
uint32 TileIndex
The index/ID of a Tile.
@ CBM_VEHICLE_SOUND_EFFECT
Vehicle uses custom sound effects.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
const GRFFile * GetGRF() const
Retrieve the NewGRF the vehicle is tied to.
ClientSettings _settings_client
The current settings for this game.
SoundID GetNewGRFSoundID(const GRFFile *file, SoundID sound_id)
Resolve NewGRF sound ID.
byte grf_container_ver
NewGRF container version if the sound is from a NewGRF.
uint16 GetVehicleCallback(CallbackID callback, uint32 param1, uint32 param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
void ReadBlock(void *ptr, size_t size)
Read a block.
byte ReadByte()
Read a byte from the file.
void SkipBytes(int n)
Skip n bytes ahead in the file.
bool LoadNewGRFSound(SoundEntry *sound)
Extract meta data from a NewGRF sound.
void PlayTileSound(const GRFFile *file, SoundID sound_id, TileIndex tile)
Play a NewGRF sound effect at the location of a specific tile.
SoundSettings sound
sound effect settings
@ CBID_VEHICLE_SOUND_EFFECT
Called to play a special sound effect.
EngineID engine_type
The type of engine used for this vehicle.
static uint32 BSWAP32(uint32 x)
Perform a 32 bits endianness bitswap on x.
uint16 ReadWord()
Read a word (16 bits) from the file (in low endian format).
uint32 ReadDword()
Read a double word (32 bits) from the file (in low endian format).
size_t GetPos() const
Get position in the file.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
bool vehicle
Play vehicle sound effects.
static const uint ORIGINAL_SAMPLE_COUNT
The number of sounds in the original sample.cat.
const std::string & GetSimplifiedFilename() const
Get the simplified filename of the opened file.
void SeekTo(size_t pos, int mode)
Seek in the current file.
VehicleSoundEvent
Events at which a sound might be played.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Dynamic data of a loaded NewGRF.
A file from which bytes, words and double words are read in (potentially) a random order.
#define AllocaM(T, num_elements)
alloca() has to be called in the parent function, so define AllocaM() as a macro