diff --git a/src/drawing/drawing.c b/src/drawing/drawing.c index 888b4e43cb..cb75ded2b0 100644 --- a/src/drawing/drawing.c +++ b/src/drawing/drawing.c @@ -178,74 +178,6 @@ void load_palette(){ platform_update_palette((char*)0x01424680, 10, 236); } -/** -* -* rct2: 0x006EC9CE -* @param x (ax) -* @param y (cx) -* @param base_height (di) -* @param clearance_height (si) -*/ -void gfx_invalidate_tile_if_zoomed(int x, int y, int base_height, int clearance_height) -{ - x += 16; - y += 16; - int left, top, right, bottom; - switch (RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32)) { - case 0: - left = (-x + y) - 32; - right = (-x + y) + 32; - top = ((y + x) / 2) - 32 - clearance_height; - bottom = ((y + x) / 2) + 32 - base_height; - break; - case 1: - left = (-x - y) - 32; - right = (-x - y) + 32; - top = ((y - x) / 2) - 32 - clearance_height; - bottom = ((y - x) / 2) + 32 - base_height; - break; - case 2: - left = (x - y) - 32; - right = (x - y) + 32; - top = ((-y - x) / 2) - 32 - clearance_height; - bottom = ((-y - x) / 2) + 32 - base_height; - break; - case 3: - left = (x + y) - 32; - right = (x + y) + 32; - top = ((-y + x) / 2) - 32 - clearance_height; - bottom = ((-y + x) / 2) + 32 - base_height; - break; - } - for (rct_viewport** viewport_p = RCT2_ADDRESS(RCT2_ADDRESS_ACTIVE_VIEWPORT_PTR_ARRAY, rct_viewport*); *viewport_p; ++viewport_p) - { - rct_viewport* viewport = *viewport_p; - if (viewport->zoom < 1) { - if (right > viewport->view_x && bottom > viewport->view_y && left < viewport->view_x + viewport->view_width) { - if (left < viewport->view_x) { - left = viewport->view_x; - } - if (right > viewport->view_x + viewport->view_width) { - right = viewport->view_x + viewport->view_width; - } - if (top < viewport->view_y + viewport->view_height) { - if (top < viewport->view_y) { - top = viewport->view_y; - } - if (bottom > viewport->view_y + viewport->view_height) { - bottom = viewport->view_y + viewport->view_height; - } - left = ((left - viewport->view_x) >> viewport->zoom) + viewport->x; - top = ((top - viewport->view_y) >> viewport->zoom) + viewport->y; - right = ((right - viewport->view_x) >> viewport->zoom) + viewport->x; - bottom = ((bottom - viewport->view_y) >> viewport->zoom) + viewport->y; - gfx_set_dirty_blocks(left, top, right, bottom); - } - } - } - } -} - /** * * rct2: 0x006ED7E5 diff --git a/src/drawing/drawing.h b/src/drawing/drawing.h index 4e061cd5f8..a6269c8f01 100644 --- a/src/drawing/drawing.h +++ b/src/drawing/drawing.h @@ -83,7 +83,6 @@ rct_drawpixelinfo* clip_drawpixelinfo(rct_drawpixelinfo* dpi, int left, int widt void gfx_set_dirty_blocks(uint16 left, uint16 top, uint16 right, uint16 bottom); void gfx_draw_all_dirty_blocks(); void gfx_redraw_screen_rect(short left, short top, short right, short bottom); -void gfx_invalidate_tile_if_zoomed(int x, int y, int base_height, int clearance_height); void gfx_invalidate_screen(); // palette diff --git a/src/interface/viewport.c b/src/interface/viewport.c index 71d6c5206a..c3bcf35d45 100644 --- a/src/interface/viewport.c +++ b/src/interface/viewport.c @@ -2471,4 +2471,36 @@ void get_map_coordinates_from_pos(int screenX, int screenY, int flags, sint16 *x if (x != NULL) *x = RCT2_GLOBAL(0x9AC14C, int16_t); if (y != NULL) *y = RCT2_GLOBAL(0x9AC14E, int16_t); if (mapElement != NULL) *mapElement = RCT2_GLOBAL(0x9AC150, rct_map_element*); -} \ No newline at end of file +} + +/** + * Left, top, right and bottom represent 2D map coordinates at zoom 0. + */ +void viewport_invalidate(rct_viewport *viewport, int left, int top, int right, int bottom) +{ + int viewportLeft = viewport->view_x; + int viewportTop = viewport->view_y; + int viewportRight = viewport->view_x + viewport->view_width; + int viewportBottom = viewport->view_y + viewport->view_height; + if (right > viewportLeft && bottom > viewportTop) { + left = max(left, viewportLeft); + top = max(top, viewportTop); + right = min(right, viewportRight); + bottom = min(bottom, viewportBottom); + + uint8 zoom = 1 << viewport->zoom; + left -= viewportLeft; + top -= viewportTop; + right -= viewportLeft; + bottom -= viewportTop; + left /= zoom; + top /= zoom; + right /= zoom; + bottom /= zoom; + left += viewport->x; + top += viewport->y; + right += viewport->x; + bottom += viewport->y; + gfx_set_dirty_blocks(left, top, right, bottom); + } +} diff --git a/src/interface/viewport.h b/src/interface/viewport.h index 62cfa47c7f..6cbcd5b264 100644 --- a/src/interface/viewport.h +++ b/src/interface/viewport.h @@ -130,4 +130,6 @@ void sub_0x68615B(int ebp); void sub_688485(); void sub_688217(); +void viewport_invalidate(rct_viewport *viewport, int left, int top, int right, int bottom); + #endif diff --git a/src/peep/peep.c b/src/peep/peep.c index 1c55217281..7b1557767d 100644 --- a/src/peep/peep.c +++ b/src/peep/peep.c @@ -2777,7 +2777,7 @@ static void peep_update_mowing(rct_peep* peep){ if ((map_element->properties.surface.terrain & MAP_ELEMENT_SURFACE_TERRAIN_MASK) == (TERRAIN_GRASS << 5)){ map_element->properties.surface.grass_length = 0; - gfx_invalidate_tile_if_zoomed(peep->next_x, peep->next_y, map_element->base_height * 8, map_element->base_height * 8 + 16); + map_invalidate_tile_zoom0(peep->next_x, peep->next_y, map_element->base_height * 8, map_element->base_height * 8 + 16); } peep->staff_lawns_mown++; peep->var_45 |= (1 << 5); @@ -2827,7 +2827,7 @@ static void peep_update_watering(rct_peep* peep){ continue; map_element->properties.scenery.age = 0; - gfx_invalidate_tile_if_zoomed(x, y, map_element->base_height * 8, map_element->clearance_height * 8); + map_invalidate_tile_zoom0(x, y, map_element->base_height * 8, map_element->clearance_height * 8); peep->staff_gardens_watered++; peep->var_45 |= (1 << 4); } while (!map_element_is_last_for_tile(map_element++)); @@ -2897,7 +2897,7 @@ static void peep_update_emptying_bin(rct_peep* peep){ map_element->properties.path.addition_status |= ((3 << peep->var_37) << peep->var_37); - gfx_invalidate_tile_if_zoomed(peep->next_x, peep->next_y, map_element->base_height * 8, map_element->clearance_height * 8); + map_invalidate_tile_zoom0(peep->next_x, peep->next_y, map_element->base_height * 8, map_element->clearance_height * 8); peep->staff_bins_emptied++; peep->var_45 |= (1 << 4); @@ -3316,7 +3316,7 @@ static void peep_update_walking_break_scenery(rct_peep* peep){ map_element->flags |= MAP_ELEMENT_FLAG_BROKEN; - map_invalidate_tile( + map_invalidate_tile_zoom1( peep->next_x, peep->next_y, (map_element->base_height << 3) + 32, @@ -3541,7 +3541,7 @@ static void peep_update_using_bin(rct_peep* peep){ // Then placeing the new value. map_element->properties.path.addition_status |= rubbish_in_bin << selected_bin; - gfx_invalidate_tile_if_zoomed(peep->next_x, peep->next_y, map_element->base_height << 3, map_element->clearance_height << 3); + map_invalidate_tile_zoom0(peep->next_x, peep->next_y, map_element->base_height << 3, map_element->clearance_height << 3); peep_state_reset(peep); } } diff --git a/src/ride/ride.c b/src/ride/ride.c index c1a2538c99..67fcaee246 100644 --- a/src/ride/ride.c +++ b/src/ride/ride.c @@ -1756,12 +1756,12 @@ static void ride_chairlift_update(rct_ride *ride) x = (ride->var_13A & 0xFF) * 32; y = (ride->var_13A >> 8) * 32; z = ride->var_13E * 8; - map_invalidate_tile(x, y, z, z + (4 * 8)); + map_invalidate_tile_zoom1(x, y, z, z + (4 * 8)); x = (ride->var_13C & 0xFF) * 32; y = (ride->var_13C >> 8) * 32; z = ride->var_13F * 8; - map_invalidate_tile(x, y, z, z + (4 * 8)); + map_invalidate_tile_zoom1(x, y, z, z + (4 * 8)); } /** @@ -1837,7 +1837,7 @@ static void ride_spiral_slide_update(rct_ride *ride) x += RCT2_GLOBAL(0x0098DDB8 + (rotation * 4), sint16); y += RCT2_GLOBAL(0x0098DDBA + (rotation * 4), sint16); - gfx_invalidate_tile_if_zoomed(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile_zoom0(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); } } diff --git a/src/ride/station.c b/src/ride/station.c index c982a44757..9dffe1680a 100644 --- a/src/ride/station.c +++ b/src/ride/station.c @@ -300,7 +300,7 @@ static void ride_invalidate_station_start(rct_ride *ride, int stationIndex, int mapElement->properties.track.sequence |= 0x80; // Invalidate map tile - map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile_zoom1(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); } rct_map_element *ride_get_station_start_track_element(rct_ride *ride, int stationIndex) diff --git a/src/windows/sign.c b/src/windows/sign.c index 1c92097184..7c9cc5ed9e 100644 --- a/src/windows/sign.c +++ b/src/windows/sign.c @@ -623,7 +623,7 @@ static void window_sign_small_dropdown() ((w->var_492 & 0x7) << 5); map_element->flags |= ((w->var_492 & 0x18) << 2); - gfx_invalidate_viewport_tile(x, y, map_element->base_height * 8, map_element->clearance_height * 8); + map_invalidate_tile(x, y, map_element->base_height * 8, map_element->clearance_height * 8); window_invalidate(w); } diff --git a/src/world/map.c b/src/world/map.c index 826df6347e..381a568992 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -66,9 +66,11 @@ static void map_update_grass_length(int x, int y, rct_map_element *mapElement); static void map_set_grass_length(int x, int y, rct_map_element *mapElement, int length); static void sub_68AE2A(int x, int y); -void rotate_map_coordinates(sint16* x, sint16* y, int rotation){ +void rotate_map_coordinates(sint16 *x, sint16 *y, int rotation) +{ int temp; - switch (rotation){ + + switch (rotation) { case MAP_ELEMENT_DIRECTION_WEST: break; case MAP_ELEMENT_DIRECTION_NORTH: @@ -660,16 +662,6 @@ int map_is_location_in_park(int x, int y) return 0; } -/** - * - * rct2: 0x006ECB60 - * NOTE: x, y and z are in pixels, not tile units - */ -void map_invalidate_tile(int x, int y, int zLow, int zHigh) -{ - RCT2_CALLPROC_X(0x006ECB60, x, 0, y, 0, zHigh, zLow, 0); -} - /** * * rct2: 0x006E0E01 @@ -897,7 +889,7 @@ void game_command_remove_banner(int* eax, int* ebx, int* ecx, int* edx, int* esi uint8 bannerType = banner->type; if (*ebx & GAME_COMMAND_FLAG_APPLY) { map_element_remove_banner_entry(map_element); - map_invalidate_tile(x, y, z, z + 32); + map_invalidate_tile_zoom1(x, y, z, z + 32); map_element_remove(map_element); } rct_scenery_entry *scenery_entry = (rct_scenery_entry*)object_entry_groups[OBJECT_TYPE_BANNERS].chunks[bannerType]; @@ -1003,7 +995,7 @@ void game_command_set_fence_colour(int* eax, int* ebx, int* ecx, int* edx, int* if(scenery_entry->wall.flags & 0x80){ map_element->properties.fence.item[0] = color3; } - map_invalidate_tile(x, y, z, z + 0x48); + map_invalidate_tile_zoom1(x, y, z, z + 0x48); } *ebx = 0; } else { @@ -1167,7 +1159,7 @@ void game_command_set_banner_colour(int* eax, int* ebx, int* ecx, int* edx, int* window_invalidate(window); } gBanners[map_element->properties.banner.index].colour = color; - map_invalidate_tile(x, y, z, z + 32); + map_invalidate_tile_zoom1(x, y, z, z + 32); } *ebx = 0; @@ -1953,7 +1945,7 @@ void game_command_remove_fence(int* eax, int* ebx, int* ecx, int* edx, int* esi, } map_element_remove_banner_entry(map_element); - map_invalidate_tile(x, y, map_element->base_height * 8, (map_element->base_height * 8) + 72); + map_invalidate_tile_zoom1(x, y, map_element->base_height * 8, (map_element->base_height * 8) + 72); map_element_remove(map_element); *ebx = 0; } @@ -2478,7 +2470,7 @@ void game_command_place_fence(int* eax, int* ebx, int* ecx, int* edx, int* esi, } RCT2_GLOBAL(0x00F64EBC, rct_map_element*) = map_element; - map_invalidate_tile(position.x, position.y, map_element->base_height * 8, map_element->base_height * 8 + 72); + map_invalidate_tile_zoom1(position.x, position.y, map_element->base_height * 8, map_element->base_height * 8 + 72); } if (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY){ @@ -2706,15 +2698,6 @@ void game_command_place_large_scenery(int* eax, int* ebx, int* ecx, int* edx, in *ebx = MONEY32_UNDEFINED; } -/** - * - * rct2: 0x006EC6D7 - */ -void map_invalidate_tile_full(int x, int y) -{ - RCT2_CALLPROC_X(0x006EC6D7, x, 0, y, 0, 0, 0, 0); -} - int map_get_station(rct_map_element *mapElement) { return (mapElement->properties.track.sequence & 0x70) >> 4; @@ -2975,7 +2958,7 @@ void map_remove_intersecting_walls(int x, int y, int z0, int z1, int direction) continue; map_element_remove_banner_entry(mapElement); - map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->base_height * 8 + 72); + map_invalidate_tile_zoom1(x, y, mapElement->base_height * 8, mapElement->base_height * 8 + 72); map_element_remove(mapElement); mapElement--; } while (!map_element_is_last_for_tile(mapElement++)); @@ -3084,7 +3067,7 @@ static void map_set_grass_length(int x, int y, rct_map_element *mapElement, int mapElement->properties.surface.grass_length = length; z0 = mapElement->base_height * 8; z1 = z0 + 16; - gfx_invalidate_viewport_tile(x, y, z0, z1); + map_invalidate_tile(x, y, z0, z1); } void sub_6A7594() @@ -3334,32 +3317,6 @@ bool map_element_is_underground(rct_map_element *mapElement) return true; } -void map_rotate_position(int direction, int *x, int *y) -{ - int offsetX, offsetY; - - switch (direction) { - case 0: - offsetX = (*x); - offsetY = (*y); - break; - case 1: - offsetX = (*y); - offsetY = -(*x); - break; - case 2: - offsetX = -(*x); - offsetY = -(*y); - break; - case 3: - offsetX = -(*y); - offsetY = (*x); - break; - } - *x = offsetX; - *y = offsetY; -} - rct_map_element *map_get_large_scenery_segment(int x, int y, int z, int direction, int sequence) { rct_map_element *mapElement = map_get_first_element_at(x >> 5, y >> 5); @@ -3385,7 +3342,7 @@ bool map_large_scenery_get_origin( rct_map_element *mapElement; rct_scenery_entry *sceneryEntry; rct_large_scenery_tile *tile; - int offsetX, offsetY; + sint16 offsetX, offsetY; mapElement = map_get_large_scenery_segment(x, y, z, direction, sequence); if (mapElement == NULL) @@ -3396,7 +3353,7 @@ bool map_large_scenery_get_origin( offsetX = tile->x_offset; offsetY = tile->y_offset; - map_rotate_position(direction, &offsetX, &offsetY); + rotate_map_coordinates(&offsetX, &offsetY, direction); *outX = x - offsetX; *outY = y - offsetY; @@ -3410,12 +3367,11 @@ bool map_large_scenery_get_origin( */ void sign_set_colour(int x, int y, int z, int direction, int sequence, uint8 mainColour, uint8 textColour) { - // RCT2_CALLPROC_X(0x006B9B05, x, direction << 8, y, z | (type << 8), 0, 0, 0); - rct_map_element *mapElement; rct_scenery_entry *sceneryEntry; rct_large_scenery_tile *sceneryTiles, *tile; - int x0, y0, z0, offsetX, offsetY; + sint16 offsetX, offsetY; + int x0, y0, z0; // Get the given segment of the large scenery element mapElement = map_get_large_scenery_segment(x, y, z, direction, sequence); @@ -3428,7 +3384,7 @@ void sign_set_colour(int x, int y, int z, int direction, int sequence, uint8 mai tile = &sceneryTiles[sequence]; offsetX = tile->x_offset; offsetY = tile->y_offset; - map_rotate_position(direction, &offsetX, &offsetY); + rotate_map_coordinates(&offsetX, &offsetY, direction); x0 = x - offsetX; y0 = y - offsetY; z0 = (z * 8) - tile->z_offset; @@ -3438,7 +3394,7 @@ void sign_set_colour(int x, int y, int z, int direction, int sequence, uint8 mai for (tile = sceneryTiles; tile->x_offset != -1; tile++, sequence++) { offsetX = tile->x_offset; offsetY = tile->y_offset; - map_rotate_position(direction, &offsetX, &offsetY); + rotate_map_coordinates(&offsetX, &offsetY, direction); x = x0 + offsetX; y = y0 + offsetY; @@ -3450,7 +3406,94 @@ void sign_set_colour(int x, int y, int z, int direction, int sequence, uint8 mai mapElement->properties.scenerymultiple.colour[0] |= mainColour; mapElement->properties.scenerymultiple.colour[1] |= textColour; - gfx_invalidate_viewport_tile(x, y, mapElement->base_height * 8 , mapElement->clearance_height * 8); + map_invalidate_tile(x, y, mapElement->base_height * 8 , mapElement->clearance_height * 8); } } } + +static void translate_3d_to_2d(int rotation, int *x, int *y) +{ + int rx, ry; + + switch (rotation & 3) { + case 0: + rx = (*y) - (*x); + ry = (*x) + (*y); + break; + case 1: + rx = -(*x) - (*y); + ry = (*y) - (*x); + break; + case 2: + rx = (*x) - (*y); + ry = -(*x) - (*y); + break; + case 3: + rx = (*x) + (*y); + ry = (*x) - (*y); + break; + } + ry /= 2; + + *x = rx; + *y = ry; +} + +void map_invalidate_tile_under_zoom(int x, int y, int z0, int z1, int maxZoom) +{ + int x1, y1, x2, y2; + rct_viewport *viewport; + + x += 16; + y += 16; + translate_3d_to_2d(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32), &x, &y); + + x1 = x - 32; + y1 = y - 32 - z1; + x2 = x + 32; + y2 = y + 32 - z0; + + viewport = RCT2_GLOBAL(RCT2_ADDRESS_ACTIVE_VIEWPORT_PTR_ARRAY, rct_viewport*); + while (viewport->width != 0) { + if (maxZoom == -1 || viewport->zoom <= maxZoom) { + viewport_invalidate(viewport, x1, y1, x2, y2); + } + viewport++; + } +} + +/** + * + * rct2: 0x006EC847 + */ +void map_invalidate_tile(int x, int y, int z0, int z1) +{ + map_invalidate_tile_under_zoom(x, y, z0, z1, -1); +} + +/** + * + * rct2: 0x006ECB60 + */ +void map_invalidate_tile_zoom1(int x, int y, int z0, int z1) +{ + map_invalidate_tile_under_zoom(x, y, z0, z1, 1); +} + +/** + * + * rct2: 0x006EC9CE + */ +void map_invalidate_tile_zoom0(int x, int y, int z0, int z1) +{ + map_invalidate_tile_under_zoom(x, y, z0, z1, 0); +} + +/** + * + * rct2: 0x006EC6D7 + */ +void map_invalidate_tile_full(int x, int y) +{ + map_invalidate_tile(x, y, 0, 2080); +} diff --git a/src/world/map.h b/src/world/map.h index f3e6399f10..ae2477c493 100644 --- a/src/world/map.h +++ b/src/world/map.h @@ -276,8 +276,6 @@ int map_coord_is_connected(int x, int y, int z, uint8 faceDirection); void sub_6A876D(); int map_is_location_owned(int x, int y, int z); int map_is_location_in_park(int x, int y); -void map_invalidate_tile(int x, int y, int zLow, int zHigh); -void map_invalidate_tile_full(int x, int y); int map_get_station(rct_map_element *mapElement); void map_element_remove(rct_map_element *mapElement); void sub_6A6AA7(int x, int y, rct_map_element *mapElement); @@ -289,7 +287,7 @@ int sub_68B044(); rct_map_element *map_element_insert(int x, int y, int z, int flags); int map_can_construct_with_clear_at(int x, int y, int zLow, int zHigh, void *clearFunc, uint8 bl); int map_can_construct_at(int x, int y, int zLow, int zHigh, uint8 bl); -void rotate_map_coordinates(sint16* x, sint16* y, int rotation); +void rotate_map_coordinates(sint16 *x, sint16 *y, int rotation); rct_xy16 coordinate_3d_to_2d(const rct_xyz16* coordinate_3d, int rotation); money32 map_clear_scenery(int x0, int y0, int x1, int y1, int flags); money32 lower_water(sint16 x0, sint16 y0, sint16 x1, sint16 y1, uint8 flags); @@ -343,4 +341,9 @@ void map_extend_boundary_surface(); void sign_set_colour(int x, int y, int z, int direction, int sequence, uint8 mainColour, uint8 textColour); +void map_invalidate_tile(int x, int y, int z0, int z1); +void map_invalidate_tile_zoom1(int x, int y, int z0, int z1); +void map_invalidate_tile_zoom0(int x, int y, int z0, int z1); +void map_invalidate_tile_full(int x, int y); + #endif diff --git a/src/world/map_animation.c b/src/world/map_animation.c index 62f879448d..e612e07ed8 100644 --- a/src/world/map_animation.c +++ b/src/world/map_animation.c @@ -124,7 +124,7 @@ static bool map_animation_invalidate_ride_entrance(int x, int y, int baseZ) entranceDefinition = &RideEntranceDefinitions[ride->entrance_style]; int height = (mapElement->base_height * 8) + entranceDefinition->height + 8; - map_invalidate_tile(x, y, height, height + 16); + map_invalidate_tile_zoom1(x, y, height, height + 16); return false; } while (!map_element_is_last_for_tile(mapElement++)); @@ -153,7 +153,7 @@ static bool map_animation_invalidate_queue_banner(int x, int y, int baseZ) int direction = ((mapElement->type >> 6) + RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint8)) & 3; if (direction == MAP_ELEMENT_DIRECTION_NORTH || direction == MAP_ELEMENT_DIRECTION_EAST) { baseZ = mapElement->base_height * 8; - map_invalidate_tile(x, y, baseZ + 16, baseZ + 30); + map_invalidate_tile_zoom1(x, y, baseZ + 16, baseZ + 30); } return false; } while (!map_element_is_last_for_tile(mapElement++)); @@ -183,7 +183,7 @@ static bool map_animation_invalidate_small_scenery(int x, int y, int baseZ) sceneryEntry = g_smallSceneryEntries[mapElement->properties.scenery.type]; if (sceneryEntry->small_scenery.flags & 0xD800) { - map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile_zoom1(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); return false; } @@ -216,7 +216,7 @@ static bool map_animation_invalidate_small_scenery(int x, int y, int baseZ) break; } } - map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile_zoom1(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); return false; } } while (!map_element_is_last_for_tile(mapElement++)); @@ -243,7 +243,7 @@ static bool map_animation_invalidate_park_entrance(int x, int y, int baseZ) continue; baseZ = mapElement->base_height * 8; - map_invalidate_tile(x, y, baseZ + 32, baseZ + 64); + map_invalidate_tile_zoom1(x, y, baseZ + 32, baseZ + 64); return false; } while (!map_element_is_last_for_tile(mapElement++)); @@ -267,7 +267,7 @@ static bool map_animation_invalidate_track_waterfall(int x, int y, int baseZ) if (mapElement->properties.track.type == TRACK_ELEM_WATERFALL) { int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, z + 14, z + 46); + map_invalidate_tile_zoom1(x, y, z + 14, z + 46); return false; } } while (!map_element_is_last_for_tile(mapElement++)); @@ -292,7 +292,7 @@ static bool map_animation_invalidate_track_rapids(int x, int y, int baseZ) if (mapElement->properties.track.type == TRACK_ELEM_RAPIDS) { int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, z + 14, z + 18); + map_invalidate_tile_zoom1(x, y, z + 14, z + 18); return false; } } while (!map_element_is_last_for_tile(mapElement++)); @@ -318,7 +318,7 @@ static bool map_animation_invalidate_track_onridephoto(int x, int y, int baseZ) if (mapElement->properties.track.type == TRACK_ELEM_ON_RIDE_PHOTO) { int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile_zoom1(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); if (mapElement->properties.track.sequence & 0xF0) { mapElement->properties.track.sequence -= 0x10; return false; @@ -348,7 +348,7 @@ static bool map_animation_invalidate_track_whirlpool(int x, int y, int baseZ) if (mapElement->properties.track.type == TRACK_ELEM_WHIRLPOOL) { int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, z + 14, z + 18); + map_invalidate_tile_zoom1(x, y, z + 14, z + 18); return false; } } while (!map_element_is_last_for_tile(mapElement++)); @@ -373,7 +373,7 @@ static bool map_animation_invalidate_track_spinningtunnel(int x, int y, int base if (mapElement->properties.track.type == TRACK_ELEM_SPINNING_TUNNEL) { int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, z + 14, z + 32); + map_invalidate_tile_zoom1(x, y, z + 14, z + 32); return false; } } while (!map_element_is_last_for_tile(mapElement++)); @@ -406,7 +406,7 @@ static bool map_animation_invalidate_banner(int x, int y, int baseZ) continue; baseZ = mapElement->base_height * 8; - map_invalidate_tile(x, y, baseZ, baseZ + 16); + map_invalidate_tile_zoom1(x, y, baseZ, baseZ + 16); return false; } while (!map_element_is_last_for_tile(mapElement++)); @@ -433,7 +433,7 @@ static bool map_animation_invalidate_large_scenery(int x, int y, int baseZ) sceneryEntry = g_largeSceneryEntries[mapElement->properties.scenery.type & 0x3FF]; if (sceneryEntry->large_scenery.flags & (1 << 3)) { int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, z, z + 16); + map_invalidate_tile_zoom1(x, y, z, z + 16); wasInvalidated = true; } } while (!map_element_is_last_for_tile(mapElement++)); @@ -488,7 +488,7 @@ static bool map_animation_invalidate_wall_unknown(int x, int y, int baseZ) mapElement->properties.fence.item[2] = bl; if (di & 1) { int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, z, z + 32); + map_invalidate_tile_zoom1(x, y, z, z + 32); } if (di & 2) wasInvalidated = true; @@ -519,7 +519,7 @@ static bool map_animation_invalidate_wall(int x, int y, int baseZ) continue; int z = mapElement->base_height * 8; - map_invalidate_tile(x, y, z, z + 16); + map_invalidate_tile_zoom1(x, y, z, z + 16); wasInvalidated = true; } while (!map_element_is_last_for_tile(mapElement++)); diff --git a/src/world/park.c b/src/world/park.c index 627c806e10..2cb4a1e96d 100644 --- a/src/world/park.c +++ b/src/world/park.c @@ -715,81 +715,6 @@ int park_get_entrance_index(int x, int y, int z) return -1; } -static void translate_3d_to_2d(int rotation, int *x, int *y) -{ - int rx, ry; - - switch (rotation & 3) { - case 0: - rx = (*y) - (*x); - ry = (*x) + (*y); - break; - case 1: - rx = -(*x) - (*y); - ry = (*y) - (*x); - break; - case 2: - rx = (*x) - (*y); - ry = -(*x) - (*y); - break; - case 3: - rx = (*x) + (*y); - ry = (*x) - (*y); - break; - } - ry /= 2; - - *x = rx; - *y = ry; -} - -/** - * - * rct2: 0x006EC847 - */ -void gfx_invalidate_viewport_tile(int x, int y, int z0, int z1) -{ - int x1, y1, x2, y2; - rct_viewport *viewport; - - x += 16; - y += 16; - translate_3d_to_2d(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_ROTATION, uint32), &x, &y); - - x1 = x - 32; - y1 = y - 32 - z1; - x2 = x + 32; - y2 = y + 32 - z0; - - viewport = RCT2_GLOBAL(RCT2_ADDRESS_ACTIVE_VIEWPORT_PTR_ARRAY, rct_viewport*); - while (viewport->width != 0) { - int viewport_x2 = viewport->view_x + viewport->view_width; - int viewport_y2 = viewport->view_y + viewport->view_height; - if (x2 > viewport->view_x && y2 > viewport->view_y) { - x1 = max(x1, viewport->view_x); - y1 = max(y1, viewport->view_y); - x2 = min(x2, viewport_x2); - y2 = min(y2, viewport_y2); - - uint8 zoom = 1 << viewport->zoom; - x1 -= viewport->view_x; - y1 -= viewport->view_y; - x2 -= viewport->view_x; - y2 -= viewport->view_y; - x1 /= zoom; - y1 /= zoom; - x2 /= zoom; - y2 /= zoom; - x1 += viewport->x; - y1 += viewport->y; - x2 += viewport->x; - y2 += viewport->y; - gfx_set_dirty_blocks(x1, y1, x2, y2); - } - viewport++; - } -} - /** * * rct2: 0x00664D05 @@ -850,7 +775,7 @@ void update_park_fences(int x, int y) if (sufaceElement->properties.surface.ownership != newOwnership) { int z0 = sufaceElement->base_height * 8; int z1 = z0 + 16; - gfx_invalidate_viewport_tile(x, y, z0, z1); + map_invalidate_tile(x, y, z0, z1); sufaceElement->properties.surface.ownership = newOwnership; } } @@ -868,7 +793,7 @@ void park_remove_entrance_segment(int x, int y, int z) if (mapElement->properties.entrance.type != ENTRANCE_TYPE_PARK_ENTRANCE) continue; - gfx_invalidate_viewport_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); map_element_remove(mapElement); update_park_fences(x, y); } while (!map_element_is_last_for_tile(mapElement++)); @@ -1057,7 +982,7 @@ int map_buy_land_rights_for_tile(int x, int y, int setting, int flags) { TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_CONSTRUCTION_RIGHTS_OWNED; uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y, baseHeight, baseHeight + 16); + map_invalidate_tile(x, y, baseHeight, baseHeight + 16); } cost = RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCTION_RIGHTS_COST, uint16); return cost; @@ -1068,7 +993,7 @@ int map_buy_land_rights_for_tile(int x, int y, int setting, int flags) { TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership &= 0xEF; uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y, baseHeight, baseHeight + 16); + map_invalidate_tile(x, y, baseHeight, baseHeight + 16); } cost = 0; break; @@ -1078,7 +1003,7 @@ int map_buy_land_rights_for_tile(int x, int y, int setting, int flags) { TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_AVAILABLE; uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y, baseHeight, baseHeight + 16); + map_invalidate_tile(x, y, baseHeight, baseHeight + 16); } cost = 0; break; @@ -1087,7 +1012,7 @@ int map_buy_land_rights_for_tile(int x, int y, int setting, int flags) { TILE_MAP_ELEMENT_POINTER(tile_idx)->properties.surface.ownership |= OWNERSHIP_CONSTRUCTION_RIGHTS_AVAILABLE; uint16 baseHeight = TILE_MAP_ELEMENT_POINTER(tile_idx)->base_height; baseHeight *= 8; - gfx_invalidate_viewport_tile(x, y, baseHeight, baseHeight + 16); + map_invalidate_tile(x, y, baseHeight, baseHeight + 16); } cost = 0; break; diff --git a/src/world/park.h b/src/world/park.h index 855454434c..f50cd9dd93 100644 --- a/src/world/park.h +++ b/src/world/park.h @@ -80,7 +80,7 @@ void game_command_remove_park_entrance(int *eax, int *ebx, int *ecx, int *edx, i void game_command_set_park_name(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); void game_command_buy_land_rights(int *eax, int *ebx, int *ecx, int *edx, int *esi, int *edi, int *ebp); -void gfx_invalidate_viewport_tile(int x, int y, int z0, int z1); +void map_invalidate_tile(int x, int y, int z0, int z1); void park_remove_ghost_entrance(); money32 park_place_ghost_entrance(int x, int y, int z, int direction); diff --git a/src/world/scenery.c b/src/world/scenery.c index 3a05927927..cbf9bf3ca3 100644 --- a/src/world/scenery.c +++ b/src/world/scenery.c @@ -82,7 +82,7 @@ void scenery_update_age(int x, int y, rct_map_element *mapElement) case MAP_ELEMENT_TYPE_SCENERY_MULTIPLE: case MAP_ELEMENT_TYPE_ENTRANCE: case MAP_ELEMENT_TYPE_PATH: - map_invalidate_tile(x, y, mapElementAbove->base_height * 8, mapElementAbove->clearance_height * 8); + map_invalidate_tile_zoom1(x, y, mapElementAbove->base_height * 8, mapElementAbove->clearance_height * 8); scenery_increase_age(x, y, mapElement); return; case MAP_ELEMENT_TYPE_SCENERY: @@ -97,7 +97,7 @@ void scenery_update_age(int x, int y, rct_map_element *mapElement) // Reset age / water plant mapElement->properties.scenery.age = 0; - map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile_zoom1(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); } void scenery_increase_age(int x, int y, rct_map_element *mapElement) @@ -107,7 +107,7 @@ void scenery_increase_age(int x, int y, rct_map_element *mapElement) if (mapElement->properties.scenery.age < 255) { mapElement->properties.scenery.age++; - map_invalidate_tile(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); + map_invalidate_tile_zoom1(x, y, mapElement->base_height * 8, mapElement->clearance_height * 8); } }