OpenTTD Source: src/newgrf_sound.cpp File Reference

OpenTTD Source 15.3

Functions | Variables
newgrf_sound.cpp File Reference

Handling NewGRF provided sounds. More...

`#include "stdafx.h"`
`#include "engine_base.h"`
`#include "newgrf.h"`
`#include "newgrf_engine.h"`
`#include "newgrf_sound.h"`
`#include "vehicle_base.h"`
`#include "sound_func.h"`
`#include "soundloader_func.h"`
`#include "string_func.h"`
`#include "random_access_file_type.h"`
`#include "debug.h"`
`#include "settings_type.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Functions
SoundEntry * | AllocateSound (uint num)
| Allocate sound slots.
void | InitializeSoundPool ()
SoundEntry * | GetSound (SoundID index)
uint | GetNumSounds ()
size_t | GetSoundPoolAllocatedMemory ()
| Get size of memory allocated to sound effects.
bool | LoadNewGRFSound (SoundEntry &sound, SoundID sound_id)
| Extract meta data from a NewGRF sound.
SoundID | GetNewGRFSoundID (const GRFFile *file, SoundID sound_id)
| Resolve NewGRF sound ID.
bool | PlayVehicleSound (const Vehicle *v, VehicleSoundEvent event, bool force)
| Checks whether a NewGRF wants to play a different vehicle sound effect.
void | PlayTileSound (const GRFFile *file, SoundID sound_id, TileIndex tile)
| Play a NewGRF sound effect at the location of a specific tile.

## Variables
static std::vector< SoundEntry > | _sounds

## Detailed Description

Handling NewGRF provided sounds.

Definition in file newgrf_sound.cpp.

## Function Documentation

## ◆ AllocateSound()

SoundEntry * AllocateSound | ( | uint | num | ) |

Allocate sound slots.

Parameters

  num | Number of slots to allocate.

Returns
  First allocated slot.

Definition at line 33 of file newgrf_sound.cpp.

## ◆ GetNewGRFSoundID()

SoundID GetNewGRFSoundID | ( | const GRFFile * | file,
|  | SoundID | sound_id
| ) |  |

Resolve NewGRF sound ID.

Parameters

  file | NewGRF to get sound from.
  sound_id | GRF-specific sound ID. (GRF-local for IDs above ORIGINAL_SAMPLE_COUNT)

Returns
  Translated (global) sound ID, or INVALID_SOUND.

Definition at line 125 of file newgrf_sound.cpp.

References ORIGINAL_SAMPLE_COUNT.

Referenced by AircraftVehicleChangeInfo(), PlayTileSound(), PlayVehicleSound(), RoadVehicleChangeInfo(), and ShipVehicleChangeInfo().

## ◆ GetNumSounds()

uint GetNumSounds | ( |  | ) |

Definition at line 57 of file newgrf_sound.cpp.

## ◆ GetSound()

SoundEntry * GetSound | ( | SoundID | index | ) |

Definition at line 50 of file newgrf_sound.cpp.

## ◆ GetSoundPoolAllocatedMemory()

size_t GetSoundPoolAllocatedMemory | ( |  | ) |

Get size of memory allocated to sound effects.

Returns
  Approximate memory allocated by loaded sound effects.

Definition at line 66 of file newgrf_sound.cpp.

## ◆ InitializeSoundPool()

void InitializeSoundPool | ( |  | ) |

Definition at line 41 of file newgrf_sound.cpp.

## ◆ LoadNewGRFSound()

bool LoadNewGRFSound | ( | SoundEntry & | sound,
|  | SoundID | sound_id
| ) |  |

Extract meta data from a NewGRF sound.

Parameters

  sound | Sound to load.

Returns
  True if a valid sound was loaded.

Definition at line 83 of file newgrf_sound.cpp.

References Debug, RandomAccessFile::GetSimplifiedFilename(), SoundEntry::grf_container_ver, RandomAccessFile::ReadBlock(), RandomAccessFile::ReadByte(), RandomAccessFile::ReadDword(), RandomAccessFile::ReadWord(), RandomAccessFile::SeekTo(), and StrMakeValid().

## ◆ PlayTileSound()

void PlayTileSound | ( | const GRFFile * | file,
|  | SoundID | sound_id,
|  | TileIndex | tile
| ) |  |

Play a NewGRF sound effect at the location of a specific tile.

Parameters

  file | NewGRF triggering the sound effect.
  sound_id | Sound effect the NewGRF wants to play.
  tile | Location of the effect.

Definition at line 176 of file newgrf_sound.cpp.

References GetNewGRFSoundID().

Referenced by AmbientSoundEffectCallback(), AnimationBase< Tbase, Tspec, Tobj, Textra, GetCallback, Tframehelper >::AnimateTile(), and AnimationBase< Tbase, Tspec, Tobj, Textra, GetCallback, Tframehelper >::ChangeAnimationFrame().

## ◆ PlayVehicleSound()

bool PlayVehicleSound | ( | const Vehicle * | v,
|  | VehicleSoundEvent | event,
|  | bool | force
| ) |  |

Checks whether a NewGRF wants to play a different vehicle sound effect.

Parameters

  v | Vehicle to play sound effect for.
  event | Trigger for the sound effect.
  force | Should we play the sound effect even if vehicle sound effects are muted?

Returns
  false if the default sound effect shall be played instead.

Definition at line 143 of file newgrf_sound.cpp.

References _settings_client, CALLBACK_FAILED, EngineInfo::callback_mask, CBID_VEHICLE_SOUND_EFFECT, Vehicle::engine_type, Vehicle::GetGRF(), GetNewGRFSoundID(), GetVehicleCallback(), ClientSettings::sound, SoundEffect, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), and SoundSettings::vehicle.

Referenced by AircraftController(), AircraftLandAirplane(), Vehicle::HandleBreakdown(), Ship::PlayLeaveStationSound(), Train::PlayLeaveStationSound(), and Vehicle::ShowVisualEffect().

## Variable Documentation

## ◆ _sounds

std::vector<SoundEntry> _sounds
| static

Definition at line 25 of file newgrf_sound.cpp.