From a0775f9ac91b3ae7eb09367629fb74fcad0edee1 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Fri, 6 Feb 2015 19:54:38 +0000 Subject: [PATCH] Refactor track_place to use new structs --- src/ride/track.h | 28 ++++++++++++++++++++ src/windows/track_place.c | 56 +++++++++++---------------------------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/ride/track.h b/src/ride/track.h index 3bd13b5b74..2ab8bc6a84 100644 --- a/src/ride/track.h +++ b/src/ride/track.h @@ -35,6 +35,34 @@ typedef struct { uint8 pad[2]; } rct_trackdefinition; +/** +* Size: 0x0A +*/ +typedef struct { + uint8 var_00; + sint16 x; + sint16 y; + uint8 pad_05[3]; + uint8 var_08; + uint8 unk_09; +} rct_preview_track; + +/** +* Size: 0x04 +*/ +typedef struct { + union { + uint32 all; + struct { + sint8 x; + sint8 y; + uint8 unk_2; + uint8 type; + }; + }; +} rct_maze_element; + +/* Size: 0x02 */ typedef struct{ uint8 type; uint8 flags; diff --git a/src/windows/track_place.c b/src/windows/track_place.c index 7fd79dfe9c..77776e1b95 100644 --- a/src/windows/track_place.c +++ b/src/windows/track_place.c @@ -114,33 +114,6 @@ static void window_track_place_clear_mini_preview() memset(_window_track_place_mini_preview, 220, TRACK_MINI_PREVIEW_SIZE); } -/** - * Size: 0x0A - */ -typedef struct { - uint8 var_00; - sint16 x; - sint16 y; - uint8 pad_05[3]; - uint8 var_08; - uint8 unk_09; -} rct_preview_track; - -/** - * Size: 0x04 - */ -typedef struct { - union { - uint32 all; - struct { - sint8 x; - sint8 y; - uint8 unk_2; - uint8 type; - }; - }; -} rct_preview_maze; - #define swap(x, y) x = x ^ y; y = x ^ y; x = x ^ y; /** @@ -149,10 +122,11 @@ typedef struct { */ static void window_track_place_draw_mini_preview() { - rct_track_design *design = (rct_track_design*)0x009D8178; - uint8 *pixel, colour, *trackPtr, bits; + rct_track_td6 *track = RCT2_ADDRESS(0x009D8178, rct_track_td6); + uint8 *pixel, colour, bits; int i, rotation, pass, x, y, pixelX, pixelY, originX, originY, minX, minY, maxX, maxY; - rct_preview_maze *mazeBlock; + rct_maze_element *mazeElement; + rct_track_element *trackElement; rct_preview_track *trackBlock; window_track_place_clear_mini_preview(); @@ -171,14 +145,14 @@ static void window_track_place_draw_mini_preview() originY -= ((maxY + minY) >> 6) << 5; } - if (design->track_td6.type != RIDE_TYPE_MAZE) { + if (track->type != RIDE_TYPE_MAZE) { #pragma region Track rotation = RCT2_GLOBAL(RCT2_ADDRESS_TRACK_PREVIEW_ROTATION, uint8) + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32); - trackPtr = design->preview[0]; + trackElement = RCT2_ADDRESS(0x009D821B, rct_track_element); - while (*trackPtr != 255) { - int trackType = *trackPtr; + while (trackElement->type != 255) { + int trackType = trackElement->type; if (trackType == 101) trackType = 255; @@ -264,7 +238,7 @@ static void window_track_place_draw_mini_preview() originX += RCT2_GLOBAL(0x00993CCC + (rotation * 4), sint16); originY += RCT2_GLOBAL(0x00993CCE + (rotation * 4), sint16); } - trackPtr += 2; + trackElement++; } #pragma endregion @@ -272,10 +246,10 @@ static void window_track_place_draw_mini_preview() #pragma region Maze rotation = (RCT2_GLOBAL(RCT2_ADDRESS_TRACK_PREVIEW_ROTATION, uint8) + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32)) & 3; - mazeBlock = (rct_preview_maze*)design->preview[0]; - while (mazeBlock->all != 0) { - x = mazeBlock->x * 32; - y = mazeBlock->y * 32; + mazeElement = RCT2_ADDRESS(0x009D821B, rct_maze_element); + while (mazeElement->all != 0) { + x = mazeElement->x * 32; + y = mazeElement->y * 32; switch (rotation) { case 1: x = -x; @@ -294,7 +268,7 @@ static void window_track_place_draw_mini_preview() y += originY; // Entrance or exit is a lighter colour - colour = mazeBlock->type == 8 || mazeBlock->type == 128 ? 222 : 218; + colour = mazeElement->type == 8 || mazeElement->type == 128 ? 222 : 218; if (pass == 0) { minX = min(minX, x); @@ -315,7 +289,7 @@ static void window_track_place_draw_mini_preview() } } } - mazeBlock++; + mazeElement++; } #pragma endregion