From 334b8cca057589cd17fafc664dfc6c75a95de004 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Sun, 16 Oct 2016 21:15:40 +0200 Subject: [PATCH] Extract all of `intercept.c` to C++ --- OpenRCT2.xcodeproj/project.pbxproj | 94 +++++++----- test/testpaint/FunctionCall.cpp | 17 +++ test/testpaint/FunctionCall.hpp | 1 + test/testpaint/PaintIntercept.cpp | 11 +- test/testpaint/Printer.cpp | 116 +++++++------- test/testpaint/Printer.hpp | 27 ++++ test/testpaint/String.cpp | 32 ++++ test/testpaint/String.hpp | 23 +++ test/testpaint/TestTrack.cpp | 204 +++++++++++++++++++++++++ test/testpaint/TestTrack.hpp | 29 ++++ test/testpaint/generate.cpp | 35 ++--- test/testpaint/intercept.c | 237 ----------------------------- test/testpaint/intercept.h | 5 - test/testpaint/main.cpp | 3 +- test/testpaint/testpaint.vcxproj | 3 +- 15 files changed, 472 insertions(+), 365 deletions(-) create mode 100644 test/testpaint/Printer.hpp create mode 100644 test/testpaint/String.cpp create mode 100644 test/testpaint/String.hpp create mode 100644 test/testpaint/TestTrack.cpp create mode 100644 test/testpaint/TestTrack.hpp delete mode 100644 test/testpaint/intercept.c diff --git a/OpenRCT2.xcodeproj/project.pbxproj b/OpenRCT2.xcodeproj/project.pbxproj index 006a16790a..b3952fc3af 100644 --- a/OpenRCT2.xcodeproj/project.pbxproj +++ b/OpenRCT2.xcodeproj/project.pbxproj @@ -19,10 +19,19 @@ 791166FB1D7486EF005912EA /* NetworkServerAdvertiser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 791166F91D7486EF005912EA /* NetworkServerAdvertiser.cpp */; }; 85060FD31D8C17CC00DFA2B3 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = 8594C05F1D885CF600235E93 /* track_data_old.c */; }; 8594C0601D885CF600235E93 /* track_data_old.c in Sources */ = {isa = PBXBuildFile; fileRef = 8594C05F1D885CF600235E93 /* track_data_old.c */; }; - 85AFA2111D7DB83E00221B42 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85AFA20F1D7DB83E00221B42 /* main.cpp */; }; 85B468FC1D96822F000F1DB5 /* paint_helpers.c in Sources */ = {isa = PBXBuildFile; fileRef = 85B468FB1D96822F000F1DB5 /* paint_helpers.c */; }; 85B468FD1D96822F000F1DB5 /* paint_helpers.c in Sources */ = {isa = PBXBuildFile; fileRef = 85B468FB1D96822F000F1DB5 /* paint_helpers.c */; }; - 85B5C0B01D81D912001B99A8 /* intercept_2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85B5C0AF1D81D912001B99A8 /* intercept_2.cpp */; }; + C606CCBE1DB4054000FE4015 /* compat.c in Sources */ = {isa = PBXBuildFile; fileRef = C606CCAB1DB4054000FE4015 /* compat.c */; }; + C606CCBF1DB4054000FE4015 /* data.c in Sources */ = {isa = PBXBuildFile; fileRef = C606CCAC1DB4054000FE4015 /* data.c */; }; + C606CCC01DB4054000FE4015 /* FunctionCall.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCAE1DB4054000FE4015 /* FunctionCall.cpp */; }; + C606CCC11DB4054000FE4015 /* generate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCB01DB4054000FE4015 /* generate.cpp */; }; + C606CCC21DB4054000FE4015 /* intercept_2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCB11DB4054000FE4015 /* intercept_2.cpp */; }; + C606CCC41DB4054000FE4015 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCB41DB4054000FE4015 /* main.cpp */; }; + C606CCC51DB4054000FE4015 /* PaintIntercept.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCB51DB4054000FE4015 /* PaintIntercept.cpp */; }; + C606CCC61DB4054000FE4015 /* Printer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCB61DB4054000FE4015 /* Printer.cpp */; }; + C606CCC71DB4054000FE4015 /* String.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCB81DB4054000FE4015 /* String.cpp */; }; + C606CCC81DB4054000FE4015 /* TestTrack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCBA1DB4054000FE4015 /* TestTrack.cpp */; }; + C606CCC91DB4054000FE4015 /* Utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C606CCBC1DB4054000FE4015 /* Utils.cpp */; }; C612A8991D64825300B634CA /* vehicle_data.c in Sources */ = {isa = PBXBuildFile; fileRef = C612A8971D64825300B634CA /* vehicle_data.c */; }; C61FB7241CF86356004CE991 /* NetworkUser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C61FB7221CF86356004CE991 /* NetworkUser.cpp */; }; C64FDA641D6D9A2100F259B9 /* air_powered_vertical_coaster.c in Sources */ = {isa = PBXBuildFile; fileRef = C686F8BB1CDBC3B7009F9BFC /* air_powered_vertical_coaster.c */; }; @@ -106,15 +115,11 @@ C64FDAC01D6D9E3B00F259B9 /* track_data.c in Sources */ = {isa = PBXBuildFile; fileRef = D442717B1CC81B3200D84D28 /* track_data.c */; }; C64FDAC21D6DA0B800F259B9 /* diagnostic.c in Sources */ = {isa = PBXBuildFile; fileRef = D44270FE1CC81B3200D84D28 /* diagnostic.c */; }; C64FDAC31D6DA41000F259B9 /* track_paint.c in Sources */ = {isa = PBXBuildFile; fileRef = D442717D1CC81B3200D84D28 /* track_paint.c */; }; - C64FDAC51D6DA55E00F259B9 /* compat.c in Sources */ = {isa = PBXBuildFile; fileRef = C64FDAC41D6DA55E00F259B9 /* compat.c */; }; - C64FDAC81D6DA72400F259B9 /* intercept.c in Sources */ = {isa = PBXBuildFile; fileRef = C64FDAC71D6DA72400F259B9 /* intercept.c */; }; - C64FDACA1D6DA92D00F259B9 /* data.c in Sources */ = {isa = PBXBuildFile; fileRef = C64FDAC91D6DA92D00F259B9 /* data.c */; }; C64FDACB1D6DBCC700F259B9 /* hook.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271121CC81B3200D84D28 /* hook.c */; }; C650B2191CCABBDD00B4D91C /* S4Importer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C650B2151CCABBDD00B4D91C /* S4Importer.cpp */; }; C650B21A1CCABBDD00B4D91C /* tables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C650B2171CCABBDD00B4D91C /* tables.cpp */; }; C650B21C1CCABC4400B4D91C /* ConvertCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C650B21B1CCABC4400B4D91C /* ConvertCommand.cpp */; }; C6575A371D46AFBA00C3E79F /* debug_paint.c in Sources */ = {isa = PBXBuildFile; fileRef = C6575A361D46AFBA00C3E79F /* debug_paint.c */; }; - C65A9EAF1DB2C01B003C3557 /* PaintIntercept.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C65A9EAE1DB2C01B003C3557 /* PaintIntercept.cpp */; }; C686F8AC1CDBC37E009F9BFC /* banner.c in Sources */ = {isa = PBXBuildFile; fileRef = C686F8981CDBC37E009F9BFC /* banner.c */; }; C686F8AD1CDBC37E009F9BFC /* entrance.c in Sources */ = {isa = PBXBuildFile; fileRef = C686F8991CDBC37E009F9BFC /* entrance.c */; }; C686F8AE1CDBC37E009F9BFC /* fence.c in Sources */ = {isa = PBXBuildFile; fileRef = C686F89A1CDBC37E009F9BFC /* fence.c */; }; @@ -207,7 +212,6 @@ C686F9581CDBC4C7009F9BFC /* vehicle_paint.c in Sources */ = {isa = PBXBuildFile; fileRef = C686F9561CDBC4C7009F9BFC /* vehicle_paint.c */; }; C6B5A7D41CDFE4CB00C9C006 /* S6Exporter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6B5A7D01CDFE4CB00C9C006 /* S6Exporter.cpp */; }; C6B5A7D51CDFE4CB00C9C006 /* S6Importer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6B5A7D21CDFE4CB00C9C006 /* S6Importer.cpp */; }; - C6BDA02B1DB3DFD600271C0A /* Printer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6BDA0291DB3DFC900271C0A /* Printer.cpp */; }; D41B73EF1C2101890080A7B9 /* libcurl.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D41B73EE1C2101890080A7B9 /* libcurl.tbd */; }; D41B741D1C210A7A0080A7B9 /* libiconv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = D41B741C1C210A7A0080A7B9 /* libiconv.tbd */; }; D41B74731C2125E50080A7B9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D41B74721C2125E50080A7B9 /* Assets.xcassets */; }; @@ -395,6 +399,7 @@ D44272A61CC81B3200D84D28 /* scenery.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271F01CC81B3200D84D28 /* scenery.c */; }; D44272A71CC81B3200D84D28 /* sprite.c in Sources */ = {isa = PBXBuildFile; fileRef = D44271F21CC81B3200D84D28 /* sprite.c */; }; D452919B1DAA204200C11788 /* generate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D45291991DAA202C00C11788 /* generate.cpp */; }; + D45A38BB1CF3006400659A24 /* engines in Resources */ = {isa = PBXBuildFile; fileRef = D45A38B21CF3006400659A24 /* engines */; }; D45A38BC1CF3006400659A24 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38B31CF3006400659A24 /* libcrypto.dylib */; }; D45A38BE1CF3006400659A24 /* libjansson.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38B51CF3006400659A24 /* libjansson.dylib */; }; D45A38C01CF3006400659A24 /* libSDL2_ttf.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D45A38B71CF3006400659A24 /* libSDL2_ttf.dylib */; }; @@ -496,26 +501,36 @@ 791166F91D7486EF005912EA /* NetworkServerAdvertiser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkServerAdvertiser.cpp; sourceTree = ""; }; 791166FA1D7486EF005912EA /* NetworkServerAdvertiser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkServerAdvertiser.h; sourceTree = ""; }; 8594C05F1D885CF600235E93 /* track_data_old.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = track_data_old.c; sourceTree = ""; }; - 85AFA20F1D7DB83E00221B42 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; - 85AFA2101D7DB83E00221B42 /* intercept.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = intercept.h; sourceTree = ""; }; - 85AFA2141D7DDFA100221B42 /* data.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = data.h; sourceTree = ""; }; 85B468FB1D96822F000F1DB5 /* paint_helpers.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = paint_helpers.c; sourceTree = ""; }; - 85B5C0AF1D81D912001B99A8 /* intercept_2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = intercept_2.cpp; sourceTree = ""; }; + C606CCAB1DB4054000FE4015 /* compat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat.c; sourceTree = ""; }; + C606CCAC1DB4054000FE4015 /* data.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = data.c; sourceTree = ""; }; + C606CCAD1DB4054000FE4015 /* data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = data.h; sourceTree = ""; }; + C606CCAE1DB4054000FE4015 /* FunctionCall.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FunctionCall.cpp; sourceTree = ""; }; + C606CCAF1DB4054000FE4015 /* FunctionCall.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = FunctionCall.hpp; sourceTree = ""; }; + C606CCB01DB4054000FE4015 /* generate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = generate.cpp; sourceTree = ""; }; + C606CCB11DB4054000FE4015 /* intercept_2.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = intercept_2.cpp; sourceTree = ""; }; + C606CCB31DB4054000FE4015 /* intercept.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = intercept.h; sourceTree = ""; }; + C606CCB41DB4054000FE4015 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; + C606CCB51DB4054000FE4015 /* PaintIntercept.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PaintIntercept.cpp; sourceTree = ""; }; + C606CCB61DB4054000FE4015 /* Printer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Printer.cpp; sourceTree = ""; }; + C606CCB71DB4054000FE4015 /* Printer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Printer.hpp; sourceTree = ""; }; + C606CCB81DB4054000FE4015 /* String.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = String.cpp; sourceTree = ""; }; + C606CCB91DB4054000FE4015 /* String.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = String.hpp; sourceTree = ""; }; + C606CCBA1DB4054000FE4015 /* TestTrack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TestTrack.cpp; sourceTree = ""; }; + C606CCBB1DB4054000FE4015 /* TestTrack.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TestTrack.hpp; sourceTree = ""; }; + C606CCBC1DB4054000FE4015 /* Utils.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Utils.cpp; sourceTree = ""; }; + C606CCBD1DB4054000FE4015 /* Utils.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Utils.hpp; sourceTree = ""; }; C612A8971D64825300B634CA /* vehicle_data.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vehicle_data.c; sourceTree = ""; }; C612A8981D64825300B634CA /* vehicle_data.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = vehicle_data.h; sourceTree = ""; }; C61FB7221CF86356004CE991 /* NetworkUser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkUser.cpp; sourceTree = ""; usesTabs = 0; }; C61FB7231CF86356004CE991 /* NetworkUser.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = NetworkUser.h; sourceTree = ""; usesTabs = 0; }; C64FDA5D1D6D99F400F259B9 /* PaintTest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = PaintTest; sourceTree = BUILT_PRODUCTS_DIR; }; - C64FDAC41D6DA55E00F259B9 /* compat.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = compat.c; sourceTree = ""; }; - C64FDAC71D6DA72400F259B9 /* intercept.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = intercept.c; sourceTree = ""; }; - C64FDAC91D6DA92D00F259B9 /* data.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = data.c; sourceTree = ""; }; C650B2151CCABBDD00B4D91C /* S4Importer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = S4Importer.cpp; sourceTree = ""; usesTabs = 0; }; C650B2161CCABBDD00B4D91C /* S4Importer.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = S4Importer.h; sourceTree = ""; usesTabs = 0; }; C650B2171CCABBDD00B4D91C /* tables.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tables.cpp; sourceTree = ""; usesTabs = 0; }; C650B2181CCABBDD00B4D91C /* Tables.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = Tables.h; sourceTree = ""; usesTabs = 0; }; C650B21B1CCABC4400B4D91C /* ConvertCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConvertCommand.cpp; sourceTree = ""; usesTabs = 0; }; C6575A361D46AFBA00C3E79F /* debug_paint.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = debug_paint.c; sourceTree = ""; }; - C65A9EAE1DB2C01B003C3557 /* PaintIntercept.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PaintIntercept.cpp; sourceTree = ""; }; C686F8981CDBC37E009F9BFC /* banner.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = banner.c; sourceTree = ""; }; C686F8991CDBC37E009F9BFC /* entrance.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = entrance.c; sourceTree = ""; }; C686F89A1CDBC37E009F9BFC /* fence.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fence.c; sourceTree = ""; }; @@ -616,7 +631,6 @@ C6B5A7D11CDFE4CB00C9C006 /* S6Exporter.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = S6Exporter.h; sourceTree = ""; }; C6B5A7D21CDFE4CB00C9C006 /* S6Importer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = S6Importer.cpp; sourceTree = ""; }; C6B5A7D31CDFE4CB00C9C006 /* S6Importer.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = S6Importer.h; sourceTree = ""; }; - C6BDA0291DB3DFC900271C0A /* Printer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Printer.cpp; sourceTree = ""; }; D41B73EE1C2101890080A7B9 /* libcurl.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libcurl.tbd; path = usr/lib/libcurl.tbd; sourceTree = SDKROOT; }; D41B741C1C210A7A0080A7B9 /* libiconv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libiconv.tbd; path = usr/lib/libiconv.tbd; sourceTree = SDKROOT; }; D41B74721C2125E50080A7B9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = distribution/macos/Assets.xcassets; sourceTree = SOURCE_ROOT; }; @@ -913,6 +927,7 @@ D44271F31CC81B3200D84D28 /* sprite.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sprite.h; sourceTree = ""; }; D44271F41CC81B3200D84D28 /* water.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = water.h; sourceTree = ""; }; D45291991DAA202C00C11788 /* generate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = generate.cpp; sourceTree = ""; }; + D45A38B21CF3006400659A24 /* engines */ = {isa = PBXFileReference; lastKnownFileType = folder; path = engines; sourceTree = ""; }; D45A38B31CF3006400659A24 /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libcrypto.dylib; sourceTree = ""; }; D45A38B41CF3006400659A24 /* libfreetype.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libfreetype.dylib; sourceTree = ""; }; D45A38B51CF3006400659A24 /* libjansson.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libjansson.dylib; sourceTree = ""; }; @@ -1171,16 +1186,24 @@ C64FDA5E1D6D99F400F259B9 /* Paint */ = { isa = PBXGroup; children = ( - C64FDAC41D6DA55E00F259B9 /* compat.c */, - C64FDAC91D6DA92D00F259B9 /* data.c */, - 85AFA2141D7DDFA100221B42 /* data.h */, - D45291991DAA202C00C11788 /* generate.cpp */, - 85B5C0AF1D81D912001B99A8 /* intercept_2.cpp */, - C64FDAC71D6DA72400F259B9 /* intercept.c */, - 85AFA2101D7DB83E00221B42 /* intercept.h */, - 85AFA20F1D7DB83E00221B42 /* main.cpp */, - C65A9EAE1DB2C01B003C3557 /* PaintIntercept.cpp */, - C6BDA0291DB3DFC900271C0A /* Printer.cpp */, + C606CCAB1DB4054000FE4015 /* compat.c */, + C606CCAC1DB4054000FE4015 /* data.c */, + C606CCAD1DB4054000FE4015 /* data.h */, + C606CCAE1DB4054000FE4015 /* FunctionCall.cpp */, + C606CCAF1DB4054000FE4015 /* FunctionCall.hpp */, + C606CCB01DB4054000FE4015 /* generate.cpp */, + C606CCB11DB4054000FE4015 /* intercept_2.cpp */, + C606CCB31DB4054000FE4015 /* intercept.h */, + C606CCB41DB4054000FE4015 /* main.cpp */, + C606CCB51DB4054000FE4015 /* PaintIntercept.cpp */, + C606CCB61DB4054000FE4015 /* Printer.cpp */, + C606CCB71DB4054000FE4015 /* Printer.hpp */, + C606CCB81DB4054000FE4015 /* String.cpp */, + C606CCB91DB4054000FE4015 /* String.hpp */, + C606CCBA1DB4054000FE4015 /* TestTrack.cpp */, + C606CCBB1DB4054000FE4015 /* TestTrack.hpp */, + C606CCBC1DB4054000FE4015 /* Utils.cpp */, + C606CCBD1DB4054000FE4015 /* Utils.hpp */, ); name = Paint; path = test/testpaint; @@ -2371,7 +2394,6 @@ C64FDA651D6D9A2100F259B9 /* bobsleigh_coaster.c in Sources */, C64FDA661D6D9A2100F259B9 /* compact_inverted_coaster.c in Sources */, C64FDA671D6D9A2100F259B9 /* corkscrew_roller_coaster.c in Sources */, - 85AFA2111D7DB83E00221B42 /* main.cpp in Sources */, C64FDA681D6D9A2100F259B9 /* flying_roller_coaster.c in Sources */, C64FDA691D6D9A2100F259B9 /* giga_coaster.c in Sources */, C64FDA6A1D6D9A2100F259B9 /* heartline_twister_coaster.c in Sources */, @@ -2382,25 +2404,26 @@ C64FDA6F1D6D9A2100F259B9 /* lay_down_roller_coaster.c in Sources */, C64FDA701D6D9A2100F259B9 /* lim_launched_roller_coaster.c in Sources */, C64FDA711D6D9A2100F259B9 /* looping_roller_coaster.c in Sources */, - C64FDAC81D6DA72400F259B9 /* intercept.c in Sources */, C64FDA721D6D9A2100F259B9 /* mine_ride.c in Sources */, C64FDA731D6D9A2100F259B9 /* mine_train_coaster.c in Sources */, C64FDA741D6D9A2100F259B9 /* mini_roller_coaster.c in Sources */, C64FDA751D6D9A2100F259B9 /* mini_suspended_coaster.c in Sources */, C64FDA761D6D9A2100F259B9 /* multi_dimension_roller_coaster.c in Sources */, C64FDA771D6D9A2100F259B9 /* reverse_freefall_coaster.c in Sources */, + C606CCBE1DB4054000FE4015 /* compat.c in Sources */, C64FDA781D6D9A2100F259B9 /* reverser_roller_coaster.c in Sources */, C64FDA791D6D9A2100F259B9 /* side_friction_roller_coaster.c in Sources */, - C64FDACA1D6DA92D00F259B9 /* data.c in Sources */, C64FDA7A1D6D9A2100F259B9 /* spiral_roller_coaster.c in Sources */, + C606CCC21DB4054000FE4015 /* intercept_2.cpp in Sources */, C64FDA7B1D6D9A2100F259B9 /* stand_up_roller_coaster.c in Sources */, + C606CCC61DB4054000FE4015 /* Printer.cpp in Sources */, C64FDA7C1D6D9A2100F259B9 /* steeplechase.c in Sources */, C64FDA7D1D6D9A2100F259B9 /* suspended_swinging_coaster.c in Sources */, - C6BDA02B1DB3DFD600271C0A /* Printer.cpp in Sources */, C64FDA7E1D6D9A2100F259B9 /* twister_roller_coaster.c in Sources */, C64FDA7F1D6D9A2100F259B9 /* vertical_drop_roller_coaster.c in Sources */, C64FDA801D6D9A2100F259B9 /* virginia_reel.c in Sources */, C64FDA811D6D9A2100F259B9 /* wild_mouse.c in Sources */, + C606CCC41DB4054000FE4015 /* main.cpp in Sources */, C64FDA821D6D9A2100F259B9 /* wooden_roller_coaster.c in Sources */, C64FDA831D6D9A2100F259B9 /* wooden_wild_mouse.c in Sources */, C64FDA841D6D9A2100F259B9 /* car_ride.c in Sources */, @@ -2409,26 +2432,28 @@ 85060FD31D8C17CC00DFA2B3 /* track_data_old.c in Sources */, C64FDA871D6D9A2100F259B9 /* dodgems.c in Sources */, C64FDA881D6D9A2100F259B9 /* ferris_wheel.c in Sources */, - D452919B1DAA204200C11788 /* generate.cpp in Sources */, C64FDA891D6D9A2100F259B9 /* flying_saucers.c in Sources */, + C606CCC11DB4054000FE4015 /* generate.cpp in Sources */, C64FDA8A1D6D9A2100F259B9 /* ghost_train.c in Sources */, + C606CCBF1DB4054000FE4015 /* data.c in Sources */, C64FDA8B1D6D9A2100F259B9 /* haunted_house.c in Sources */, C64FDA8C1D6D9A2100F259B9 /* maze.c in Sources */, C64FDA8D1D6D9A2100F259B9 /* merry_go_round.c in Sources */, C64FDA8E1D6D9A2100F259B9 /* mini_golf.c in Sources */, + C606CCC81DB4054000FE4015 /* TestTrack.cpp in Sources */, C64FDA8F1D6D9A2100F259B9 /* mini_helicopters.c in Sources */, + C606CCC51DB4054000FE4015 /* PaintIntercept.cpp in Sources */, C64FDA901D6D9A2100F259B9 /* monorail_cycles.c in Sources */, - 85B5C0B01D81D912001B99A8 /* intercept_2.cpp in Sources */, C64FDA911D6D9A2100F259B9 /* observation_tower.c in Sources */, C64FDA921D6D9A2100F259B9 /* space_rings.c in Sources */, C64FDA931D6D9A2100F259B9 /* spiral_slide.c in Sources */, C64FDA941D6D9A2100F259B9 /* facility.c in Sources */, - C64FDAC51D6DA55E00F259B9 /* compat.c in Sources */, C64FDA951D6D9A2100F259B9 /* misc.c in Sources */, C64FDA961D6D9A2100F259B9 /* shop.c in Sources */, C64FDA971D6D9A2100F259B9 /* 3d_cinema.c in Sources */, C64FDA981D6D9A2100F259B9 /* enterprise.c in Sources */, C64FDA991D6D9A2100F259B9 /* go_karts.c in Sources */, + C606CCC01DB4054000FE4015 /* FunctionCall.cpp in Sources */, C64FDA9A1D6D9A2100F259B9 /* launched_freefall.c in Sources */, C64FDA9B1D6D9A2100F259B9 /* magic_carpet.c in Sources */, C64FDA9C1D6D9A2100F259B9 /* motion_simulator.c in Sources */, @@ -2438,6 +2463,7 @@ C64FDAA01D6D9A2100F259B9 /* top_spin.c in Sources */, C64FDAA11D6D9A2100F259B9 /* twist.c in Sources */, C64FDAA21D6D9A2100F259B9 /* chairlift.c in Sources */, + C606CCC71DB4054000FE4015 /* String.cpp in Sources */, C64FDAA31D6D9A2100F259B9 /* lift.c in Sources */, C64FDAA41D6D9A2100F259B9 /* miniature_railway.c in Sources */, C64FDAA51D6D9A2100F259B9 /* monorail.c in Sources */, @@ -2447,11 +2473,11 @@ C64FDAA81D6D9A2100F259B9 /* dingy_slide.c in Sources */, C64FDAA91D6D9A2100F259B9 /* log_flume.c in Sources */, C64FDAAA1D6D9A2100F259B9 /* river_rafts.c in Sources */, + C606CCC91DB4054000FE4015 /* Utils.cpp in Sources */, C64FDAAB1D6D9A2100F259B9 /* river_rapids.c in Sources */, C64FDAAC1D6D9A2100F259B9 /* splash_boats.c in Sources */, C64FDAAD1D6D9A2100F259B9 /* submarine_ride.c in Sources */, C64FDAAE1D6D9A2100F259B9 /* water_coaster.c in Sources */, - C65A9EAF1DB2C01B003C3557 /* PaintIntercept.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/test/testpaint/FunctionCall.cpp b/test/testpaint/FunctionCall.cpp index b499a136be..c0074f34c9 100644 --- a/test/testpaint/FunctionCall.cpp +++ b/test/testpaint/FunctionCall.cpp @@ -29,6 +29,23 @@ enum SpriteGroup { static void canonicalizeFunctionCall(function_call *call); static SpriteGroup getSpriteGroup(uint16 spriteIndex); +bool FunctionCall::AssertsEquals(std::vector expected, std::vector actual) { + if (expected.size() != actual.size()) { + return false; + } + + for (int i = 0; i < expected.size(); i++) { + function_call expectedCall = expected[i]; + function_call actualCall = actual[i]; + + if (!AssertsEquals(expectedCall, actualCall)) { + return false; + } + } + + return true; +} + bool FunctionCall::AssertsEquals(function_call expected, function_call actual) { canonicalizeFunctionCall(&actual); canonicalizeFunctionCall(&expected); diff --git a/test/testpaint/FunctionCall.hpp b/test/testpaint/FunctionCall.hpp index c0225af9ac..aabe4e565e 100644 --- a/test/testpaint/FunctionCall.hpp +++ b/test/testpaint/FunctionCall.hpp @@ -22,4 +22,5 @@ class FunctionCall { public: static bool AssertsEquals(function_call expected, function_call actual); + static bool AssertsEquals(std::vector expected, std::vector actual); }; diff --git a/test/testpaint/PaintIntercept.cpp b/test/testpaint/PaintIntercept.cpp index ed6412d25c..a56564b662 100644 --- a/test/testpaint/PaintIntercept.cpp +++ b/test/testpaint/PaintIntercept.cpp @@ -163,12 +163,15 @@ private: } static void CheckSegmentSupportHeight() { - // First get last known support height state - if (memcmp(gSupportSegments, &DefaultSegmentHeight, sizeof(support_height) * 9) == 0) { - // Nothing changed - return; + bool hasChanged = false; + for (int i = 0; i < 9; i++) { + if (gSupportSegments[i].height != 0) hasChanged = true; + if (gSupportSegments[i].slope != 0xFF) hasChanged = true; } + if (!hasChanged) { + return; + } function_call call = {0}; call.function = SET_SEGMENT_HEIGHT; diff --git a/test/testpaint/Printer.cpp b/test/testpaint/Printer.cpp index a742e58e90..bd3d8fb8b2 100644 --- a/test/testpaint/Printer.cpp +++ b/test/testpaint/Printer.cpp @@ -14,72 +14,86 @@ *****************************************************************************/ #pragma endregion -#include - +#include "Printer.hpp" +#include "String.hpp" #include "intercept.h" -class Printer { -public: - static std::string PrintFunction(function_call call, uint16 baseHeight) { - std::string imageId = GetImageIdString(call.paint.image_id); +namespace Printer { + + static const char *functionNames[] = { + "sub_98196C", + "sub_98197C", + "sub_98198C", + "sub_98199C", + "metal_a_supports_paint_setup", + "metal_b_supports_paint_setup", + "wooden_a_supports_paint_setup", + "wooden_b_supports_paint_setup", + }; + + static std::string GetImageIdString(uint32 imageId); + + static std::string GetHeightOffset(uint16 height, uint16 baseHeight); + + static std::string GetOffsetExpressionString(int offset); + + std::string PrintFunctionCalls(std::vector calls, uint16 baseHeight) { + std::string out; + + for (auto &&call : calls) { + out += PrintFunctionCall(call, baseHeight).c_str(); + out += "\n"; + } + + return out; + } + + std::string PrintFunctionCall(function_call call, uint16 baseHeight) { + std::string imageId = GetImageIdString(call.supports.colour_flags); + const char *functionName = functionNames[call.function]; switch (call.function) { case SUPPORTS_WOOD_A: - return StringFormat("wooden_a_supports_paint_setup(%d, %d, %s, %s)", call.supports.type, call.supports.special, - GetHeightOffset(call.supports.height, baseHeight).c_str(), imageId.c_str()); case SUPPORTS_WOOD_B: - return StringFormat("wooden_b_supports_paint_setup(%d, %d, %s, %s)", call.supports.type, call.supports.special, - call.supports.height, imageId.c_str()); + return String::Format( + "%s(%d, %d, %s, %s)", functionName, call.supports.type, call.supports.special, + GetHeightOffset(call.supports.height, baseHeight).c_str(), imageId.c_str() + ); case SUPPORTS_METAL_A: - return StringFormat("metal_a_supports_paint_setup(%d, %d, %d, %s, %s)", call.supports.type, - call.supports.segment, call.supports.special, GetHeightOffset(call.supports.height, baseHeight).c_str(), imageId.c_str()); case SUPPORTS_METAL_B: - return StringFormat("metal_b_supports_paint_setup(%d, %d, %d, %s, %s)", call.supports.type, - call.supports.segment, call.supports.special, GetHeightOffset(call.supports.height, baseHeight).c_str(), imageId.c_str()); + return String::Format( + "%s(%d, %d, %d, %s, %s)", functionName, call.supports.type, call.supports.segment, call.supports.special, + GetHeightOffset(call.supports.height, baseHeight).c_str(), imageId.c_str() + ); case SET_SEGMENT_HEIGHT: return "paint_util_set_segment_support_height"; } - std::string functionCallName = "?"; - switch (call.function) { - case PAINT_98196C: - functionCallName = "sub_98196C"; - break; - case PAINT_98197C: - functionCallName = "sub_98197C"; - break; - case PAINT_98198C: - functionCallName = "sub_98198C"; - break; - case PAINT_98199C: - functionCallName = "sub_98199C"; - break; - } + std::string s = String::Format("%s(", functionName); - std::string s = StringFormat("%s(", functionCallName.c_str()); - - s += StringFormat("%s, ", imageId.c_str()); - s += StringFormat("%d, %d, ", call.paint.offset.x, call.paint.offset.y); - s += StringFormat( + imageId = GetImageIdString(call.paint.image_id); + s += String::Format("%s, ", imageId.c_str()); + s += String::Format("%d, %d, ", call.paint.offset.x, call.paint.offset.y); + s += String::Format( "%d, %d, %d, ", call.paint.bound_box_length.x, call.paint.bound_box_length.y, call.paint.bound_box_length.z ); - s += StringFormat("%s, ", GetHeightOffset(call.paint.z_offset, baseHeight).c_str()); + s += String::Format("%s, ", GetHeightOffset(call.paint.z_offset, baseHeight).c_str()); if (call.function != PAINT_98196C) { - s += StringFormat( + s += String::Format( "%d, %d, %s, ", call.paint.bound_box_offset.x, call.paint.bound_box_offset.y, GetHeightOffset(call.paint.bound_box_offset.z, baseHeight).c_str() ); } - s += StringFormat("%d)", call.paint.rotation); + s += String::Format("%d)", call.paint.rotation); if (call.function != PAINT_98196C) { - s += StringFormat( + s += String::Format( " = { %d, %d, %s }, { %d, %d, %s }, { %d, %d, %d }", call.paint.offset.x, call.paint.offset.y, GetHeightOffset(call.paint.z_offset, baseHeight).c_str(), call.paint.bound_box_offset.x, call.paint.bound_box_offset.y, @@ -90,7 +104,6 @@ public: return s; } -private: static std::string GetImageIdString(uint32 imageId) { std::string result; @@ -104,15 +117,15 @@ private: else if (palette == Intercept2::DEFAULT_SCHEME_MISC) paletteName = "SCHEME_MISC"; else if (palette == Intercept2::DEFAULT_SCHEME_3) paletteName = "SCHEME_3"; else { - paletteName = StringFormat("0x%08X", palette); + paletteName = String::Format("0x%08X", palette); } if (image == 0) { result = paletteName; } else if (image & 0x70000) { - result = StringFormat("%s | vehicle.base_image_id + %d", paletteName.c_str(), image & ~0x70000); + result = String::Format("%s | vehicle.base_image_id + %d", paletteName.c_str(), image & ~0x70000); } else { - result = StringFormat("%s | %d", paletteName.c_str(), image); + result = String::Format("%s | %d", paletteName.c_str(), image); } return result; @@ -121,7 +134,7 @@ private: static std::string GetHeightOffset(uint16 height, uint16 baseHeight) { int offset = height - baseHeight; - return StringFormat("height%s", GetOffsetExpressionString(offset).c_str()); + return String::Format("height%s", GetOffsetExpressionString(offset).c_str()); } static std::string GetOffsetExpressionString(int offset) @@ -130,21 +143,4 @@ private: if (offset > 0) return std::string(" + ") + std::to_string(offset); return std::string(); } - - static std::string StringFormat(const char *format, ...) { - va_list args; - char buffer[512]; - - va_start(args, format); - vsnprintf(buffer, sizeof(buffer), format, args); - va_end(args); - - return std::string(buffer); - } }; - -extern "C" { -void printFunctionCall(utf8string out, size_t len, function_call call, uint16 baseHeight) { - snprintf(out, len, "%s", Printer::PrintFunction(call, baseHeight).c_str()); -} -} diff --git a/test/testpaint/Printer.hpp b/test/testpaint/Printer.hpp new file mode 100644 index 0000000000..d8815bdee0 --- /dev/null +++ b/test/testpaint/Printer.hpp @@ -0,0 +1,27 @@ +#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 +#include + +#include "intercept.h" + +namespace Printer { + std::string PrintFunctionCall(function_call call, uint16 baseHeight); + std::string PrintFunctionCalls(std::vector calls, uint16 baseHeight); +} diff --git a/test/testpaint/String.cpp b/test/testpaint/String.cpp new file mode 100644 index 0000000000..0189d9cd5a --- /dev/null +++ b/test/testpaint/String.cpp @@ -0,0 +1,32 @@ +#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 "String.hpp" + +namespace String { + std::string Format(const char * format, ...) + { + va_list args; + char buffer[512]; + + va_start(args, format); + vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); + + return std::string(buffer); + } +}; + diff --git a/test/testpaint/String.hpp b/test/testpaint/String.hpp new file mode 100644 index 0000000000..67c232530a --- /dev/null +++ b/test/testpaint/String.hpp @@ -0,0 +1,23 @@ +#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 + +namespace String { + std::string Format(const char *format, ...); +} diff --git a/test/testpaint/TestTrack.cpp b/test/testpaint/TestTrack.cpp new file mode 100644 index 0000000000..bb90af069c --- /dev/null +++ b/test/testpaint/TestTrack.cpp @@ -0,0 +1,204 @@ +#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 +#include + +#include "intercept.h" +#include "Printer.hpp" +#include "String.hpp" +#include "TestTrack.hpp" +#include "Utils.hpp" +#include "FunctionCall.hpp" + +extern "C" { +#include "../../src/ride/ride.h" +#include "../../src/ride/track.h" +#include "../../src/ride/track_data.h" +} + +static void CallOriginal( + uint8 rideType, + uint8 trackType, + uint8 direction, + uint8 trackSequence, + uint16 height, + rct_map_element *mapElement +) { + uint32 *trackDirectionList = (uint32 *) RideTypeTrackPaintFunctionsOld[rideType][trackType]; + const uint8 rideIndex = 0; + + // Have to call from this point as it pushes esi and expects callee to pop it + RCT2_CALLPROC_X( + 0x006C4934, + rideType, + (int) trackDirectionList, + direction, + height, + (int) &mapElement, + rideIndex * sizeof(rct_ride), + trackSequence + ); +} + +static void CallNew( + uint8 rideType, + uint8 trackType, + uint8 direction, + uint8 trackSequence, + uint16 height, + rct_map_element *mapElement +) { + TRACK_PAINT_FUNCTION_GETTER newPaintFunctionGetter = RideTypeTrackPaintFunctions[rideType]; + TRACK_PAINT_FUNCTION newPaintFunction = newPaintFunctionGetter(trackType, direction); + + newPaintFunction(0, trackSequence, direction, height, mapElement); +} + +uint8 TestTrack::TestPaintTrackElement(uint8 rideType, uint8 trackType) { + if (!Utils::rideSupportsTrackType(rideType, trackType)) { + return TEST_FAILED; + } + + + std::string error = ""; + uint8 retVal = TestPaintTrackElementCalls(rideType, trackType, &error); + + if (retVal != TEST_SUCCESS) { + printf("%s\n", error.c_str()); + } + + return retVal; +} + +uint8 TestTrack::TestPaintTrackElementCalls(uint8 rideType, uint8 trackType, std::string *error) { + if (rideType == RIDE_TYPE_CHAIRLIFT) { + if (trackType == TRACK_ELEM_BEGIN_STATION || trackType == TRACK_ELEM_MIDDLE_STATION || + trackType == TRACK_ELEM_END_STATION) { + // These rides check neighbouring tiles for tracks + return TEST_SKIPPED; + } + } + + uint8 rideIndex = 0; + uint16 height = 3 * 16; + + rct_map_element mapElement = {0}; + mapElement.flags |= MAP_ELEMENT_FLAG_LAST_TILE; + mapElement.properties.track.type = trackType; + mapElement.base_height = height / 16; + g_currently_drawn_item = &mapElement; + + rct_map_element surfaceElement = {0}; + surfaceElement.type = MAP_ELEMENT_TYPE_SURFACE; + surfaceElement.base_height = 2; + gSurfaceElement = &surfaceElement; + gDidPassSurface = true; + + intercept_reset_environment(); + + int sequenceCount = getTrackSequenceCount(rideType, trackType); + + *error += String::Format("rct2: 0x%08X\n", RideTypeTrackPaintFunctionsOld[rideType][trackType]); + + function_call callBuffer[256] = {0}; + int callCount = 0; + + int chainLift = 0; + int inverted = 0; + + // TODO: test chainlift + // TODO: test inverted + // TODO: test supports + // TODO: test entrance styles + + for (int currentRotation = 0; currentRotation < 4; currentRotation++) { + gCurrentRotation = currentRotation; + for (int direction = 0; direction < 4; direction++) { + for (int trackSequence = 0; trackSequence < sequenceCount; trackSequence++) { + RCT2_GLOBAL(0x009DE56A, sint16) = 64; // x + RCT2_GLOBAL(0x009DE56E, sint16) = 64; // y + + std::string caseName = String::Format( + "[direction:%d trackSequence:%d chainLift:%d inverted:%d]", + direction, trackSequence, chainLift, inverted + ); + + intercept_clear_calls(); + intercept_reset_segment_heights(); + + CallOriginal(rideType, trackType, direction, trackSequence, height, &mapElement); + + callCount = intercept_get_calls(callBuffer); + std::vector oldCalls; + oldCalls.insert(oldCalls.begin(), callBuffer, callBuffer + callCount); + + intercept_clear_calls(); + testpaint_clear_ignore(); + intercept_reset_segment_heights(); + + CallNew(rideType, trackType, direction, trackSequence, height, &mapElement); + + if (testpaint_is_ignored(direction, trackSequence)) { + *error += String::Format("[ IGNORED ] %s\n", caseName.c_str()); + continue; + } + + callCount = intercept_get_calls(callBuffer); + std::vector newCalls; + newCalls.insert(newCalls.begin(), callBuffer, callBuffer + callCount); + + bool sucess = true; + if (oldCalls.size() != newCalls.size()) { + *error += String::Format( + "Call counts don't match (was %d, expected %d). %s\n", + newCalls.size(), oldCalls.size(), caseName.c_str() + ); + sucess = false; + } else if (!FunctionCall::AssertsEquals(oldCalls, newCalls)) { + *error += String::Format("Calls don't match. %s\n", caseName.c_str()); + sucess = false; + } + + if (!sucess) { + *error += " Expected:\n"; + *error += Printer::PrintFunctionCalls(oldCalls, height); + *error += " Actual:\n"; + *error += Printer::PrintFunctionCalls(newCalls, height); + + return TEST_FAILED; + } + } + } + } + + bool segmentSuccess = testSupportSegments(rideType, trackType); + if (!segmentSuccess) { + return TEST_FAILED; + } + + bool tunnelSuccess = testTunnels(rideType, trackType); + if (!tunnelSuccess) { + return TEST_FAILED; + } + + bool verticalTunnelSuccess = testVerticalTunnels(rideType, trackType); + if (!verticalTunnelSuccess) { + return TEST_FAILED; + } + + return TEST_SUCCESS; +} \ No newline at end of file diff --git a/test/testpaint/TestTrack.hpp b/test/testpaint/TestTrack.hpp new file mode 100644 index 0000000000..7f049766aa --- /dev/null +++ b/test/testpaint/TestTrack.hpp @@ -0,0 +1,29 @@ +#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 + +#include "../../src/common.h" + +class TestTrack { +public: + static uint8 TestPaintTrackElement(uint8 rideType, uint8 trackType); + +private: + static uint8 TestPaintTrackElementCalls(uint8 rideType, uint8 trackType, std::string * error); +}; diff --git a/test/testpaint/generate.cpp b/test/testpaint/generate.cpp index 64265577b7..615692f9ef 100644 --- a/test/testpaint/generate.cpp +++ b/test/testpaint/generate.cpp @@ -19,6 +19,7 @@ #include #include "intercept.h" +#include "String.hpp" extern "C" { @@ -630,17 +631,17 @@ private: { const char * funcName = GetFunctionCallName(call.function); std::string imageId = GetImageIdString(call.paint.image_id); - std::string s = StringFormat("%s_rotated(direction, %s, ", funcName, imageId.c_str()); + std::string s = String::Format("%s_rotated(direction, %s, ", funcName, imageId.c_str()); s += FormatXYSwap(call.paint.offset.x, call.paint.offset.y, direction); s += ", "; s += FormatXYSwap(call.paint.bound_box_length.x, call.paint.bound_box_length.y, direction); - s += StringFormat(", %d, height%s", call.paint.bound_box_length.z, GetOffsetExpressionString(call.paint.z_offset - height).c_str()); + s += String::Format(", %d, height%s", call.paint.bound_box_length.z, GetOffsetExpressionString(call.paint.z_offset - height).c_str()); if (call.function != PAINT_98196C) { s += ", "; s += FormatXYSwap(call.paint.bound_box_offset.x, call.paint.bound_box_offset.y, direction); - s += StringFormat(", height%s", GetOffsetExpressionString(call.paint.bound_box_offset.z - height).c_str()); + s += String::Format(", height%s", GetOffsetExpressionString(call.paint.bound_box_offset.z - height).c_str()); } s += ");"; @@ -651,11 +652,11 @@ private: { if (direction & 1) { - return StringFormat("%d, %d", y, x); + return String::Format("%d, %d", y, x); } else { - return StringFormat("%d, %d", x, y); + return String::Format("%d, %d", x, y); } } @@ -912,12 +913,12 @@ private: if (ssh.height == 0xFFFF) { szCall += "0xFFFF"; - szCall += StringFormat(", 0);", ssh.slope); + szCall += String::Format(", 0);", ssh.slope); } else { szCall += std::to_string(ssh.height); - szCall += StringFormat(", 0x%02X);", ssh.slope); + szCall += String::Format(", 0x%02X);", ssh.slope); } WriteLine(tabs, szCall); } @@ -953,15 +954,15 @@ private: else if (palette == Intercept2::DEFAULT_SCHEME_MISC) paletteName = "gTrackColours[SCHEME_MISC]"; else if (palette == Intercept2::DEFAULT_SCHEME_3) paletteName = "gTrackColours[SCHEME_3]"; else { - paletteName = StringFormat("0x%08X", palette); + paletteName = String::Format("0x%08X", palette); } if (image == 0) { result = paletteName; } else if (image & 0x70000) { - result = StringFormat("%s | vehicle.base_image_id + %d", paletteName.c_str(), image & ~0x70000); + result = String::Format("%s | vehicle.base_image_id + %d", paletteName.c_str(), image & ~0x70000); } else { - result = StringFormat("%s | %d", paletteName.c_str(), image); + result = String::Format("%s | %d", paletteName.c_str(), image); } return result; } @@ -982,7 +983,7 @@ private: if (segmentsPrinted > 0) { s += " | "; } - s += StringFormat("SEGMENT_%02X", 0xB4 + 4 * i); + s += String::Format("SEGMENT_%02X", 0xB4 + 4 * i); segmentsPrinted++; } } @@ -1093,18 +1094,6 @@ private: } fprintf(_file, "%s\n", s.c_str()); } - - static std::string StringFormat(const char * format, ...) - { - va_list args; - char buffer[512]; - - va_start(args, format); - vsnprintf(buffer, sizeof(buffer), format, args); - va_end(args); - - return std::string(buffer); - } }; extern "C" diff --git a/test/testpaint/intercept.c b/test/testpaint/intercept.c deleted file mode 100644 index 1a8ea16387..0000000000 --- a/test/testpaint/intercept.c +++ /dev/null @@ -1,237 +0,0 @@ -#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 "intercept.h" -#include "data.h" -#include "../../src/paint/paint.h" -#include "../../src/paint/supports.h" -#include "../../src/ride/track_data.h" -#include "../../src/interface/viewport.h" -#include "../../src/hook.h" - -#define BLANK_SUPPORT {.height = 0, .slope = 0xFF} -const support_height DefaultSegmentHeight[9] = { - BLANK_SUPPORT, BLANK_SUPPORT, BLANK_SUPPORT, - BLANK_SUPPORT, BLANK_SUPPORT, BLANK_SUPPORT, - BLANK_SUPPORT, BLANK_SUPPORT, BLANK_SUPPORT -}; - -static bool assertFunctionCallArrayEquals(function_call expected[], uint8 expectedCount, function_call actual[], uint8 actualCount) { - if (expectedCount != actualCount) { - return false; - } - - for (int i = 0; i < expectedCount; i++) { - function_call expectedCall = expected[i]; - function_call actualCall = actual[i]; - - if (!assertFunctionCallEquals(expectedCall, actualCall)) { - return false; - } - } - - return true; -} - -static void printFunctionCallArray(utf8string out, size_t len, function_call calls[], uint8 count, uint16 baseHeight) { - for (int i = 0; i < count; i++) { - utf8string callOut = malloc(1024); - printFunctionCall(callOut, 1024, calls[i], baseHeight); - size_t slen = strlen(out); - if (slen < len) - snprintf(out + slen, len - slen, "%s\n", callOut); - } -} - - -extern bool testSupportSegments(uint8 rideType, uint8 trackType); -extern bool testTunnels(uint8 rideType, uint8 trackType); -extern bool testVerticalTunnels(uint8 rideType, uint8 trackType); - -static uint8 testTrackElement(uint8 rideType, uint8 trackType, utf8string error, size_t len) { - if (rideType == RIDE_TYPE_CHAIRLIFT) { - if (trackType == TRACK_ELEM_BEGIN_STATION || trackType == TRACK_ELEM_MIDDLE_STATION || trackType == TRACK_ELEM_END_STATION) { - // These rides check neighbouring tiles for tracks - return TEST_SKIPPED; - } - } - - uint8 rideIndex = 0; - rct_map_element mapElement = { 0 }; - mapElement.flags |= MAP_ELEMENT_FLAG_LAST_TILE; - mapElement.properties.track.type = trackType; - mapElement.base_height = 3; - - g_currently_drawn_item = &mapElement; - - rct_map_element surfaceElement = { 0 }; - surfaceElement.type = MAP_ELEMENT_TYPE_SURFACE; - surfaceElement.base_height = 2; - - intercept_reset_environment(); - - int height = 48; - - snprintf(error, len, "rct2: 0x%08X\n", RideTypeTrackPaintFunctionsOld[rideType][trackType]); - - TRACK_PAINT_FUNCTION_GETTER newPaintGetter = RideTypeTrackPaintFunctions[rideType]; - int sequenceCount = getTrackSequenceCount(rideType, trackType); - - for (int supports = 0; supports < 2; supports++) { - if (supports == 0) { - intercept_simulate_wooden_supports(false); - } else { - intercept_simulate_wooden_supports(true); - } - for (int inverted = 0; inverted < 2; inverted++) { - if (inverted == 0) { - mapElement.properties.track.colour &= ~TRACK_ELEMENT_COLOUR_FLAG_INVERTED; - } else { - mapElement.properties.track.colour |= TRACK_ELEMENT_COLOUR_FLAG_INVERTED; - } - for (int chainLift = 0; chainLift < 2; chainLift++) { - if (chainLift == 0) { - mapElement.type &= ~0x80; - } else { - mapElement.type |= 0x80; - } - for (int currentRotation = 0; currentRotation < 4; currentRotation++) { - gCurrentRotation = currentRotation; - for (int direction = 0; direction < 4; direction++) { - TRACK_PAINT_FUNCTION newPaintFunction = newPaintGetter(trackType, direction); - for (int trackSequence = 0; trackSequence < sequenceCount; trackSequence++) { - RCT2_GLOBAL(0x009DE56A, sint16) = 64; // x - RCT2_GLOBAL(0x009DE56E, sint16) = 64; // y - gDidPassSurface = true; // Above surface - gSurfaceElement = &surfaceElement; - - intercept_clear_calls(); - intercept_reset_segment_heights(); - - uint32 *trackDirectionList = (uint32 *)RideTypeTrackPaintFunctionsOld[rideType][trackType]; - - // Have to call from this point as it pushes esi and expects callee to pop it - RCT2_CALLPROC_X( - 0x006C4934, - rideType, - (int) trackDirectionList, - direction, - height, - (int) &mapElement, - rideIndex * sizeof(rct_ride), - trackSequence - ); - // segment heights - // tunnels - - function_call oldCalls[256]; - int oldCallCount = intercept_get_calls(oldCalls); - - intercept_clear_calls(); - - testpaint_clear_ignore(); - intercept_reset_segment_heights(); - - newPaintFunction(rideIndex, trackSequence, direction, height, &mapElement); - if (testpaint_is_ignored(direction, trackSequence)) { - snprintf(error, len, "[ IGNORED ] [direction:%d trackSequence:%d chainLift:%d inverted:%d]\n", - direction, trackSequence, chainLift, inverted); - continue; - } - - function_call newCalls[256]; - int newCallCount = intercept_get_calls(newCalls); - - if (!assertFunctionCallArrayEquals(oldCalls, oldCallCount, newCalls, newCallCount)) { - utf8string diff = malloc(2048); - - snprintf(diff, 2048, "<<< EXPECTED\n"); - printFunctionCallArray(diff, 2048, oldCalls, oldCallCount, height); - - size_t slen = strlen(diff); - if (slen < 2048) - snprintf(diff + slen, 2048 - slen, "====\n"); - printFunctionCallArray(diff, 2048, newCalls, newCallCount, height); - - slen = strlen(diff); - if (slen < 2048) - snprintf(diff + slen, 2048 - slen, ">>> ACTUAL\n"); - - if (oldCallCount != newCallCount) { - slen = strlen(error); - if (slen < len) - snprintf(error + slen, len - slen, "Call counts don't match (was %d, expected %d) [direction:%d trackSequence:%d chainLift:%d inverted:%d]", - newCallCount, oldCallCount, direction, trackSequence, chainLift, inverted); - } else { - slen = strlen(error); - if (slen < len) - snprintf(error + slen, len - slen, "Calls don't match [direction:%d trackSequence:%d chainLift:%d inverted:%d]", - direction, trackSequence, chainLift, inverted); - } - - slen = strlen(error); - if (slen < len) - snprintf(error + slen, len - slen, "\n%s", diff); - - free(diff); - - return TEST_FAILED; - } - - } - } - } - } - } - } - - bool segmentSuccess = testSupportSegments(rideType, trackType); - if (!segmentSuccess) { - return TEST_FAILED; - } - - bool tunnelSuccess = testTunnels(rideType, trackType); - if (!tunnelSuccess) { - return TEST_FAILED; - } - - bool verticalTunnelSuccess = testVerticalTunnels(rideType, trackType); - if (!verticalTunnelSuccess) { - return TEST_FAILED; - } - - return TEST_SUCCESS; -} - -uint8 testTrackPainting(int rideType, int trackType) { - TRACK_PAINT_FUNCTION_GETTER newPaintGetter = RideTypeTrackPaintFunctions[rideType]; - if (newPaintGetter == NULL) { - return false; - } - - if (newPaintGetter(trackType, 0) == NULL) { - return false; - } - - utf8string error = malloc(2048); - int retVal = testTrackElement(rideType, trackType, error, 2048); - if (retVal != TEST_SUCCESS) { - printf("%s\n", error); - } - free(error); - - return retVal; -} diff --git a/test/testpaint/intercept.h b/test/testpaint/intercept.h index 07b32ab6a8..b63ee38f6e 100644 --- a/test/testpaint/intercept.h +++ b/test/testpaint/intercept.h @@ -82,7 +82,6 @@ extern "C" #endif void initHooks(); int getTrackSequenceCount(uint8 rideType, uint8 trackType); - uint8 testTrackPainting(int rideType, int trackType); bool testSupportSegments(uint8 rideType, uint8 trackType); bool testTunnels(uint8 rideType, uint8 trackType); bool testVerticalTunnels(uint8 rideType, uint8 trackType); @@ -91,14 +90,10 @@ extern "C" void intercept_reset_environment(); void intercept_reset_segment_heights(); void intercept_reset_tunnels(); - void intercept_simulate_wooden_supports(bool enabled); - void printFunctionCall(utf8string out, size_t len, function_call call, uint16 baseHeight); bool assertFunctionCallEquals(function_call expected, function_call actual); int generatePaintCode(uint8 rideType); - extern const support_height DefaultSegmentHeight[9]; - #ifdef __cplusplus } #endif diff --git a/test/testpaint/main.cpp b/test/testpaint/main.cpp index 269e2cfc3b..78383d4482 100644 --- a/test/testpaint/main.cpp +++ b/test/testpaint/main.cpp @@ -24,6 +24,7 @@ #endif // defined(__unix__) #include "intercept.h" +#include "TestTrack.hpp" #include "Utils.hpp" extern "C" { @@ -449,7 +450,7 @@ int main(int argc, char *argv[]) { ColouredPrintF(CLIColour::GREEN, "[ RUN ] "); printf("%s.%s\n", rideTypeName, trackTypeName); - int retVal = testTrackPainting(tc.rideType, trackType); + int retVal = TestTrack::TestPaintTrackElement(tc.rideType, trackType); switch (retVal) { case TEST_SUCCESS: ColouredPrintF(CLIColour::GREEN, "[ OK ] "); diff --git a/test/testpaint/testpaint.vcxproj b/test/testpaint/testpaint.vcxproj index ca9561ec02..5ecb055bdc 100644 --- a/test/testpaint/testpaint.vcxproj +++ b/test/testpaint/testpaint.vcxproj @@ -97,11 +97,12 @@ - + +