From 870a8b55e5457be8aaa651019ae5a44fcaca2826 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 25 Apr 2016 21:37:48 +0100 Subject: [PATCH] add global macros for viewport variables --- src/drawing/supports.c | 4 +-- src/editor.c | 11 ++++---- src/game.c | 24 ++++++++--------- src/interface/screenshot.c | 15 +++++------ src/interface/viewport.c | 32 +++++++++++------------ src/interface/viewport.h | 7 +++++ src/interface/window.c | 2 +- src/rct1/S4Importer.cpp | 8 +++--- src/ride/track.c | 10 +++---- src/scenario.c | 46 +++++++++++++++++---------------- src/title.c | 24 ++++++++--------- src/windows/editor_main.c | 2 +- src/windows/main.c | 2 +- src/windows/ride_construction.c | 6 ++--- 14 files changed, 99 insertions(+), 94 deletions(-) diff --git a/src/drawing/supports.c b/src/drawing/supports.c index a9783d7443..c8c9fdbf14 100644 --- a/src/drawing/supports.c +++ b/src/drawing/supports.c @@ -161,7 +161,7 @@ bool wooden_a_supports_paint_setup(int supportType, int special, int height, uin *underground = false; } - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) { + if (gCurrentViewportFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) { return false; } @@ -311,7 +311,7 @@ bool wooden_b_supports_paint_setup(int supportType, int special, int height, uin */ bool metal_a_supports_paint_setup(int supportType, int segment, int special, int height, uint32 imageColourFlags) { - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) { + if (gCurrentViewportFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) { return false; } diff --git a/src/editor.c b/src/editor.c index fcd52740f8..dbcb49fe97 100644 --- a/src/editor.c +++ b/src/editor.c @@ -536,13 +536,12 @@ static void editor_finalise_main_view() rct_viewport *viewport = w->viewport; w->viewport_target_sprite = -1; - w->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16); - w->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16); + w->saved_view_x = gSavedViewX; + w->saved_view_y = gSavedViewY; + gCurrentRotation = gSavedViewRotation; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) >> 8; - - int zoom_difference = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) - viewport->zoom; - viewport->zoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) & 0xFF; + int zoom_difference = gSavedViewZoom - viewport->zoom; + viewport->zoom = gSavedViewZoom; if (zoom_difference != 0) { if (zoom_difference >= 0) { viewport->view_width <<= zoom_difference; diff --git a/src/game.c b/src/game.c index 82955101ef..d9e6339cdc 100644 --- a/src/game.c +++ b/src/game.c @@ -974,19 +974,19 @@ void game_load_init() mainWindow = window_get_main(); mainWindow->viewport_target_sprite = -1; - mainWindow->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16); - mainWindow->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16); - uint8 _cl = (RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF) - mainWindow->viewport->zoom; - mainWindow->viewport->zoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF; - *((char*)(&RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32))) = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) >> 8; - if (_cl != 0) { - if (_cl < 0) { - _cl = -_cl; - mainWindow->viewport->view_width >>= _cl; - mainWindow->viewport->view_height >>= _cl; + mainWindow->saved_view_x = gSavedViewX; + mainWindow->saved_view_y = gSavedViewY; + uint8 zoomDifference = gSavedViewZoom - mainWindow->viewport->zoom; + mainWindow->viewport->zoom = gSavedViewZoom; + gCurrentRotation = gSavedViewRotation; + if (zoomDifference != 0) { + if (zoomDifference < 0) { + zoomDifference = -zoomDifference; + mainWindow->viewport->view_width >>= zoomDifference; + mainWindow->viewport->view_height >>= zoomDifference; } else { - mainWindow->viewport->view_width <<= _cl; - mainWindow->viewport->view_height <<= _cl; + mainWindow->viewport->view_width <<= zoomDifference; + mainWindow->viewport->view_height <<= zoomDifference; } } mainWindow->saved_view_x -= mainWindow->viewport->view_width >> 1; diff --git a/src/interface/screenshot.c b/src/interface/screenshot.c index ff292df40e..55d546eede 100644 --- a/src/interface/screenshot.c +++ b/src/interface/screenshot.c @@ -217,8 +217,7 @@ void screenshot_giant() viewport.view_x = x - ((viewport.view_width << zoom) / 2); viewport.view_y = y - ((viewport.view_height << zoom) / 2); viewport.zoom = zoom; - - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) = rotation; + gCurrentRotation = rotation; // Ensure sprites appear regardless of rotation reset_all_sprite_quadrant_placements(); @@ -358,14 +357,12 @@ int cmdline_for_screenshot(const char **argv, int argc) viewport.view_x = x - ((viewport.view_width << customZoom) / 2); viewport.view_y = y - ((viewport.view_height << customZoom) / 2); viewport.zoom = customZoom; - - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) = customRotation; + gCurrentRotation = customRotation; } else { - viewport.view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16) - (viewport.view_width / 2); - viewport.view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16) - (viewport.view_height / 2); - viewport.zoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) & 0xFF; - - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) >> 8; + viewport.view_x = gSavedViewX - (viewport.view_width / 2); + viewport.view_y = gSavedViewY - (viewport.view_height / 2); + viewport.zoom = gSavedViewZoom; + gCurrentRotation = gSavedViewRotation; } // Ensure sprites appear regardless of rotation diff --git a/src/interface/viewport.c b/src/interface/viewport.c index d6bc3fc90f..f1c27bb9b7 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -764,7 +764,7 @@ void paint_attached_ps(paint_struct* ps, paint_struct* attached_ps, rct_drawpixe sint16 y = attached_ps->attached_y + ps->y; int image_id = attached_ps->image_id; - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_SEETHROUGH_RIDES){ + if (gCurrentViewportFlags & VIEWPORT_FLAG_SEETHROUGH_RIDES) { if (ps->sprite_type == 3){ if (image_id & 0x40000000){ image_id &= 0x7FFFF; @@ -773,7 +773,7 @@ void paint_attached_ps(paint_struct* ps, paint_struct* attached_ps, rct_drawpixe } } - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_SEETHROUGH_SCENERY){ + if (gCurrentViewportFlags & VIEWPORT_FLAG_SEETHROUGH_SCENERY) { if (ps->sprite_type == 5){ if (image_id & 0x40000000){ image_id &= 0x7FFFF; @@ -809,7 +809,7 @@ void sub_688485(){ } } int image_id = ps->image_id; - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_SEETHROUGH_RIDES){ + if (gCurrentViewportFlags & VIEWPORT_FLAG_SEETHROUGH_RIDES) { if (ps->sprite_type == 3){ if (!(image_id & 0x40000000)){ image_id &= 0x7FFFF; @@ -817,7 +817,7 @@ void sub_688485(){ } } } - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_UNDERGROUND_INSIDE){ + if (gCurrentViewportFlags & VIEWPORT_FLAG_UNDERGROUND_INSIDE) { if (ps->sprite_type == 9){ if (!(image_id & 0x40000000)){ image_id &= 0x7FFFF; @@ -825,7 +825,7 @@ void sub_688485(){ } } } - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_SEETHROUGH_SCENERY){ + if (gCurrentViewportFlags & VIEWPORT_FLAG_SEETHROUGH_SCENERY) { if (ps->sprite_type == 10 || ps->sprite_type == 12 || ps->sprite_type == 9 || ps->sprite_type == 5){ if (!(image_id & 0x40000000)){ image_id &= 0x7FFFF; @@ -1307,7 +1307,7 @@ void sprite_paint_setup(const uint16 eax, const uint16 ecx){ if (RCT2_GLOBAL(0x9DEA6F, uint8) & 1) return; - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_INVISIBLE_SPRITES) return; + if (gCurrentViewportFlags & VIEWPORT_FLAG_INVISIBLE_SPRITES) return; dpi = RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*); if (dpi->zoom_level > 2) return; @@ -1624,7 +1624,7 @@ void viewport_track_paint_setup(uint8 direction, int height, rct_map_element *ma trackSequence = mapElement->properties.track.sequence & 0x0F; trackColourScheme = mapElement->properties.track.colour & 3; - if ((RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_TRACK_HEIGHTS) && dpi->zoom_level == 0) { + if ((gCurrentViewportFlags & VIEWPORT_FLAG_TRACK_HEIGHTS) && dpi->zoom_level == 0) { RCT2_GLOBAL(RCT2_ADDRESS_PAINT_SETUP_CURRENT_TYPE, uint8) = 0; if (RCT2_ADDRESS(0x00999694, uint32)[trackType] & (1 << trackSequence)) { uint16 ax = RideData5[ride->type].z_offset; @@ -1714,7 +1714,7 @@ void viewport_entrance_paint_setup(uint8 direction, int height, rct_map_element* rct_drawpixelinfo* dpi = RCT2_GLOBAL(0x140E9A8, rct_drawpixelinfo*); - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_PATH_HEIGHTS && + if (gCurrentViewportFlags & VIEWPORT_FLAG_PATH_HEIGHTS && dpi->zoom_level == 0){ uint32 ebx = (map_element->properties.entrance.type << 4) | @@ -2372,7 +2372,7 @@ static void viewport_draw_money_effects() * ebp: bottom */ void viewport_paint(rct_viewport* viewport, rct_drawpixelinfo* dpi, int left, int top, int right, int bottom){ - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) = viewport->flags; + gCurrentViewportFlags = viewport->flags; RCT2_GLOBAL(RCT2_ADDRESS_VIEWPORT_ZOOM, uint16) = viewport->zoom; uint16 width = right - left; @@ -2439,9 +2439,9 @@ void viewport_paint(rct_viewport* viewport, rct_drawpixelinfo* dpi, int left, in dpi2->bits = bits_pointer; dpi2->pitch = pitch; - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & (VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_UNDERGROUND_INSIDE)){ + if (gCurrentViewportFlags & (VIEWPORT_FLAG_HIDE_VERTICAL | VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_UNDERGROUND_INSIDE)){ uint8 colour = 0x0A; - if (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_INVISIBLE_SPRITES){ + if (gCurrentViewportFlags & VIEWPORT_FLAG_INVISIBLE_SPRITES){ colour = 0; } gfx_clear(dpi2, colour); @@ -2455,7 +2455,7 @@ void viewport_paint(rct_viewport* viewport, rct_drawpixelinfo* dpi, int left, in sub_688485(); int weather_colour = RCT2_ADDRESS(0x98195C, uint32)[gClimateCurrentWeatherGloom]; - if ((weather_colour != -1) && (!(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) & VIEWPORT_FLAG_INVISIBLE_SPRITES)) && (!(RCT2_GLOBAL(0x9DEA6F, uint8) & 1))){ + if ((weather_colour != -1) && (!(gCurrentViewportFlags & VIEWPORT_FLAG_INVISIBLE_SPRITES)) && (!(RCT2_GLOBAL(0x9DEA6F, uint8) & 1))){ gfx_fill_rect(dpi2, dpi2->x, dpi2->y, dpi2->width + dpi2->x - 1, dpi2->height + dpi2->y - 1, weather_colour); } viewport_draw_money_effects(); @@ -3312,12 +3312,12 @@ void screen_get_map_xy_side_with_z(sint16 screenX, sint16 screenY, sint16 z, sin */ uint8 get_current_rotation() { - uint32 rotation = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32); - uint32 rotation_masked = rotation & 3; + uint8 rotation = gCurrentRotation; + uint8 rotation_masked = rotation & 3; #if DEBUG_LEVEL_1 if (rotation != rotation_masked) { - log_error("Found wrong rotation %d! Will return %d instead.", rotation, rotation_masked); + log_error("Found wrong rotation %d! Will return %d instead.", (uint32)rotation, (uint32)rotation_masked); } #endif // DEBUG_LEVEL_1 - return (uint8)rotation_masked; + return rotation_masked; } diff --git a/src/interface/viewport.h b/src/interface/viewport.h index 6390f49ea9..d11c332a0d 100644 --- a/src/interface/viewport.h +++ b/src/interface/viewport.h @@ -90,6 +90,13 @@ typedef struct { #define MAX_VIEWPORT_COUNT MAX_WINDOW_COUNT +#define gSavedViewX RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16) +#define gSavedViewY RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16) +#define gSavedViewZoom RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint8) +#define gSavedViewRotation RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION + 1, uint8) +#define gCurrentRotation RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) +#define gCurrentViewportFlags RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) + // rct2: 0x014234BC extern rct_viewport g_viewport_list[MAX_VIEWPORT_COUNT]; diff --git a/src/interface/window.c b/src/interface/window.c index b3d6c46e6e..bba4b958c9 100644 --- a/src/interface/window.c +++ b/src/interface/window.c @@ -1428,7 +1428,7 @@ void window_rotate_camera(rct_window *w, int direction) z = map_element_height(x, y); } - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32) = (get_current_rotation() + direction) & 3; + gCurrentRotation = (get_current_rotation() + direction) & 3; int new_x, new_y; center_2d_coordinates(x, y, z, &new_x, &new_y, viewport); diff --git a/src/rct1/S4Importer.cpp b/src/rct1/S4Importer.cpp index feb8768dd4..792f63b710 100644 --- a/src/rct1/S4Importer.cpp +++ b/src/rct1/S4Importer.cpp @@ -1032,10 +1032,10 @@ void S4Importer::ImportScenarioObjective() void S4Importer::ImportSavedView() { - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, uint16) = _s4.view_x; - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, uint16) = _s4.view_y; - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint8) = _s4.view_zoom; - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION + 1, uint8) = _s4.view_rotation; + gSavedViewX = _s4.view_x; + gSavedViewY = _s4.view_y; + gSavedViewZoom = _s4.view_zoom; + gSavedViewRotation = _s4.view_rotation; } void S4Importer::ClearExtraTileEntries() diff --git a/src/ride/track.c b/src/ride/track.c index 17d21a7775..b42d7da2de 100644 --- a/src/ride/track.c +++ b/src/ride/track.c @@ -744,7 +744,7 @@ void reload_map_backup() gMapSizeUnits = *(uint16*)(backup_info + 4); gMapSizeMinus2 = *(uint16*)(backup_info + 6); gMapSize = *(uint16*)(backup_info + 8); - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32) = *(uint32*)(backup_info + 10); + gCurrentRotation = *(uint8*)(backup_info + 10); free(RCT2_GLOBAL(0xF440ED, uint8*)); free(RCT2_GLOBAL(0xF440F1, uint8*)); @@ -2149,7 +2149,7 @@ void draw_track_preview(uint8** preview){ int x = center_y - center_x - width / 2; int y = (center_y + center_x) / 2 - center_z - height / 2; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32) = 0; + gCurrentRotation = 0; view->width = 370; view->height = 217; @@ -2179,7 +2179,7 @@ void draw_track_preview(uint8** preview){ dpi->bits += TRACK_PREVIEW_IMAGE_SIZE; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32) = 1; + gCurrentRotation = 1; x = -center_y - center_x - width / 2; y = (center_y - center_x) / 2 - center_z - height / 2; @@ -2194,7 +2194,7 @@ void draw_track_preview(uint8** preview){ dpi->bits += TRACK_PREVIEW_IMAGE_SIZE; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32) = 2; + gCurrentRotation = 2; x = center_x - center_y - width / 2; y = (-center_y - center_x) / 2 - center_z - height / 2; @@ -2209,7 +2209,7 @@ void draw_track_preview(uint8** preview){ dpi->bits += TRACK_PREVIEW_IMAGE_SIZE; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32) = 3; + gCurrentRotation = 3; x = center_x + center_y - width / 2; y = (center_x - center_y) / 2 - center_z - height / 2; diff --git a/src/scenario.c b/src/scenario.c index c6c72d4dc9..b3251ef1fd 100644 --- a/src/scenario.c +++ b/src/scenario.c @@ -243,20 +243,20 @@ void scenario_begin() mainWindow = window_get_main(); mainWindow->viewport_target_sprite = -1; - mainWindow->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16); - mainWindow->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16); + mainWindow->saved_view_x = gSavedViewX; + mainWindow->saved_view_y = gSavedViewY; - uint8 _cl = (RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF) - mainWindow->viewport->zoom; - mainWindow->viewport->zoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF; - *((char*)(&RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32))) = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) >> 8; - if (_cl != 0) { - if (_cl < 0) { - _cl = -_cl; - mainWindow->viewport->view_width >>= _cl; - mainWindow->viewport->view_height >>= _cl; + uint8 zoomDifference = gSavedViewZoom - mainWindow->viewport->zoom; + mainWindow->viewport->zoom = gSavedViewZoom; + gCurrentRotation = gSavedViewRotation; + if (zoomDifference != 0) { + if (zoomDifference < 0) { + zoomDifference = -zoomDifference; + mainWindow->viewport->view_width >>= zoomDifference; + mainWindow->viewport->view_height >>= zoomDifference; } else { - mainWindow->viewport->view_width <<= _cl; - mainWindow->viewport->view_height <<= _cl; + mainWindow->viewport->view_width <<= zoomDifference; + mainWindow->viewport->view_height <<= zoomDifference; } } mainWindow->saved_view_x -= mainWindow->viewport->view_width >> 1; @@ -983,15 +983,16 @@ int scenario_save(SDL_RWops* rw, int flags) viewZoom = viewport->zoom; viewRotation = get_current_rotation(); } else { - viewX = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, uint16); - viewY = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, uint16); - viewZoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) & 0xFF; - viewRotation = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) >> 8; + viewX = gSavedViewX; + viewY = gSavedViewY; + viewZoom = gSavedViewZoom; + viewRotation = gSavedViewRotation; } - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, uint16) = viewX; - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, uint16) = viewY; - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) = viewZoom | (viewRotation << 8); + gSavedViewX = viewX; + gSavedViewY = viewY; + gSavedViewZoom = viewZoom; + gSavedViewRotation = viewRotation; // Prepare S6 rct_s6_data *s6 = malloc(sizeof(rct_s6_data)); @@ -1063,9 +1064,10 @@ int scenario_save_network(SDL_RWops* rw) viewRotation = 0; } - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, uint16) = viewX; - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, uint16) = viewY; - RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, uint16) = viewZoom | (viewRotation << 8); + gSavedViewX = viewX; + gSavedViewY = viewY; + gSavedViewZoom = viewZoom; + gSavedViewRotation = viewRotation; // Prepare S6 rct_s6_data *s6 = malloc(sizeof(rct_s6_data)); diff --git a/src/title.c b/src/title.c index 24231fe320..3cc441c407 100644 --- a/src/title.c +++ b/src/title.c @@ -191,21 +191,21 @@ static int title_load_park(const char *path) w = window_get_main(); w->viewport_target_sprite = -1; - w->saved_view_x = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_X, sint16); - w->saved_view_y = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_Y, sint16); + w->saved_view_x = gSavedViewX; + w->saved_view_y = gSavedViewY; { - char _cl = (RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF) - w->viewport->zoom; - w->viewport->zoom = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) & 0xFF; - *((char*)(&RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32))) = RCT2_GLOBAL(RCT2_ADDRESS_SAVED_VIEW_ZOOM_AND_ROTATION, sint16) >> 8; - if (_cl != 0) { - if (_cl < 0) { - _cl = -_cl; - w->viewport->view_width >>= _cl; - w->viewport->view_height >>= _cl; + char zoomDifference = gSavedViewZoom - w->viewport->zoom; + w->viewport->zoom = gSavedViewZoom; + gCurrentRotation = gSavedViewRotation; + if (zoomDifference != 0) { + if (zoomDifference < 0) { + zoomDifference = -zoomDifference; + w->viewport->view_width >>= zoomDifference; + w->viewport->view_height >>= zoomDifference; } else { - w->viewport->view_width <<= _cl; - w->viewport->view_height <<= _cl; + w->viewport->view_width <<= zoomDifference; + w->viewport->view_height <<= zoomDifference; } } w->saved_view_x -= w->viewport->view_width >> 1; diff --git a/src/windows/editor_main.c b/src/windows/editor_main.c index 81dc70a4f9..f1f46b1915 100644 --- a/src/windows/editor_main.c +++ b/src/windows/editor_main.c @@ -80,7 +80,7 @@ void window_editor_main_open() viewport_create(window, window->x, window->y, window->width, window->height, 0, 0x0FFF, 0x0FFF, 0, 0x1, -1); window->viewport->flags |= 0x0400; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32) = 0; + gCurrentRotation = 0; RCT2_GLOBAL(0x009E32B0, uint8) = 0; RCT2_GLOBAL(0x009E32B2, uint8) = 0; RCT2_GLOBAL(0x009E32B3, uint8) = 0; diff --git a/src/windows/main.c b/src/windows/main.c index 24082984c6..c356c8c190 100644 --- a/src/windows/main.c +++ b/src/windows/main.c @@ -83,7 +83,7 @@ void window_main_open() viewport_create(window, window->x, window->y, window->width, window->height, 0,0x0FFF,0x0FFF, 0, 0x1, -1); window->viewport->flags |= VIEWPORT_FLAG_SOUND_ON; - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, sint32) = 0; + gCurrentRotation = 0; RCT2_GLOBAL(0x009E32B0, uint8) = 0; RCT2_GLOBAL(0x009E32B2, uint8) = 0; RCT2_GLOBAL(0x009E32B3, uint8) = 0; diff --git a/src/windows/ride_construction.c b/src/windows/ride_construction.c index d37dcac400..0c3bfde735 100644 --- a/src/windows/ride_construction.c +++ b/src/windows/ride_construction.c @@ -2277,8 +2277,8 @@ static void sub_6CBCE2( int preserve_current_viewport_flags; int x, y, baseZ, clearanceZ, offsetX, offsetY; - preserve_current_viewport_flags = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16); - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) = 0; + preserve_current_viewport_flags = gCurrentViewportFlags; + gCurrentViewportFlags = 0; trackDirection &= 3; RCT2_GLOBAL(0x00EE7880, uint32) = 0x00F1A4CC; @@ -2387,7 +2387,7 @@ static void sub_6CBCE2( sub_688217(); sub_688485(); - RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_VIEWPORT_FLAGS, uint16) = preserve_current_viewport_flags; + gCurrentViewportFlags = preserve_current_viewport_flags; } /**