Test vertical tunnels properly

This commit is contained in:
Marijn van der Werf 2017-01-17 23:57:53 +01:00
parent 6016339773
commit 2ffbbe0678
5 changed files with 55 additions and 16 deletions

View File

@ -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;
}

View File

@ -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];

View File

@ -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>
@ -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
);

View File

@ -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;
}

View File

@ -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);
};