Skip to content

Commit

Permalink
Merge pull request #10328 from tupaschoal/rotate-ride-coords
Browse files Browse the repository at this point in the history
Use CoordsXY and ScreenCoordsXY for rotate in Ride*.*
  • Loading branch information
Gymnasiast committed Dec 10, 2019
2 parents e72d2ab + 01c6243 commit 8e805f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 34 deletions.
26 changes: 11 additions & 15 deletions src/openrct2-ui/windows/RideConstruction.cpp
Expand Up @@ -2367,32 +2367,28 @@ static void window_ride_construction_draw_track_piece(
while ((trackBlock + 1)->index != 0xFF)
trackBlock++;

int16_t x = trackBlock->x;
int16_t z = trackBlock->z;
int16_t y = trackBlock->y;
CoordsXYZ mapCoords{ trackBlock->x, trackBlock->z, trackBlock->y };
if (trackBlock->var_09 & 2)
{
x = 0;
y = 0;
mapCoords.x = 0;
mapCoords.y = 0;
}

rotate_map_coordinates(&x, &y, trackDirection & 3);
auto rotatedMapCoords = mapCoords.Rotate(trackDirection);
// this is actually case 0, but the other cases all jump to it
x = 4112 + (x / 2);
y = 4112 + (y / 2);
z = 1024 + z;
mapCoords.x = 4112 + (rotatedMapCoords.x / 2);
mapCoords.y = 4112 + (rotatedMapCoords.y / 2);
mapCoords.z = 1024 + mapCoords.z;

int16_t previewZOffset = ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_FLAT_RIDE)
? FlatRideTrackDefinitions[trackType].preview_z_offset
: TrackDefinitions[trackType].preview_z_offset;
z -= previewZOffset;
mapCoords.z -= previewZOffset;

const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z);
x = rotatedCoords.x;
y = rotatedCoords.y;
const ScreenCoordsXY rotatedScreenCoords = translate_3d_to_2d_with_z(get_current_rotation(), mapCoords);

dpi->x += x - width / 2;
dpi->y += y - height / 2 - 16;
dpi->x += rotatedScreenCoords.x - width / 2;
dpi->y += rotatedScreenCoords.y - height / 2 - 16;
uint32_t d = unknown << 16;
d |= rideIndex;
d |= trackType << 8;
Expand Down
21 changes: 6 additions & 15 deletions src/openrct2/ride/Ride.cpp
Expand Up @@ -2899,9 +2899,9 @@ static void ride_music_update(Ride* ride)
return;
}

int32_t x = ride->stations[0].Start.x * 32 + 16;
int32_t y = ride->stations[0].Start.y * 32 + 16;
int32_t z = ride->stations[0].Height * 8;
TileCoordsXYZ stationTileCoords{ ride->stations[0].Start.x, ride->stations[0].Start.y, ride->stations[0].Height };
CoordsXYZ rideCoords{ stationTileCoords.ToCoordsXYZ() };
rideCoords = { rideCoords.ToTileCentre(), rideCoords.z };

int32_t sampleRate = 22050;

Expand All @@ -2914,7 +2914,7 @@ static void ride_music_update(Ride* ride)
sampleRate += 22050;
}

ride->music_position = ride_music_params_update(x, y, z, ride, sampleRate, ride->music_position, &ride->music_tune_id);
ride->music_position = ride_music_params_update(rideCoords, ride, sampleRate, ride->music_position, &ride->music_tune_id);
}

#pragma endregion
Expand Down Expand Up @@ -3563,12 +3563,11 @@ static int32_t ride_music_params_update_label_58(uint32_t position, uint8_t* tun
* @param tuneId (bh)
* @returns new position (ebp)
*/
int32_t ride_music_params_update(
int16_t x, int16_t y, int16_t z, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId)
int32_t ride_music_params_update(CoordsXYZ rideCoords, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId)
{
if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gGameSoundsOff && g_music_tracking_viewport != nullptr)
{
const LocationXY16 rotatedCoords = ride_get_rotated_coords(x, y, z);
const ScreenCoordsXY rotatedCoords = translate_3d_to_2d_with_z(get_current_rotation(), rideCoords);
rct_viewport* viewport = g_music_tracking_viewport;
int16_t view_width = viewport->view_width;
int16_t view_width2 = view_width * 2;
Expand Down Expand Up @@ -7658,14 +7657,6 @@ StationObject* ride_get_station_object(const Ride* ride)
return static_cast<StationObject*>(objManager.GetLoadedObject(OBJECT_TYPE_STATION, ride->entrance_style));
}

LocationXY16 ride_get_rotated_coords(int16_t x, int16_t y, int16_t z)
{
CoordsXYZ coords3d = { x, y, z };
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
LocationXY16 rotatedCoords = { (int16_t)screenCoords.x, (int16_t)screenCoords.y };
return rotatedCoords;
}

// Normally, a station has at most one entrance and one exit, which are at the same height
// as the station. But in hacked parks, neither can be taken for granted. This code ensures
// that the ride->entrances and ride->exits arrays will point to one of them. There is
Expand Down
5 changes: 1 addition & 4 deletions src/openrct2/ride/Ride.h
Expand Up @@ -1169,8 +1169,7 @@ int32_t sub_6C683D(
int32_t* x, int32_t* y, int32_t* z, int32_t direction, int32_t type, uint16_t extra_params, TileElement** output_element,
uint16_t flags);
void ride_set_map_tooltip(TileElement* tileElement);
int32_t ride_music_params_update(
int16_t x, int16_t y, int16_t z, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId);
int32_t ride_music_params_update(CoordsXYZ rideCoords, Ride* ride, uint16_t sampleRate, uint32_t position, uint8_t* tuneId);
void ride_music_update_final();
void ride_prepare_breakdown(Ride* ride, int32_t breakdownReason);
TileElement* ride_get_station_start_track_element(Ride* ride, int32_t stationIndex);
Expand Down Expand Up @@ -1279,8 +1278,6 @@ StationObject* ride_get_station_object(const Ride* ride);

void ride_action_modify(Ride* ride, int32_t modifyType, int32_t flags);

LocationXY16 ride_get_rotated_coords(int16_t x, int16_t y, int16_t z);

void determine_ride_entrance_and_exit_locations();
void ride_clear_leftover_entrances(Ride* ride);

Expand Down
5 changes: 5 additions & 0 deletions src/openrct2/world/Location.hpp
Expand Up @@ -273,6 +273,11 @@ struct TileCoordsXYZ
return !(*this == other);
}

CoordsXYZ ToCoordsXYZ()
{
return { x * 32, y * 32, z * 8 };
}

int32_t x = 0, y = 0, z = 0;
};

Expand Down

0 comments on commit 8e805f5

Please sign in to comment.