From 8f3c43fcf1b1df8a1265458db06290c4850f8c5d Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Wed, 7 Sep 2016 13:26:53 +0200 Subject: [PATCH 1/2] Partially integrate side tunnels --- src/paint/map_element/map_element.c | 27 +++++++++----- src/paint/map_element/map_element.h | 17 +++++++++ src/paint/map_element/surface.c | 56 +++++++++++------------------ 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/src/paint/map_element/map_element.c b/src/paint/map_element/map_element.c index 312c8c103d..a2cf71d677 100644 --- a/src/paint/map_element/map_element.c +++ b/src/paint/map_element/map_element.c @@ -33,6 +33,13 @@ #include "../../game.h" #include "../supports.h" +#ifdef NO_RCT2 +tunnel_entry gLeftTunnels[65]; +uint8 gLeftTunnelCount; +tunnel_entry gRightTunnels[65]; +uint8 gRightTunnelCount; +#endif + static void blank_tiles_paint(int x, int y); static void sub_68B3FB(int x, int y); @@ -134,9 +141,11 @@ static void sub_68B3FB(int x, int y) { rct_drawpixelinfo *dpi = unk_140E9A8; - RCT2_GLOBAL(0x141F56A, uint16_t) = 0; - RCT2_GLOBAL(0x9E3138, uint8_t) = 0xFF; - RCT2_GLOBAL(0x9E30B6, uint8_t) = 0xFF; + gLeftTunnelCount = 0; + gRightTunnelCount = 0; + gLeftTunnels[0] = (tunnel_entry){0xFF, 0xFF}; + gRightTunnels[0] = (tunnel_entry){0xFF, 0xFF}; + RCT2_GLOBAL(0x9E323C, uint8_t) = 0xFF; RCT2_GLOBAL(0x9DE56A, uint16_t) = x; RCT2_GLOBAL(0x9DE56E, uint16_t) = y; @@ -302,16 +311,16 @@ static void sub_68B3FB(int x, int y) void paint_util_push_tunnel_left(uint16 height, uint8 type) { - uint32 eax = 0xFFFF0000 | ((height / 16) & 0xFF) | type << 8; - RCT2_ADDRESS(0x009E3138, uint32)[RCT2_GLOBAL(0x141F56A, uint8) / 2] = eax; - RCT2_GLOBAL(0x141F56A, uint8)++; + gLeftTunnels[gLeftTunnelCount] = (tunnel_entry){.height = (height / 16), .type = type}; + gLeftTunnels[gLeftTunnelCount + 1] = (tunnel_entry){0xFF, 0xFF}; + gLeftTunnelCount++; } void paint_util_push_tunnel_right(uint16 height, uint8 type) { - uint32 eax = 0xFFFF0000 | ((height / 16) & 0xFF) | type << 8; - RCT2_ADDRESS(0x009E30B6, uint32)[RCT2_GLOBAL(0x141F56B, uint8) / 2] = eax; - RCT2_GLOBAL(0x141F56B, uint8)++; + gRightTunnels[gRightTunnelCount] = (tunnel_entry){.height = (height / 16), .type = type}; + gRightTunnels[gRightTunnelCount + 1] = (tunnel_entry){0xFF, 0xFF}; + gRightTunnelCount++; } void paint_util_set_general_support_height(sint16 height, uint8 slope) diff --git a/src/paint/map_element/map_element.h b/src/paint/map_element/map_element.h index 58f53fae26..a42a4917ba 100644 --- a/src/paint/map_element/map_element.h +++ b/src/paint/map_element/map_element.h @@ -62,6 +62,23 @@ enum TUNNEL_14 = 0x0E }; +typedef struct tunnel_entry { + uint8 height; + uint8 type; +} tunnel_entry; + +#ifdef NO_RCT2 +extern tunnel_entry gLeftTunnels[65]; +extern uint8 gLeftTunnelCount; +extern tunnel_entry gRightTunnels[65]; +extern uint8 gRightTunnelCount; +#else +#define gLeftTunnels RCT2_ADDRESS(0x009E3138, tunnel_entry) +#define gLeftTunnelCount RCT2_GLOBAL(0x0141F56A, uint8) +#define gRightTunnels RCT2_ADDRESS(0x009E30B6, tunnel_entry) +#define gRightTunnelCount RCT2_GLOBAL(0x0141F56B, uint8) +#endif + extern bool gShowSupportSegmentHeights; void paint_util_push_tunnel_left(uint16 height, uint8 type); diff --git a/src/paint/map_element/surface.c b/src/paint/map_element/surface.c index a9b77f9356..5e5f0b7df2 100644 --- a/src/paint/map_element/surface.c +++ b/src/paint/map_element/surface.c @@ -539,7 +539,7 @@ static void viewport_surface_draw_land_side_bottom(enum edge edge, uint8 height, rct_xy16 tunnelBounds = {1, 1}; rct_xy16 tunnelTopBoundBoxOffset = {0, 0}; - uint32 tunnelArray; + tunnel_entry * tunnelArray; switch (edge) { case EDGE_BOTTOMLEFT: regs.al = self.corner_heights.left; @@ -553,7 +553,7 @@ static void viewport_surface_draw_land_side_bottom(enum edge edge, uint8 height, tunnelBounds.x = 32; tunnelTopBoundBoxOffset.y = 31; - tunnelArray = 0x9E3138; + tunnelArray = gLeftTunnels; break; case EDGE_BOTTOMRIGHT: @@ -568,7 +568,7 @@ static void viewport_surface_draw_land_side_bottom(enum edge edge, uint8 height, tunnelBounds.y = 32; tunnelTopBoundBoxOffset.x = 31; - tunnelArray = 0x009E30B6; + tunnelArray = gRightTunnels; break; default: @@ -629,15 +629,14 @@ static void viewport_surface_draw_land_side_bottom(enum edge edge, uint8 height, return; } - if (curHeight != RCT2_GLOBAL(tunnelArray, uint8)) { + if (curHeight != tunnelArray[0].height) { // Normal walls - while (curHeight > RCT2_GLOBAL(tunnelArray, uint8)) { - for (int offset = 0; offset <= 0x7E; offset += 4) { - RCT2_GLOBAL(tunnelArray + offset, uint32) = RCT2_GLOBAL(tunnelArray + 2 + offset, uint32); - } + while (curHeight > tunnelArray[0].height) { + // TODO: Should probably be done by just keeping track of the current index + memcpy(&tunnelArray[0], &tunnelArray[1], sizeof(tunnel_entry) * 64); } - if (curHeight != RCT2_GLOBAL(tunnelArray, uint8)) { + if (curHeight != tunnelArray[0].height) { sub_98196C(base_image_id, offset.x, offset.y, bounds.x, bounds.y, 15, curHeight * 16, rotation); curHeight++; @@ -646,7 +645,7 @@ static void viewport_surface_draw_land_side_bottom(enum edge edge, uint8 height, } // Tunnels - uint8 tunnelType = RCT2_GLOBAL(tunnelArray + 1, uint8); + uint8 tunnelType = tunnelArray[0].type; uint8 tunnelHeight = stru_97B570[tunnelType][0]; sint16 zOffset = curHeight; @@ -681,9 +680,8 @@ static void viewport_surface_draw_land_side_bottom(enum edge edge, uint8 height, curHeight += stru_97B570[tunnelType][0]; - for (int offset = 0; offset <= 0x7E; offset += 4) { - RCT2_GLOBAL(tunnelArray + offset, uint32) = RCT2_GLOBAL(tunnelArray + 2 + offset, uint32); - } + // TODO: Should probably be done by just keeping track of the current index + memcpy(&tunnelArray[0], &tunnelArray[1], sizeof(tunnel_entry) * 64); } } @@ -801,7 +799,7 @@ static void viewport_surface_draw_water_side_bottom(enum edge edge, uint8 height rct_xy16 tunnelBounds = {1, 1}; rct_xy16 tunnelTopBoundBoxOffset = {0, 0}; - uint32 tunnelArray; + tunnel_entry * tunnelArray; switch (edge) { case EDGE_BOTTOMLEFT: regs.al = self.corner_heights.left; @@ -815,7 +813,7 @@ static void viewport_surface_draw_water_side_bottom(enum edge edge, uint8 height tunnelBounds.x = 32; tunnelTopBoundBoxOffset.y = 31; - tunnelArray = 0x9E3138; + tunnelArray = gLeftTunnels; break; case EDGE_BOTTOMRIGHT: @@ -830,7 +828,7 @@ static void viewport_surface_draw_water_side_bottom(enum edge edge, uint8 height tunnelBounds.y = 32; tunnelTopBoundBoxOffset.x = 31; - tunnelArray = 0x009E30B6; + tunnelArray = gRightTunnels; break; default: @@ -901,12 +899,11 @@ static void viewport_surface_draw_water_side_bottom(enum edge edge, uint8 height return; } - if (curHeight != RCT2_GLOBAL(tunnelArray, uint8)) { + if (curHeight != tunnelArray[0].height) { // Normal walls - while (curHeight > RCT2_GLOBAL(tunnelArray, uint8)) { - for (int offset = 0; offset <= 0x7E; offset += 4) { - RCT2_GLOBAL(tunnelArray + offset, uint32) = RCT2_GLOBAL(tunnelArray + 2 + offset, uint32); - } + while (curHeight > tunnelArray[0].height) { + // TODO: Should probably be done by just keeping track of the current index + memcpy(&tunnelArray[0], &tunnelArray[1], sizeof(tunnel_entry) * 64); } sub_98196C(base_image_id, offset.x, offset.y, bounds.x, bounds.y, 15, curHeight * 16, rotation); @@ -916,7 +913,7 @@ static void viewport_surface_draw_water_side_bottom(enum edge edge, uint8 height } // Tunnels - uint8 tunnelType = RCT2_GLOBAL(tunnelArray + 1, uint8); + uint8 tunnelType = tunnelArray[0].type; uint8 tunnelHeight = stru_97B570[tunnelType][0]; sint16 zOffset = curHeight; @@ -951,9 +948,8 @@ static void viewport_surface_draw_water_side_bottom(enum edge edge, uint8 height curHeight += stru_97B570[tunnelType][0]; - for (int offset = 0; offset <= 0x7E; offset += 4) { - RCT2_GLOBAL(tunnelArray + offset, uint32) = RCT2_GLOBAL(tunnelArray + 2 + offset, uint32); - } + // TODO: Should probably be done by just keeping track of the current index + memcpy(&tunnelArray[0], &tunnelArray[1], sizeof(tunnel_entry) * 64); } } @@ -1322,11 +1318,6 @@ void surface_paint(uint8 direction, uint16 height, rct_map_element * mapElement) log_verbose("eax: %d", eax); } - for (int i = 0; i <= 0x7C; i += 4) { - RCT2_GLOBAL(0x009E2F30 + i, uint32) = RCT2_GLOBAL(0x009E3138 + i, uint32); - RCT2_GLOBAL(0x009E2EAE + i, uint32) = RCT2_GLOBAL(0x009E30B6 + i, uint32); - } - viewport_surface_draw_land_side_top(EDGE_TOPLEFT, height / 16, eax / 32, tileDescriptors[0], tileDescriptors[3]); viewport_surface_draw_land_side_top(EDGE_TOPRIGHT, height / 16, eax / 32, tileDescriptors[0], tileDescriptors[4]); viewport_surface_draw_land_side_bottom(EDGE_BOTTOMLEFT, height / 16, eax / 32, tileDescriptors[0], tileDescriptors[1]); @@ -1356,11 +1347,6 @@ void surface_paint(uint8 direction, uint16 height, rct_map_element * mapElement) paint_attach_to_previous_ps(SPR_WATER_OVERLAY + image_offset, 0, 0); - for (int i = 0; i <= 0x7C; i += 4) { - RCT2_GLOBAL(0x009E3138 + i, uint32) = RCT2_GLOBAL(0x009E2F30 + i, uint32); - RCT2_GLOBAL(0x009E30B6 + i, uint32) = RCT2_GLOBAL(0x009E2EAE + i, uint32); - } - // This wasn't in the original, but the code depended on globals that were only set in a different conditional uint8 al_edgeStyle = mapElement->properties.surface.slope & 0xE0; uint8 di_type = mapElement->type & 0x80; From 3ddf3e350bed70545dec8b8b34abff0937d25c68 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Wed, 7 Sep 2016 14:31:18 +0200 Subject: [PATCH 2/2] Backup and restore tunnels after first side paint --- src/paint/map_element/surface.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/paint/map_element/surface.c b/src/paint/map_element/surface.c index 5e5f0b7df2..8652bd6b63 100644 --- a/src/paint/map_element/surface.c +++ b/src/paint/map_element/surface.c @@ -1318,11 +1318,19 @@ void surface_paint(uint8 direction, uint16 height, rct_map_element * mapElement) log_verbose("eax: %d", eax); } + tunnel_entry backupLeftTunnels[65]; + tunnel_entry backupRightTunnels[65]; + + memcpy(backupLeftTunnels, gLeftTunnels, sizeof(tunnel_entry) * 65); + memcpy(backupRightTunnels, gRightTunnels, sizeof(tunnel_entry) * 65); + viewport_surface_draw_land_side_top(EDGE_TOPLEFT, height / 16, eax / 32, tileDescriptors[0], tileDescriptors[3]); viewport_surface_draw_land_side_top(EDGE_TOPRIGHT, height / 16, eax / 32, tileDescriptors[0], tileDescriptors[4]); viewport_surface_draw_land_side_bottom(EDGE_BOTTOMLEFT, height / 16, eax / 32, tileDescriptors[0], tileDescriptors[1]); viewport_surface_draw_land_side_bottom(EDGE_BOTTOMRIGHT, height / 16, eax / 32, tileDescriptors[0], tileDescriptors[2]); + memcpy(gLeftTunnels, backupLeftTunnels, sizeof(tunnel_entry) * 65); + memcpy(gRightTunnels, backupRightTunnels, sizeof(tunnel_entry) * 65); } RCT2_GLOBAL(0x009E3298, uint16) = 0;