Skip to content

Commit

Permalink
Merge pull request #5087 from marijnvdwerf/fix/vertical-tunnels
Browse files Browse the repository at this point in the history
Test vertical tunnels properly
  • Loading branch information
Gymnasiast committed Jan 18, 2017
2 parents 2fda0c8 + 2c6100a commit f6b55b4
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 21 deletions.
7 changes: 7 additions & 0 deletions src/openrct2/paint/map_element/map_element.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/openrct2/paint/map_element/map_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/ride/coaster/bolliger_mabillard_track.c
Original file line number Diff line number Diff line change
Expand Up @@ -3062,7 +3062,7 @@ void bolliger_mabillard_track_60_deg_up_to_90_deg_up(uint8 rideIndex, uint8 trac
if (direction == 0 || direction == 3) {
paint_util_push_tunnel_rotated(direction, height - 8, TUNNEL_7);
}
paint_util_set_vertical_tunnel(height + 48);
paint_util_set_vertical_tunnel(height + 56);
paint_util_set_segment_support_height(paint_util_rotate_segments(SEGMENT_C4 | SEGMENT_CC | SEGMENT_D0, direction), 0xFFFF, 0);
paint_util_set_general_support_height(height + 56, 0x20);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/ride/coaster/compact_inverted_coaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -3526,7 +3526,7 @@ static void compact_inverted_rc_track_60_deg_up_to_90_deg_up(uint8 rideIndex, ui
if (direction == 0 || direction == 3) {
paint_util_push_tunnel_rotated(direction, height - 8, TUNNEL_4);
}
paint_util_set_vertical_tunnel(height + 48);
paint_util_set_vertical_tunnel(height + 56);
paint_util_set_segment_support_height(paint_util_rotate_segments(SEGMENT_C4 | SEGMENT_CC | SEGMENT_D0, direction), 0xFFFF, 0);
paint_util_set_general_support_height(height + 72, 0x20);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/ride/coaster/inverted_impulse_coaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static void inverted_impulse_rc_track_60_deg_up_to_90_deg_up(uint8 rideIndex, ui
if (direction == 0 || direction == 3) {
paint_util_push_tunnel_rotated(direction, height - 8, TUNNEL_4);
}
paint_util_set_vertical_tunnel(height + 48);
paint_util_set_vertical_tunnel(height + 56);
paint_util_set_segment_support_height(paint_util_rotate_segments(SEGMENT_C4 | SEGMENT_CC | SEGMENT_D0, direction), 0xFFFF, 0);
paint_util_set_general_support_height(height + 72, 0x20);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/ride/coaster/lim_launched_roller_coaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ static void lim_launched_rc_track_60_deg_up_to_90_deg_up(uint8 rideIndex, uint8
if (direction == 0 || direction == 3) {
paint_util_push_tunnel_rotated(direction, height - 8, TUNNEL_1);
}
paint_util_set_vertical_tunnel(height + 48);
paint_util_set_vertical_tunnel(height + 56);
paint_util_set_segment_support_height(paint_util_rotate_segments(SEGMENT_C4 | SEGMENT_CC | SEGMENT_D0, direction), 0xFFFF, 0);
paint_util_set_general_support_height(height + 56, 0x20);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/ride/coaster/multi_dimension_roller_coaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -4182,7 +4182,7 @@ static void multi_dimension_rc_track_60_deg_up_to_90_deg_up(uint8 rideIndex, uin
if (direction == 0 || direction == 3) {
paint_util_push_tunnel_rotated(direction, height - 8, TUNNEL_7);
}
paint_util_set_vertical_tunnel(height + 48);
paint_util_set_vertical_tunnel(height + 56);
paint_util_set_segment_support_height(paint_util_rotate_segments(SEGMENT_C4 | SEGMENT_CC | SEGMENT_D0, direction), 0xFFFF, 0);
paint_util_set_general_support_height(height + 56, 0x20);
break;
Expand Down
38 changes: 24 additions & 14 deletions test/testpaint/TestTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "VerticalTunnelCall.hpp"

extern "C" {
#include <openrct2/paint/map_element/map_element.h>
#include <openrct2/paint/supports.h>
#include <openrct2/ride/ride.h>
#include <openrct2/ride/track.h>
Expand Down Expand Up @@ -700,46 +701,55 @@ 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
);
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
);
Expand Down
19 changes: 18 additions & 1 deletion test/testpaint/VerticalTunnelCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion test/testpaint/VerticalTunnelCall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
#include <openrct2/common.h>

namespace VerticalTunnelCall {
bool HeightIsConsistent(uint8 heights[4]);
uint16 GetTunnelHeight(uint16 baseHeight, uint8 *calls);
bool HeightIsConsistent(uint16 *heights);
};

0 comments on commit f6b55b4

Please sign in to comment.