From f813a2871b4c8edc1d8bd7dc08428e3becfaa3a6 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Sun, 16 Oct 2016 19:22:02 +0200 Subject: [PATCH] Extract function comparison --- test/testpaint/FunctionCall.cpp | 129 ++++++++++++++++++++++++++++++++ test/testpaint/FunctionCall.hpp | 25 +++++++ test/testpaint/intercept.c | 101 ------------------------- 3 files changed, 154 insertions(+), 101 deletions(-) create mode 100644 test/testpaint/FunctionCall.cpp create mode 100644 test/testpaint/FunctionCall.hpp diff --git a/test/testpaint/FunctionCall.cpp b/test/testpaint/FunctionCall.cpp new file mode 100644 index 0000000000..b499a136be --- /dev/null +++ b/test/testpaint/FunctionCall.cpp @@ -0,0 +1,129 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#include "FunctionCall.hpp" + +enum SpriteGroup { + SPRITEGROUP_NONE, + + SPRITEGROUP_FENCE_METAL_A, // 14568 + SPRITEGROUP_FENCE_METAL_B, // 14990 + SPRITEGROUP_FENCE_SPIRAL_SLIDE, // 20564 + SPRITEGROUP_FLOOR_CORK, // 22134 + SPRITEGROUP_FENCE_ROPE, // 22138 +}; + +static void canonicalizeFunctionCall(function_call *call); +static SpriteGroup getSpriteGroup(uint16 spriteIndex); + +bool FunctionCall::AssertsEquals(function_call expected, function_call actual) { + canonicalizeFunctionCall(&actual); + canonicalizeFunctionCall(&expected); + + if (expected.function != actual.function) { + return false; + } + + uint8 function = expected.function; + + if (function == SUPPORTS_WOOD_A || function == SUPPORTS_WOOD_B) { + if (expected.supports.type != actual.supports.type) return false; + if (expected.supports.special != actual.supports.special) return false; + if (expected.supports.height != actual.supports.height) return false; + if (expected.supports.colour_flags != actual.supports.colour_flags) return false; + + return true; + } + + if (function == SUPPORTS_METAL_A || function == SUPPORTS_METAL_B) { + if (expected.supports.type != actual.supports.type) return false; + if (expected.supports.segment != actual.supports.segment) return false; + if (expected.supports.special != actual.supports.special) return false; + if (expected.supports.height != actual.supports.height) return false; + if (expected.supports.colour_flags != actual.supports.colour_flags) return false; + + return true; + } + + if (function == SET_SEGMENT_HEIGHT) { + return true; + } + + if (expected.paint.image_id != actual.paint.image_id) { + SpriteGroup expectedSpriteGroup = getSpriteGroup(expected.paint.image_id & 0x7FFFF); + SpriteGroup actualSpriteGroup = getSpriteGroup(actual.paint.image_id & 0x7FFFF); + + if (expectedSpriteGroup != actualSpriteGroup) return false; + + if (expectedSpriteGroup == SPRITEGROUP_NONE) return false; + + return true; + } + + if (expected.paint.offset.x != actual.paint.offset.x) return false; + if (expected.paint.offset.y != actual.paint.offset.y) return false; + if (expected.paint.bound_box_length.x != actual.paint.bound_box_length.x) return false; + if (expected.paint.bound_box_length.y != actual.paint.bound_box_length.y) return false; + if (expected.paint.bound_box_length.z != actual.paint.bound_box_length.z) return false; + if (function != PAINT_98196C) { + if (expected.paint.bound_box_offset.x != actual.paint.bound_box_offset.x) return false; + if (expected.paint.bound_box_offset.y != actual.paint.bound_box_offset.y) return false; + if (expected.paint.bound_box_offset.z != actual.paint.bound_box_offset.z) return false; + } + if (expected.paint.z_offset != actual.paint.z_offset) return false; + if (expected.paint.rotation != actual.paint.rotation) return false; + + return true; +} + +static void canonicalizeFunctionCall(function_call *call) { + if (call->function != PAINT_98197C) return; + if (call->paint.offset.x != call->paint.bound_box_offset.x) return; + if (call->paint.offset.y != call->paint.bound_box_offset.y) return; + if (call->paint.z_offset != call->paint.bound_box_offset.z) return; + + call->function = PAINT_98196C; +} + +static SpriteGroup getSpriteGroup(uint16 spriteIndex) { + if (spriteIndex >= 14568 && spriteIndex <= 14571) { + return SPRITEGROUP_FENCE_METAL_A; + } + + if (spriteIndex >= 14990 && spriteIndex <= 14993) { + return SPRITEGROUP_FENCE_METAL_B; + } + + if (spriteIndex >= 20564 && spriteIndex <= 20567) { + return SPRITEGROUP_FENCE_SPIRAL_SLIDE; + } + + if (spriteIndex >= 22134 && spriteIndex <= 22137) { + return SPRITEGROUP_FLOOR_CORK; + } + + if (spriteIndex >= 22138 && spriteIndex <= 22141) { + return SPRITEGROUP_FENCE_ROPE; + } + + return SPRITEGROUP_NONE; +} + +extern "C" { + bool assertFunctionCallEquals(function_call expected, function_call actual) { + return FunctionCall::AssertsEquals(expected, actual); + } +} \ No newline at end of file diff --git a/test/testpaint/FunctionCall.hpp b/test/testpaint/FunctionCall.hpp new file mode 100644 index 0000000000..c0225af9ac --- /dev/null +++ b/test/testpaint/FunctionCall.hpp @@ -0,0 +1,25 @@ +#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers +/***************************************************************************** + * OpenRCT2, an open source clone of Roller Coaster Tycoon 2. + * + * OpenRCT2 is the work of many authors, a full list can be found in contributors.md + * For more information, visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * A full copy of the GNU General Public License can be found in licence.txt + *****************************************************************************/ +#pragma endregion + +#pragma once + +#include "../../src/common.h" +#include "intercept.h" + +class FunctionCall { +public: + static bool AssertsEquals(function_call expected, function_call actual); +}; diff --git a/test/testpaint/intercept.c b/test/testpaint/intercept.c index 0f1e3f1037..f912573e7b 100644 --- a/test/testpaint/intercept.c +++ b/test/testpaint/intercept.c @@ -37,108 +37,7 @@ extern const utf8string RideNames[91]; extern const utf8string TrackNames[256]; extern const utf8string FlatTrackNames[256]; -enum { - SPRITEGROUP_NONE, - SPRITEGROUP_FENCE_METAL_A, // 14568 - SPRITEGROUP_FENCE_METAL_B, // 14990 - SPRITEGROUP_FENCE_SPIRAL_SLIDE, // 20564 - SPRITEGROUP_FLOOR_CORK, // 22134 - SPRITEGROUP_FENCE_ROPE, // 22138 -}; - -static int getSpriteGroup(uint16 spriteIndex) { - if (spriteIndex >= 14568 && spriteIndex <= 14571) { - return SPRITEGROUP_FENCE_METAL_A; - } - - if (spriteIndex >= 14990 && spriteIndex <= 14993) { - return SPRITEGROUP_FENCE_METAL_B; - } - - if (spriteIndex >= 20564 && spriteIndex <= 20567) { - return SPRITEGROUP_FENCE_SPIRAL_SLIDE; - } - - if (spriteIndex >= 22134 && spriteIndex <= 22137) { - return SPRITEGROUP_FLOOR_CORK; - } - - if (spriteIndex >= 22138 && spriteIndex <= 22141) { - return SPRITEGROUP_FENCE_ROPE; - } - - return SPRITEGROUP_NONE; -} - -static void canonicalizeFunctionCall(function_call *call) { - if (call->function != PAINT_98197C) return; - if (call->paint.offset.x != call->paint.bound_box_offset.x) return; - if (call->paint.offset.y != call->paint.bound_box_offset.y) return; - if (call->paint.z_offset != call->paint.bound_box_offset.z) return; - - call->function = PAINT_98196C; -} - -bool assertFunctionCallEquals(function_call expected, function_call actual) { - canonicalizeFunctionCall(&actual); - canonicalizeFunctionCall(&expected); - - if (expected.function != actual.function) { - return false; - } - - uint8 function = expected.function; - - if (function == SUPPORTS_WOOD_A || function == SUPPORTS_WOOD_B) { - if (expected.supports.type != actual.supports.type) return false; - if (expected.supports.special != actual.supports.special) return false; - if (expected.supports.height != actual.supports.height) return false; - if (expected.supports.colour_flags != actual.supports.colour_flags) return false; - - return true; - } - - if (function == SUPPORTS_METAL_A || function == SUPPORTS_METAL_B) { - if (expected.supports.type != actual.supports.type) return false; - if (expected.supports.segment != actual.supports.segment) return false; - if (expected.supports.special != actual.supports.special) return false; - if (expected.supports.height != actual.supports.height) return false; - if (expected.supports.colour_flags != actual.supports.colour_flags) return false; - - return true; - } - - if (function == SET_SEGMENT_HEIGHT) { - return true; - } - - if (expected.paint.image_id != actual.paint.image_id) { - int expectedSpriteGroup = getSpriteGroup(expected.paint.image_id & 0x7FFFF); - int actualSpriteGroup = getSpriteGroup(actual.paint.image_id & 0x7FFFF); - - if (expectedSpriteGroup != actualSpriteGroup) return false; - - if (expectedSpriteGroup == SPRITEGROUP_NONE) return false; - - return true; - } - - if (expected.paint.offset.x != actual.paint.offset.x) return false; - if (expected.paint.offset.y != actual.paint.offset.y) return false; - if (expected.paint.bound_box_length.x != actual.paint.bound_box_length.x) return false; - if (expected.paint.bound_box_length.y != actual.paint.bound_box_length.y) return false; - if (expected.paint.bound_box_length.z != actual.paint.bound_box_length.z) return false; - if (function != PAINT_98196C) { - if (expected.paint.bound_box_offset.x != actual.paint.bound_box_offset.x) return false; - if (expected.paint.bound_box_offset.y != actual.paint.bound_box_offset.y) return false; - if (expected.paint.bound_box_offset.z != actual.paint.bound_box_offset.z) return false; - } - if (expected.paint.z_offset != actual.paint.z_offset) return false; - if (expected.paint.rotation != actual.paint.rotation) return false; - - return true; -} static bool assertFunctionCallArrayEquals(function_call expected[], uint8 expectedCount, function_call actual[], uint8 actualCount) { if (expectedCount != actualCount) {