MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / LimitCameraView

Method LimitCameraView

Sources/Jazz2/LevelHandler.cpp:1917–1984  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1915 }
1916
1917 void LevelHandler::LimitCameraView(Actors::Player* player, Vector2f playerPos, std::int32_t left, std::int32_t width)
1918 {
1919 _levelBounds.X = left;
1920 if (width > 0.0f) {
1921 _levelBounds.W = width;
1922 } else {
1923 _levelBounds.W = _tileMap->GetLevelBounds().X - left;
1924 }
1925
1926 Rectf bounds = _levelBounds.As<float>();
1927 if (left == 0 && width == 0) {
1928 for (auto& viewport : _assignedViewports) {
1929 viewport->_viewBounds = bounds;
1930 }
1931 _viewBoundsTarget = bounds;
1932 } else {
1933 Rendering::PlayerViewport* currentViewport = nullptr;
1934 float maxViewWidth = 0.0f;
1935 for (auto& viewport : _assignedViewports) {
1936 auto size = viewport->GetViewportSize();
1937 if (maxViewWidth < size.X) {
1938 maxViewWidth = (float)size.X;
1939 }
1940 if (viewport->_targetActor == player) {
1941 currentViewport = viewport.get();
1942 }
1943 }
1944
1945 if (bounds.W < maxViewWidth) {
1946 bounds.X -= (maxViewWidth - bounds.W);
1947 bounds.W = maxViewWidth;
1948 }
1949
1950 if (_viewBoundsTarget != bounds) {
1951 _viewBoundsTarget = bounds;
1952
1953 if (currentViewport != nullptr) {
1954 float limit = currentViewport->_cameraPos.X - (maxViewWidth * 0.6f);
1955 if (currentViewport->_viewBounds.X < limit) {
1956 currentViewport->_viewBounds.W += (currentViewport->_viewBounds.X - limit);
1957 currentViewport->_viewBounds.X = limit;
1958 }
1959 }
1960
1961 // Warp all other distant players to this player
1962 for (auto& viewport : _assignedViewports) {
1963 if (viewport->_targetActor != player) {
1964 float limit = viewport->_cameraPos.X - (maxViewWidth * 0.6f);
1965 if (viewport->_viewBounds.X < limit) {
1966 viewport->_viewBounds.W += (viewport->_viewBounds.X - limit);
1967 viewport->_viewBounds.X = limit;
1968 }
1969
1970 auto pos = viewport->_targetActor->_pos;
1971 if ((pos.X < bounds.X || pos.X >= bounds.X + bounds.W) && (pos - playerPos).Length() > 100.0f) {
1972 if (auto* otherPlayer = runtime_cast<Actors::Player>(viewport->_targetActor)) {
1973 otherPlayer->WarpToPosition(playerPos, WarpFlags::SkipWarpIn);
1974 if (currentViewport != nullptr) {

Callers 2

OnHandleAreaEventsMethod · 0.80
limitXScrollMethod · 0.80

Calls 5

GetViewportSizeMethod · 0.80
GetLevelBoundsMethod · 0.45
getMethod · 0.45
LengthMethod · 0.45
WarpToPositionMethod · 0.45

Tested by

no test coverage detected