1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Refactor out all uses of gCurrentRotation, remove gCurrentRotation

This commit is contained in:
ζeh Matt
2024-02-18 02:57:33 +02:00
parent 8864f6cf51
commit 2661cf8772
8 changed files with 15 additions and 20 deletions

View File

@@ -587,7 +587,7 @@ public:
mainWindow->viewport_target_sprite = EntityId::GetNull(); mainWindow->viewport_target_sprite = EntityId::GetNull();
mainWindow->savedViewPos = viewPos; mainWindow->savedViewPos = viewPos;
viewport->zoom = zoom; viewport->zoom = zoom;
gCurrentRotation = rotation; viewport->rotation = rotation;
if (zoomDifference != ZoomLevel{ 0 }) if (zoomDifference != ZoomLevel{ 0 })
{ {

View File

@@ -35,8 +35,8 @@ public:
if (viewport != nullptr) if (viewport != nullptr)
{ {
SetViewportFlags(); SetViewportFlags();
viewport->rotation = 0;
} }
gCurrentRotation = 0;
gShowGridLinesRefCount = 0; gShowGridLinesRefCount = 0;
gShowLandRightsRefCount = 0; gShowLandRightsRefCount = 0;
gShowConstructionRightsRefCount = 0; gShowConstructionRightsRefCount = 0;

View File

@@ -498,7 +498,7 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti
auto zoom = ZoomLevel{ customZoom }; auto zoom = ZoomLevel{ customZoom };
auto rotation = std::atoi(argv[4]) & 3; auto rotation = std::atoi(argv[4]) & 3;
viewport = GetGiantViewport(rotation, zoom); viewport = GetGiantViewport(rotation, zoom);
gCurrentRotation = rotation; viewport.rotation = rotation;
} }
else else
{ {
@@ -554,7 +554,7 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti
viewport.viewPos = { coords2d.x - ((viewport.view_width << customZoom) / 2), viewport.viewPos = { coords2d.x - ((viewport.view_width << customZoom) / 2),
coords2d.y - ((viewport.view_height << customZoom) / 2) }; coords2d.y - ((viewport.view_height << customZoom) / 2) };
viewport.zoom = ZoomLevel{ static_cast<int8_t>(customZoom) }; viewport.zoom = ZoomLevel{ static_cast<int8_t>(customZoom) };
gCurrentRotation = customRotation; viewport.rotation = customRotation;
} }
else else
{ {
@@ -562,7 +562,7 @@ int32_t CommandLineForScreenshot(const char** argv, int32_t argc, ScreenshotOpti
viewport.viewPos = { gameState.SavedView viewport.viewPos = { gameState.SavedView
- ScreenCoordsXY{ (viewport.view_width / 2), (viewport.view_height / 2) } }; - ScreenCoordsXY{ (viewport.view_width / 2), (viewport.view_height / 2) } };
viewport.zoom = gameState.SavedViewZoom; viewport.zoom = gameState.SavedViewZoom;
gCurrentRotation = gameState.SavedViewRotation; viewport.rotation = gameState.SavedViewRotation;
} }
} }
@@ -656,8 +656,7 @@ void CaptureImage(const CaptureOptions& options)
viewport = GetGiantViewport(options.Rotation, options.Zoom); viewport = GetGiantViewport(options.Rotation, options.Zoom);
} }
auto backupRotation = gCurrentRotation; viewport.rotation = options.Rotation;
gCurrentRotation = options.Rotation;
if (options.Transparent) if (options.Transparent)
{ {
@@ -669,6 +668,4 @@ void CaptureImage(const CaptureOptions& options)
RenderViewport(nullptr, viewport, dpi); RenderViewport(nullptr, viewport, dpi);
WriteDpiToFile(outputPath, dpi, gPalette); WriteDpiToFile(outputPath, dpi, gPalette);
ReleaseDPI(dpi); ReleaseDPI(dpi);
gCurrentRotation = backupRotation;
} }

View File

@@ -65,8 +65,6 @@ Viewport* g_music_tracking_viewport;
static std::unique_ptr<JobPool> _paintJobs; static std::unique_ptr<JobPool> _paintJobs;
static std::vector<PaintSession*> _paintColumns; static std::vector<PaintSession*> _paintColumns;
uint8_t gCurrentRotation;
static uint32_t _currentImageType; static uint32_t _currentImageType;
InteractionInfo::InteractionInfo(const PaintStruct* ps) InteractionInfo::InteractionInfo(const PaintStruct* ps)
: Loc(ps->MapPos) : Loc(ps->MapPos)
@@ -2055,7 +2053,13 @@ std::optional<CoordsXY> ScreenGetMapXYSideWithZ(const ScreenCoordsXY& screenCoor
*/ */
uint8_t GetCurrentRotation() uint8_t GetCurrentRotation()
{ {
uint8_t rotation = gCurrentRotation; auto* viewport = ViewportGetMain();
if (viewport == nullptr)
{
LOG_ERROR("No viewport found! Will return 0.");
return 0;
}
uint8_t rotation = viewport->rotation;
uint8_t rotation_masked = rotation & 3; uint8_t rotation_masked = rotation & 3;
#if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1
if (rotation != rotation_masked) if (rotation != rotation_masked)

View File

@@ -123,8 +123,6 @@ extern uint8_t gShowConstructionRightsRefCount;
// rct2: 0x014234BC // rct2: 0x014234BC
extern Viewport* g_music_tracking_viewport; extern Viewport* g_music_tracking_viewport;
extern uint8_t gCurrentRotation;
void ViewportInitAll(); void ViewportInitAll();
std::optional<ScreenCoordsXY> centre_2d_coordinates(const CoordsXYZ& loc, Viewport* viewport); std::optional<ScreenCoordsXY> centre_2d_coordinates(const CoordsXYZ& loc, Viewport* viewport);
void ViewportCreate(WindowBase* w, const ScreenCoordsXY& screenCoords, int32_t width, int32_t height, const Focus& focus); void ViewportCreate(WindowBase* w, const ScreenCoordsXY& screenCoords, int32_t width, int32_t height, const Focus& focus);

View File

@@ -933,7 +933,7 @@ void WindowRotateCamera(WindowBase& w, int32_t direction)
coords.z = TileElementHeight(coords); coords.z = TileElementHeight(coords);
} }
gCurrentRotation = (GetCurrentRotation() + direction) & 3; viewport->rotation = (viewport->rotation + direction) & 3;
auto centreLoc = centre_2d_coordinates(coords, viewport); auto centreLoc = centre_2d_coordinates(coords, viewport);

View File

@@ -2081,9 +2081,8 @@ void TrackDesignDrawPreview(TrackDesign* td6, uint8_t* pixels)
const ScreenCoordsXY offset = { size_x / 2, size_y / 2 }; const ScreenCoordsXY offset = { size_x / 2, size_y / 2 };
for (uint8_t i = 0; i < 4; i++) for (uint8_t i = 0; i < 4; i++)
{ {
gCurrentRotation = i;
view.viewPos = Translate3DTo2DWithZ(i, centre) - offset; view.viewPos = Translate3DTo2DWithZ(i, centre) - offset;
view.rotation = i;
ViewportRender(dpi, &view, { {}, ScreenCoordsXY{ size_x, size_y } }); ViewportRender(dpi, &view, { {}, ScreenCoordsXY{ size_x, size_y } });
dpi.bits += TRACK_PREVIEW_IMAGE_SIZE; dpi.bits += TRACK_PREVIEW_IMAGE_SIZE;

View File

@@ -111,7 +111,6 @@ static std::vector<TileElement> _tileElementsStash;
static size_t _tileElementsInUse; static size_t _tileElementsInUse;
static size_t _tileElementsInUseStash; static size_t _tileElementsInUseStash;
static TileCoordsXY _mapSizeStash; static TileCoordsXY _mapSizeStash;
static int32_t _currentRotationStash;
void StashMap() void StashMap()
{ {
@@ -119,7 +118,6 @@ void StashMap()
_tileIndexStash = std::move(_tileIndex); _tileIndexStash = std::move(_tileIndex);
_tileElementsStash = std::move(gameState.TileElements); _tileElementsStash = std::move(gameState.TileElements);
_mapSizeStash = GetGameState().MapSize; _mapSizeStash = GetGameState().MapSize;
_currentRotationStash = gCurrentRotation;
_tileElementsInUseStash = _tileElementsInUse; _tileElementsInUseStash = _tileElementsInUse;
} }
@@ -129,7 +127,6 @@ void UnstashMap()
_tileIndex = std::move(_tileIndexStash); _tileIndex = std::move(_tileIndexStash);
gameState.TileElements = std::move(_tileElementsStash); gameState.TileElements = std::move(_tileElementsStash);
GetGameState().MapSize = _mapSizeStash; GetGameState().MapSize = _mapSizeStash;
gCurrentRotation = _currentRotationStash;
_tileElementsInUse = _tileElementsInUseStash; _tileElementsInUse = _tileElementsInUseStash;
} }