From a38154a0f3ed710e4869cc852c11db2adf5b0934 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 8 Apr 2021 21:05:34 +0100 Subject: [PATCH] Update map tile loop to support large maps --- src/openrct2/ParkFile.cpp | 5 ++--- src/openrct2/rct2/S6Importer.cpp | 4 ++-- src/openrct2/world/Map.cpp | 33 ++++++++++++++++++-------------- src/openrct2/world/Map.h | 3 +-- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/openrct2/ParkFile.cpp b/src/openrct2/ParkFile.cpp index 06cfc13dc7..a79112950c 100644 --- a/src/openrct2/ParkFile.cpp +++ b/src/openrct2/ParkFile.cpp @@ -380,9 +380,8 @@ namespace OpenRCT2 cs.ReadWrite(gLandPrice); cs.ReadWrite(gConstructionRightsPrice); - cs.ReadWrite(gGrassSceneryTileLoopPosition); // TODO (this needs to be xy32) - cs.ReadWrite(gWidePathTileLoopX); - cs.ReadWrite(gWidePathTileLoopY); + cs.ReadWrite(gGrassSceneryTileLoopPosition); + cs.ReadWrite(gWidePathTileLoopPosition); ReadWriteRideRatingCalculationData(cs, gRideRatingsCalcData); }); diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 814cbbc883..b010a499bf 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -447,8 +447,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 diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index c11694c9c3..4e67d9b352 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -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; } /** @@ -1485,7 +1483,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; @@ -1500,12 +1498,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++; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index ca0a47afc8..ef72403de3 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -98,8 +98,7 @@ enum extern const std::array CoordsDirectionDelta; extern const TileCoordsXY TileDirectionDelta[]; -extern uint16_t gWidePathTileLoopX; -extern uint16_t gWidePathTileLoopY; +extern TileCoordsXY gWidePathTileLoopPosition; extern uint16_t gGrassSceneryTileLoopPosition; extern int16_t gMapSizeUnits;