From b5211a41dec9a17db067e8145dbebf863c9d24b3 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 10 Sep 2016 12:35:18 +0100 Subject: [PATCH] Integrate viewport ref counters --- src/interface/viewport.c | 27 +++++++++++++++------------ src/interface/viewport.h | 8 ++++++++ src/windows/editor_main.c | 6 +++--- src/windows/main.c | 6 +++--- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/interface/viewport.c b/src/interface/viewport.c index 6a1af32580..fbb774b79c 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -39,6 +39,9 @@ //#define DEBUG_SHOW_DIRTY_BOX uint32 gCurrentViewportFlags = 0; +uint8 gShowGridLinesRefCount; +uint8 gShowLandRightsRefCount; +uint8 gShowConstuctionRightsRefCount; rct_viewport g_viewport_list[MAX_VIEWPORT_COUNT]; rct_viewport *g_music_tracking_viewport; @@ -857,7 +860,7 @@ rct_xy16 viewport_coord_to_map_coord(int x, int y, int z) */ void show_gridlines() { - if (RCT2_GLOBAL(0x009E32B0, uint8) == 0) { + if (gShowGridLinesRefCount == 0) { rct_window *mainWindow = window_get_main(); if (mainWindow != NULL) { if (!(mainWindow->viewport->flags & VIEWPORT_FLAG_GRIDLINES)) { @@ -866,7 +869,7 @@ void show_gridlines() } } } - RCT2_GLOBAL(0x009E32B0, uint8)++; + gShowGridLinesRefCount++; } /** @@ -875,8 +878,8 @@ void show_gridlines() */ void hide_gridlines() { - RCT2_GLOBAL(0x009E32B0, uint8)--; - if (RCT2_GLOBAL(0x009E32B0, uint8) == 0) { + gShowGridLinesRefCount--; + if (gShowGridLinesRefCount == 0) { rct_window *mainWindow = window_get_main(); if (mainWindow != NULL) { if (!gConfigGeneral.always_show_gridlines) { @@ -893,7 +896,7 @@ void hide_gridlines() */ void show_land_rights() { - if (RCT2_GLOBAL(0x009E32B2, uint8) == 0) { + if (gShowLandRightsRefCount == 0) { rct_window *mainWindow = window_get_main(); if (mainWindow != NULL) { if (!(mainWindow->viewport->flags & VIEWPORT_FLAG_LAND_OWNERSHIP)) { @@ -902,7 +905,7 @@ void show_land_rights() } } } - RCT2_GLOBAL(0x009E32B2, uint8)++; + gShowLandRightsRefCount++; } /** @@ -911,8 +914,8 @@ void show_land_rights() */ void hide_land_rights() { - RCT2_GLOBAL(0x009E32B2, uint8)--; - if (RCT2_GLOBAL(0x009E32B2, uint8) == 0) { + gShowLandRightsRefCount--; + if (gShowLandRightsRefCount == 0) { rct_window *mainWindow = window_get_main(); if (mainWindow != NULL) { if (mainWindow->viewport->flags & VIEWPORT_FLAG_LAND_OWNERSHIP) { @@ -929,7 +932,7 @@ void hide_land_rights() */ void show_construction_rights() { - if (RCT2_GLOBAL(0x009E32B3, uint8) == 0) { + if (gShowConstuctionRightsRefCount == 0) { rct_window *mainWindow = window_get_main(); if (mainWindow != NULL) { if (!(mainWindow->viewport->flags & VIEWPORT_FLAG_CONSTRUCTION_RIGHTS)) { @@ -938,7 +941,7 @@ void show_construction_rights() } } } - RCT2_GLOBAL(0x009E32B3, uint8)++; + gShowConstuctionRightsRefCount++; } /** @@ -947,8 +950,8 @@ void show_construction_rights() */ void hide_construction_rights() { - RCT2_GLOBAL(0x009E32B3, uint8)--; - if (RCT2_GLOBAL(0x009E32B3, uint8) == 0) { + gShowConstuctionRightsRefCount--; + if (gShowConstuctionRightsRefCount == 0) { rct_window *mainWindow = window_get_main(); if (mainWindow != NULL) { if (mainWindow->viewport->flags & VIEWPORT_FLAG_CONSTRUCTION_RIGHTS) { diff --git a/src/interface/viewport.h b/src/interface/viewport.h index c948032aec..29b0908a1d 100644 --- a/src/interface/viewport.h +++ b/src/interface/viewport.h @@ -90,6 +90,14 @@ typedef struct viewport_interaction_info { extern uint32 gCurrentViewportFlags; +/** + * A reference counter for whether something is forcing the grid lines to show. When the counter + * is decremented to 0, the grid lines are hidden. + */ +extern uint8 gShowGridLinesRefCount; +extern uint8 gShowLandRightsRefCount; +extern uint8 gShowConstuctionRightsRefCount; + // rct2: 0x014234BC extern rct_viewport g_viewport_list[MAX_VIEWPORT_COUNT]; extern rct_viewport *g_music_tracking_viewport; diff --git a/src/windows/editor_main.c b/src/windows/editor_main.c index 2f074faf0c..9ad78940e9 100644 --- a/src/windows/editor_main.c +++ b/src/windows/editor_main.c @@ -77,9 +77,9 @@ void window_editor_main_open() window->viewport->flags |= 0x0400; gCurrentRotation = 0; - RCT2_GLOBAL(0x009E32B0, uint8) = 0; - RCT2_GLOBAL(0x009E32B2, uint8) = 0; - RCT2_GLOBAL(0x009E32B3, uint8) = 0; + gShowGridLinesRefCount = 0; + gShowLandRightsRefCount = 0; + gShowConstuctionRightsRefCount = 0; gFootpathSelectedType = 0; window_top_toolbar_open(); diff --git a/src/windows/main.c b/src/windows/main.c index 9b09aaa491..5ff74a1de9 100644 --- a/src/windows/main.c +++ b/src/windows/main.c @@ -80,9 +80,9 @@ 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; gCurrentRotation = 0; - RCT2_GLOBAL(0x009E32B0, uint8) = 0; - RCT2_GLOBAL(0x009E32B2, uint8) = 0; - RCT2_GLOBAL(0x009E32B3, uint8) = 0; + gShowGridLinesRefCount = 0; + gShowLandRightsRefCount = 0; + gShowConstuctionRightsRefCount = 0; gFootpathSelectedType = 0; }