From 23246c2d3f8d8a6ee48af707e72b82531ce35bc1 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 8 Oct 2016 21:49:28 +0100 Subject: [PATCH] Merge cases with identical calls --- test/testpaint/generate.cpp | 28 ++++++++++++++++++++++++++++ test/testpaint/intercept.c | 3 +-- test/testpaint/intercept.h | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/test/testpaint/generate.cpp b/test/testpaint/generate.cpp index d5f7f1ae4c..80e769a3a9 100644 --- a/test/testpaint/generate.cpp +++ b/test/testpaint/generate.cpp @@ -333,6 +333,16 @@ private: if (calls[direction].size() == 0) continue; WriteLine(tabs, "case %d:", direction); + for (int d2 = direction + 1; d2 < 4; d2++) + { + if (CompareFunctionCalls(calls[direction], calls[d2])) + { + // Clear identical other direction calls and add case for it + calls[d2].clear(); + WriteLine(tabs, "case %d:", d2); + } + } + for (auto call : calls[direction]) { GenerateCalls(tabs + 1, call, height); @@ -406,6 +416,24 @@ private: } } + bool CompareFunctionCalls(const std::vector &a, const std::vector &b) + { + if (a.size() != b.size()) return false; + for (size_t i = 0; i < a.size(); i++) + { + if (!CompareFunctionCall(a[i], b[i])) + { + return false; + } + } + return true; + } + + bool CompareFunctionCall(const function_call a, const function_call &b) + { + return assertFunctionCallEquals(a, b); + } + const char * GetFunctionCallName(int function) { const char * functionNames[] = { diff --git a/test/testpaint/intercept.c b/test/testpaint/intercept.c index d076d79027..3f4346df49 100644 --- a/test/testpaint/intercept.c +++ b/test/testpaint/intercept.c @@ -32,7 +32,6 @@ extern const utf8string TrackNames[256]; extern const utf8string FlatTrackNames[256]; static uint8 callCount; -static bool assertFunctionCallEquals(function_call expected, function_call actual); static function_call calls[256]; void intercept_clear_calls() @@ -267,7 +266,7 @@ static void canonicalizeFunctionCall(function_call *call) { call->function = PAINT_98196C; } -static bool assertFunctionCallEquals(function_call expected, function_call actual) { +bool assertFunctionCallEquals(function_call expected, function_call actual) { canonicalizeFunctionCall(&actual); canonicalizeFunctionCall(&expected); diff --git a/test/testpaint/intercept.h b/test/testpaint/intercept.h index 19c6d553be..624688fac1 100644 --- a/test/testpaint/intercept.h +++ b/test/testpaint/intercept.h @@ -83,6 +83,7 @@ extern "C" bool testVerticalTunnels(uint8 rideType, uint8 trackType); void intercept_clear_calls(); int intercept_get_calls(function_call * buffer); + bool assertFunctionCallEquals(function_call expected, function_call actual); int generatePaintCode(uint8 rideType); #ifdef __cplusplus