* Decide 'where' (between left and right speaker) to play the sound effect. * Note: Callers must determine if sound effects are enabled. This plays a sound regardless of the setting. * @param sound Sound effect to play * @param left Left edge of virtual coordinates where the sound is produced * @param right Right edge of virtual coordinates where the sound is produced * @param top Top e
| 200 | * @param bottom Bottom edge of virtual coordinates where the sound is produced |
| 201 | */ |
| 202 | static void SndPlayScreenCoordFx(SoundID sound, int left, int right, int top, int bottom) |
| 203 | { |
| 204 | /* Iterate from back, so that main viewport is checked first */ |
| 205 | for (const Window *w : Window::IterateFromBack()) { |
| 206 | if (w->viewport == nullptr) continue; |
| 207 | |
| 208 | const Viewport &vp = *w->viewport; |
| 209 | if (left < vp.virtual_left + vp.virtual_width && right > vp.virtual_left && |
| 210 | top < vp.virtual_top + vp.virtual_height && bottom > vp.virtual_top) { |
| 211 | int screen_x = (left + right) / 2 - vp.virtual_left; |
| 212 | int width = (vp.virtual_width == 0 ? 1 : vp.virtual_width); |
| 213 | float panning = (float)screen_x / width; |
| 214 | |
| 215 | StartSound( |
| 216 | sound, |
| 217 | panning, |
| 218 | _vol_factor_by_zoom[to_underlying(vp.zoom)] |
| 219 | ); |
| 220 | return; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void SndPlayTileFx(SoundID sound, TileIndex tile) |
| 226 | { |
no test coverage detected