From ec082b4ac85fdb7bbf9cfb5da12f3b124674a8d2 Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 7 Oct 2016 23:52:01 +0100 Subject: [PATCH] Generate set segment support height and other fixes --- src/ride/coaster/wild_mouse.c | 7 +- test/testpaint/generate.cpp | 100 +++++++++++++++++++++----- test/testpaint/intercept.h | 78 +++++++++++++++++--- test/testpaint/intercept_2.cpp | 36 +--------- test/testpaint/main.cpp | 9 ++- test/testpaint/testpaint.vcxproj.user | 2 +- 6 files changed, 167 insertions(+), 65 deletions(-) diff --git a/src/ride/coaster/wild_mouse.c b/src/ride/coaster/wild_mouse.c index e54ac5bfb1..79ce4bd0f2 100644 --- a/src/ride/coaster/wild_mouse.c +++ b/src/ride/coaster/wild_mouse.c @@ -38,7 +38,8 @@ enum { SPR_WILD_MOUSE_ROTATION_CONTROL_TOGGLE_NW_SE = 16909, SPR_WILD_MOUSE_FLAT_CHAIN_SW_NE = 16910, SPR_WILD_MOUSE_FLAT_CHAIN_NW_SE = 16911, - + SPR_WILD_MOUSE_FLAT_CHAIN_NE_SW = 16912, + SPR_WILD_MOUSE_FLAT_CHAIN_SE_NW = 16913, SPR_WILD_MOUSE_FLAT_TO_25_DEG_SW_NE = 16914, SPR_WILD_MOUSE_FLAT_TO_25_DEG_NW_SE = 16915, SPR_WILD_MOUSE_FLAT_TO_25_DEG_NE_SW = 16916, @@ -172,8 +173,8 @@ static void wild_mouse_track_flat(uint8 rideIndex, uint8 trackSequence, uint8 di static const uint32 imageIds[4][2] = { { SPR_WILD_MOUSE_FLAT_SW_NE, SPR_WILD_MOUSE_FLAT_CHAIN_SW_NE }, { SPR_WILD_MOUSE_FLAT_NW_SE, SPR_WILD_MOUSE_FLAT_CHAIN_NW_SE }, - { SPR_WILD_MOUSE_FLAT_SW_NE, SPR_WILD_MOUSE_FLAT_CHAIN_SW_NE }, - { SPR_WILD_MOUSE_FLAT_NW_SE, SPR_WILD_MOUSE_FLAT_CHAIN_NW_SE }, + { SPR_WILD_MOUSE_FLAT_SW_NE, SPR_WILD_MOUSE_FLAT_CHAIN_NE_SW }, + { SPR_WILD_MOUSE_FLAT_NW_SE, SPR_WILD_MOUSE_FLAT_CHAIN_SE_NW }, }; diff --git a/test/testpaint/generate.cpp b/test/testpaint/generate.cpp index 3533ffa120..5bdba5f3f5 100644 --- a/test/testpaint/generate.cpp +++ b/test/testpaint/generate.cpp @@ -18,10 +18,11 @@ #include #include +#include "intercept.h" + extern "C" { #include "data.h" - #include "intercept.h" #include "../../src/interface/viewport.h" #include "../../src/rct2.h" #include "../../src/ride/ride.h" @@ -77,15 +78,14 @@ private: void GenerateTrackFunction(int trackType) { - std::string trackName = TrackNames[trackType]; int numSequences = getTrackSequenceCount(_rideType, trackType); int height = 48; - WriteLine(0, "static void " + _rideName + "_track_" + trackName + "(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement)"); + WriteLine(0, "static void " + GetTrackFunctionName(trackType) + "(uint8 rideIndex, uint8 trackSequence, uint8 direction, int height, rct_map_element * mapElement)"); WriteLine(0, "{"); + std::vector segmentSupportCalls[4]; support_height generalSupports[4] = { 0 }; - for (int direction = 0; direction < 4; direction++) { int trackSequence = 0; @@ -97,19 +97,74 @@ private: CallOriginal(trackType, direction, trackSequence, height, &mapElement); + segmentSupportCalls[direction] = Intercept2::getSegmentCalls(gSupportSegments, direction); generalSupports[direction] = gSupport; + generalSupports[direction].height -= height; } + GenerateSegmentSupportCall(segmentSupportCalls); + GenerateGeneralSupportCall(generalSupports); + + WriteLine(0, "}"); + } + + void GenerateSegmentSupportCall(std::vector segmentSupportCalls[4]) + { + for (size_t i = 0; i < segmentSupportCalls[0].size(); i++) + { + auto ssh = segmentSupportCalls[0][i]; + std::string szCall = "paint_util_set_segment_support_height("; + if (ssh.segments == SEGMENTS_ALL) + { + szCall += "SEGMENTS_ALL"; + } + else + { + szCall += "paint_util_rotate_segments("; + szCall += GetORedSegments(ssh.segments); + szCall += ", direction)"; + } + szCall += ", "; + if (ssh.height == 0xFFFF) + { + szCall += "0xFFFF"; + szCall += StringFormat(", 0);", ssh.slope); + } + else + { + szCall += std::to_string(ssh.height); + szCall += StringFormat(", 0x%02X);", ssh.slope); + } + WriteLine(1, szCall); + } + } + + void GenerateGeneralSupportCall(support_height generalSupports[4]) + { if (AllMatch(generalSupports, 4)) { - WriteLine(1, "paint_util_set_general_support_height(height + %d, 0x%02X);", generalSupports[0].height - height, generalSupports[0].slope); + WriteLine(1, "paint_util_set_general_support_height(height + %d, 0x%02X);", generalSupports[0].height, generalSupports[0].slope); } else { WriteLine(1, "#error Unsupported: different directional general supports"); } + } - WriteLine(0, "}"); + std::string GetORedSegments(int segments) + { + std::string s; + int segmentsPrinted = 0; + for (int i = 0; i < 9; i++) { + if (segments & segment_offsets[i]) { + if (segmentsPrinted > 0) { + s += " | "; + } + s += StringFormat("SEGMENT_%02X", 0xB4 + 4 * i); + segmentsPrinted++; + } + } + return s; } template @@ -127,16 +182,11 @@ private: void CallOriginal(int trackType, int direction, int trackSequence, int height, rct_map_element *mapElement) { - constexpr uint32 DEFAULT_SCHEME_TRACK = COLOUR_GREY << 19 | COLOUR_WHITE << 24 | 0xA0000000; - constexpr uint32 DEFAULT_SCHEME_SUPPORTS = COLOUR_LIGHT_BLUE << 19 | COLOUR_ICY_BLUE << 24 | 0xA0000000; - constexpr uint32 DEFAULT_SCHEME_MISC = COLOUR_DARK_PURPLE << 19 | COLOUR_LIGHT_PURPLE << 24 | 0xA0000000; - constexpr uint32 DEFAULT_SCHEME_3 = COLOUR_BRIGHT_PURPLE << 19 | COLOUR_DARK_BLUE << 24 | 0xA0000000; - gPaintInteractionType = VIEWPORT_INTERACTION_ITEM_RIDE; - gTrackColours[SCHEME_TRACK] = DEFAULT_SCHEME_TRACK; - gTrackColours[SCHEME_SUPPORTS] = DEFAULT_SCHEME_SUPPORTS; - gTrackColours[SCHEME_MISC] = DEFAULT_SCHEME_MISC; - gTrackColours[SCHEME_3] = DEFAULT_SCHEME_3; + gTrackColours[SCHEME_TRACK] = Intercept2::DEFAULT_SCHEME_TRACK; + gTrackColours[SCHEME_SUPPORTS] = Intercept2::DEFAULT_SCHEME_SUPPORTS; + gTrackColours[SCHEME_MISC] = Intercept2::DEFAULT_SCHEME_MISC; + gTrackColours[SCHEME_3] = Intercept2::DEFAULT_SCHEME_3; rct_drawpixelinfo dpi = { 0 }; dpi.zoom_level = 1; @@ -186,7 +236,7 @@ private: if (IsTrackTypeSupported(trackType)) { WriteLine(1, "case " + std::string(TrackElemNames[trackType]) + ":"); - WriteLine(2, "return NULL;"); + WriteLine(2, "return %s;", GetTrackFunctionName(trackType).c_str()); } } WriteLine(1, "}"); @@ -194,6 +244,12 @@ private: WriteLine(0, "}"); } + std::string GetTrackFunctionName(int trackType) + { + std::string trackName = TrackNames[trackType]; + return _rideName + "_track_" + trackName; + } + bool IsTrackTypeSupported(int trackType) { if (trackType == TRACK_ELEM_BEGIN_STATION || @@ -235,6 +291,18 @@ private: fprintf(_file, s.c_str()); fprintf(_file, "\n"); } + + static std::string StringFormat(const char * format, ...) + { + va_list args; + char buffer[512]; + + va_start(args, format); + vsprintf(buffer, format, args); + va_end(args); + + return std::string(buffer); + } }; extern "C" diff --git a/test/testpaint/intercept.h b/test/testpaint/intercept.h index a4ed85752c..6a0cff586c 100644 --- a/test/testpaint/intercept.h +++ b/test/testpaint/intercept.h @@ -19,19 +19,77 @@ #include "../../src/common.h" +#ifdef __cplusplus +extern "C" +{ +#endif + #include "../../src/interface/colour.h" + #include "../../src/paint/paint.h" +#ifdef __cplusplus +} +#endif + #define gRideEntries RCT2_ADDRESS(RCT2_ADDRESS_RIDE_ENTRIES, rct_ride_entry*) #define gCurrentRotation RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8) -bool testRide(int rideType); -void initHooks(); -int getTrackSequenceCount(uint8 rideType, uint8 trackType); -bool rideIsImplemented(int rideType); -bool rideSupportsTrackType(int rideType, int trackType); -bool testTrackPainting(int rideType, int trackType); -bool testSupportSegments(uint8 rideType, uint8 trackType); -bool testTunnels(uint8 rideType, uint8 trackType); -bool testVerticalTunnels(uint8 rideType, uint8 trackType); +#ifdef __cplusplus +extern "C" +{ +#endif + bool testRide(int rideType); + void initHooks(); + int getTrackSequenceCount(uint8 rideType, uint8 trackType); + bool rideIsImplemented(int rideType); + bool rideSupportsTrackType(int rideType, int trackType); + bool testTrackPainting(int rideType, int trackType); + bool testSupportSegments(uint8 rideType, uint8 trackType); + bool testTunnels(uint8 rideType, uint8 trackType); + bool testVerticalTunnels(uint8 rideType, uint8 trackType); -int generatePaintCode(uint8 rideType); + int generatePaintCode(uint8 rideType); +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus + +#include + +namespace Intercept2 +{ + static const uint32 DEFAULT_SCHEME_TRACK = COLOUR_GREY << 19 | COLOUR_WHITE << 24 | 0xA0000000; + static const uint32 DEFAULT_SCHEME_SUPPORTS = COLOUR_LIGHT_BLUE << 19 | COLOUR_ICY_BLUE << 24 | 0xA0000000; + static const uint32 DEFAULT_SCHEME_MISC = COLOUR_DARK_PURPLE << 19 | COLOUR_LIGHT_PURPLE << 24 | 0xA0000000; + static const uint32 DEFAULT_SCHEME_3 = COLOUR_BRIGHT_PURPLE << 19 | COLOUR_DARK_BLUE << 24 | 0xA0000000; + + struct SegmentSupportCall + { + uint16 segments; + sint32 height; + sint16 slope; + }; + + struct SupportCall + { + sint32 height; + sint16 slope; + }; + + enum { + TUNNELCALL_SKIPPED, + TUNNELCALL_NONE, + TUNNELCALL_CALL, + }; + + struct TunnelCall { + uint8 call; + sint16 offset; + uint8 type; + }; + + std::vector getSegmentCalls(support_height supports[9], uint8 rotation); +} + +#endif #endif // #endif _TEST_PAINT_INTERCEPT_H_ diff --git a/test/testpaint/intercept_2.cpp b/test/testpaint/intercept_2.cpp index ab865be2dd..92afc5341a 100644 --- a/test/testpaint/intercept_2.cpp +++ b/test/testpaint/intercept_2.cpp @@ -17,8 +17,9 @@ #include #include +#include "intercept.h" + extern "C" { - #include "intercept.h" #include "../../src/paint/paint.h" #include "../../src/paint/supports.h" #include "../../src/ride/track_data.h" @@ -28,37 +29,6 @@ extern "C" { namespace Intercept2 { - - static const uint32 DEFAULT_SCHEME_TRACK = COLOUR_GREY << 19 | COLOUR_WHITE << 24 | 0xA0000000; - static const uint32 DEFAULT_SCHEME_SUPPORTS = COLOUR_LIGHT_BLUE << 19 | COLOUR_ICY_BLUE << 24 | 0xA0000000; - static const uint32 DEFAULT_SCHEME_MISC = COLOUR_DARK_PURPLE << 19 | COLOUR_LIGHT_PURPLE << 24 | 0xA0000000; - static const uint32 DEFAULT_SCHEME_3 = COLOUR_BRIGHT_PURPLE << 19 | COLOUR_DARK_BLUE << 24 | 0xA0000000; - - struct SegmentSupportCall - { - uint16 segments; - sint32 height; - sint16 slope; - }; - - struct SupportCall - { - sint32 height; - sint16 slope; - }; - - enum { - TUNNELCALL_SKIPPED, - TUNNELCALL_NONE, - TUNNELCALL_CALL, - }; - - struct TunnelCall { - uint8 call; - sint16 offset; - uint8 type; - }; - static bool SortSegmentSupportCalls(SegmentSupportCall lhs, SegmentSupportCall rhs) { if (lhs.height != rhs.height) { @@ -72,7 +42,7 @@ namespace Intercept2 return lhs.segments < rhs.segments; } - static std::vector getSegmentCalls(support_height supports[9], uint8 rotation) + std::vector getSegmentCalls(support_height supports[9], uint8 rotation) { uint16 positionsRemaining = SEGMENTS_ALL; diff --git a/test/testpaint/main.cpp b/test/testpaint/main.cpp index 2f6d079827..3fdb6a7691 100644 --- a/test/testpaint/main.cpp +++ b/test/testpaint/main.cpp @@ -23,9 +23,10 @@ #include #endif // defined(__unix__) +#include "intercept.h" + extern "C" { #include "data.h" -#include "intercept.h" #include "../../src/rct2.h" #include "../../src/ride/ride.h" #include "../../src/ride/ride_data.h" @@ -377,7 +378,11 @@ int main(int argc, char *argv[]) { if (specificRideType > 90) { fprintf(stderr, "No ride or invalid ride specified.\n"); return 1; - } + } + + openrct2_setup_rct2_segment(); + initHooks(); + return generatePaintCode(specificRideType); } diff --git a/test/testpaint/testpaint.vcxproj.user b/test/testpaint/testpaint.vcxproj.user index 9d6e2bebff..12a5d640ed 100644 --- a/test/testpaint/testpaint.vcxproj.user +++ b/test/testpaint/testpaint.vcxproj.user @@ -4,7 +4,7 @@ $(TargetDir)\openrct2.exe $(TargetDir) WindowsLocalDebugger - --ride-type 88 --generate + --ride-type 54 --generate false