From 5b43f19708faadd9367f6b63297a9b446e7a8499 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Wed, 4 Dec 2019 23:08:26 -0300 Subject: [PATCH 1/2] Use CoordsXY for Paint rotations --- src/openrct2/paint/Paint.cpp | 45 ++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index f620d904b1..9f1cf007ab 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -71,8 +71,7 @@ static void paint_session_add_ps_to_quadrant(paint_session* session, paint_struc * Extracted from 0x0098196c, 0x0098197c, 0x0098198c, 0x0098199c */ static paint_struct* sub_9819_c( - paint_session* session, uint32_t image_id, const CoordsXYZ& offset, LocationXYZ16 boundBoxSize, - LocationXYZ16 boundBoxOffset) + paint_session* session, uint32_t image_id, const CoordsXYZ& offset, CoordsXYZ boundBoxSize, CoordsXYZ boundBoxOffset) { if (session->NextFreePaintStruct >= session->EndOfPaintStructArray) return nullptr; @@ -119,22 +118,22 @@ static paint_struct* sub_9819_c( case 0: boundBoxSize.x--; boundBoxSize.y--; - rotate_map_coordinates(&boundBoxOffset.x, &boundBoxOffset.y, 0); - rotate_map_coordinates(&boundBoxSize.x, &boundBoxSize.y, 0); + boundBoxOffset = { boundBoxOffset.Rotate(0), boundBoxOffset.z }; + boundBoxSize = { boundBoxSize.Rotate(0), boundBoxSize.z }; break; case 1: boundBoxSize.x--; - rotate_map_coordinates(&boundBoxOffset.x, &boundBoxOffset.y, 3); - rotate_map_coordinates(&boundBoxSize.x, &boundBoxSize.y, 3); + boundBoxOffset = { boundBoxOffset.Rotate(3), boundBoxOffset.z }; + boundBoxSize = { boundBoxSize.Rotate(3), boundBoxSize.z }; break; case 2: - rotate_map_coordinates(&boundBoxSize.x, &boundBoxSize.y, 2); - rotate_map_coordinates(&boundBoxOffset.x, &boundBoxOffset.y, 2); + boundBoxSize = { boundBoxSize.Rotate(2), boundBoxSize.z }; + boundBoxOffset = { boundBoxOffset.Rotate(2), boundBoxOffset.z }; break; case 3: boundBoxSize.y--; - rotate_map_coordinates(&boundBoxSize.x, &boundBoxSize.y, 1); - rotate_map_coordinates(&boundBoxOffset.x, &boundBoxOffset.y, 1); + boundBoxSize = { boundBoxSize.Rotate(1), boundBoxSize.z }; + boundBoxOffset = { boundBoxOffset.Rotate(1), boundBoxOffset.z }; break; } @@ -751,7 +750,7 @@ paint_struct* sub_98196C( z_offset, }; - LocationXYZ16 boundBox = { + CoordsXYZ boundBox = { bound_box_length_x, // di bound_box_length_y, // si bound_box_length_z, @@ -764,26 +763,26 @@ paint_struct* sub_98196C( boundBox.x--; boundBox.y--; - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_WEST); + boundBox = { boundBox.Rotate(TILE_ELEMENT_DIRECTION_WEST), boundBox.z }; break; case 1: coord_3d = CoordsXYZ{ coord_3d.Rotate(TILE_ELEMENT_DIRECTION_SOUTH), coord_3d.z }; boundBox.x--; - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_SOUTH); + boundBox = { boundBox.Rotate(TILE_ELEMENT_DIRECTION_SOUTH), boundBox.z }; break; case 2: coord_3d = CoordsXYZ{ coord_3d.Rotate(TILE_ELEMENT_DIRECTION_EAST), coord_3d.z }; - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_EAST); + boundBox = { boundBox.Rotate(TILE_ELEMENT_DIRECTION_EAST), boundBox.z }; break; case 3: coord_3d = CoordsXYZ{ coord_3d.Rotate(TILE_ELEMENT_DIRECTION_NORTH), coord_3d.z }; boundBox.y--; - rotate_map_coordinates(&boundBox.x, &boundBox.y, TILE_ELEMENT_DIRECTION_NORTH); + boundBox = { boundBox.Rotate(TILE_ELEMENT_DIRECTION_NORTH), boundBox.z }; break; } @@ -880,8 +879,8 @@ paint_struct* sub_98197C( session->UnkF1AD2C = nullptr; CoordsXYZ offset = { x_offset, y_offset, z_offset }; - LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; - LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; + CoordsXYZ boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; + CoordsXYZ boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; paint_struct* ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset); if (ps == nullptr) @@ -891,9 +890,9 @@ paint_struct* sub_98197C( session->LastRootPS = ps; - LocationXY16 attach = { (int16_t)ps->bounds.x, (int16_t)ps->bounds.y }; + CoordsXY attach = { ps->bounds.x, ps->bounds.y }; - rotate_map_coordinates(&attach.x, &attach.y, session->CurrentRotation); + attach = attach.Rotate(session->CurrentRotation); switch (session->CurrentRotation) { case 0: @@ -942,8 +941,8 @@ paint_struct* sub_98198C( session->UnkF1AD2C = nullptr; CoordsXYZ offset = { x_offset, y_offset, z_offset }; - LocationXYZ16 boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; - LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; + CoordsXYZ boundBoxSize = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; + CoordsXYZ boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; paint_struct* ps = sub_9819_c(session, image_id, offset, boundBoxSize, boundBoxOffset); if (ps == nullptr) @@ -988,8 +987,8 @@ paint_struct* sub_98199C( } CoordsXYZ offset = { x_offset, y_offset, z_offset }; - LocationXYZ16 boundBox = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; - LocationXYZ16 boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; + CoordsXYZ boundBox = { bound_box_length_x, bound_box_length_y, bound_box_length_z }; + CoordsXYZ boundBoxOffset = { bound_box_offset_x, bound_box_offset_y, bound_box_offset_z }; paint_struct* ps = sub_9819_c(session, image_id, offset, boundBox, boundBoxOffset); if (ps == nullptr) From 2ddde8a344646d9387f609cbb68f6a5c8ccdc466 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Mon, 9 Dec 2019 17:19:45 -0300 Subject: [PATCH 2/2] Simplify attach calculation on Paint.cpp --- src/openrct2/paint/Paint.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 9f1cf007ab..b157f88600 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -890,9 +890,7 @@ paint_struct* sub_98197C( session->LastRootPS = ps; - CoordsXY attach = { ps->bounds.x, ps->bounds.y }; - - attach = attach.Rotate(session->CurrentRotation); + auto attach = CoordsXY{ ps->bounds.x, ps->bounds.y }.Rotate(session->CurrentRotation); switch (session->CurrentRotation) { case 0: