mirror of https://github.com/OpenRCT2/OpenRCT2.git
Refactor track_design_draw_preview
This commit is contained in:
parent
8bc69b549f
commit
9c645e0a0f
|
@ -1687,11 +1687,11 @@ void track_design_draw_preview(rct_track_td6 *td6, uint8 *pixels)
|
||||||
|
|
||||||
rct_viewport* view = RCT2_ADDRESS(0x9D8161, rct_viewport);
|
rct_viewport* view = RCT2_ADDRESS(0x9D8161, rct_viewport);
|
||||||
rct_drawpixelinfo* dpi = RCT2_ADDRESS(0x9D8151, rct_drawpixelinfo);
|
rct_drawpixelinfo* dpi = RCT2_ADDRESS(0x9D8151, rct_drawpixelinfo);
|
||||||
int left, top, right, bottom;
|
|
||||||
|
|
||||||
int center_x = (gTrackPreviewMin.x + gTrackPreviewMax.x) / 2 + 16;
|
rct_xyz32 centre;
|
||||||
int center_y = (gTrackPreviewMin.y + gTrackPreviewMax.y) / 2 + 16;
|
centre.x = (gTrackPreviewMin.x + gTrackPreviewMax.x) / 2 + 16;
|
||||||
int center_z = (gTrackPreviewMin.z + gTrackPreviewMax.z) / 2;
|
centre.y = (gTrackPreviewMin.y + gTrackPreviewMax.y) / 2 + 16;
|
||||||
|
centre.z = (gTrackPreviewMin.z + gTrackPreviewMax.z) / 2;
|
||||||
|
|
||||||
int width = gTrackPreviewMax.x - gTrackPreviewMin.x;
|
int width = gTrackPreviewMax.x - gTrackPreviewMin.x;
|
||||||
int height = gTrackPreviewMax.y - gTrackPreviewMin.y;
|
int height = gTrackPreviewMax.y - gTrackPreviewMin.y;
|
||||||
|
@ -1710,19 +1710,12 @@ void track_design_draw_preview(rct_track_td6 *td6, uint8 *pixels)
|
||||||
width = 370 << zoom_level;
|
width = 370 << zoom_level;
|
||||||
height = 217 << zoom_level;
|
height = 217 << zoom_level;
|
||||||
|
|
||||||
int x = center_y - center_x - width / 2;
|
|
||||||
int y = (center_y + center_x) / 2 - center_z - height / 2;
|
|
||||||
|
|
||||||
gCurrentRotation = 0;
|
|
||||||
|
|
||||||
view->width = 370;
|
view->width = 370;
|
||||||
view->height = 217;
|
view->height = 217;
|
||||||
view->view_width = width;
|
view->view_width = width;
|
||||||
view->view_height = height;
|
view->view_height = height;
|
||||||
view->x = 0;
|
view->x = 0;
|
||||||
view->y = 0;
|
view->y = 0;
|
||||||
view->view_x = x;
|
|
||||||
view->view_y = y;
|
|
||||||
view->zoom = zoom_level;
|
view->zoom = zoom_level;
|
||||||
view->flags = VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_INVISIBLE_SPRITES;
|
view->flags = VIEWPORT_FLAG_HIDE_BASE | VIEWPORT_FLAG_INVISIBLE_SPRITES;
|
||||||
|
|
||||||
|
@ -1734,57 +1727,25 @@ void track_design_draw_preview(rct_track_td6 *td6, uint8 *pixels)
|
||||||
dpi->pitch = 0;
|
dpi->pitch = 0;
|
||||||
dpi->bits = pixels;
|
dpi->bits = pixels;
|
||||||
|
|
||||||
top = y;
|
rct_xy32 offset = { width / 2, height / 2 };
|
||||||
left = x;
|
for (int i = 0; i < 4; i++) {
|
||||||
bottom = y + height;
|
gCurrentRotation = i;
|
||||||
right = x + width;
|
|
||||||
|
|
||||||
|
rct_xy32 pos2d = translate_3d_to_2d_with_z(i, centre);
|
||||||
|
pos2d.x -= offset.x;
|
||||||
|
pos2d.y -= offset.y;
|
||||||
|
|
||||||
|
sint32 left = pos2d.x;
|
||||||
|
sint32 top = pos2d.y;
|
||||||
|
sint32 right = left + width;
|
||||||
|
sint32 bottom = top + height;
|
||||||
|
|
||||||
|
view->view_x = left;
|
||||||
|
view->view_y = top;
|
||||||
viewport_paint(view, dpi, left, top, right, bottom);
|
viewport_paint(view, dpi, left, top, right, bottom);
|
||||||
|
|
||||||
dpi->bits += TRACK_PREVIEW_IMAGE_SIZE;
|
dpi->bits += TRACK_PREVIEW_IMAGE_SIZE;
|
||||||
|
}
|
||||||
gCurrentRotation = 1;
|
|
||||||
x = -center_y - center_x - width / 2;
|
|
||||||
y = (center_y - center_x) / 2 - center_z - height / 2;
|
|
||||||
|
|
||||||
view->view_x = x;
|
|
||||||
view->view_y = y;
|
|
||||||
top = y;
|
|
||||||
left = x;
|
|
||||||
bottom = y + height;
|
|
||||||
right = x + width;
|
|
||||||
|
|
||||||
viewport_paint(view, dpi, left, top, right, bottom);
|
|
||||||
|
|
||||||
dpi->bits += TRACK_PREVIEW_IMAGE_SIZE;
|
|
||||||
|
|
||||||
gCurrentRotation = 2;
|
|
||||||
x = center_x - center_y - width / 2;
|
|
||||||
y = (-center_y - center_x) / 2 - center_z - height / 2;
|
|
||||||
|
|
||||||
view->view_x = x;
|
|
||||||
view->view_y = y;
|
|
||||||
top = y;
|
|
||||||
left = x;
|
|
||||||
bottom = y + height;
|
|
||||||
right = x + width;
|
|
||||||
|
|
||||||
viewport_paint(view, dpi, left, top, right, bottom);
|
|
||||||
|
|
||||||
dpi->bits += TRACK_PREVIEW_IMAGE_SIZE;
|
|
||||||
|
|
||||||
gCurrentRotation = 3;
|
|
||||||
x = center_x + center_y - width / 2;
|
|
||||||
y = (center_x - center_y) / 2 - center_z - height / 2;
|
|
||||||
|
|
||||||
view->view_x = x;
|
|
||||||
view->view_y = y;
|
|
||||||
top = y;
|
|
||||||
left = x;
|
|
||||||
bottom = y + height;
|
|
||||||
right = x + width;
|
|
||||||
|
|
||||||
viewport_paint(view, dpi, left, top, right, bottom);
|
|
||||||
|
|
||||||
ride_delete(rideIndex);
|
ride_delete(rideIndex);
|
||||||
track_design_preview_restore_map(mapBackup);
|
track_design_preview_restore_map(mapBackup);
|
||||||
|
|
|
@ -4905,6 +4905,30 @@ static void translate_3d_to_2d(int rotation, int *x, int *y)
|
||||||
*y = ry;
|
*y = ry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rct_xy32 translate_3d_to_2d_with_z(sint32 rotation, rct_xyz32 pos)
|
||||||
|
{
|
||||||
|
rct_xy32 result;
|
||||||
|
switch (rotation & 3) {
|
||||||
|
case 0:
|
||||||
|
result.x = pos.y - pos.x;
|
||||||
|
result.y = (pos.x + pos.y) / 2 - pos.z;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
result.x = -pos.x - pos.y;
|
||||||
|
result.y = (pos.y - pos.x) / 2 - pos.z;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
result.x = pos.x - pos.y;
|
||||||
|
result.y = (-pos.x - pos.y) / 2 - pos.z;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
result.x = pos.x + pos.y;
|
||||||
|
result.y = (pos.x - pos.y) / 2 - pos.z;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static void map_invalidate_tile_under_zoom(int x, int y, int z0, int z1, int maxZoom)
|
static void map_invalidate_tile_under_zoom(int x, int y, int z0, int z1, int maxZoom)
|
||||||
{
|
{
|
||||||
if (gOpenRCT2Headless) return;
|
if (gOpenRCT2Headless) return;
|
||||||
|
|
|
@ -275,6 +275,14 @@ typedef struct rct_xyz16 {
|
||||||
} rct_xyz16;
|
} rct_xyz16;
|
||||||
assert_struct_size(rct_xyz16, 6);
|
assert_struct_size(rct_xyz16, 6);
|
||||||
|
|
||||||
|
typedef struct rct_xy32 {
|
||||||
|
sint32 x, y;
|
||||||
|
} rct_xy32;
|
||||||
|
|
||||||
|
typedef struct rct_xyz32 {
|
||||||
|
sint32 x, y, z;
|
||||||
|
} rct_xyz32;
|
||||||
|
|
||||||
typedef struct rct_xy_element {
|
typedef struct rct_xy_element {
|
||||||
int x, y;
|
int x, y;
|
||||||
rct_map_element *element;
|
rct_map_element *element;
|
||||||
|
@ -492,6 +500,7 @@ bool map_large_scenery_get_origin(
|
||||||
);
|
);
|
||||||
|
|
||||||
void map_offset_with_rotation(sint16 *x, sint16 *y, sint16 offsetX, sint16 offsetY, uint8 rotation);
|
void map_offset_with_rotation(sint16 *x, sint16 *y, sint16 offsetX, sint16 offsetY, uint8 rotation);
|
||||||
|
rct_xy32 translate_3d_to_2d_with_z(sint32 rotation, rct_xyz32 pos);
|
||||||
|
|
||||||
rct_map_element *map_get_track_element_at(int x, int y, int z);
|
rct_map_element *map_get_track_element_at(int x, int y, int z);
|
||||||
rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int trackType);
|
rct_map_element *map_get_track_element_at_of_type(int x, int y, int z, int trackType);
|
||||||
|
|
Loading…
Reference in New Issue