MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ViewportUpdatePosition

Function ViewportUpdatePosition

src/openrct2/interface/Viewport.cpp:507–608  ·  view source on GitHub ↗

* * rct2: 0x006E7A3A */

Source from the content-addressed store, hash-verified

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())

Callers 1

WindowUpdateAllViewportsFunction · 0.85

Calls 15

AssertFunction · 0.85
GetContextFunction · 0.85
ViewportPosToMapPosFunction · 0.85
GetMapSizeMinus2Function · 0.85
centre2dCoordinatesFunction · 0.85
ViewportMoveFunction · 0.85
GetDrawingEngineMethod · 0.80
ViewWidthMethod · 0.80
ViewHeightMethod · 0.80

Tested by

no test coverage detected