Update map tile loop to support large maps.

This commit is contained in:
Ted John 2021-04-08 21:05:34 +01:00 committed by duncanspumpkin
parent c87860b3d3
commit 051a09d2b7
3 changed files with 22 additions and 18 deletions

View File

@ -459,8 +459,8 @@ 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

View File

@ -90,8 +90,7 @@ uint8_t gMapSelectArrowDirection;
uint8_t gMapGroundFlags;
uint16_t gWidePathTileLoopX;
uint16_t gWidePathTileLoopY;
TileCoordsXY gWidePathTileLoopPosition;
uint16_t gGrassSceneryTileLoopPosition;
int16_t gMapSizeUnits;
@ -273,8 +272,7 @@ void map_init(int32_t size)
}
gGrassSceneryTileLoopPosition = 0;
gWidePathTileLoopX = 0;
gWidePathTileLoopY = 0;
gWidePathTileLoopPosition = {};
gMapSizeUnits = size * 32 - 32;
gMapSizeMinus2 = size * 32 - 2;
gMapSize = size;
@ -599,8 +597,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 +615,8 @@ void map_update_path_wide_flags()
}
}
}
gWidePathTileLoopX = x;
gWidePathTileLoopY = y;
gWidePathTileLoopPosition.x = x;
gWidePathTileLoopPosition.y = y;
}
/**
@ -1484,7 +1482,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 +1497,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++;

View File

@ -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;