diff --git a/src/openrct2-ui/windows/TrackDesignPlace.cpp b/src/openrct2-ui/windows/TrackDesignPlace.cpp index 798342f63f..89416ff3d0 100644 --- a/src/openrct2-ui/windows/TrackDesignPlace.cpp +++ b/src/openrct2-ui/windows/TrackDesignPlace.cpp @@ -547,7 +547,7 @@ static Widget _trackPlaceWidgets[] = { uint8_t rotation = (_currentTrackPieceDirection + GetCurrentRotation()) & 3; for (const auto& mazeElement : td6->mazeElements) { - auto rotatedMazeCoords = origin + TileCoordsXY{ mazeElement.x, mazeElement.y }.ToCoordsXY().Rotate(rotation); + auto rotatedMazeCoords = origin + mazeElement.location.ToCoordsXY().Rotate(rotation); if (pass == 0) { diff --git a/src/openrct2/core/DataSerialiserTraits.h b/src/openrct2/core/DataSerialiserTraits.h index aa70623df8..34363cf0e2 100644 --- a/src/openrct2/core/DataSerialiserTraits.h +++ b/src/openrct2/core/DataSerialiserTraits.h @@ -703,19 +703,20 @@ template<> struct DataSerializerTraitsT { static void encode(OpenRCT2::IStream* stream, const TrackDesignMazeElement& val) { - uint32_t temp = ByteSwapBE(val.all); - stream->Write(&temp); + stream->Write(&val.location); + stream->Write(&val.mazeEntry); } static void decode(OpenRCT2::IStream* stream, TrackDesignMazeElement& val) { - uint32_t temp; - stream->Read(&temp); - val.all = ByteSwapBE(temp); + stream->Read(&val.location); + stream->Read(&val.mazeEntry); } static void log(OpenRCT2::IStream* stream, const TrackDesignMazeElement& val) { char msg[128] = {}; - snprintf(msg, sizeof(msg), "TrackDesignMazeElement(all = %d)", val.all); + snprintf( + msg, sizeof(msg), "TrackDesignMazeElement(x = %d, y = %d, entry = %d)", val.location.x, val.location.y, + val.mazeEntry); stream->Write(msg, strlen(msg)); } }; diff --git a/src/openrct2/rct12/RCT12.cpp b/src/openrct2/rct12/RCT12.cpp index bba9511d29..c50c69db10 100644 --- a/src/openrct2/rct12/RCT12.cpp +++ b/src/openrct2/rct12/RCT12.cpp @@ -946,10 +946,9 @@ void ImportMazeElement(TrackDesign& td, const TD46MazeElement& td46MazeElement) else { TrackDesignMazeElement mazeElement{}; - mazeElement.x = td46MazeElement.x; - mazeElement.y = td46MazeElement.y; - mazeElement.direction = td46MazeElement.Direction; - mazeElement.type = td46MazeElement.Type; + mazeElement.location.x = td46MazeElement.x; + mazeElement.location.y = td46MazeElement.y; + mazeElement.mazeEntry = td46MazeElement.MazeEntry; td.mazeElements.push_back(mazeElement); } } diff --git a/src/openrct2/rct2/T6Exporter.cpp b/src/openrct2/rct2/T6Exporter.cpp index 4277bf4acf..67d35fc0b4 100644 --- a/src/openrct2/rct2/T6Exporter.cpp +++ b/src/openrct2/rct2/T6Exporter.cpp @@ -104,7 +104,9 @@ namespace RCT2 { for (const auto& mazeElement : _trackDesign->mazeElements) { - tempStream.WriteValue(mazeElement.all); + tempStream.WriteValue(mazeElement.location.x); + tempStream.WriteValue(mazeElement.location.y); + tempStream.WriteValue(mazeElement.mazeEntry); } for (const auto& entranceElement : _trackDesign->entranceElements) diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 971c7cc6c1..62fa799f38 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -376,9 +376,9 @@ ResultWithMessage TrackDesign::CreateTrackDesignMaze(TrackDesignState& tds, cons TrackDesignMazeElement maze{}; - maze.maze_entry = tileElement->AsTrack()->GetMazeEntry(); - maze.x = (x - startLoc.x) / COORDS_XY_STEP; - maze.y = (y - startLoc.y) / COORDS_XY_STEP; + maze.mazeEntry = tileElement->AsTrack()->GetMazeEntry(); + maze.location.x = (x - startLoc.x) / COORDS_XY_STEP; + maze.location.y = (y - startLoc.y) / COORDS_XY_STEP; _saveDirection = tileElement->GetDirection(); mazeElements.push_back(maze); @@ -906,16 +906,16 @@ static void TrackDesignMirrorMaze(TrackDesign* td6) { for (auto& maze : td6->mazeElements) { - maze.y = -maze.y; + maze.location.y = -maze.location.y; - uint16_t maze_entry = maze.maze_entry; - uint16_t new_entry = 0; - for (uint8_t position = UtilBitScanForward(maze_entry); position != 0xFF; position = UtilBitScanForward(maze_entry)) + auto mazeEntry = maze.mazeEntry; + uint16_t newEntry = 0; + for (uint8_t position = UtilBitScanForward(mazeEntry); position != 0xFF; position = UtilBitScanForward(mazeEntry)) { - maze_entry &= ~(1 << position); - new_entry |= (1 << maze_segment_mirror_map[position]); + mazeEntry &= ~(1 << position); + newEntry |= (1 << maze_segment_mirror_map[position]); } - maze.maze_entry = new_entry; + maze.mazeEntry = newEntry; } } @@ -1456,7 +1456,7 @@ static GameActions::Result TrackDesignPlaceMaze( for (const auto& maze_element : td.mazeElements) { uint8_t rotation = _currentTrackPieceDirection & 3; - CoordsXY mazeMapPos = TileCoordsXY(maze_element.x, maze_element.y).ToCoordsXY(); + CoordsXY mazeMapPos = maze_element.location.ToCoordsXY(); auto mapCoord = mazeMapPos.Rotate(rotation); mapCoord += origin; @@ -1473,7 +1473,7 @@ static GameActions::Result TrackDesignPlaceMaze( uint8_t flags; money64 cost = 0; - uint16_t maze_entry = Numerics::rol16(maze_element.maze_entry, rotation * 4); + uint16_t mazeEntry = Numerics::rol16(maze_element.mazeEntry, rotation * 4); if (tds.PlaceOperation == PTD_OPERATION_PLACE_TRACK_PREVIEW) { @@ -1497,7 +1497,7 @@ static GameActions::Result TrackDesignPlaceMaze( flags |= GAME_COMMAND_FLAG_REPLAY; } - auto mazePlace = MazePlaceTrackAction({ mapCoord, origin.z }, ride.id, maze_entry); + auto mazePlace = MazePlaceTrackAction({ mapCoord, origin.z }, ride.id, mazeEntry); mazePlace.SetFlags(flags); auto res = flags & GAME_COMMAND_FLAG_APPLY ? GameActions::ExecuteNested(&mazePlace) : GameActions::QueryNested(&mazePlace); diff --git a/src/openrct2/ride/TrackDesign.h b/src/openrct2/ride/TrackDesign.h index df942eed2b..6fc224bd8e 100644 --- a/src/openrct2/ride/TrackDesign.h +++ b/src/openrct2/ride/TrackDesign.h @@ -90,27 +90,10 @@ struct TrackDesignTrackElement } }; -/* Maze Element entry size: 0x04 */ struct TrackDesignMazeElement { - union - { - uint32_t all; - struct - { - int8_t x; - int8_t y; - union - { - uint16_t maze_entry; - struct - { - uint8_t direction; - uint8_t type; - }; - }; - }; - }; + TileCoordsXY location{}; + uint16_t mazeEntry{}; }; class DataSerialiser;