1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 22:34:33 +01:00

Use a vector for map selection tiles

This commit is contained in:
duncanspumpkin
2019-03-28 18:29:51 +00:00
parent 7b2363f0ef
commit 30a5194085
9 changed files with 96 additions and 123 deletions

View File

@@ -1165,9 +1165,9 @@ static void window_footpath_set_enabled_and_pressed_widgets()
gMapSelectFlags |= MAP_SELECT_FLAG_GREEN;
int32_t direction = gFootpathConstructDirection;
gMapSelectionTiles[0].x = gFootpathConstructFromPosition.x + CoordsDirectionDelta[direction].x;
gMapSelectionTiles[0].y = gFootpathConstructFromPosition.y + CoordsDirectionDelta[direction].y;
gMapSelectionTiles[1].x = -1;
gMapSelectionTiles.clear();
gMapSelectionTiles.push_back({ gFootpathConstructFromPosition.x + CoordsDirectionDelta[direction].x,
gFootpathConstructFromPosition.y + CoordsDirectionDelta[direction].y });
map_invalidate_map_selection_tiles();
}

View File

@@ -1235,14 +1235,12 @@ static void window_map_place_park_entrance_tool_update(int32_t x, int32_t y)
}
sideDirection = (direction + 1) & 3;
gMapSelectionTiles[0].x = mapX;
gMapSelectionTiles[0].y = mapY;
gMapSelectionTiles[1].x = mapX + CoordsDirectionDelta[sideDirection].x;
gMapSelectionTiles[1].y = mapY + CoordsDirectionDelta[sideDirection].y;
gMapSelectionTiles[2].x = mapX - CoordsDirectionDelta[sideDirection].x;
gMapSelectionTiles[2].y = mapY - CoordsDirectionDelta[sideDirection].y;
gMapSelectionTiles[3].x = -1;
gMapSelectionTiles[3].y = -1;
gMapSelectionTiles.clear();
gMapSelectionTiles.push_back({ mapX, mapY });
gMapSelectionTiles.push_back(
{ mapX + CoordsDirectionDelta[sideDirection].x, mapY + CoordsDirectionDelta[sideDirection].y });
gMapSelectionTiles.push_back(
{ mapX - CoordsDirectionDelta[sideDirection].x, mapY - CoordsDirectionDelta[sideDirection].y });
gMapSelectArrowPosition.x = mapX;
gMapSelectArrowPosition.y = mapY;

View File

@@ -3345,7 +3345,7 @@ static void window_ride_construction_select_map_tiles(
trackBlock = get_track_def_from_ride(ride, trackType);
trackDirection &= 3;
int32_t selectionTileIndex = 0;
gMapSelectionTiles.clear();
while (trackBlock->index != 255)
{
switch (trackDirection)
@@ -3368,13 +3368,10 @@ static void window_ride_construction_select_map_tiles(
offsetY = trackBlock->x;
break;
}
gMapSelectionTiles[selectionTileIndex].x = x + offsetX;
gMapSelectionTiles[selectionTileIndex].y = y + offsetY;
selectionTileIndex++;
gMapSelectionTiles.push_back({ x + offsetX, y + offsetY });
trackBlock++;
}
gMapSelectionTiles[selectionTileIndex].x = -1;
gMapSelectionTiles[selectionTileIndex].y = -1;
}
/**
@@ -3510,10 +3507,8 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY)
gMapSelectArrowPosition.x = x;
gMapSelectArrowPosition.y = y;
gMapSelectArrowPosition.z = z;
gMapSelectionTiles[0].x = x;
gMapSelectionTiles[0].y = y;
gMapSelectionTiles[1].x = -1;
gMapSelectionTiles[1].y = -1;
gMapSelectionTiles.clear();
gMapSelectionTiles.push_back({ x, y });
ride_id_t rideIndex;
int32_t trackType, trackDirection, liftHillAndAlternativeState;
@@ -3539,16 +3534,14 @@ void ride_construction_toolupdate_construct(int32_t screenX, int32_t screenY)
if (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE_CONSTRUCT)
{
int32_t highestZ = 0;
LocationXY16* selectedTile = gMapSelectionTiles;
while (selectedTile->x != -1)
for (const auto& selectedTile : gMapSelectionTiles)
{
if (selectedTile->x < (256 * 32) && selectedTile->y < (256 * 32))
if (selectedTile.x < (256 * 32) && selectedTile.y < (256 * 32))
{
z = map_get_highest_z(selectedTile->x >> 5, selectedTile->y >> 5);
z = map_get_highest_z(selectedTile.x / 32, selectedTile.y / 32);
if (z > highestZ)
highestZ = z;
}
selectedTile++;
}
}
// loc_6CC8BF:
@@ -3764,17 +3757,15 @@ void ride_construction_tooldown_construct(int32_t screenX, int32_t screenY)
highestZ = 0;
if (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE_CONSTRUCT)
{
LocationXY16* selectedTile = gMapSelectionTiles;
while (selectedTile->x != -1)
for (const auto& selectedTile : gMapSelectionTiles)
{
if (selectedTile->x >= (256 * 32) || selectedTile->y >= (256 * 32))
if (selectedTile.x >= (256 * 32) || selectedTile.y >= (256 * 32))
continue;
z = map_get_highest_z(selectedTile->x >> 5, selectedTile->y >> 5);
z = map_get_highest_z(selectedTile.x / 32, selectedTile.y / 32);
if (z > highestZ)
highestZ = z;
selectedTile++;
}
}

View File

@@ -2757,7 +2757,7 @@ static void top_toolbar_tool_update_scenery(int16_t x, int16_t y)
case SCENERY_TYPE_LARGE:
{
scenery = get_large_scenery_entry(selected_scenery);
LocationXY16* selectedTile = gMapSelectionTiles;
gMapSelectionTiles.clear();
for (rct_large_scenery_tile* tile = scenery->large_scenery.tiles; tile->x_offset != (int16_t)(uint16_t)0xFFFF;
tile++)
@@ -2769,11 +2769,8 @@ static void top_toolbar_tool_update_scenery(int16_t x, int16_t y)
tileLocation.x += mapTile.x;
tileLocation.y += mapTile.y;
selectedTile->x = tileLocation.x;
selectedTile->y = tileLocation.y;
selectedTile++;
gMapSelectionTiles.push_back({tileLocation.x, tileLocation.y});
}
selectedTile->x = -1;
gMapSelectFlags |= MAP_SELECT_FLAG_ENABLE_CONSTRUCT;
map_invalidate_map_selection_tiles();

View File

@@ -105,12 +105,12 @@ void virtual_floor_invalidate()
if (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE_CONSTRUCT)
{
for (LocationXY16* tile = gMapSelectionTiles; tile->x != -1; tile++)
for (const auto& tile : gMapSelectionTiles)
{
min_position.x = std::min(min_position.x, tile->x);
min_position.y = std::min(min_position.y, tile->y);
max_position.x = std::max(max_position.x, tile->x);
max_position.y = std::max(max_position.y, tile->y);
min_position.x = std::min<int16_t>(min_position.x, tile.x);
min_position.y = std::min<int16_t>(min_position.y, tile.y);
max_position.x = std::max<int16_t>(max_position.x, tile.x);
max_position.y = std::max<int16_t>(max_position.y, tile.y);
}
}
@@ -186,10 +186,10 @@ bool virtual_floor_tile_is_floor(int16_t x, int16_t y)
else if (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE_CONSTRUCT)
{
// Check if we are anywhere near the selection tiles (larger scenery / rides)
for (LocationXY16* tile = gMapSelectionTiles; tile->x != -1; tile++)
for (const auto& tile : gMapSelectionTiles)
{
if (x >= tile->x - _virtualFloorBaseSize && y >= tile->y - _virtualFloorBaseSize
&& x <= tile->x + _virtualFloorBaseSize && y <= tile->y + _virtualFloorBaseSize)
if (x >= tile.x - _virtualFloorBaseSize && y >= tile.y - _virtualFloorBaseSize
&& x <= tile.x + _virtualFloorBaseSize && y <= tile.y + _virtualFloorBaseSize)
{
return true;
}
@@ -223,9 +223,9 @@ static void virtual_floor_get_tile_properties(
// See if we are on top of the selection tiles
if (gMapSelectFlags & MAP_SELECT_FLAG_ENABLE_CONSTRUCT)
{
for (LocationXY16* tile = gMapSelectionTiles; tile->x != -1; tile++)
for (const auto& tile : gMapSelectionTiles)
{
if (x == tile->x && y == tile->y)
if (x == tile.x && y == tile.y)
{
*outLit = true;
break;

View File

@@ -1193,9 +1193,9 @@ void surface_paint(paint_session* session, uint8_t direction, uint16_t height, c
{
const LocationXY16& pos = session->MapPosition;
for (const LocationXY16* tile = gMapSelectionTiles; tile->x != -1; tile++)
for (const auto& tile : gMapSelectionTiles)
{
if (tile->x != pos.x || tile->y != pos.y)
if (tile.x != pos.x || tile.y != pos.y)
{
continue;
}

View File

@@ -673,24 +673,14 @@ void track_design_mirror(rct_track_td6* td6)
static void track_design_add_selection_tile(int16_t x, int16_t y)
{
LocationXY16* selectionTile = gMapSelectionTiles;
// Subtract 2 because the tile gets incremented later on
for (; (selectionTile < gMapSelectionTiles + std::size(gMapSelectionTiles) - 2) && (selectionTile->x != -1);
selectionTile++)
for (const auto tile:gMapSelectionTiles)
{
if (selectionTile->x == x && selectionTile->y == y)
{
return;
}
if (selectionTile + 1 >= &gMapSelectionTiles[300])
if (tile.x == x && tile.y == y)
{
return;
}
}
selectionTile->x = x;
selectionTile->y = y;
selectionTile++;
selectionTile->x = -1;
gMapSelectionTiles.push_back(CoordsXY{x,y});
}
static void track_design_update_max_min_coordinates(int16_t x, int16_t y, int16_t z)
@@ -703,11 +693,51 @@ static void track_design_update_max_min_coordinates(int16_t x, int16_t y, int16_
gTrackPreviewMax.z = std::max(gTrackPreviewMax.z, z);
}
static bool TrackDesignPlaceSceneryTileRemoveGhost(
static bool TrackDesignPlaceSceneryElementGetEntry(uint8_t& entry_type, uint8_t& entry_index, rct_td6_scenery_element* scenery)
{
if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index))
{
entry_type = object_entry_get_type(&scenery->scenery_object);
if (entry_type != OBJECT_TYPE_PATHS)
{
_trackDesignPlaceStateSceneryUnavailable = true;
return true;
}
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
{
_trackDesignPlaceStateSceneryUnavailable = true;
return true;
}
entry_index = 0;
for (PathSurfaceEntry* path = get_path_surface_entry(0); entry_index < object_entry_group_counts[OBJECT_TYPE_PATHS];
path = get_path_surface_entry(entry_index), entry_index++)
{
if (path == nullptr)
{
return true;
}
if (path->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)
{
return true;
}
}
if (entry_index == object_entry_group_counts[OBJECT_TYPE_PATHS])
{
_trackDesignPlaceStateSceneryUnavailable = true;
return true;
}
}
return false;
}
static bool TrackDesignPlaceSceneryElementRemoveGhost(
CoordsXY mapCoord, rct_td6_scenery_element* scenery, uint8_t rotation, int32_t originZ)
{
uint8_t entry_type, entry_index;
if (TrackDesignPlaceSceneryTileGetEntry(entry_type, entry_index, scenery))
if (TrackDesignPlaceSceneryElementGetEntry(entry_type, entry_index, scenery))
{
return true;
}
@@ -771,48 +801,7 @@ static bool TrackDesignPlaceSceneryTileRemoveGhost(
return true;
}
static bool TrackDesignPlaceSceneryTileGetEntry(uint8_t& entry_type, uint8_t& entry_index, rct_td6_scenery_element* scenery)
{
uint8_t entry_type, entry_index;
if (!find_object_in_entry_group(&scenery->scenery_object, &entry_type, &entry_index))
{
entry_type = object_entry_get_type(&scenery->scenery_object);
if (entry_type != OBJECT_TYPE_PATHS)
{
_trackDesignPlaceStateSceneryUnavailable = true;
return true;
}
if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER)
{
_trackDesignPlaceStateSceneryUnavailable = true;
return true;
}
entry_index = 0;
for (PathSurfaceEntry* path = get_path_surface_entry(0); entry_index < object_entry_group_counts[OBJECT_TYPE_PATHS];
path = get_path_surface_entry(entry_index), entry_index++)
{
if (path == nullptr)
{
return true;
}
if (path->flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)
{
return true;
}
}
if (entry_index == object_entry_group_counts[OBJECT_TYPE_PATHS])
{
_trackDesignPlaceStateSceneryUnavailable = true;
return true;
}
}
return false;
}
static bool TrackDesignPlaceSceneryTileGetPlaceZ(rct_td6_scenery_element* scenery)
static bool TrackDesignPlaceSceneryElementGetPlaceZ(rct_td6_scenery_element* scenery)
{
int32_t z = scenery->z * 8 + _trackDesignPlaceZ;
if (z < _trackDesignPlaceSceneryZ)
@@ -821,28 +810,28 @@ static bool TrackDesignPlaceSceneryTileGetPlaceZ(rct_td6_scenery_element* scener
}
uint8_t entry_type, entry_index;
TrackDesignPlaceSceneryTileGetEntry(entry_type, entry_index, scenery);
TrackDesignPlaceSceneryElementGetEntry(entry_type, entry_index, scenery);
return true;
}
static bool TrackDesignPlaceSceneryTile(
static bool TrackDesignPlaceSceneryElement(
CoordsXY mapCoord, LocationXY8 tile, uint8_t mode, rct_td6_scenery_element* scenery, uint8_t rotation, int32_t originZ)
{
if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES && mode == 0)
{
track_design_add_selection_tile(tile.x, tile.y);
track_design_add_selection_tile(mapCoord.x, mapCoord.y);
return true;
}
if (_trackDesignPlaceOperation == PTD_OPERATION_REMOVE_GHOST && mode == 0)
{
return TrackDesignPlaceSceneryTileRemoveGhost(mapCoord, scenery, rotation, originZ);
return TrackDesignPlaceSceneryElementRemoveGhost(mapCoord, scenery, rotation, originZ);
}
if (_trackDesignPlaceOperation == PTD_OPERATION_GET_PLACE_Z)
{
return TrackDesignPlaceSceneryTileGetPlaceZ(scenery);
return TrackDesignPlaceSceneryElementGetPlaceZ(scenery);
}
if (_trackDesignPlaceOperation == PTD_OPERATION_PLACE_QUERY || _trackDesignPlaceOperation == PTD_OPERATION_PLACE
@@ -850,7 +839,7 @@ static bool TrackDesignPlaceSceneryTile(
|| _trackDesignPlaceOperation == PTD_OPERATION_PLACE_TRACK_PREVIEW)
{
uint8_t entry_type, entry_index;
if (TrackDesignPlaceSceneryTileGetEntry(entry_type, entry_index, scenery))
if (TrackDesignPlaceSceneryElementGetEntry(entry_type, entry_index, scenery))
{
return true;
}
@@ -1097,7 +1086,7 @@ static bool TrackDesignPlaceSceneryTile(
*
* rct2: 0x006D0964
*/
static int32_t track_design_place_scenery(
static int32_t track_design_place_all_scenery(
rct_td6_scenery_element* scenery_start, int32_t originX, int32_t originY, int32_t originZ)
{
for (uint8_t mode = 0; mode <= 1; mode++)
@@ -1139,7 +1128,7 @@ static int32_t track_design_place_scenery(
CoordsXY mapCoord = { tile.x * 32, tile.y * 32 };
track_design_update_max_min_coordinates(mapCoord.x, mapCoord.y, originZ);
if (!TrackDesignPlaceSceneryTile(mapCoord, tile, mode, scenery, rotation, originZ))
if (!TrackDesignPlaceSceneryElement(mapCoord, tile, mode, scenery, rotation, originZ))
{
return 0;
}
@@ -1152,7 +1141,7 @@ static int32_t track_design_place_maze(rct_track_td6* td6, int16_t x, int16_t y,
{
if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES)
{
gMapSelectionTiles->x = -1;
gMapSelectionTiles.clear();
gMapSelectArrowPosition.x = x;
gMapSelectArrowPosition.y = y;
gMapSelectArrowPosition.z = tile_element_height(x, y) & 0xFFFF;
@@ -1366,7 +1355,7 @@ static bool track_design_place_ride(rct_track_td6* td6, int16_t x, int16_t y, in
gTrackPreviewOrigin.z = z;
if (_trackDesignPlaceOperation == PTD_OPERATION_DRAW_OUTLINES)
{
gMapSelectionTiles->x = -1;
gMapSelectionTiles.clear();
gMapSelectArrowPosition.x = x;
gMapSelectArrowPosition.y = y;
gMapSelectArrowPosition.z = tile_element_height(x, y) & 0xFFFF;
@@ -1698,7 +1687,7 @@ int32_t place_virtual_track(
rct_td6_scenery_element* scenery = td6->scenery_elements;
if (track_place_success && scenery != nullptr)
{
if (!track_design_place_scenery(scenery, gTrackPreviewOrigin.x, gTrackPreviewOrigin.y, gTrackPreviewOrigin.z))
if (!track_design_place_all_scenery(scenery, gTrackPreviewOrigin.x, gTrackPreviewOrigin.y, gTrackPreviewOrigin.z))
{
return _trackDesignPlaceCost;
}

View File

@@ -88,7 +88,7 @@ int16_t gMapBaseZ;
TileElement gTileElements[MAX_TILE_TILE_ELEMENT_POINTERS * 3];
TileElement* gTileElementTilePointers[MAX_TILE_TILE_ELEMENT_POINTERS];
LocationXY16 gMapSelectionTiles[300];
std::vector<CoordsXY> gMapSelectionTiles;
std::vector<PeepSpawn> gPeepSpawns;
TileElement* gNextFreeTileElement;
@@ -1394,13 +1394,11 @@ void map_remove_all_rides()
*/
void map_invalidate_map_selection_tiles()
{
LocationXY16* position;
if (!(gMapSelectFlags & MAP_SELECT_FLAG_ENABLE_CONSTRUCT))
return;
for (position = gMapSelectionTiles; position->x != -1; position++)
map_invalidate_tile_full(position->x, position->y);
for (const auto& position : gMapSelectionTiles)
map_invalidate_tile_full(position.x, position.y);
}
void map_get_bounding_box(

View File

@@ -107,7 +107,7 @@ extern uint8_t gMapGroundFlags;
extern TileElement gTileElements[MAX_TILE_TILE_ELEMENT_POINTERS * 3];
extern TileElement* gTileElementTilePointers[MAX_TILE_TILE_ELEMENT_POINTERS];
extern LocationXY16 gMapSelectionTiles[300];
extern std::vector<CoordsXY> gMapSelectionTiles;
extern std::vector<PeepSpawn> gPeepSpawns;
extern TileElement* gNextFreeTileElement;