forked from rosebudai/OpenRCT2-Web
Merge pull request #14791 from duncanspumpkin/map
Map refactor from NSF
This commit is contained in:
28 files changed
+359
-294
No files matched your search
@@ -55,7 +55,7 @@ GameActions::Result::Ptr BannerPlaceAction::Query() const
|
||||
res->Expenditure = ExpenditureType::Landscaping;
|
||||
res->ErrorTitle = STR_CANT_POSITION_THIS_HERE;
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
log_error("No free map elements.");
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE);
|
||||
@@ -118,7 +118,7 @@ GameActions::Result::Ptr BannerPlaceAction::Execute() const
|
||||
res->Expenditure = ExpenditureType::Landscaping;
|
||||
res->ErrorTitle = STR_CANT_POSITION_THIS_HERE;
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
log_error("No free map elements.");
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_POSITION_THIS_HERE);
|
||||
|
||||
@@ -216,7 +216,7 @@ GameActions::Result::Ptr FootpathPlaceAction::ElementInsertQuery(GameActions::Re
|
||||
{
|
||||
bool entrancePath = false, entranceIsSamePath = false;
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_CANT_BUILD_FOOTPATH_HERE);
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ GameActions::Result::Ptr FootpathPlaceFromTrackAction::ElementInsertQuery(GameAc
|
||||
{
|
||||
bool entrancePath = false, entranceIsSamePath = false;
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ GameActions::Result::Ptr LargeSceneryPlaceAction::Query() const
|
||||
}
|
||||
}
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(totalNumTiles))
|
||||
if (!CheckMapCapacity(sceneryEntry->tiles, totalNumTiles))
|
||||
{
|
||||
log_error("No free map elements available");
|
||||
return std::make_unique<LargeSceneryPlaceActionResult>(GameActions::Status::NoFreeElements);
|
||||
@@ -240,7 +240,7 @@ GameActions::Result::Ptr LargeSceneryPlaceAction::Execute() const
|
||||
|
||||
res->Position.z = maxHeight;
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(totalNumTiles))
|
||||
if (!CheckMapCapacity(sceneryEntry->tiles, totalNumTiles))
|
||||
{
|
||||
log_error("No free map elements available");
|
||||
return std::make_unique<LargeSceneryPlaceActionResult>(GameActions::Status::NoFreeElements);
|
||||
@@ -340,6 +340,22 @@ int16_t LargeSceneryPlaceAction::GetTotalNumTiles(rct_large_scenery_tile* tiles)
|
||||
return totalNumTiles;
|
||||
}
|
||||
|
||||
bool LargeSceneryPlaceAction::CheckMapCapacity(rct_large_scenery_tile* tiles, int16_t numTiles) const
|
||||
{
|
||||
for (rct_large_scenery_tile* tile = tiles; tile->x_offset != -1; tile++)
|
||||
{
|
||||
auto curTile = CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction);
|
||||
|
||||
curTile.x += _loc.x;
|
||||
curTile.y += _loc.y;
|
||||
if (!MapCheckCapacityAndReorganise(curTile, numTiles))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int16_t LargeSceneryPlaceAction::GetMaxSurfaceHeight(rct_large_scenery_tile* tiles) const
|
||||
{
|
||||
int16_t maxHeight = -1;
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
|
||||
private:
|
||||
int16_t GetTotalNumTiles(rct_large_scenery_tile * tiles) const;
|
||||
bool CheckMapCapacity(rct_large_scenery_tile * tiles, int16_t numTiles) const;
|
||||
int16_t GetMaxSurfaceHeight(rct_large_scenery_tile * tiles) const;
|
||||
void SetNewLargeSceneryElement(LargeSceneryElement & sceneryElement, uint8_t tileNum) const;
|
||||
};
|
||||
@@ -39,7 +39,7 @@ GameActions::Result::Ptr MazePlaceTrackAction::Query() const
|
||||
res->Position = _loc + CoordsXYZ{ 8, 8, 0 };
|
||||
res->Expenditure = ExpenditureType::RideConstruction;
|
||||
res->ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
res->Error = GameActions::Status::NoFreeElements;
|
||||
res->ErrorMessage = STR_TILE_ELEMENT_LIMIT_REACHED;
|
||||
@@ -137,7 +137,7 @@ GameActions::Result::Ptr MazePlaceTrackAction::Execute() const
|
||||
return res;
|
||||
}
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
res->Error = GameActions::Status::NoFreeElements;
|
||||
res->ErrorMessage = STR_NONE;
|
||||
|
||||
@@ -51,7 +51,7 @@ GameActions::Result::Ptr MazeSetTrackAction::Query() const
|
||||
res->Position = _loc + CoordsXYZ{ 8, 8, 0 };
|
||||
res->Expenditure = ExpenditureType::RideConstruction;
|
||||
res->ErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
res->Error = GameActions::Status::NoFreeElements;
|
||||
res->ErrorMessage = STR_TILE_ELEMENT_LIMIT_REACHED;
|
||||
@@ -159,7 +159,7 @@ GameActions::Result::Ptr MazeSetTrackAction::Execute() const
|
||||
return res;
|
||||
}
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
res->Error = GameActions::Status::NoFreeElements;
|
||||
res->ErrorMessage = STR_NONE;
|
||||
|
||||
@@ -51,7 +51,7 @@ GameActions::Result::Ptr PlaceParkEntranceAction::Query() const
|
||||
res->Expenditure = ExpenditureType::LandPurchase;
|
||||
res->Position = { _loc.x, _loc.y, _loc.z };
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(3))
|
||||
if (!CheckMapCapacity(3))
|
||||
{
|
||||
return std::make_unique<GameActions::Result>(
|
||||
GameActions::Status::NoFreeElements, STR_CANT_BUILD_PARK_ENTRANCE_HERE, STR_NONE);
|
||||
@@ -170,3 +170,25 @@ GameActions::Result::Ptr PlaceParkEntranceAction::Execute() const
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool PlaceParkEntranceAction::CheckMapCapacity(int16_t numTiles) const
|
||||
{
|
||||
CoordsXYZ entranceLoc = _loc;
|
||||
for (uint8_t index = 0; index < 3; index++)
|
||||
{
|
||||
if (index == 1)
|
||||
{
|
||||
entranceLoc += CoordsDirectionDelta[(_loc.direction - 1) & 0x3];
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
entranceLoc.x += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].x * 2;
|
||||
entranceLoc.y += CoordsDirectionDelta[(_loc.direction + 1) & 0x3].y * 2;
|
||||
}
|
||||
if (!MapCheckCapacityAndReorganise(entranceLoc, numTiles))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -26,4 +26,7 @@ public:
|
||||
void Serialise(DataSerialiser & stream) override;
|
||||
GameActions::Result::Ptr Query() const override;
|
||||
GameActions::Result::Ptr Execute() const override;
|
||||
|
||||
private:
|
||||
bool CheckMapCapacity(int16_t numTiles) const;
|
||||
};
|
||||
@@ -47,12 +47,6 @@ GameActions::Result::Ptr PlacePeepSpawnAction::Query() const
|
||||
res->Expenditure = ExpenditureType::LandPurchase;
|
||||
res->Position = _location;
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(3))
|
||||
{
|
||||
return std::make_unique<GameActions::Result>(
|
||||
GameActions::Status::NoFreeElements, STR_ERR_CANT_PLACE_PEEP_SPAWN_HERE, STR_NONE);
|
||||
}
|
||||
|
||||
if (!LocationValid(_location) || _location.x <= 16 || _location.y <= 16 || _location.x >= (gMapSizeUnits - 16)
|
||||
|| _location.y >= (gMapSizeUnits - 16))
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ GameActions::Result::Ptr RideEntranceExitPlaceAction::Query() const
|
||||
{
|
||||
auto errorTitle = _isExit ? STR_CANT_BUILD_MOVE_EXIT_FOR_THIS_RIDE_ATTRACTION
|
||||
: STR_CANT_BUILD_MOVE_ENTRANCE_FOR_THIS_RIDE_ATTRACTION;
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
return MakeResult(GameActions::Status::NoFreeElements, errorTitle);
|
||||
}
|
||||
@@ -217,7 +217,7 @@ GameActions::Result::Ptr RideEntranceExitPlaceAction::TrackPlaceQuery(const Coor
|
||||
{
|
||||
auto errorTitle = isExit ? STR_CANT_BUILD_MOVE_EXIT_FOR_THIS_RIDE_ATTRACTION
|
||||
: STR_CANT_BUILD_MOVE_ENTRANCE_FOR_THIS_RIDE_ATTRACTION;
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(loc))
|
||||
{
|
||||
return MakeResult(GameActions::Status::NoFreeElements, errorTitle);
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ GameActions::Result::Ptr SmallSceneryPlaceAction::Query() const
|
||||
res->Position.z = surfaceHeight;
|
||||
}
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
return std::make_unique<SmallSceneryPlaceActionResult>(GameActions::Status::NoFreeElements);
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ GameActions::Result::Ptr TrackPlaceAction::Query() const
|
||||
numElements++;
|
||||
}
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(numElements))
|
||||
if (!CheckMapCapacity(numElements))
|
||||
{
|
||||
log_warning("Not enough free map elements to place track.");
|
||||
return std::make_unique<TrackPlaceActionResult>(GameActions::Status::NoFreeElements, STR_TILE_ELEMENT_LIMIT_REACHED);
|
||||
@@ -650,3 +650,18 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const
|
||||
res->Cost = cost + ((price / 2) * 10);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool TrackPlaceAction::CheckMapCapacity(int16_t numTiles) const
|
||||
{
|
||||
for (const rct_preview_track* trackBlock = TrackBlocks[_trackType]; trackBlock->index != 0xFF; trackBlock++)
|
||||
{
|
||||
auto rotatedTrack = CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(_origin.direction);
|
||||
|
||||
auto tileCoords = CoordsXY{ _origin.x, _origin.y } + rotatedTrack;
|
||||
if (!MapCheckCapacityAndReorganise(tileCoords, numTiles))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -47,4 +47,7 @@ public:
|
||||
void Serialise(DataSerialiser & stream) override;
|
||||
GameActions::Result::Ptr Query() const override;
|
||||
GameActions::Result::Ptr Execute() const override;
|
||||
|
||||
private:
|
||||
bool CheckMapCapacity(int16_t numTiles) const;
|
||||
};
|
||||
@@ -290,7 +290,7 @@ GameActions::Result::Ptr WallPlaceAction::Query() const
|
||||
}
|
||||
}
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_TILE_ELEMENT_LIMIT_REACHED);
|
||||
}
|
||||
@@ -361,7 +361,7 @@ GameActions::Result::Ptr WallPlaceAction::Execute() const
|
||||
}
|
||||
}
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!MapCheckCapacityAndReorganise(_loc))
|
||||
{
|
||||
return MakeResult(GameActions::Status::NoFreeElements, STR_TILE_ELEMENT_LIMIT_REACHED);
|
||||
}
|
||||
|
||||
@@ -1247,8 +1247,8 @@ static int32_t cc_remove_park_fences(InteractiveConsole& console, [[maybe_unused
|
||||
|
||||
static int32_t cc_show_limits(InteractiveConsole& console, [[maybe_unused]] const arguments_t& argv)
|
||||
{
|
||||
map_reorganise_elements();
|
||||
int32_t tileElementCount = gNextFreeTileElement - gTileElements - 1;
|
||||
const auto& tileElements = GetTileElements();
|
||||
const auto tileElementCount = tileElements.size();
|
||||
|
||||
int32_t rideCount = ride_get_count();
|
||||
int32_t spriteCount = 0;
|
||||
@@ -1270,7 +1270,7 @@ static int32_t cc_show_limits(InteractiveConsole& console, [[maybe_unused]] cons
|
||||
}
|
||||
|
||||
console.WriteFormatLine("Sprites: %d/%d", spriteCount, MAX_ENTITIES);
|
||||
console.WriteFormatLine("Map Elements: %d/%d", tileElementCount, MAX_TILE_ELEMENTS);
|
||||
console.WriteFormatLine("Map Elements: %zu/%d", tileElementCount, MAX_TILE_ELEMENTS);
|
||||
console.WriteFormatLine("Banners: %d/%zu", bannerCount, MAX_BANNERS);
|
||||
console.WriteFormatLine("Rides: %d/%d", rideCount, MAX_RIDES);
|
||||
console.WriteFormatLine("Staff: %d/%d", staffCount, STAFF_MAX_COUNT);
|
||||
|
||||
@@ -2770,7 +2770,6 @@ bool NetworkBase::LoadMap(IStream* stream)
|
||||
bool NetworkBase::SaveMap(IStream* stream, const std::vector<const ObjectRepositoryItem*>& objects) const
|
||||
{
|
||||
bool result = false;
|
||||
map_reorganise_elements();
|
||||
viewport_set_saved_view();
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1483,38 +1483,44 @@ private:
|
||||
// Build tile pointer cache (needed to get the first element at a certain location)
|
||||
auto tilePointerIndex = TilePointerIndex<RCT12TileElement>(RCT1_MAX_MAP_SIZE, _s4.tile_elements);
|
||||
|
||||
TileElement* dstElement = gTileElements;
|
||||
|
||||
std::vector<TileElement> tileElements;
|
||||
for (TileCoordsXY coords = { 0, 0 }; coords.y < MAXIMUM_MAP_SIZE_TECHNICAL; coords.y++)
|
||||
{
|
||||
for (coords.x = 0; coords.x < MAXIMUM_MAP_SIZE_TECHNICAL; coords.x++)
|
||||
{
|
||||
if (coords.x >= RCT1_MAX_MAP_SIZE || coords.y >= RCT1_MAX_MAP_SIZE)
|
||||
{
|
||||
dstElement->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
dstElement->SetLastForTile(true);
|
||||
dstElement++;
|
||||
continue;
|
||||
auto& dstElement = tileElements.emplace_back();
|
||||
dstElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
dstElement.SetLastForTile(true);
|
||||
}
|
||||
|
||||
// This is the equivalent of map_get_first_element_at(x, y), but on S4 data.
|
||||
RCT12TileElement* srcElement = tilePointerIndex.GetFirstElementAt(coords);
|
||||
do
|
||||
else
|
||||
{
|
||||
if (srcElement->base_height == RCT12_MAX_ELEMENT_HEIGHT)
|
||||
continue;
|
||||
// This is the equivalent of map_get_first_element_at(x, y), but on S4 data.
|
||||
RCT12TileElement* srcElement = tilePointerIndex.GetFirstElementAt(coords);
|
||||
do
|
||||
{
|
||||
if (srcElement->base_height == RCT12_MAX_ELEMENT_HEIGHT)
|
||||
continue;
|
||||
|
||||
auto numAddedElements = ImportTileElement(dstElement, srcElement);
|
||||
dstElement += numAddedElements;
|
||||
} while (!(srcElement++)->IsLastForTile());
|
||||
// Reserve 8 elements for import
|
||||
auto originalSize = tileElements.size();
|
||||
tileElements.resize(originalSize + 16);
|
||||
auto dstElement = tileElements.data() + originalSize;
|
||||
auto numAddedElements = ImportTileElement(dstElement, srcElement);
|
||||
tileElements.resize(originalSize + numAddedElements);
|
||||
} while (!(srcElement++)->IsLastForTile());
|
||||
|
||||
// Set last element flag in case the original last element was never added
|
||||
(dstElement - 1)->SetLastForTile(true);
|
||||
// Set last element flag in case the original last element was never added
|
||||
if (tileElements.size() > 0)
|
||||
{
|
||||
tileElements.back().SetLastForTile(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
map_update_tile_pointers();
|
||||
|
||||
SetTileElements(std::move(tileElements));
|
||||
FixEntrancePositions();
|
||||
}
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ void S6Exporter::Export()
|
||||
_s6.scenario_srand_1 = state.s1;
|
||||
|
||||
// Map elements must be reorganised prior to saving otherwise save may be invalid
|
||||
map_reorganise_elements();
|
||||
ReorganiseTileElements();
|
||||
ExportTileElements();
|
||||
ExportEntities();
|
||||
ExportParkName();
|
||||
@@ -419,8 +419,8 @@ void S6Exporter::Export()
|
||||
|
||||
// pad_13CE730
|
||||
// rct1_scenario_flags
|
||||
_s6.wide_path_tile_loop_x = gWidePathTileLoopX;
|
||||
_s6.wide_path_tile_loop_y = gWidePathTileLoopY;
|
||||
_s6.wide_path_tile_loop_x = gWidePathTileLoopPosition.x;
|
||||
_s6.wide_path_tile_loop_y = gWidePathTileLoopPosition.y;
|
||||
// pad_13CE778
|
||||
|
||||
String::Set(_s6.scenario_filename, sizeof(_s6.scenario_filename), gScenarioFileName);
|
||||
@@ -1580,10 +1580,16 @@ void S6Exporter::ExportMapAnimations()
|
||||
|
||||
void S6Exporter::ExportTileElements()
|
||||
{
|
||||
const auto& tileElements = GetTileElements();
|
||||
for (uint32_t index = 0; index < RCT2_MAX_TILE_ELEMENTS; index++)
|
||||
{
|
||||
auto src = &gTileElements[index];
|
||||
auto dst = &_s6.tile_elements[index];
|
||||
if (index >= tileElements.size())
|
||||
{
|
||||
dst = {};
|
||||
continue;
|
||||
}
|
||||
auto src = &tileElements[index];
|
||||
if (src->base_height == MAX_ELEMENT_HEIGHT)
|
||||
{
|
||||
std::memcpy(dst, src, sizeof(*dst));
|
||||
@@ -1598,10 +1604,10 @@ void S6Exporter::ExportTileElements()
|
||||
ExportTileElement(dst, src);
|
||||
}
|
||||
}
|
||||
_s6.next_free_tile_element_pointer_index = gNextFreeTileElementPointerIndex;
|
||||
_s6.next_free_tile_element_pointer_index = static_cast<uint32_t>(tileElements.size());
|
||||
}
|
||||
|
||||
void S6Exporter::ExportTileElement(RCT12TileElement* dst, TileElement* src)
|
||||
void S6Exporter::ExportTileElement(RCT12TileElement* dst, const TileElement* src)
|
||||
{
|
||||
// Todo: allow for changing definition of OpenRCT2 tile element types - replace with a map
|
||||
uint8_t tileElementType = src->GetType();
|
||||
@@ -1852,7 +1858,6 @@ int32_t scenario_save(const utf8* path, int32_t flags)
|
||||
window_close_construction_windows();
|
||||
}
|
||||
|
||||
map_reorganise_elements();
|
||||
viewport_set_saved_view();
|
||||
|
||||
bool result = false;
|
||||
|
||||
@@ -73,7 +73,7 @@ private:
|
||||
void ExportMapAnimations();
|
||||
|
||||
void ExportTileElements();
|
||||
void ExportTileElement(RCT12TileElement* dst, TileElement* src);
|
||||
void ExportTileElement(RCT12TileElement* dst, const TileElement* src);
|
||||
|
||||
std::optional<uint16_t> AllocateUserString(std::string_view value);
|
||||
void ExportUserStrings();
|
||||
|
||||
@@ -459,13 +459,12 @@ public:
|
||||
|
||||
// pad_13CE730
|
||||
// rct1_scenario_flags
|
||||
gWidePathTileLoopX = _s6.wide_path_tile_loop_x;
|
||||
gWidePathTileLoopY = _s6.wide_path_tile_loop_y;
|
||||
gWidePathTileLoopPosition.x = _s6.wide_path_tile_loop_x;
|
||||
gWidePathTileLoopPosition.y = _s6.wide_path_tile_loop_y;
|
||||
// pad_13CE778
|
||||
|
||||
// Fix and set dynamic variables
|
||||
map_strip_ghost_flag_from_elements();
|
||||
map_update_tile_pointers();
|
||||
game_convert_strings_to_utf8();
|
||||
map_count_remaining_land_rights();
|
||||
determine_ride_entrance_and_exit_locations();
|
||||
@@ -1040,16 +1039,16 @@ public:
|
||||
// Build tile pointer cache (needed to get the first element at a certain location)
|
||||
auto tilePointerIndex = TilePointerIndex<RCT12TileElement>(RCT2_MAXIMUM_MAP_SIZE_TECHNICAL, _s6.tile_elements);
|
||||
|
||||
TileElement* dstElement = gTileElements;
|
||||
std::vector<TileElement> tileElements;
|
||||
for (TileCoordsXY coords = { 0, 0 }; coords.y < MAXIMUM_MAP_SIZE_TECHNICAL; coords.y++)
|
||||
{
|
||||
for (coords.x = 0; coords.x < MAXIMUM_MAP_SIZE_TECHNICAL; coords.x++)
|
||||
{
|
||||
if (coords.x >= RCT2_MAXIMUM_MAP_SIZE_TECHNICAL || coords.y >= RCT2_MAXIMUM_MAP_SIZE_TECHNICAL)
|
||||
{
|
||||
dstElement->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
dstElement->SetLastForTile(true);
|
||||
dstElement++;
|
||||
auto& dstElement = tileElements.emplace_back();
|
||||
dstElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
dstElement.SetLastForTile(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1057,17 +1056,18 @@ public:
|
||||
// This might happen with damaged parks. Make sure there is *something* to avoid crashes.
|
||||
if (srcElement == nullptr)
|
||||
{
|
||||
dstElement->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
dstElement->SetLastForTile(true);
|
||||
dstElement++;
|
||||
auto& dstElement = tileElements.emplace_back();
|
||||
dstElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
dstElement.SetLastForTile(true);
|
||||
continue;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
auto& dstElement = tileElements.emplace_back();
|
||||
if (srcElement->base_height == RCT12_MAX_ELEMENT_HEIGHT)
|
||||
{
|
||||
std::memcpy(dstElement, srcElement, sizeof(*srcElement));
|
||||
std::memcpy(&dstElement, srcElement, sizeof(*srcElement));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1076,19 +1076,20 @@ public:
|
||||
if (tileElementType == RCT12TileElementType::Corrupt
|
||||
|| tileElementType == RCT12TileElementType::EightCarsCorrupt14
|
||||
|| tileElementType == RCT12TileElementType::EightCarsCorrupt15)
|
||||
std::memcpy(dstElement, srcElement, sizeof(*srcElement));
|
||||
std::memcpy(&dstElement, srcElement, sizeof(*srcElement));
|
||||
else
|
||||
ImportTileElement(dstElement, srcElement);
|
||||
ImportTileElement(&dstElement, srcElement);
|
||||
}
|
||||
|
||||
dstElement++;
|
||||
} while (!(srcElement++)->IsLastForTile());
|
||||
|
||||
// Set last element flag in case the original last element was never added
|
||||
if (tileElements.size() > 0)
|
||||
{
|
||||
tileElements.back().SetLastForTile(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gNextFreeTileElementPointerIndex = _s6.next_free_tile_element_pointer_index;
|
||||
|
||||
map_update_tile_pointers();
|
||||
SetTileElements(std::move(tileElements));
|
||||
}
|
||||
|
||||
void ImportTileElement(TileElement* dst, const RCT12TileElement* src)
|
||||
|
||||
@@ -96,10 +96,6 @@ static bool _trackDesignPlaceStateHasScenery = false;
|
||||
static bool _trackDesignPlaceStatePlaceScenery = true;
|
||||
static bool _trackDesignPlaceIsReplay = false;
|
||||
|
||||
static std::unique_ptr<map_backup> track_design_preview_backup_map();
|
||||
|
||||
static void track_design_preview_restore_map(map_backup* backup);
|
||||
|
||||
static void track_design_preview_clear_map();
|
||||
|
||||
rct_string_id TrackDesign::CreateTrackDesign(const Ride& ride)
|
||||
@@ -1985,12 +1981,7 @@ static bool track_design_place_preview(TrackDesign* td6, money32* cost, Ride** o
|
||||
*/
|
||||
void track_design_draw_preview(TrackDesign* td6, uint8_t* pixels)
|
||||
{
|
||||
// Make a copy of the map
|
||||
auto mapBackup = track_design_preview_backup_map();
|
||||
if (mapBackup == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StashMap();
|
||||
track_design_preview_clear_map();
|
||||
|
||||
if (gScreenFlags & SCREEN_FLAGS_TRACK_MANAGER)
|
||||
@@ -2004,7 +1995,7 @@ void track_design_draw_preview(TrackDesign* td6, uint8_t* pixels)
|
||||
if (!track_design_place_preview(td6, &cost, &ride, &flags))
|
||||
{
|
||||
std::fill_n(pixels, TRACK_PREVIEW_IMAGE_SIZE * 4, 0x00);
|
||||
track_design_preview_restore_map(mapBackup.get());
|
||||
UnstashMap();
|
||||
return;
|
||||
}
|
||||
td6->cost = cost;
|
||||
@@ -2087,43 +2078,7 @@ void track_design_draw_preview(TrackDesign* td6, uint8_t* pixels)
|
||||
}
|
||||
|
||||
ride->Delete();
|
||||
track_design_preview_restore_map(mapBackup.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a backup of the map as it will be cleared for drawing the track
|
||||
* design preview.
|
||||
* rct2: 0x006D1C68
|
||||
*/
|
||||
static std::unique_ptr<map_backup> track_design_preview_backup_map()
|
||||
{
|
||||
auto backup = std::make_unique<map_backup>();
|
||||
if (backup != nullptr)
|
||||
{
|
||||
std::memcpy(backup->tile_elements, gTileElements, sizeof(backup->tile_elements));
|
||||
std::memcpy(backup->tile_pointers, gTileElementTilePointers, sizeof(backup->tile_pointers));
|
||||
backup->next_free_tile_element = gNextFreeTileElement;
|
||||
backup->map_size_units = gMapSizeUnits;
|
||||
backup->map_size_units_minus_2 = gMapSizeMinus2;
|
||||
backup->map_size = gMapSize;
|
||||
backup->current_rotation = get_current_rotation();
|
||||
}
|
||||
return backup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the map from a backup.
|
||||
* rct2: 0x006D2378
|
||||
*/
|
||||
static void track_design_preview_restore_map(map_backup* backup)
|
||||
{
|
||||
std::memcpy(gTileElements, backup->tile_elements, sizeof(backup->tile_elements));
|
||||
std::memcpy(gTileElementTilePointers, backup->tile_pointers, sizeof(backup->tile_pointers));
|
||||
gNextFreeTileElement = backup->next_free_tile_element;
|
||||
gMapSizeUnits = backup->map_size_units;
|
||||
gMapSizeMinus2 = backup->map_size_units_minus_2;
|
||||
gMapSize = backup->map_size;
|
||||
gCurrentRotation = backup->current_rotation;
|
||||
UnstashMap();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2132,26 +2087,30 @@ static void track_design_preview_restore_map(map_backup* backup)
|
||||
*/
|
||||
static void track_design_preview_clear_map()
|
||||
{
|
||||
// These values were previously allocated in backup map but
|
||||
// it seems more fitting to place in this function
|
||||
auto numTiles = MAXIMUM_MAP_SIZE_TECHNICAL * MAXIMUM_MAP_SIZE_TECHNICAL;
|
||||
|
||||
gMapSizeUnits = 255 * COORDS_XY_STEP;
|
||||
gMapSizeMinus2 = (264 * 32) - 2;
|
||||
gMapSize = 256;
|
||||
|
||||
for (int32_t i = 0; i < MAX_TILE_TILE_ELEMENT_POINTERS; i++)
|
||||
// Reserve ~8 elements per tile
|
||||
std::vector<TileElement> tileElements;
|
||||
tileElements.reserve(numTiles * 8);
|
||||
|
||||
for (int32_t i = 0; i < numTiles; i++)
|
||||
{
|
||||
TileElement* tile_element = &gTileElements[i];
|
||||
tile_element->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
tile_element->SetLastForTile(true);
|
||||
tile_element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
|
||||
tile_element->AsSurface()->SetWaterHeight(0);
|
||||
tile_element->AsSurface()->SetSurfaceStyle(0);
|
||||
tile_element->AsSurface()->SetEdgeStyle(0);
|
||||
tile_element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
tile_element->AsSurface()->SetOwnership(OWNERSHIP_OWNED);
|
||||
tile_element->AsSurface()->SetParkFences(0);
|
||||
auto* element = &tileElements.emplace_back();
|
||||
element->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
element->SetLastForTile(true);
|
||||
element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
|
||||
element->AsSurface()->SetWaterHeight(0);
|
||||
element->AsSurface()->SetSurfaceStyle(0);
|
||||
element->AsSurface()->SetEdgeStyle(0);
|
||||
element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
element->AsSurface()->SetOwnership(OWNERSHIP_OWNED);
|
||||
element->AsSurface()->SetParkFences(0);
|
||||
}
|
||||
map_update_tile_pointers();
|
||||
SetTileElements(std::move(tileElements));
|
||||
}
|
||||
|
||||
bool track_design_are_entrance_and_exit_placed()
|
||||
|
||||
+182
-141
@@ -81,6 +81,8 @@ const std::array<CoordsXY, 8> CoordsDirectionDelta = {
|
||||
const TileCoordsXY TileDirectionDelta[] = { { -1, 0 }, { 0, +1 }, { +1, 0 }, { 0, -1 },
|
||||
{ -1, +1 }, { +1, +1 }, { +1, -1 }, { -1, -1 } };
|
||||
|
||||
constexpr size_t MIN_TILE_ELEMENTS = 1024;
|
||||
|
||||
uint16_t gMapSelectFlags;
|
||||
uint16_t gMapSelectType;
|
||||
CoordsXY gMapSelectPositionA;
|
||||
@@ -90,8 +92,7 @@ uint8_t gMapSelectArrowDirection;
|
||||
|
||||
uint8_t gMapGroundFlags;
|
||||
|
||||
uint16_t gWidePathTileLoopX;
|
||||
uint16_t gWidePathTileLoopY;
|
||||
TileCoordsXY gWidePathTileLoopPosition;
|
||||
uint16_t gGrassSceneryTileLoopPosition;
|
||||
|
||||
int16_t gMapSizeUnits;
|
||||
@@ -100,14 +101,9 @@ int16_t gMapSize;
|
||||
int16_t gMapSizeMaxXY;
|
||||
int16_t gMapBaseZ;
|
||||
|
||||
TileElement gTileElements[MAX_TILE_ELEMENTS_WITH_SPARE_ROOM];
|
||||
TileElement* gTileElementTilePointers[MAX_TILE_TILE_ELEMENT_POINTERS];
|
||||
std::vector<CoordsXY> gMapSelectionTiles;
|
||||
std::vector<PeepSpawn> gPeepSpawns;
|
||||
|
||||
TileElement* gNextFreeTileElement;
|
||||
uint32_t gNextFreeTileElementPointerIndex;
|
||||
|
||||
bool gLandMountainMode;
|
||||
bool gLandPaintMode;
|
||||
bool gClearSmallScenery;
|
||||
@@ -119,6 +115,122 @@ uint16_t gLandRemainingConstructionSales;
|
||||
|
||||
bool gMapLandRightsUpdateSuccess;
|
||||
|
||||
static TilePointerIndex<TileElement> _tileIndex;
|
||||
static std::vector<TileElement> _tileElements;
|
||||
static TilePointerIndex<TileElement> _tileIndexStash;
|
||||
static std::vector<TileElement> _tileElementsStash;
|
||||
static int32_t _mapSizeUnitsStash;
|
||||
static int32_t _mapSizeMinus2Stash;
|
||||
static int32_t _mapSizeStash;
|
||||
static int32_t _currentRotationStash;
|
||||
|
||||
void StashMap()
|
||||
{
|
||||
_tileIndexStash = std::move(_tileIndex);
|
||||
_tileElementsStash = std::move(_tileElements);
|
||||
_mapSizeUnitsStash = gMapSizeUnits;
|
||||
_mapSizeMinus2Stash = gMapSizeMinus2;
|
||||
_mapSizeStash = gMapSize;
|
||||
_currentRotationStash = gCurrentRotation;
|
||||
}
|
||||
|
||||
void UnstashMap()
|
||||
{
|
||||
_tileIndex = std::move(_tileIndexStash);
|
||||
_tileElements = std::move(_tileElementsStash);
|
||||
gMapSizeUnits = _mapSizeUnitsStash;
|
||||
gMapSizeMinus2 = _mapSizeMinus2Stash;
|
||||
gMapSize = _mapSizeStash;
|
||||
gCurrentRotation = _currentRotationStash;
|
||||
}
|
||||
|
||||
const std::vector<TileElement>& GetTileElements()
|
||||
{
|
||||
return _tileElements;
|
||||
}
|
||||
|
||||
void SetTileElements(std::vector<TileElement>&& tileElements)
|
||||
{
|
||||
_tileElements = std::move(tileElements);
|
||||
_tileIndex = TilePointerIndex<TileElement>(MAXIMUM_MAP_SIZE_TECHNICAL, _tileElements.data());
|
||||
}
|
||||
|
||||
static void ReorganiseTileElements(size_t capacity)
|
||||
{
|
||||
context_setcurrentcursor(CursorID::ZZZ);
|
||||
|
||||
std::vector<TileElement> newElements;
|
||||
newElements.reserve(std::max(MIN_TILE_ELEMENTS, capacity));
|
||||
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
||||
{
|
||||
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
||||
{
|
||||
const auto* element = map_get_first_element_at(TileCoordsXY{ x, y }.ToCoordsXY());
|
||||
if (element == nullptr)
|
||||
{
|
||||
auto& newElement = newElements.emplace_back();
|
||||
newElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
newElement.SetLastForTile(true);
|
||||
newElement.base_height = 14;
|
||||
newElement.clearance_height = 14;
|
||||
newElement.AsSurface()->SetWaterHeight(0);
|
||||
newElement.AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
|
||||
newElement.AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
newElement.AsSurface()->SetOwnership(OWNERSHIP_UNOWNED);
|
||||
newElement.AsSurface()->SetParkFences(0);
|
||||
newElement.AsSurface()->SetSurfaceStyle(0);
|
||||
newElement.AsSurface()->SetEdgeStyle(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
newElements.push_back(*element);
|
||||
} while (!(element++)->IsLastForTile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetTileElements(std::move(newElements));
|
||||
}
|
||||
|
||||
void ReorganiseTileElements()
|
||||
{
|
||||
ReorganiseTileElements(_tileElements.size());
|
||||
}
|
||||
|
||||
static bool map_check_free_elements_and_reorganise(size_t numElements)
|
||||
{
|
||||
auto freeElements = _tileElements.capacity() - _tileElements.size();
|
||||
if (freeElements >= numElements)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto newCapacity = std::min<size_t>(MAX_TILE_ELEMENTS, _tileElements.capacity() * 2);
|
||||
if (newCapacity - _tileElements.size() < numElements)
|
||||
{
|
||||
// Limit reached
|
||||
gGameCommandErrorText = STR_ERR_LANDSCAPE_DATA_AREA_FULL;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ReorganiseTileElements(newCapacity);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static size_t CountElementsOnTile(const CoordsXY& loc);
|
||||
|
||||
bool MapCheckCapacityAndReorganise(const CoordsXY& loc, size_t numElements)
|
||||
{
|
||||
auto numElementsOnTile = CountElementsOnTile(loc);
|
||||
return map_check_free_elements_and_reorganise(numElementsOnTile + numElements);
|
||||
}
|
||||
|
||||
static void clear_elements_at(const CoordsXY& loc);
|
||||
static ScreenCoordsXY translate_3d_to_2d(int32_t rotation, const CoordsXY& pos);
|
||||
|
||||
@@ -174,7 +286,7 @@ TileElement* map_get_first_element_at(const CoordsXY& elementPos)
|
||||
return nullptr;
|
||||
}
|
||||
auto tileElementPos = TileCoordsXY{ elementPos };
|
||||
return gTileElementTilePointers[tileElementPos.x + tileElementPos.y * MAXIMUM_MAP_SIZE_TECHNICAL];
|
||||
return _tileIndex.GetFirstElementAt(tileElementPos);
|
||||
}
|
||||
|
||||
TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n)
|
||||
@@ -211,7 +323,7 @@ void map_set_tile_element(const TileCoordsXY& tilePos, TileElement* elements)
|
||||
log_error("Trying to access element outside of range");
|
||||
return;
|
||||
}
|
||||
gTileElementTilePointers[tilePos.x + tilePos.y * MAXIMUM_MAP_SIZE_TECHNICAL] = elements;
|
||||
_tileIndex.SetTile(tilePos, elements);
|
||||
}
|
||||
|
||||
SurfaceElement* map_get_surface_element_at(const CoordsXY& coords)
|
||||
@@ -254,33 +366,34 @@ BannerElement* map_get_banner_element_at(const CoordsXYZ& bannerPos, uint8_t pos
|
||||
*/
|
||||
void map_init(int32_t size)
|
||||
{
|
||||
gNextFreeTileElementPointerIndex = 0;
|
||||
auto numTiles = MAXIMUM_MAP_SIZE_TECHNICAL * MAXIMUM_MAP_SIZE_TECHNICAL;
|
||||
|
||||
for (int32_t i = 0; i < MAX_TILE_TILE_ELEMENT_POINTERS; i++)
|
||||
std::vector<TileElement> tileElements;
|
||||
tileElements.resize(numTiles);
|
||||
for (int32_t i = 0; i < numTiles; i++)
|
||||
{
|
||||
TileElement* tile_element = &gTileElements[i];
|
||||
tile_element->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
tile_element->SetLastForTile(true);
|
||||
tile_element->base_height = 14;
|
||||
tile_element->clearance_height = 14;
|
||||
tile_element->AsSurface()->SetWaterHeight(0);
|
||||
tile_element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
|
||||
tile_element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
tile_element->AsSurface()->SetOwnership(OWNERSHIP_UNOWNED);
|
||||
tile_element->AsSurface()->SetParkFences(0);
|
||||
tile_element->AsSurface()->SetSurfaceStyle(0);
|
||||
tile_element->AsSurface()->SetEdgeStyle(0);
|
||||
auto* element = &tileElements[i];
|
||||
element->ClearAs(TILE_ELEMENT_TYPE_SURFACE);
|
||||
element->SetLastForTile(true);
|
||||
element->base_height = 14;
|
||||
element->clearance_height = 14;
|
||||
element->AsSurface()->SetWaterHeight(0);
|
||||
element->AsSurface()->SetSlope(TILE_ELEMENT_SLOPE_FLAT);
|
||||
element->AsSurface()->SetGrassLength(GRASS_LENGTH_CLEAR_0);
|
||||
element->AsSurface()->SetOwnership(OWNERSHIP_UNOWNED);
|
||||
element->AsSurface()->SetParkFences(0);
|
||||
element->AsSurface()->SetSurfaceStyle(0);
|
||||
element->AsSurface()->SetEdgeStyle(0);
|
||||
}
|
||||
SetTileElements(std::move(tileElements));
|
||||
|
||||
gGrassSceneryTileLoopPosition = 0;
|
||||
gWidePathTileLoopX = 0;
|
||||
gWidePathTileLoopY = 0;
|
||||
gWidePathTileLoopPosition = {};
|
||||
gMapSizeUnits = size * 32 - 32;
|
||||
gMapSizeMinus2 = size * 32 - 2;
|
||||
gMapSize = size;
|
||||
gMapSizeMaxXY = size * 32 - 33;
|
||||
gMapBaseZ = 7;
|
||||
map_update_tile_pointers();
|
||||
map_remove_out_of_range_elements();
|
||||
AutoCreateMapAnimations();
|
||||
|
||||
@@ -340,40 +453,12 @@ void map_count_remaining_land_rights()
|
||||
*/
|
||||
void map_strip_ghost_flag_from_elements()
|
||||
{
|
||||
for (auto& element : gTileElements)
|
||||
for (auto& element : _tileElements)
|
||||
{
|
||||
element.SetGhost(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0068AFFD
|
||||
*/
|
||||
void map_update_tile_pointers()
|
||||
{
|
||||
int32_t i, x, y;
|
||||
|
||||
for (i = 0; i < MAX_TILE_TILE_ELEMENT_POINTERS; i++)
|
||||
{
|
||||
gTileElementTilePointers[i] = TILE_UNDEFINED_TILE_ELEMENT;
|
||||
}
|
||||
|
||||
TileElement* tileElement = gTileElements;
|
||||
TileElement** tile = gTileElementTilePointers;
|
||||
for (y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
||||
{
|
||||
for (x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
||||
{
|
||||
*tile++ = tileElement;
|
||||
while (!(tileElement++)->IsLastForTile())
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
gNextFreeTileElement = tileElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the absolute height of an element, given its (x,y) coordinates
|
||||
*
|
||||
@@ -599,8 +684,8 @@ void map_update_path_wide_flags()
|
||||
// Presumably update_path_wide_flags is too computationally expensive to call for every
|
||||
// tile every update, so gWidePathTileLoopX and gWidePathTileLoopY store the x and y
|
||||
// progress. A maximum of 128 calls is done per update.
|
||||
uint16_t x = gWidePathTileLoopX;
|
||||
uint16_t y = gWidePathTileLoopY;
|
||||
auto x = gWidePathTileLoopPosition.x;
|
||||
auto y = gWidePathTileLoopPosition.y;
|
||||
for (int32_t i = 0; i < 128; i++)
|
||||
{
|
||||
footpath_update_path_wide_flags({ x, y });
|
||||
@@ -617,8 +702,8 @@ void map_update_path_wide_flags()
|
||||
}
|
||||
}
|
||||
}
|
||||
gWidePathTileLoopX = x;
|
||||
gWidePathTileLoopY = y;
|
||||
gWidePathTileLoopPosition.x = x;
|
||||
gWidePathTileLoopPosition.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -927,9 +1012,9 @@ void tile_element_remove(TileElement* tileElement)
|
||||
(tileElement - 1)->SetLastForTile(true);
|
||||
tileElement->base_height = MAX_ELEMENT_HEIGHT;
|
||||
|
||||
if ((tileElement + 1) == gNextFreeTileElement)
|
||||
if (tileElement == &_tileElements.back())
|
||||
{
|
||||
gNextFreeTileElement--;
|
||||
_tileElements.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1031,77 +1116,28 @@ void map_invalidate_selection_rect()
|
||||
viewports_invalidate(left, top, right, bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0068B111
|
||||
*/
|
||||
void map_reorganise_elements()
|
||||
static size_t CountElementsOnTile(const CoordsXY& loc)
|
||||
{
|
||||
context_setcurrentcursor(CursorID::ZZZ);
|
||||
|
||||
auto newTileElements = std::make_unique<TileElement[]>(MAX_TILE_ELEMENTS_WITH_SPARE_ROOM);
|
||||
TileElement* newElementsPtr = newTileElements.get();
|
||||
|
||||
if (newTileElements == nullptr)
|
||||
size_t count = 0;
|
||||
auto* element = _tileIndex.GetFirstElementAt(TileCoordsXY(loc));
|
||||
do
|
||||
{
|
||||
log_fatal("Unable to allocate memory for map elements.");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t y = 0; y < MAXIMUM_MAP_SIZE_TECHNICAL; y++)
|
||||
{
|
||||
for (int32_t x = 0; x < MAXIMUM_MAP_SIZE_TECHNICAL; x++)
|
||||
{
|
||||
TileElement* startElement = map_get_first_element_at(TileCoordsXY{ x, y }.ToCoordsXY());
|
||||
if (startElement == nullptr)
|
||||
continue;
|
||||
TileElement* endElement = startElement;
|
||||
while (!(endElement++)->IsLastForTile())
|
||||
;
|
||||
|
||||
const auto numElements = static_cast<uint32_t>(endElement - startElement);
|
||||
std::memcpy(newElementsPtr, startElement, numElements * sizeof(TileElement));
|
||||
newElementsPtr += numElements;
|
||||
}
|
||||
}
|
||||
|
||||
const auto numElements = static_cast<uint32_t>(newElementsPtr - newTileElements.get());
|
||||
std::memcpy(gTileElements, newTileElements.get(), numElements * sizeof(TileElement));
|
||||
std::memset(gTileElements + numElements, 0, (MAX_TILE_ELEMENTS_WITH_SPARE_ROOM - numElements) * sizeof(TileElement));
|
||||
|
||||
map_update_tile_pointers();
|
||||
count++;
|
||||
} while (!(element++)->IsLastForTile());
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* rct2: 0x0068B044
|
||||
* 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 numElements)
|
||||
static TileElement* AllocateTileElements(size_t count)
|
||||
{
|
||||
if (numElements != 0)
|
||||
if (!map_check_free_elements_and_reorganise(count))
|
||||
{
|
||||
auto tileElementEnd = &gTileElements[MAX_TILE_ELEMENTS];
|
||||
|
||||
// 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();
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
log_error("Cannot insert new element");
|
||||
return nullptr;
|
||||
}
|
||||
return true;
|
||||
|
||||
auto oldSize = _tileElements.size();
|
||||
_tileElements.resize(_tileElements.size() + count);
|
||||
return &_tileElements[oldSize];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1111,21 +1147,20 @@ bool map_check_free_elements_and_reorganise(int32_t numElements)
|
||||
TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementType type)
|
||||
{
|
||||
const auto& tileLoc = TileCoordsXYZ(loc);
|
||||
TileElement *originalTileElement, *newTileElement, *insertedElement;
|
||||
bool isLastForTile = false;
|
||||
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
auto numElementsOnTileOld = CountElementsOnTile(loc);
|
||||
auto numElementsOnTileNew = numElementsOnTileOld + 1;
|
||||
auto* newTileElement = AllocateTileElements(numElementsOnTileNew);
|
||||
auto* originalTileElement = _tileIndex.GetFirstElementAt(tileLoc);
|
||||
if (newTileElement == nullptr)
|
||||
{
|
||||
log_error("Cannot insert new element");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
newTileElement = gNextFreeTileElement;
|
||||
originalTileElement = gTileElementTilePointers[tileLoc.y * MAXIMUM_MAP_SIZE_TECHNICAL + tileLoc.x];
|
||||
|
||||
// Set tile index pointer to point to new element block
|
||||
gTileElementTilePointers[tileLoc.y * MAXIMUM_MAP_SIZE_TECHNICAL + tileLoc.x] = newTileElement;
|
||||
_tileIndex.SetTile(tileLoc, newTileElement);
|
||||
|
||||
bool isLastForTile = false;
|
||||
if (originalTileElement == nullptr)
|
||||
{
|
||||
isLastForTile = true;
|
||||
@@ -1152,7 +1187,7 @@ TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants
|
||||
}
|
||||
|
||||
// Insert new map element
|
||||
insertedElement = newTileElement;
|
||||
auto* insertedElement = newTileElement;
|
||||
newTileElement->type = 0;
|
||||
newTileElement->SetType(static_cast<uint8_t>(type));
|
||||
newTileElement->SetBaseZ(loc.z);
|
||||
@@ -1178,7 +1213,6 @@ TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants
|
||||
} while (!((newTileElement - 1)->IsLastForTile()));
|
||||
}
|
||||
|
||||
gNextFreeTileElement = newTileElement;
|
||||
return insertedElement;
|
||||
}
|
||||
|
||||
@@ -1484,7 +1518,7 @@ void map_update_tiles()
|
||||
if (gScreenFlags & ignoreScreenFlags)
|
||||
return;
|
||||
|
||||
// Update 43 more tiles
|
||||
// Update 43 more tiles (for each 256x256 block)
|
||||
for (int32_t j = 0; j < 43; j++)
|
||||
{
|
||||
int32_t x = 0;
|
||||
@@ -1499,12 +1533,19 @@ void map_update_tiles()
|
||||
interleaved_xy >>= 1;
|
||||
}
|
||||
|
||||
auto mapPos = TileCoordsXY{ x, y }.ToCoordsXY();
|
||||
auto* surfaceElement = map_get_surface_element_at(mapPos);
|
||||
if (surfaceElement != nullptr)
|
||||
// Repeat for each 256x256 block on the map
|
||||
for (int32_t blockY = 0; blockY < gMapSize; blockY += 256)
|
||||
{
|
||||
surfaceElement->UpdateGrassLength(mapPos);
|
||||
scenery_update_tile(mapPos);
|
||||
for (int32_t blockX = 0; blockX < gMapSize; blockX += 256)
|
||||
{
|
||||
auto mapPos = TileCoordsXY{ blockX + x, blockY + y }.ToCoordsXY();
|
||||
auto* surfaceElement = map_get_surface_element_at(mapPos);
|
||||
if (surfaceElement != nullptr)
|
||||
{
|
||||
surfaceElement->UpdateGrassLength(mapPos);
|
||||
scenery_update_tile(mapPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gGrassSceneryTileLoopPosition++;
|
||||
|
||||
+16
-12
@@ -98,8 +98,7 @@ enum
|
||||
extern const std::array<CoordsXY, 8> CoordsDirectionDelta;
|
||||
extern const TileCoordsXY TileDirectionDelta[];
|
||||
|
||||
extern uint16_t gWidePathTileLoopX;
|
||||
extern uint16_t gWidePathTileLoopY;
|
||||
extern TileCoordsXY gWidePathTileLoopPosition;
|
||||
extern uint16_t gGrassSceneryTileLoopPosition;
|
||||
|
||||
extern int16_t gMapSizeUnits;
|
||||
@@ -117,15 +116,9 @@ extern uint8_t gMapSelectArrowDirection;
|
||||
|
||||
extern uint8_t gMapGroundFlags;
|
||||
|
||||
extern TileElement gTileElements[MAX_TILE_ELEMENTS_WITH_SPARE_ROOM];
|
||||
extern TileElement* gTileElementTilePointers[MAX_TILE_TILE_ELEMENT_POINTERS];
|
||||
|
||||
extern std::vector<CoordsXY> gMapSelectionTiles;
|
||||
extern std::vector<PeepSpawn> gPeepSpawns;
|
||||
|
||||
extern TileElement* gNextFreeTileElement;
|
||||
extern uint32_t gNextFreeTileElementPointerIndex;
|
||||
|
||||
// Used in the land tool window to enable mountain tool / land smoothing
|
||||
extern bool gLandMountainMode;
|
||||
// Used in the land tool window to allow dragging and changing land styles
|
||||
@@ -147,9 +140,11 @@ extern const uint8_t tile_element_raise_styles[9][32];
|
||||
template<typename T> class TilePointerIndex
|
||||
{
|
||||
std::vector<T*> TilePointers;
|
||||
uint16_t MapSize;
|
||||
uint16_t MapSize{};
|
||||
|
||||
public:
|
||||
TilePointerIndex() = default;
|
||||
|
||||
explicit TilePointerIndex(const uint16_t mapSize, T* tileElements)
|
||||
{
|
||||
MapSize = mapSize;
|
||||
@@ -172,13 +167,23 @@ public:
|
||||
{
|
||||
return TilePointers[coords.x + (coords.y * MapSize)];
|
||||
}
|
||||
|
||||
void SetTile(TileCoordsXY coords, T* tileElement)
|
||||
{
|
||||
TilePointers[coords.x + (coords.y * MapSize)] = tileElement;
|
||||
}
|
||||
};
|
||||
|
||||
void ReorganiseTileElements();
|
||||
const std::vector<TileElement>& GetTileElements();
|
||||
void SetTileElements(std::vector<TileElement>&& tileElements);
|
||||
void StashMap();
|
||||
void UnstashMap();
|
||||
|
||||
void map_init(int32_t size);
|
||||
|
||||
void map_count_remaining_land_rights();
|
||||
void map_strip_ghost_flag_from_elements();
|
||||
void map_update_tile_pointers();
|
||||
TileElement* map_get_first_element_at(const CoordsXY& elementPos);
|
||||
TileElement* map_get_nth_element_at(const CoordsXY& coords, int32_t n);
|
||||
void map_set_tile_element(const TileCoordsXY& tilePos, TileElement* elements);
|
||||
@@ -211,8 +216,7 @@ void tile_element_remove(TileElement* tileElement);
|
||||
void map_remove_all_rides();
|
||||
void map_invalidate_map_selection_tiles();
|
||||
void map_invalidate_selection_rect();
|
||||
void map_reorganise_elements();
|
||||
bool map_check_free_elements_and_reorganise(int32_t num_elements);
|
||||
bool MapCheckCapacityAndReorganise(const CoordsXY& loc, size_t numElements = 1);
|
||||
TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementType type);
|
||||
|
||||
template<typename T> T* TileElementInsert(const CoordsXYZ& loc, int32_t occupiedQuadrants)
|
||||
|
||||
@@ -231,8 +231,6 @@ void mapgen_generate(mapgen_settings* settings)
|
||||
// Place the trees
|
||||
if (settings->trees != 0)
|
||||
mapgen_place_trees();
|
||||
|
||||
map_reorganise_elements();
|
||||
}
|
||||
|
||||
static void mapgen_place_tree(int32_t type, const CoordsXY& loc)
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace OpenRCT2::TileInspector
|
||||
GameActionResultPtr InsertCorruptElementAt(const CoordsXY& loc, int16_t elementIndex, bool isExecuting)
|
||||
{
|
||||
// Make sure there is enough space for the new element
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!!MapCheckCapacityAndReorganise(loc))
|
||||
return std::make_unique<GameActions::Result>(GameActions::Status::NoFreeElements, STR_NONE);
|
||||
|
||||
if (isExecuting)
|
||||
@@ -359,7 +359,7 @@ namespace OpenRCT2::TileInspector
|
||||
GameActionResultPtr PasteElementAt(const CoordsXY& loc, TileElement element, bool isExecuting)
|
||||
{
|
||||
// Make sure there is enough space for the new element
|
||||
if (!map_check_free_elements_and_reorganise(1))
|
||||
if (!!MapCheckCapacityAndReorganise(loc))
|
||||
{
|
||||
return std::make_unique<GameActions::Result>(GameActions::Status::NoFreeElements, STR_NONE);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,6 @@ static std::unique_ptr<IContext> localStartGame(const std::string& parkPath)
|
||||
reset_all_sprite_quadrant_placements();
|
||||
scenery_set_default_placement_configuration();
|
||||
load_palette();
|
||||
map_reorganise_elements();
|
||||
EntityTweener::Get().Reset();
|
||||
AutoCreateMapAnimations();
|
||||
fix_invalid_vehicle_sprite_sizes();
|
||||
|
||||
@@ -75,7 +75,6 @@ static void GameInit(bool retainSpatialIndices)
|
||||
reset_all_sprite_quadrant_placements();
|
||||
scenery_set_default_placement_configuration();
|
||||
load_palette();
|
||||
map_reorganise_elements();
|
||||
EntityTweener::Get().Reset();
|
||||
AutoCreateMapAnimations();
|
||||
fix_invalid_vehicle_sprite_sizes();
|
||||
|
||||
Reference in new issue
Block a user