mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 11:03:00 +01:00
Create ScreenCoords struct. Refactor 3d_to_2d again
This commit is contained in:
@@ -254,7 +254,7 @@ void screenshot_giant()
|
||||
int32_t z = tile_element_height({ centreX, centreY });
|
||||
|
||||
CoordsXYZ centreCoords3d = { centreX, centreY, z };
|
||||
CoordsXY centreCoords2d = translate_3d_to_2d_with_z(rotation, centreCoords3d);
|
||||
auto centreCoords2d = translate_3d_to_2d_with_z(rotation, centreCoords3d);
|
||||
|
||||
viewport.view_x = centreCoords2d.x - ((viewport.view_width << zoom) / 2);
|
||||
viewport.view_y = centreCoords2d.y - ((viewport.view_height << zoom) / 2);
|
||||
@@ -525,7 +525,7 @@ int32_t cmdline_for_screenshot(const char** argv, int32_t argc, ScreenshotOption
|
||||
int32_t z = tile_element_height({ customX, customY });
|
||||
CoordsXYZ coords3d = { customX, customY, z };
|
||||
|
||||
CoordsXY coords2d = translate_3d_to_2d_with_z(customRotation, coords3d);
|
||||
auto coords2d = translate_3d_to_2d_with_z(customRotation, coords3d);
|
||||
|
||||
viewport.view_x = coords2d.x - ((viewport.view_width << customZoom) / 2);
|
||||
viewport.view_y = coords2d.y - ((viewport.view_height << customZoom) / 2);
|
||||
|
||||
@@ -7643,8 +7643,8 @@ StationObject* ride_get_station_object(const Ride* ride)
|
||||
LocationXY16 ride_get_rotated_coords(int16_t x, int16_t y, int16_t z)
|
||||
{
|
||||
CoordsXYZ coords3d = { x, y, z };
|
||||
CoordsXY coords2d = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
|
||||
LocationXY16 rotatedCoords = { (int16_t)coords2d.x, (int16_t)coords2d.y };
|
||||
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
|
||||
LocationXY16 rotatedCoords = { (int16_t)screenCoords.x, (int16_t)screenCoords.y };
|
||||
return rotatedCoords;
|
||||
}
|
||||
|
||||
|
||||
@@ -2337,12 +2337,12 @@ void track_design_draw_preview(TrackDesign* td6, uint8_t* pixels)
|
||||
{
|
||||
gCurrentRotation = i;
|
||||
|
||||
CoordsXY pos2d = translate_3d_to_2d_with_z(i, centre);
|
||||
pos2d.x -= offset.x;
|
||||
pos2d.y -= offset.y;
|
||||
auto screenCoords = translate_3d_to_2d_with_z(i, centre);
|
||||
screenCoords.x -= offset.x;
|
||||
screenCoords.y -= offset.y;
|
||||
|
||||
int32_t left = pos2d.x;
|
||||
int32_t top = pos2d.y;
|
||||
int32_t left = screenCoords.x;
|
||||
int32_t top = screenCoords.y;
|
||||
int32_t right = left + size_x;
|
||||
int32_t bottom = top + size_y;
|
||||
|
||||
|
||||
@@ -55,6 +55,19 @@ assert_struct_size(LocationXYZ16, 6);
|
||||
|
||||
constexpr int32_t COORDS_NULL = -1;
|
||||
|
||||
struct ScreenCoordsXY
|
||||
{
|
||||
int32_t x = 0;
|
||||
int32_t y = 0;
|
||||
|
||||
ScreenCoordsXY() = default;
|
||||
constexpr ScreenCoordsXY(int32_t _x, int32_t _y)
|
||||
: x(_x)
|
||||
, y(_y)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tile coordinates use 1 x/y increment per tile and 1 z increment per step.
|
||||
* Regular ('big', 'sprite') coordinates use 32 x/y increments per tile and 8 z increments per step.
|
||||
@@ -95,7 +108,7 @@ struct CoordsXY
|
||||
return { rhs.x - x, rhs.y - y };
|
||||
}
|
||||
|
||||
CoordsXY Rotate(int32_t direction)
|
||||
CoordsXY Rotate(int32_t direction) const
|
||||
{
|
||||
CoordsXY rotatedCoords;
|
||||
switch (direction & 3)
|
||||
|
||||
@@ -110,7 +110,7 @@ LocationXYZ16 gCommandPosition;
|
||||
bool gMapLandRightsUpdateSuccess;
|
||||
|
||||
static void clear_elements_at(int32_t x, int32_t y);
|
||||
static CoordsXY translate_3d_to_2d(int32_t rotation, const CoordsXY& pos);
|
||||
static ScreenCoordsXY translate_3d_to_2d(int32_t rotation, const CoordsXY& pos);
|
||||
|
||||
void rotate_map_coordinates(int16_t* x, int16_t* y, int32_t rotation)
|
||||
{
|
||||
@@ -1964,38 +1964,16 @@ bool sign_set_colour(
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: This returns a screen CoordsXY
|
||||
static CoordsXY translate_3d_to_2d(int32_t rotation, const CoordsXY& pos)
|
||||
static ScreenCoordsXY translate_3d_to_2d(int32_t rotation, const CoordsXY& pos)
|
||||
{
|
||||
return translate_3d_to_2d_with_z(rotation, CoordsXYZ{ pos, 0 });
|
||||
}
|
||||
|
||||
// TODO: This returns a screen CoordsXY
|
||||
CoordsXY translate_3d_to_2d_with_z(int32_t rotation, CoordsXYZ pos)
|
||||
ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos)
|
||||
{
|
||||
CoordsXY result = {};
|
||||
auto rotated = pos.Rotate(rotation);
|
||||
// Use right shift to avoid issues like #9301
|
||||
switch (rotation & 3)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
result.x = pos.y - pos.x;
|
||||
result.y = ((pos.x + pos.y) >> 1) - pos.z;
|
||||
break;
|
||||
case 1:
|
||||
result.x = -pos.x - pos.y;
|
||||
result.y = ((pos.y - pos.x) >> 1) - pos.z;
|
||||
break;
|
||||
case 2:
|
||||
result.x = pos.x - pos.y;
|
||||
result.y = ((-pos.x - pos.y) >> 1) - pos.z;
|
||||
break;
|
||||
case 3:
|
||||
result.x = pos.x + pos.y;
|
||||
result.y = ((pos.x - pos.y) >> 1) - pos.z;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
return ScreenCoordsXY{ rotated.y - rotated.x, ((rotated.x + rotated.y) >> 1) - pos.z };
|
||||
}
|
||||
|
||||
static void map_invalidate_tile_under_zoom(int32_t x, int32_t y, int32_t z0, int32_t z1, int32_t maxZoom)
|
||||
|
||||
@@ -233,7 +233,7 @@ bool map_large_scenery_get_origin(
|
||||
LargeSceneryElement** outElement);
|
||||
|
||||
void map_offset_with_rotation(int16_t* x, int16_t* y, int16_t offsetX, int16_t offsetY, uint8_t rotation);
|
||||
CoordsXY translate_3d_to_2d_with_z(int32_t rotation, CoordsXYZ pos);
|
||||
ScreenCoordsXY translate_3d_to_2d_with_z(int32_t rotation, const CoordsXYZ& pos);
|
||||
|
||||
TrackElement* map_get_track_element_at(int32_t x, int32_t y, int32_t z);
|
||||
TileElement* map_get_track_element_at_of_type(int32_t x, int32_t y, int32_t z, int32_t trackType);
|
||||
|
||||
@@ -666,12 +666,12 @@ void sprite_move(int16_t x, int16_t y, int16_t z, rct_sprite* sprite)
|
||||
void sprite_set_coordinates(int16_t x, int16_t y, int16_t z, rct_sprite* sprite)
|
||||
{
|
||||
CoordsXYZ coords3d = { x, y, z };
|
||||
CoordsXY newCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
|
||||
auto screenCoords = translate_3d_to_2d_with_z(get_current_rotation(), coords3d);
|
||||
|
||||
sprite->generic.sprite_left = newCoords.x - sprite->generic.sprite_width;
|
||||
sprite->generic.sprite_right = newCoords.x + sprite->generic.sprite_width;
|
||||
sprite->generic.sprite_top = newCoords.y - sprite->generic.sprite_height_negative;
|
||||
sprite->generic.sprite_bottom = newCoords.y + sprite->generic.sprite_height_positive;
|
||||
sprite->generic.sprite_left = screenCoords.x - sprite->generic.sprite_width;
|
||||
sprite->generic.sprite_right = screenCoords.x + sprite->generic.sprite_width;
|
||||
sprite->generic.sprite_top = screenCoords.y - sprite->generic.sprite_height_negative;
|
||||
sprite->generic.sprite_bottom = screenCoords.y + sprite->generic.sprite_height_positive;
|
||||
sprite->generic.x = x;
|
||||
sprite->generic.y = y;
|
||||
sprite->generic.z = z;
|
||||
|
||||
@@ -22,10 +22,12 @@ struct rct_sprite_common
|
||||
uint8_t sprite_width;
|
||||
// Height from centre of sprite to top
|
||||
uint8_t sprite_height_positive;
|
||||
// Screen Coordinates of sprite
|
||||
int16_t sprite_left;
|
||||
int16_t sprite_top;
|
||||
int16_t sprite_right;
|
||||
int16_t sprite_bottom;
|
||||
|
||||
uint8_t sprite_direction;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user