diff --git a/src/openrct2/paint/map_element/map_element.c b/src/openrct2/paint/map_element/map_element.c index 12c9d5639d..4c8d0b4685 100644 --- a/src/openrct2/paint/map_element/map_element.c +++ b/src/openrct2/paint/map_element/map_element.c @@ -45,6 +45,10 @@ uint8 gRightTunnelCount; uint8 gVerticalTunnelHeight; #endif +#ifdef __TESTPAINT__ +uint16 testPaintVerticalTunnelHeight; +#endif + static void blank_tiles_paint(sint32 x, sint32 y); static void sub_68B3FB(sint32 x, sint32 y); @@ -333,6 +337,9 @@ void paint_util_push_tunnel_right(uint16 height, uint8 type) void paint_util_set_vertical_tunnel(uint16 height) { +#ifdef __TESTPAINT__ + testPaintVerticalTunnelHeight = height; +#endif gVerticalTunnelHeight = height / 16; } diff --git a/src/openrct2/paint/map_element/map_element.h b/src/openrct2/paint/map_element/map_element.h index fec0194d39..329e06bc75 100644 --- a/src/openrct2/paint/map_element/map_element.h +++ b/src/openrct2/paint/map_element/map_element.h @@ -106,6 +106,10 @@ extern uint8 gVerticalTunnelHeight; #define gVerticalTunnelHeight RCT2_GLOBAL(0x009E323C, uint8) #endif +#ifdef __TESTPAINT__ +extern uint16 testPaintVerticalTunnelHeight; +#endif + extern bool gShowSupportSegmentHeights; extern const rct_xy16 BannerBoundBoxes[][2]; diff --git a/test/testpaint/TestTrack.cpp b/test/testpaint/TestTrack.cpp index 3a25df4d63..b4b6ccbd1e 100644 --- a/test/testpaint/TestTrack.cpp +++ b/test/testpaint/TestTrack.cpp @@ -30,6 +30,7 @@ #include "VerticalTunnelCall.hpp" extern "C" { +#include #include #include #include @@ -700,15 +701,21 @@ static uint8 TestTrackElementVerticalTunnels(uint8 rideType, uint8 trackType, ui TestPaint::ResetEnvironment(); TestPaint::ResetTunnels(); - uint8 verticalTunnelHeight[4]; + uint16 verticalTunnelHeights[4]; for (int direction = 0; direction < 4; direction++) { - gVerticalTunnelHeight = 0; - CallOriginal(rideType, trackType, direction, trackSequence, height, &mapElement); - verticalTunnelHeight[direction] = gVerticalTunnelHeight; + uint8 tunnelHeights[3] = {0}; + + for (uint8 i = 0; i < 3; i++) { + gVerticalTunnelHeight = 0; + CallOriginal(rideType, trackType, direction, trackSequence, height - 8 + i * 8, &mapElement); + tunnelHeights[i] = gVerticalTunnelHeight; + } + + verticalTunnelHeights[direction] = VerticalTunnelCall::GetTunnelHeight(height, tunnelHeights); } - if (!VerticalTunnelCall::HeightIsConsistent(verticalTunnelHeight)) { + if (!VerticalTunnelCall::HeightIsConsistent(verticalTunnelHeights)) { *error += String::Format( "Original vertical tunnel height is inconsistent, skipping test. [trackSequence:%d]\n", trackSequence @@ -716,30 +723,33 @@ static uint8 TestTrackElementVerticalTunnels(uint8 rideType, uint8 trackType, ui return TEST_SUCCESS; } - uint8 referenceHeight = verticalTunnelHeight[0]; + uint16 referenceHeight = verticalTunnelHeights[0]; for (int direction = 0; direction < 4; direction++) { - gVerticalTunnelHeight = 0; testpaint_clear_ignore(); - CallOriginal(rideType, trackType, direction, trackSequence, height, &mapElement); + + testPaintVerticalTunnelHeight = 0; + CallNew(rideType, trackType, direction, trackSequence, height, &mapElement); + if (testpaint_is_ignored(direction, trackSequence)) { continue; } - if (gVerticalTunnelHeight != referenceHeight) { - if (gVerticalTunnelHeight == 0) { + if (testPaintVerticalTunnelHeight != referenceHeight) { + if (referenceHeight == 0) { *error += String::Format( - "Expected no tunnel. Actual: %d [trackSequence:%d]\n", - gVerticalTunnelHeight, trackSequence + "Expected no tunnel. Actual: %s [trackSequence:%d]\n", + Printer::PrintHeightOffset(testPaintVerticalTunnelHeight, height).c_str(), + trackSequence ); return TEST_FAILED; } *error += String::Format( "Expected vertical tunnel height to be `%s`, was `%s`. [trackSequence:%d direction:%d]\n", - Printer::PrintHeightOffset((referenceHeight * 16), height).c_str(), - Printer::PrintHeightOffset((gVerticalTunnelHeight * 16), height).c_str(), + Printer::PrintHeightOffset(referenceHeight, height).c_str(), + Printer::PrintHeightOffset(testPaintVerticalTunnelHeight, height).c_str(), trackSequence, direction ); diff --git a/test/testpaint/VerticalTunnelCall.cpp b/test/testpaint/VerticalTunnelCall.cpp index e989febe4b..129f248335 100644 --- a/test/testpaint/VerticalTunnelCall.cpp +++ b/test/testpaint/VerticalTunnelCall.cpp @@ -16,7 +16,24 @@ #include "VerticalTunnelCall.hpp" -bool VerticalTunnelCall::HeightIsConsistent(uint8 heights[4]) { +uint16 VerticalTunnelCall::GetTunnelHeight(uint16 baseHeight, uint8 *calls) { + if (calls[0] == 0 && calls[1] == 0 && calls[2] == 0) { + return 0; + } + + for (sint16 offset = 0; offset <= 256; offset += 8) { + if (calls[0] != (baseHeight - 8 + offset) / 16) continue; + if (calls[1] != (baseHeight + 0 + offset) / 16) continue; + if (calls[2] != (baseHeight + 8 + offset) / 16) continue; + + return baseHeight + offset; + } + + log_error("Unknown tunnel height. (%d, %d, %d)", calls[0], calls[1], calls[2]); + return 0; +} + +bool VerticalTunnelCall::HeightIsConsistent(uint16 *heights) { for (int i = 1; i < 4; ++i) { if (heights[i] != heights[0]) return false; } diff --git a/test/testpaint/VerticalTunnelCall.hpp b/test/testpaint/VerticalTunnelCall.hpp index c45f64ce46..9f7a143275 100644 --- a/test/testpaint/VerticalTunnelCall.hpp +++ b/test/testpaint/VerticalTunnelCall.hpp @@ -19,5 +19,6 @@ #include namespace VerticalTunnelCall { - bool HeightIsConsistent(uint8 heights[4]); + uint16 GetTunnelHeight(uint16 baseHeight, uint8 *calls); + bool HeightIsConsistent(uint16 *heights); };