mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +01:00
Refactor viewport_adjust_for_map_height to use CoordsXYZ.
This commit is contained in:
@@ -215,17 +215,15 @@ void viewport_create(
|
|||||||
* edx is assumed to be (and always is) the current rotation, so it is not
|
* edx is assumed to be (and always is) the current rotation, so it is not
|
||||||
* needed as parameter.
|
* needed as parameter.
|
||||||
*/
|
*/
|
||||||
void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z)
|
CoordsXYZ viewport_adjust_for_map_height(const ScreenCoordsXY startCoords)
|
||||||
{
|
{
|
||||||
int16_t start_x = *x;
|
|
||||||
int16_t start_y = *y;
|
|
||||||
int16_t height = 0;
|
int16_t height = 0;
|
||||||
|
|
||||||
uint32_t rotation = get_current_rotation();
|
uint32_t rotation = get_current_rotation();
|
||||||
CoordsXY pos{};
|
CoordsXY pos{};
|
||||||
for (int32_t i = 0; i < 6; i++)
|
for (int32_t i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
pos = viewport_coord_to_map_coord(start_x, start_y, height);
|
pos = viewport_coord_to_map_coord(startCoords.x, startCoords.y, height);
|
||||||
height = tile_element_height(pos);
|
height = tile_element_height(pos);
|
||||||
|
|
||||||
// HACK: This is to prevent the x and y values being set to values outside
|
// HACK: This is to prevent the x and y values being set to values outside
|
||||||
@@ -239,9 +237,7 @@ void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*x = pos.x;
|
return { pos, height };
|
||||||
*y = pos.y;
|
|
||||||
*z = height;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ void viewport_paint(
|
|||||||
const rct_viewport* viewport, rct_drawpixelinfo* dpi, int16_t left, int16_t top, int16_t right, int16_t bottom,
|
const rct_viewport* viewport, rct_drawpixelinfo* dpi, int16_t left, int16_t top, int16_t right, int16_t bottom,
|
||||||
std::vector<paint_session>* sessions = nullptr);
|
std::vector<paint_session>* sessions = nullptr);
|
||||||
|
|
||||||
void viewport_adjust_for_map_height(int16_t* x, int16_t* y, int16_t* z);
|
CoordsXYZ viewport_adjust_for_map_height(const ScreenCoordsXY startCoords);
|
||||||
|
|
||||||
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, ScreenCoordsXY screenCoords);
|
LocationXY16 screen_coord_to_viewport_coord(rct_viewport* viewport, ScreenCoordsXY screenCoords);
|
||||||
CoordsXY viewport_coord_to_map_coord(int32_t x, int32_t y, int32_t z);
|
CoordsXY viewport_coord_to_map_coord(int32_t x, int32_t y, int32_t z);
|
||||||
|
|||||||
@@ -912,11 +912,10 @@ void window_rotate_camera(rct_window* w, int32_t direction)
|
|||||||
|
|
||||||
int16_t x = (viewport->width >> 1) + viewport->x;
|
int16_t x = (viewport->width >> 1) + viewport->x;
|
||||||
int16_t y = (viewport->height >> 1) + viewport->y;
|
int16_t y = (viewport->height >> 1) + viewport->y;
|
||||||
int16_t z;
|
|
||||||
|
|
||||||
// has something to do with checking if middle of the viewport is obstructed
|
// has something to do with checking if middle of the viewport is obstructed
|
||||||
rct_viewport* other;
|
rct_viewport* other;
|
||||||
CoordsXY coords = screen_get_map_xy({ x, y }, &other);
|
CoordsXYZ coords{ screen_get_map_xy({ x, y }, &other), 0 };
|
||||||
|
|
||||||
// other != viewport probably triggers on viewports in ride or guest window?
|
// other != viewport probably triggers on viewports in ride or guest window?
|
||||||
// x is LOCATION_NULL if middle of viewport is obstructed by another window?
|
// x is LOCATION_NULL if middle of viewport is obstructed by another window?
|
||||||
@@ -925,17 +924,16 @@ void window_rotate_camera(rct_window* w, int32_t direction)
|
|||||||
int16_t view_x = (viewport->view_width >> 1) + viewport->view_x;
|
int16_t view_x = (viewport->view_width >> 1) + viewport->view_x;
|
||||||
int16_t view_y = (viewport->view_height >> 1) + viewport->view_y;
|
int16_t view_y = (viewport->view_height >> 1) + viewport->view_y;
|
||||||
|
|
||||||
viewport_adjust_for_map_height(&view_x, &view_y, &z);
|
coords = viewport_adjust_for_map_height({ view_x, view_y });
|
||||||
coords = { view_x, view_y };
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
z = tile_element_height(coords);
|
coords.z = tile_element_height(coords);
|
||||||
}
|
}
|
||||||
|
|
||||||
gCurrentRotation = (get_current_rotation() + direction) & 3;
|
gCurrentRotation = (get_current_rotation() + direction) & 3;
|
||||||
|
|
||||||
auto centreLoc = centre_2d_coordinates({ coords, z }, viewport);
|
auto centreLoc = centre_2d_coordinates(coords, viewport);
|
||||||
|
|
||||||
if (centreLoc)
|
if (centreLoc)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user