1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Refactor map element organisation

Committing some changes that were originally for #7637.
- Refactor map_check_free_elements_and_reorganise
- Refactor map_strip_ghost_flag_from_elements
- Remove sub_68B089

I have removed sub_68B089 because this function was run every game tick
and 1000 times when trying to request some spare elements. It was a
lighter function which tried to stretch out the tile element pointers
behind any spare elements. In this day and age, doing a full tile
element defrag is very fast (even in debug mode it takes no more than
10ms), so I don't think keeping sub_68B089 is necessary.
This commit is contained in:
Ted John
2018-06-20 21:33:51 +01:00
parent 085cb7f3b1
commit f79954bde3
3 changed files with 24 additions and 71 deletions

View File

@@ -218,8 +218,6 @@ void GameState::UpdateLogic()
network_check_desynchronization();
}
sub_68B089();
date_update();
_date = Date(gDateMonthTicks, gDateMonthTicks);

View File

@@ -418,10 +418,10 @@ void map_count_remaining_land_rights()
*/
void map_strip_ghost_flag_from_elements()
{
rct_tile_element *tileElement = gTileElements;
do {
tileElement->flags &= ~TILE_ELEMENT_FLAG_GHOST;
} while (++tileElement < gTileElements + MAX_TILE_ELEMENTS);
for (auto& element : gTileElements)
{
element.flags &= ~TILE_ELEMENT_FLAG_GHOST;
}
}
/**
@@ -603,55 +603,6 @@ int32_t tile_element_height(int32_t x, int32_t y)
return height;
}
/**
*
* rct2: 0x0068B089
*/
void sub_68B089()
{
int32_t i;
rct_tile_element *tileElementFirst, *tileElement;
if (gTrackDesignSaveMode)
return;
i = gNextFreeTileElementPointerIndex;
do {
i++;
if (i >= MAX_TILE_TILE_ELEMENT_POINTERS)
i = 0;
} while (gTileElementTilePointers[i] == TILE_UNDEFINED_TILE_ELEMENT);
gNextFreeTileElementPointerIndex = i;
tileElementFirst = tileElement = gTileElementTilePointers[i];
do {
tileElement--;
if (tileElement < gTileElements)
break;
} while (tileElement->base_height == 255);
tileElement++;
if (tileElement == tileElementFirst)
return;
//
gTileElementTilePointers[i] = tileElement;
do {
*tileElement = *tileElementFirst;
tileElementFirst->base_height = 255;
tileElementFirst++;
} while (!(tileElement++)->IsLastForTile());
tileElement = gNextFreeTileElement;
do {
tileElement--;
} while (tileElement->base_height == 255);
tileElement++;
gNextFreeTileElement = tileElement;
}
/**
* Checks if the tile at coordinate at height counts as connected.
* @return 1 if connected, 0 otherwise
@@ -3185,25 +3136,30 @@ void map_reorganise_elements()
* Returns true on space available for more elements
* Reorganises the map elements to check for space
*/
bool map_check_free_elements_and_reorganise(int32_t num_elements)
bool map_check_free_elements_and_reorganise(int32_t numElements)
{
if ((gNextFreeTileElement + num_elements) <= gTileElements + MAX_TILE_ELEMENTS)
return true;
if (numElements != 0)
{
auto tileElementEnd = &gTileElements[MAX_TILE_ELEMENTS];
for (int32_t i = 1000; i != 0; --i)
sub_68B089();
// Check if is there is room for the required number of elements
auto newTileElementEnd = gNextFreeTileElement + numElements;
if (newTileElementEnd > tileElementEnd)
{
// Defragment the map element list
map_reorganise_elements();
if ((gNextFreeTileElement + num_elements) <= gTileElements + MAX_TILE_ELEMENTS)
return true;
map_reorganise_elements();
if ((gNextFreeTileElement + num_elements) <= gTileElements + MAX_TILE_ELEMENTS)
return true;
else{
gGameCommandErrorText = STR_ERR_LANDSCAPE_DATA_AREA_FULL;
return false;
// Check if there is any room again
newTileElementEnd = gNextFreeTileElement + numElements;
if (newTileElementEnd > tileElementEnd)
{
// Not enough spare elements left :'(
gGameCommandErrorText = STR_ERR_LANDSCAPE_DATA_AREA_FULL;
return false;
}
}
}
return true;
}
/**

View File

@@ -142,7 +142,6 @@ rct_tile_element *map_get_park_entrance_element_at(int32_t x, int32_t y, int32_t
rct_tile_element * map_get_ride_entrance_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
rct_tile_element * map_get_ride_exit_element_at(int32_t x, int32_t y, int32_t z, bool ghost);
int32_t tile_element_height(int32_t x, int32_t y);
void sub_68B089();
bool map_coord_is_connected(int32_t x, int32_t y, int32_t z, uint8_t faceDirection);
void map_remove_provisional_elements();
void map_restore_provisional_elements();