From 33c4698e0642d9ec7f3961356a86c58f452e9c12 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 28 Jun 2015 16:50:21 +0100 Subject: [PATCH] Implemented map_reorganise_elements. Fixed a potential issue that would cause cursors to become stuck. --- src/platform/shared.c | 1 + src/world/map.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/platform/shared.c b/src/platform/shared.c index a0a929c8b4..77418e2137 100644 --- a/src/platform/shared.c +++ b/src/platform/shared.c @@ -646,6 +646,7 @@ void platform_set_fullscreen_mode(int mode) */ void platform_set_cursor(char cursor) { + RCT2_GLOBAL(RCT2_ADDRESS_CURENT_CURSOR, uint8) = cursor; SDL_SetCursor(_cursors[cursor]); } /** diff --git a/src/world/map.c b/src/world/map.c index 1f6fe730d6..46e4a2f95f 100644 --- a/src/world/map.c +++ b/src/world/map.c @@ -35,6 +35,7 @@ #include "scenery.h" #include "../cheats.h" #include "../config.h" +#include "../cursors.h" const rct_xy16 TileDirectionDelta[] = { { -32, 0 }, @@ -2735,7 +2736,36 @@ void map_invalidate_selection_rect() */ void map_reorganise_elements() { - RCT2_CALLPROC_EBPSAFE(0x0068B111); + platform_set_cursor(CURSOR_ZZZ); + + rct_map_element* new_map_elements = rct2_malloc(0x30000 * sizeof(rct_map_element)); + rct_map_element* new_elements_pointer = new_map_elements; + + if (new_map_elements == NULL || new_map_elements == (rct_map_element*)-1){ + error_string_quit(4370, 0xFFFF); + return; + } + + rct_map_element **tile = RCT2_ADDRESS(RCT2_ADDRESS_TILE_MAP_ELEMENT_POINTERS, rct_map_element*); + for (int i = 0; i < 0x10000;){ + for (int j = 0; j < 256; ++j, ++i){ + rct_map_element* startElement = tile[i]; + rct_map_element* endElement = startElement; + while (!map_element_is_last_for_tile(endElement++)); + + uint8 num_bytes = endElement - startElement; + memcpy(new_elements_pointer, startElement, num_bytes); + new_elements_pointer += num_bytes / sizeof(rct_map_element); + } + } + + uint32 num_elements = (new_elements_pointer - new_map_elements) / sizeof(rct_map_element); + memcpy(RCT2_ADDRESS(RCT2_ADDRESS_MAP_ELEMENTS, rct_map_element), new_map_elements, num_elements * sizeof(rct_map_element)); + memset(new_map_elements + num_elements, 0, (0x30000 - num_elements) * sizeof(rct_map_element)); + + rct2_free(new_map_elements); + + map_update_tile_pointers(); } /**