* Register an instance of audible ride music for this frame at the given coordinates. */
| 380 | * Register an instance of audible ride music for this frame at the given coordinates. |
| 381 | */ |
| 382 | void UpdateMusicInstance(Ride& ride, const CoordsXYZ& rideCoords, uint16_t sampleRate) |
| 383 | { |
| 384 | if (gLegacyScene != LegacyScene::scenarioEditor && !gGameSoundsOff && gMusicTrackingViewport != nullptr) |
| 385 | { |
| 386 | auto rotatedCoords = Translate3DTo2DWithZ(GetCurrentRotation(), rideCoords); |
| 387 | auto viewport = gMusicTrackingViewport; |
| 388 | auto viewWidth = viewport->ViewWidth(); |
| 389 | auto viewWidth2 = viewWidth * 2; |
| 390 | auto viewX = viewport->viewPos.x - viewWidth2; |
| 391 | auto viewY = viewport->viewPos.y - viewWidth; |
| 392 | auto viewX2 = viewWidth2 + viewWidth2 + viewport->ViewWidth() + viewX; |
| 393 | auto viewY2 = viewWidth + viewWidth + viewport->ViewHeight() + viewY; |
| 394 | if (viewX >= rotatedCoords.x || viewY >= rotatedCoords.y || viewX2 < rotatedCoords.x || viewY2 < rotatedCoords.y) |
| 395 | { |
| 396 | RideUpdateMusicPosition(ride); |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | auto x2 = (viewport->pos.x + viewport->zoom.ApplyInversedTo(rotatedCoords.x - viewport->viewPos.x)) * 0x10000; |
| 401 | auto screenWidth = std::max(ContextGetWidth(), 64); |
| 402 | auto panX = ((x2 / screenWidth) - 0x8000) >> 4; |
| 403 | |
| 404 | auto y2 = (viewport->pos.y + viewport->zoom.ApplyInversedTo(rotatedCoords.y - viewport->viewPos.y)) * 0x10000; |
| 405 | auto screenHeight = std::max(ContextGetHeight(), 64); |
| 406 | auto panY = ((y2 / screenHeight) - 0x8000) >> 4; |
| 407 | |
| 408 | auto volX = CalculateVolume(panX); |
| 409 | auto volY = CalculateVolume(panY); |
| 410 | auto volXY = std::min(volX, volY); |
| 411 | if (volXY < gVolumeAdjustZoom * 3) |
| 412 | { |
| 413 | volXY = 0; |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | volXY = volXY - (gVolumeAdjustZoom * 3); |
| 418 | } |
| 419 | |
| 420 | int16_t newVolume = -((static_cast<uint8_t>(-volXY - 1) * static_cast<uint8_t>(-volXY - 1)) / 16) - 700; |
| 421 | if (volXY != 0 && newVolume >= -4000) |
| 422 | { |
| 423 | auto newPan = std::clamp(panX, -10000, 10000); |
| 424 | RideUpdateMusicPosition(ride, newVolume, newPan, sampleRate); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | RideUpdateMusicPosition(ride); |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | } // namespace OpenRCT2::RideAudio |
no test coverage detected