Replace some uses of play_sound_panned with play_sound_at_location

This commit is contained in:
Dom Light 2015-11-18 00:03:15 +00:00
parent e9b7e41635
commit bb62b7561a
12 changed files with 55 additions and 54 deletions

View File

@ -32,6 +32,12 @@
#include "../openrct2.h"
#include "../util/util.h"
typedef struct rct_audio_params {
bool in_range;
int volume;
int pan;
} rct_audio_params;
audio_device *gAudioDevices = NULL;
int gAudioDeviceCount;
void *gCrowdSoundChannel = 0;
@ -46,7 +52,7 @@ rct_vehicle_sound gVehicleSoundList[AUDIO_MAX_VEHICLE_SOUNDS];
rct_vehicle_sound_params gVehicleSoundParamsList[AUDIO_MAX_VEHICLE_SOUNDS];
rct_vehicle_sound_params *gVehicleSoundParamsListEnd;
bool audio_get_pan_from_location(int soundId, const rct_xyz16 *location, int *volume, int *pan);
rct_audio_params audio_get_params_from_location(int soundId, const rct_xyz16 *location);
void audio_stop_channel(void **channel);
void audio_init()
@ -99,33 +105,30 @@ int audio_play_sound_at_location(int soundId, sint16 x, sint16 y, sint16 z)
if (gGameSoundsOff)
return 0;
int volume = 0;
int pan = 0;
rct_xyz16 location;
location.x = x;
location.y = y;
location.z = z;
bool success = audio_get_pan_from_location(soundId, &location, &volume, &pan);
if (!success)
rct_audio_params params = audio_get_params_from_location(soundId, &location);
if (!params.in_range)
return soundId;
return audio_play_sound(soundId, volume, pan);
return audio_play_sound(soundId, params.volume, params.pan);
}
/**
* Returns the pan to use when playing the specified sound at a virtual location.
* Returns the audio parameters to use when playing the specified sound at a virtual location.
* @param soundId The sound effect to be played.
* @param location The location at which the sound effect is to be played.
* @param volume [out] The volume at which the sound effect should be played.
* @param pan [out] The pan at which the sound effection should be played.
* @return true if the sound is in range and should be played; otherwise, false.
* @return The audio parameters to be used when playing this sound effect.
*/
bool audio_get_pan_from_location(int soundId, const rct_xyz16 *location, int *volume, int *pan)
rct_audio_params audio_get_params_from_location(int soundId, const rct_xyz16 *location)
{
*volume = 0;
*pan = 0;
int volumeDown = 0;
rct_audio_params params;
params.in_range = true;
rct_map_element *element = map_get_surface_element_at(location->x / 32, location->y / 32);
if (element && (element->base_height * 8) - 5 > location->z)
volumeDown = 10;
@ -144,14 +147,16 @@ bool audio_get_pan_from_location(int soundId, const rct_xyz16 *location, int *vo
sint16 vy = pos2.y - viewport->view_y;
sint16 vx = pos2.x - viewport->view_x;
*pan = viewport->x + (vx >> viewport->zoom);
*volume = RCT2_ADDRESS(0x0099282C, int)[soundId] + ((-1024 * viewport->zoom - 1) << volumeDown) + 1;
params.pan = viewport->x + (vx >> viewport->zoom);
params.volume = RCT2_ADDRESS(0x0099282C, int)[soundId] + ((-1024 * viewport->zoom - 1) << volumeDown) + 1;
if (vy < 0 || vy >= viewport->view_height || vx < 0 || vx >= viewport->view_width || *volume < -10000)
return false;
if (vy < 0 || vy >= viewport->view_height || vx < 0 || vx >= viewport->view_width || params.volume < -10000) {
params.in_range = false;
return params;
}
}
return true;
return params;
}
int audio_play_sound(int soundId, int volume, int pan)

View File

@ -392,7 +392,7 @@ static void sub_68F41A(rct_peep *peep, int index)
}
if (peep->flags & PEEP_FLAGS_EXPLODE && peep->x != (sint16)0x8000){
audio_play_sound_panned(SOUND_CRASH, 0x8001, peep->x, peep->y, peep->z);
audio_play_sound_at_location(SOUND_CRASH, peep->x, peep->y, peep->z);
sprite_misc_3_create(peep->x, peep->y, peep->z + 16);
sprite_misc_5_create(peep->x, peep->y, peep->z + 16);
@ -1029,7 +1029,7 @@ int peep_update_action(sint16* x, sint16* y, sint16* xy_distance, rct_peep* peep
litter_create(peep->x, peep->y, peep->z, peep->sprite_direction, peep->sprite_index & 1);
int sound_id = SOUND_COUGH_1 + (scenario_rand() & 3);
audio_play_sound_panned(sound_id, 0x8001, peep->x, peep->y, peep->z);
audio_play_sound_at_location(sound_id, peep->x, peep->y, peep->z);
invalidate_sprite_2((rct_sprite*)peep);
*x = peep->x;
@ -1141,7 +1141,7 @@ void peep_update_sprite_type(rct_peep* peep)
) {
bl = 1;
audio_play_sound_panned(SOUND_BALLOON_POP, 0x8001, peep->x, peep->y, peep->z);
audio_play_sound_at_location(SOUND_BALLOON_POP, peep->x, peep->y, peep->z);
}
if (peep->x != SPRITE_LOCATION_NULL) {
@ -3161,7 +3161,7 @@ static void peep_update_ride_sub_state_20(rct_peep* peep){
return;
}
audio_play_sound_panned(SOUND_TOILET_FLUSH, 0x8001, peep->x, peep->y, peep->z);
audio_play_sound_at_location(SOUND_TOILET_FLUSH, peep->x, peep->y, peep->z);
peep->sub_state++;
@ -7523,7 +7523,7 @@ static void peep_spend_money(rct_peep *peep, money16 *peep_expend_type, money32
RCT2_GLOBAL(0x00141F568, uint8) = RCT2_GLOBAL(0x0013CA740, uint8);
finance_payment(-amount, RCT2_GLOBAL(RCT2_ADDRESS_NEXT_EXPENDITURE_TYPE, uint8) / 4);
audio_play_sound_panned(SOUND_PURCHASE, 0x8001, peep->x, peep->y, peep->z);
audio_play_sound_at_location(SOUND_PURCHASE, peep->x, peep->y, peep->z);
}
static void peep_set_has_ridden(rct_peep *peep, int rideIndex)

View File

@ -768,7 +768,7 @@ static void window_footpath_place_path_at_point(int x, int y)
// bp = RCT2_ADDRESS_COMMAND_MAP_Z
// dx = RCT2_ADDRESS_COMMAND_MAP_Y
// cx = RCT2_ADDRESS_COMMAND_MAP_X
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_PLACE_ITEM, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
}
}
@ -852,9 +852,8 @@ static void window_footpath_construct()
cost = footpath_place(type, x, y, z, slope, GAME_COMMAND_FLAG_APPLY);
if (cost != MONEY32_UNDEFINED) {
audio_play_sound_panned(
audio_play_sound_at_location(
SOUND_PLACE_ITEM,
0x8001,
RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCT_PATH_FROM_X, uint16),
RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCT_PATH_FROM_Y, uint16),
RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCT_PATH_FROM_Z, uint16)

View File

@ -1289,9 +1289,8 @@ static void window_map_place_park_entrance_tool_down(int x, int y)
if (price == MONEY32_UNDEFINED)
return;
audio_play_sound_panned(
audio_play_sound_at_location(
SOUND_PLACE_ITEM,
0x8001,
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16),
RCT2_GLOBAL(0x009DEA64, uint16),
RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_AGE, uint16)

View File

@ -371,9 +371,8 @@ static void window_maze_construction_entrance_tooldown(int x, int y, rct_window*
if (cost == MONEY32_UNDEFINED)
return;
audio_play_sound_panned(
audio_play_sound_at_location(
SOUND_PLACE_ITEM,
0x8001,
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, sint16),
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, sint16),
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
@ -509,6 +508,6 @@ static void window_maze_construction_construct(int direction)
_currentTrackBeginX = x;
_currentTrackBeginY = y;
if (_rideConstructionState != 7) {
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, x, y, z);
audio_play_sound_at_location(SOUND_PLACE_ITEM, x, y, z);
}
}

View File

@ -1594,7 +1594,7 @@ static void window_ride_construction_construct(rct_window *w)
return;
}
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, x, y, z);
audio_play_sound_at_location(SOUND_PLACE_ITEM, x, y, z);
if (RCT2_GLOBAL(RCT2_ADDRESS_ABOVE_GROUND_FLAGS, uint8) & TRACK_ELEMENT_LOCATION_IS_UNDERGROUND) {
viewport_set_visibility(1);
@ -3571,7 +3571,7 @@ void ride_construction_tooldown_construct(int screenX, int screenY)
}
else {
window_close_by_class(WC_ERROR);
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, _currentTrackBeginX, _currentTrackBeginY, _currentTrackBeginZ);
audio_play_sound_at_location(SOUND_PLACE_ITEM, _currentTrackBeginX, _currentTrackBeginY, _currentTrackBeginZ);
break;
}
}
@ -3680,9 +3680,8 @@ static void ride_construction_tooldown_entrance_exit(int screenX, int screenY)
return;
}
audio_play_sound_panned(
audio_play_sound_at_location(
SOUND_PLACE_ITEM,
0x8001,
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16),
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16),
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16)

View File

@ -1479,7 +1479,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
if (cost != MONEY32_UNDEFINED){
window_close_by_class(WC_ERROR);
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_PLACE_ITEM, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
success = true;
break;
}
@ -1507,7 +1507,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
if (successfulPlacements > 0) {
window_close_by_class(WC_ERROR);
} else {
audio_play_sound_panned(SOUND_ERROR, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_ERROR, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
}
break;
}
@ -1518,7 +1518,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
RCT2_GLOBAL(RCT2_ADDRESS_GAME_COMMAND_ERROR_TITLE, rct_string_id) = STR_CANT_POSITION_THIS_HERE;
int cost = game_do_command(gridX, flags, gridY, parameter_2, GAME_COMMAND_PLACE_PATH, parameter_3, 0);
if (cost != MONEY32_UNDEFINED) {
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_PLACE_ITEM, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
}
break;
}
@ -1542,7 +1542,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
if (cost != MONEY32_UNDEFINED){
window_close_by_class(WC_ERROR);
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_PLACE_ITEM, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
return;
}
@ -1556,7 +1556,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_Z_COORDINATE, sint16) += 8;
}
audio_play_sound_panned(SOUND_ERROR, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_ERROR, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
break;
}
case SCENERY_TYPE_LARGE:
@ -1579,7 +1579,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
if (cost != MONEY32_UNDEFINED){
window_close_by_class(WC_ERROR);
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_PLACE_ITEM, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
return;
}
@ -1593,7 +1593,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
RCT2_GLOBAL(RCT2_ADDRESS_SCENERY_Z_COORDINATE, sint16) += 8;
}
audio_play_sound_panned(SOUND_ERROR, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_ERROR, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
break;
}
case SCENERY_TYPE_BANNER:
@ -1613,7 +1613,7 @@ static void window_top_toolbar_scenery_tool_down(short x, short y, rct_window *w
if (cost != MONEY32_UNDEFINED) {
int bannerId = regs.edi;
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
audio_play_sound_at_location(SOUND_PLACE_ITEM, RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint16), RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint16));
window_banner_open(bannerId);
}
break;

View File

@ -541,7 +541,7 @@ static void window_track_place_tooldown(rct_window* w, int widgetIndex, int x, i
if (cost != MONEY32_UNDEFINED) {
window_close_by_class(WC_ERROR);
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, mapX, mapY, mapZ);
audio_play_sound_at_location(SOUND_PLACE_ITEM, mapX, mapY, mapZ);
RCT2_GLOBAL(0x00F440A7, uint8) = rideIndex;
if (RCT2_GLOBAL(0x00F4414E, uint8) & 1) {
@ -563,7 +563,7 @@ static void window_track_place_tooldown(rct_window* w, int widgetIndex, int x, i
}
// Unable to build track
audio_play_sound_panned(SOUND_ERROR, 0x8001, mapX, mapY, mapZ);
audio_play_sound_at_location(SOUND_ERROR, mapX, mapY, mapZ);
}
/**

View File

@ -26,7 +26,7 @@ void balloon_pop(rct_balloon *balloon)
{
balloon->popped = 1;
balloon->var_26 = 0;
audio_play_sound_panned(SOUND_BALLOON_POP, 0x8001, balloon->x, balloon->y, balloon->z);
audio_play_sound_at_location(SOUND_BALLOON_POP, balloon->x, balloon->y, balloon->z);
}
/**

View File

@ -288,7 +288,7 @@ static void duck_update_fly_away(rct_duck *duck)
*/
void duck_press(rct_duck *duck)
{
audio_play_sound_panned(SOUND_QUACK, 0x8001, duck->x, duck->y, duck->z);
audio_play_sound_at_location(SOUND_QUACK, duck->x, duck->y, duck->z);
}
/**

View File

@ -1606,7 +1606,7 @@ money32 map_set_land_ownership(uint8 flags, sint16 x1, sint16 y1, sint16 x2, sin
y += 16;
sint16 z = map_element_height(x, y) & 0xFFFF;
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, x, y, z);
audio_play_sound_at_location(SOUND_PLACE_ITEM, x, y, z);
return 0;
}
@ -1629,7 +1629,7 @@ money32 raise_land(int flags, int x, int y, int z, int ax, int ay, int bx, int b
money32 cost = 0;
if ((flags & GAME_COMMAND_FLAG_APPLY) && RCT2_GLOBAL(0x009A8C28, uint8) == 1) {
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, x, y, z);
audio_play_sound_at_location(SOUND_PLACE_ITEM, x, y, z);
}
uint8 min_height = 0xFF;
@ -1685,7 +1685,7 @@ money32 lower_land(int flags, int x, int y, int z, int ax, int ay, int bx, int b
money32 cost = 0;
if ((flags & GAME_COMMAND_FLAG_APPLY) && RCT2_GLOBAL(0x009A8C28, uint8) == 1) {
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, x, y, z);
audio_play_sound_at_location(SOUND_PLACE_ITEM, x, y, z);
}
uint8 max_height = 0;
@ -1808,7 +1808,7 @@ money32 raise_water(sint16 x0, sint16 y0, sint16 x1, sint16 y1, uint8 flags)
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint32) = x;
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint32) = y;
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint32) = z;
audio_play_sound_panned(SOUND_LAYING_OUT_WATER, 0x8001, x, y, z);
audio_play_sound_at_location(SOUND_LAYING_OUT_WATER, x, y, z);
}
// Force ride construction to recheck area
@ -1873,7 +1873,7 @@ money32 lower_water(sint16 x0, sint16 y0, sint16 x1, sint16 y1, uint8 flags)
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_X, uint32) = x;
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Y, uint32) = y;
RCT2_GLOBAL(RCT2_ADDRESS_COMMAND_MAP_Z, uint32) = z;
audio_play_sound_panned(SOUND_LAYING_OUT_WATER, 0x8001, x, y, z);
audio_play_sound_at_location(SOUND_LAYING_OUT_WATER, x, y, z);
}
// Force ride construction to recheck area
@ -2030,7 +2030,7 @@ money32 smooth_land(int flags, int centreX, int centreY, int mapLeft, int mapTop
// Play sound (only once)
if ((flags & GAME_COMMAND_FLAG_APPLY) && RCT2_GLOBAL(0x009A8C28, uint8) == 1) {
audio_play_sound_panned(SOUND_PLACE_ITEM, 0x8001, centreX, centreY, centreZ);
audio_play_sound_at_location(SOUND_PLACE_ITEM, centreX, centreY, centreZ);
}
money32 totalCost = 0;

View File

@ -71,7 +71,7 @@ void crashed_vehicle_particle_update(rct_crashed_vehicle_particle *particle)
if (waterZ != 0 && particle->z >= waterZ && z <= waterZ) {
// Splash
audio_play_sound_panned(SOUND_WATER_2, 0x8001, particle->x, particle->y, waterZ);
audio_play_sound_at_location(SOUND_WATER_2, particle->x, particle->y, waterZ);
crash_splash_create(particle->x, particle->y, waterZ);
sprite_remove((rct_sprite*)particle);
return;