* * rct2: 0x006E7A3A */
| 505 | * rct2: 0x006E7A3A |
| 506 | */ |
| 507 | void ViewportUpdatePosition(WindowBase* window) |
| 508 | { |
| 509 | // Guard against any code attempting to call this at the wrong time. |
| 510 | Guard::Assert( |
| 511 | GetContext()->GetDrawingEngine()->GetDrawingContext() != nullptr, "We must be in a valid drawing context."); |
| 512 | |
| 513 | Viewport* viewport = window->viewport; |
| 514 | if (viewport == nullptr) |
| 515 | return; |
| 516 | |
| 517 | if (!window->viewportSmartFollowSprite.IsNull()) |
| 518 | { |
| 519 | ViewportUpdateSmartFollowEntity(window); |
| 520 | } |
| 521 | |
| 522 | if (!window->viewportTargetSprite.IsNull()) |
| 523 | { |
| 524 | ViewportUpdateFollowSprite(window); |
| 525 | return; |
| 526 | } |
| 527 | |
| 528 | ViewportSetUndergroundFlag(0, window, viewport); |
| 529 | |
| 530 | auto viewportMidPoint = ScreenCoordsXY{ window->savedViewPos.x + viewport->ViewWidth() / 2, |
| 531 | window->savedViewPos.y + viewport->ViewHeight() / 2 }; |
| 532 | |
| 533 | auto mapCoord = ViewportPosToMapPos(viewportMidPoint, 0, viewport->rotation); |
| 534 | |
| 535 | // Clamp to the map minimum value |
| 536 | int32_t at_map_edge = 0; |
| 537 | if (mapCoord.x < kMapMinimumXY) |
| 538 | { |
| 539 | mapCoord.x = kMapMinimumXY; |
| 540 | at_map_edge = 1; |
| 541 | } |
| 542 | if (mapCoord.y < kMapMinimumXY) |
| 543 | { |
| 544 | mapCoord.y = kMapMinimumXY; |
| 545 | at_map_edge = 1; |
| 546 | } |
| 547 | |
| 548 | // Clamp to the map maximum value (scenario specific) |
| 549 | auto mapSizeMinus2 = GetMapSizeMinus2(); |
| 550 | if (mapCoord.x > mapSizeMinus2.x) |
| 551 | { |
| 552 | mapCoord.x = mapSizeMinus2.x; |
| 553 | at_map_edge = 1; |
| 554 | } |
| 555 | if (mapCoord.y > mapSizeMinus2.y) |
| 556 | { |
| 557 | mapCoord.y = mapSizeMinus2.y; |
| 558 | at_map_edge = 1; |
| 559 | } |
| 560 | |
| 561 | if (at_map_edge) |
| 562 | { |
| 563 | auto centreLoc = centre2dCoordinates({ mapCoord, 0 }, viewport); |
| 564 | if (centreLoc.has_value()) |
no test coverage detected