From 9436a9501e7a0b61660861a3e321eb4f8a3e144c Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 29 Oct 2024 11:08:39 +0100 Subject: [PATCH 1/5] Move bitScanForward from Util.h to Numerics.hpp --- src/openrct2-ui/interface/ViewportQuery.cpp | 5 +- .../windows/EditorObjectSelection.cpp | 2 +- src/openrct2-ui/windows/ScenarioSelect.cpp | 2 +- src/openrct2-ui/windows/Staff.cpp | 2 +- src/openrct2/actions/TrackPlaceAction.cpp | 4 +- src/openrct2/core/Numerics.hpp | 48 +++++++++++++++++++ src/openrct2/entity/Guest.cpp | 6 +-- src/openrct2/entity/Staff.cpp | 4 +- src/openrct2/object/RideObject.cpp | 3 +- src/openrct2/peep/GuestPathfinding.cpp | 14 +++--- src/openrct2/ride/Ride.cpp | 4 +- src/openrct2/ride/TrackDesign.cpp | 3 +- src/openrct2/util/Util.h | 48 ------------------- src/openrct2/world/Footpath.cpp | 2 +- 14 files changed, 75 insertions(+), 72 deletions(-) diff --git a/src/openrct2-ui/interface/ViewportQuery.cpp b/src/openrct2-ui/interface/ViewportQuery.cpp index a143d67fc5..679b569c85 100644 --- a/src/openrct2-ui/interface/ViewportQuery.cpp +++ b/src/openrct2-ui/interface/ViewportQuery.cpp @@ -12,6 +12,7 @@ #include "Window.h" #include +#include #include #include #include @@ -150,7 +151,7 @@ namespace OpenRCT2::Ui uint32_t directions = (*tileElement)->AsEntrance()->GetDirections(); if (directions & 0x0F) { - int32_t bx = UtilBitScanForward(directions); + int32_t bx = Numerics::bitScanForward(directions); bx += (*tileElement)->AsEntrance()->GetDirection(); bx &= 3; if (direction != nullptr) @@ -167,7 +168,7 @@ namespace OpenRCT2::Ui uint32_t directions = (*tileElement)->AsEntrance()->GetDirections(); if (directions & 0x0F) { - int32_t bx = (*tileElement)->GetDirectionWithOffset(UtilBitScanForward(directions)); + int32_t bx = (*tileElement)->GetDirectionWithOffset(Numerics::bitScanForward(directions)); if (direction != nullptr) *direction = bx; return info.Loc; diff --git a/src/openrct2-ui/windows/EditorObjectSelection.cpp b/src/openrct2-ui/windows/EditorObjectSelection.cpp index fea0a1c252..05875a95af 100644 --- a/src/openrct2-ui/windows/EditorObjectSelection.cpp +++ b/src/openrct2-ui/windows/EditorObjectSelection.cpp @@ -890,7 +890,7 @@ namespace OpenRCT2::Ui::Windows if (numSourcesActive == 1) { widgets[WIDX_FILTER_DROPDOWN].text = STR_OBJECT_SELECTION_ONLY_STRINGID; - auto firstActiveSource = UtilBitScanForward(sources); + auto firstActiveSource = Numerics::bitScanForward(sources); ft.Add(kSourceStringIds[firstActiveSource]); } else diff --git a/src/openrct2-ui/windows/ScenarioSelect.cpp b/src/openrct2-ui/windows/ScenarioSelect.cpp index bdfda4915f..8c4ab4d378 100644 --- a/src/openrct2-ui/windows/ScenarioSelect.cpp +++ b/src/openrct2-ui/windows/ScenarioSelect.cpp @@ -717,7 +717,7 @@ namespace OpenRCT2::Ui::Windows } else { - int32_t firstPage = UtilBitScanForward(showPages); + int32_t firstPage = Numerics::bitScanForward(showPages); if (firstPage != -1) { selected_tab = firstPage; diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 469c99b369..62ea364b92 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -883,7 +883,7 @@ namespace OpenRCT2::Ui::Windows } uint32_t staffOrders = staff->StaffOrders; - for (auto index = UtilBitScanForward(staffOrders); index != -1; index = UtilBitScanForward(staffOrders)) + for (auto index = Numerics::bitScanForward(staffOrders); index != -1; index = Numerics::bitScanForward(staffOrders)) { staffOrders &= ~(1 << index); SetCheckboxValue(WIDX_CHECKBOX_1 + index, true); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 4fcc2e39c6..500b21416d 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -640,8 +640,8 @@ GameActions::Result TrackPlaceAction::Execute() const { if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && !gameState.Cheats.DisableClearanceChecks) { - for (int32_t chosenDirection = UtilBitScanForward(availableDirections); chosenDirection != -1; - chosenDirection = UtilBitScanForward(availableDirections)) + for (int32_t chosenDirection = Numerics::bitScanForward(availableDirections); chosenDirection != -1; + chosenDirection = Numerics::bitScanForward(availableDirections)) { availableDirections &= ~(1 << chosenDirection); CoordsXY tempLoc{ mapLoc.x, mapLoc.y }; diff --git a/src/openrct2/core/Numerics.hpp b/src/openrct2/core/Numerics.hpp index 87e523f81a..2a770a56d1 100644 --- a/src/openrct2/core/Numerics.hpp +++ b/src/openrct2/core/Numerics.hpp @@ -14,8 +14,56 @@ #include #include +#ifdef _MSC_VER +# include +#endif + namespace OpenRCT2::Numerics { + inline int32_t bitScanForward(uint32_t source) + { +#if defined(_MSC_VER) && (_MSC_VER >= 1400) // Visual Studio 2005 + unsigned long i; + uint8_t success = _BitScanForward(&i, source); + return success != 0 ? i : -1; +#elif defined(__GNUC__) + int32_t success = __builtin_ffs(source); + return success - 1; +#else +# pragma message("Falling back to iterative bitscan forward, consider using intrinsics") + // This is a low-hanging optimisation boost, check if your compiler offers + // any intrinsic. + // cf. https://github.com/OpenRCT2/OpenRCT2/pull/2093 + for (int32_t i = 0; i < 32; i++) + if (source & (1u << i)) + return i; + + return -1; +#endif + } + + inline int64_t bitScanForward(uint64_t source) + { +#if defined(_MSC_VER) && (_MSC_VER >= 1400) && defined(_M_X64) // Visual Studio 2005 + unsigned long i; + uint8_t success = _BitScanForward64(&i, source); + return success != 0 ? i : -1; +#elif defined(__GNUC__) + int32_t success = __builtin_ffsll(source); + return success - 1; +#else +# pragma message("Falling back to iterative bitscan forward, consider using intrinsics") + // This is a low-hanging optimisation boost, check if your compiler offers + // any intrinsic. + // cf. https://github.com/OpenRCT2/OpenRCT2/pull/2093 + for (int32_t i = 0; i < 64; i++) + if (source & (1uLL << i)) + return i; + + return -1; +#endif + } + /** * Bitwise left rotate * @tparam _UIntType unsigned integral type diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 060601edb3..8950d68c9c 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -820,7 +820,7 @@ void Guest::UpdateConsumptionMotives() if (TimeToConsume == 0) { - int32_t chosen_food = UtilBitScanForward(GetFoodOrDrinkFlags()); + int32_t chosen_food = Numerics::bitScanForward(GetFoodOrDrinkFlags()); if (chosen_food != -1) { ShopItem food = ShopItem(chosen_food); @@ -1513,7 +1513,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price) const auto& shopItemDescriptor = GetShopItemDescriptor(shopItem); if (shopItemDescriptor.IsFoodOrDrink()) { - int32_t food = UtilBitScanForward(GetFoodOrDrinkFlags()); + int32_t food = Numerics::bitScanForward(GetFoodOrDrinkFlags()); if (food != -1) { InsertNewThought(PeepThoughtType::HaventFinished, static_cast(food)); @@ -5371,7 +5371,7 @@ void Guest::UpdateWalking() if ((!GetNextIsSurface()) && (static_cast(Id.ToUnderlying() & 0x1FF) == (currentTicks & 0x1FF)) && ((0xFFFF & ScenarioRand()) <= 4096)) { - int32_t container = UtilBitScanForward(GetEmptyContainerFlags()); + int32_t container = Numerics::bitScanForward(GetEmptyContainerFlags()); auto litterType = Litter::Type::Vomit; if (container != -1) diff --git a/src/openrct2/entity/Staff.cpp b/src/openrct2/entity/Staff.cpp index a496d9add6..5e5a6f82fb 100644 --- a/src/openrct2/entity/Staff.cpp +++ b/src/openrct2/entity/Staff.cpp @@ -683,7 +683,7 @@ Direction Staff::MechanicDirectionPath(uint8_t validDirections, PathElement* pat pathDirections |= (1 << DirectionReverse(PeepDirection)); } - Direction direction = UtilBitScanForward(pathDirections); + Direction direction = Numerics::bitScanForward(pathDirections); pathDirections &= ~(1 << direction); if (pathDirections == 0) { @@ -801,7 +801,7 @@ Direction Staff::DirectionPath(uint8_t validDirections, PathElement* pathElement pathDirections |= (1u << DirectionReverse(PeepDirection)); } - Direction direction = UtilBitScanForward(pathDirections); + Direction direction = Numerics::bitScanForward(pathDirections); // If this is the only direction they can go, then go if (pathDirections == (1u << direction)) { diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 5a96645fd8..11b734f86a 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -17,6 +17,7 @@ #include "../core/IStream.hpp" #include "../core/Json.hpp" #include "../core/Memory.hpp" +#include "../core/Numerics.hpp" #include "../core/String.hpp" #include "../drawing/Drawing.h" #include "../entity/Yaw.hpp" @@ -112,7 +113,7 @@ static constexpr SpritePrecision PrecisionFromNumFrames(uint32_t numRotationFram if (numRotationFrames == 0) return SpritePrecision::None; else - return static_cast(UtilBitScanForward(numRotationFrames) + 1); + return static_cast(Numerics::bitScanForward(numRotationFrames) + 1); } static void RideObjectUpdateRideType(RideObjectEntry& rideEntry) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 3bcbb584ca..be3b10f1de 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -602,7 +602,7 @@ namespace OpenRCT2::PathFinding uint32_t edges = path->GetEdges(); - int32_t testEdge = UtilBitScanForward(edges); + int32_t testEdge = Numerics::bitScanForward(edges); if (testEdge == -1) return false; @@ -627,7 +627,7 @@ namespace OpenRCT2::PathFinding break; } edges &= ~(1 << testEdge); - } while ((testEdge = UtilBitScanForward(edges)) != -1); + } while ((testEdge = Numerics::bitScanForward(edges)) != -1); return isThinJunction; } @@ -1008,7 +1008,7 @@ namespace OpenRCT2::PathFinding /* Remove the reverse edge (i.e. the edge back to the previous map element.) */ edges &= ~(1 << DirectionReverse(testEdge)); - int32_t nextTestEdge = UtilBitScanForward(edges); + int32_t nextTestEdge = Numerics::bitScanForward(edges); /* If there are no other edges the current search ends here. * Continue to the next map element without updating the parameters (best result so far). */ @@ -1205,7 +1205,7 @@ namespace OpenRCT2::PathFinding LogPathfinding( &peep, "Returned to %d,%d,%d; Steps: %u; edge: %d; Score: %d", loc.x >> 5, loc.y >> 5, loc.z, numSteps, nextTestEdge, *endScore); - } while ((nextTestEdge = UtilBitScanForward(edges)) != -1); + } while ((nextTestEdge = Numerics::bitScanForward(edges)) != -1); } while (!(tileElement++)->IsLastForTile()); @@ -1377,7 +1377,7 @@ namespace OpenRCT2::PathFinding if (edges == 0) return INVALID_DIRECTION; - int32_t chosenEdge = UtilBitScanForward(edges); + int32_t chosenEdge = Numerics::bitScanForward(edges); // Peep has multiple edges still to try. if (edges & ~(1 << chosenEdge)) @@ -1398,7 +1398,7 @@ namespace OpenRCT2::PathFinding * or for different edges with equal value, the edge with the * least steps (best_sub). */ int32_t numEdges = std::popcount(edges); - for (int32_t testEdge = chosenEdge; testEdge != -1; testEdge = UtilBitScanForward(edges)) + for (int32_t testEdge = chosenEdge; testEdge != -1; testEdge = Numerics::bitScanForward(edges)) { edges &= ~(1 << testEdge); uint8_t height = loc.z; @@ -1945,7 +1945,7 @@ namespace OpenRCT2::PathFinding edges &= ~(1 << direction); } - direction = UtilBitScanForward(edges); + direction = Numerics::bitScanForward(edges); // IF only one edge to choose from if ((edges & ~(1 << direction)) == 0) { diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 2099f08551..9262504fb2 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1481,7 +1481,7 @@ static int32_t RideGetNewBreakdownProblem(const Ride& ride) int32_t breakdownProblem; while (problemBits != 0) { - breakdownProblem = UtilBitScanForward(problemBits); + breakdownProblem = Numerics::bitScanForward(problemBits); problemBits &= ~(1 << breakdownProblem); totalProbability += _breakdownProblemProbabilities[breakdownProblem]; } @@ -1495,7 +1495,7 @@ static int32_t RideGetNewBreakdownProblem(const Ride& ride) problemBits = availableBreakdownProblems; do { - breakdownProblem = UtilBitScanForward(problemBits); + breakdownProblem = Numerics::bitScanForward(problemBits); problemBits &= ~(1 << breakdownProblem); randomProbability -= _breakdownProblemProbabilities[breakdownProblem]; } while (randomProbability >= 0); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 29f0832e5a..677965d7ff 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -888,7 +888,8 @@ static void TrackDesignMirrorMaze(TrackDesign& td) uint32_t mazeEntry = maze.mazeEntry; uint16_t newEntry = 0; - for (uint8_t position = UtilBitScanForward(mazeEntry); position != 0xFF; position = UtilBitScanForward(mazeEntry)) + for (uint8_t position = Numerics::bitScanForward(mazeEntry); position != 0xFF; + position = Numerics::bitScanForward(mazeEntry)) { mazeEntry &= ~(1 << position); newEntry |= (1 << maze_segment_mirror_map[position]); diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index c7db420d9a..3db5be95c2 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -19,10 +19,6 @@ #include #include -#ifdef _MSC_VER -# include -#endif - int32_t SquaredMetresToSquaredFeet(int32_t squaredMetres); int32_t MetresToFeet(int32_t metres); int32_t FeetToMetres(int32_t feet); @@ -35,50 +31,6 @@ int32_t ToHumanReadableSpeed(int32_t baseSpeed); uint16_t ToHumanReadableAirTime(uint16_t airTime); int32_t ToHumanReadableRideLength(int32_t rideLength); -inline int32_t UtilBitScanForward(uint32_t source) -{ -#if defined(_MSC_VER) && (_MSC_VER >= 1400) // Visual Studio 2005 - unsigned long i; - uint8_t success = _BitScanForward(&i, source); - return success != 0 ? i : -1; -#elif defined(__GNUC__) - int32_t success = __builtin_ffs(source); - return success - 1; -#else -# pragma message("Falling back to iterative bitscan forward, consider using intrinsics") - // This is a low-hanging optimisation boost, check if your compiler offers - // any intrinsic. - // cf. https://github.com/OpenRCT2/OpenRCT2/pull/2093 - for (int32_t i = 0; i < 32; i++) - if (source & (1u << i)) - return i; - - return -1; -#endif -} - -inline int32_t UtilBitScanForward(uint64_t source) -{ -#if defined(_MSC_VER) && (_MSC_VER >= 1400) && defined(_M_X64) // Visual Studio 2005 - unsigned long i; - uint8_t success = _BitScanForward64(&i, source); - return success != 0 ? i : -1; -#elif defined(__GNUC__) - int32_t success = __builtin_ffsll(source); - return success - 1; -#else -# pragma message("Falling back to iterative bitscan forward, consider using intrinsics") - // This is a low-hanging optimisation boost, check if your compiler offers - // any intrinsic. - // cf. https://github.com/OpenRCT2/OpenRCT2/pull/2093 - for (int32_t i = 0; i < 64; i++) - if (source & (1uLL << i)) - return i; - - return -1; -#endif -} - int32_t StrLogicalCmp(char const* a, char const* b); char* SafeStrCpy(char* destination, const char* source, size_t num); char* SafeStrCat(char* destination, const char* source, size_t size); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index aca0df9433..cff8649020 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1020,7 +1020,7 @@ static void FootpathFixOwnership(const CoordsXY& mapPos) static bool GetNextDirection(uint32_t edges, int32_t* direction) { - int32_t index = UtilBitScanForward(edges); + int32_t index = Numerics::bitScanForward(edges); if (index == -1) return false; From 4e27bac292ddff428d946a43044bb6768ccf9336 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 29 Oct 2024 11:16:26 +0100 Subject: [PATCH 2/5] Move Compression from Util into its own compilation unit --- src/openrct2/core/Compression.cpp | 176 ++++++++++++++++++++++++++++++ src/openrct2/core/Compression.h | 21 ++++ src/openrct2/core/OrcaStream.hpp | 7 +- src/openrct2/libopenrct2.vcxproj | 2 + src/openrct2/platform/Crash.cpp | 3 +- src/openrct2/util/Util.cpp | 157 -------------------------- src/openrct2/util/Util.h | 4 - 7 files changed, 205 insertions(+), 165 deletions(-) create mode 100644 src/openrct2/core/Compression.cpp create mode 100644 src/openrct2/core/Compression.h diff --git a/src/openrct2/core/Compression.cpp b/src/openrct2/core/Compression.cpp new file mode 100644 index 0000000000..23c5885a3e --- /dev/null +++ b/src/openrct2/core/Compression.cpp @@ -0,0 +1,176 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "Compression.h" + +#include "../Diagnostic.h" +#include "zlib.h" + +#include +#include +#include + +namespace OpenRCT2::Compression +{ + constexpr size_t CHUNK = 128 * 1024; + + // Compress the source to gzip-compatible stream, write to dest. + // Mainly used for compressing the crashdumps + bool gzipCompress(FILE* source, FILE* dest) + { + if (source == nullptr || dest == nullptr) + { + return false; + } + int ret, flush; + size_t have; + z_stream strm{}; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + unsigned char in[CHUNK]; + unsigned char out[CHUNK]; + int windowBits = 15; + int GZIP_ENCODING = 16; + ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, windowBits | GZIP_ENCODING, 8, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) + { + LOG_ERROR("Failed to initialise stream"); + return false; + } + do + { + strm.avail_in = uInt(fread(in, 1, CHUNK, source)); + if (ferror(source)) + { + deflateEnd(&strm); + LOG_ERROR("Failed to read data from source"); + return false; + } + flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; + strm.next_in = in; + do + { + strm.avail_out = CHUNK; + strm.next_out = out; + ret = deflate(&strm, flush); + if (ret == Z_STREAM_ERROR) + { + LOG_ERROR("Failed to compress data"); + return false; + } + have = CHUNK - strm.avail_out; + if (fwrite(out, 1, have, dest) != have || ferror(dest)) + { + deflateEnd(&strm); + LOG_ERROR("Failed to write data to destination"); + return false; + } + } while (strm.avail_out == 0); + } while (flush != Z_FINISH); + deflateEnd(&strm); + return true; + } + + std::vector gzip(const void* data, const size_t dataLen) + { + assert(data != nullptr); + + std::vector output; + z_stream strm{}; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + + { + const auto ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | 16, 8, Z_DEFAULT_STRATEGY); + if (ret != Z_OK) + { + throw std::runtime_error("deflateInit2 failed with error " + std::to_string(ret)); + } + } + + int flush = 0; + const auto* src = static_cast(data); + size_t srcRemaining = dataLen; + do + { + const auto nextBlockSize = std::min(srcRemaining, CHUNK); + srcRemaining -= nextBlockSize; + + flush = srcRemaining == 0 ? Z_FINISH : Z_NO_FLUSH; + strm.avail_in = static_cast(nextBlockSize); + strm.next_in = const_cast(src); + do + { + output.resize(output.size() + nextBlockSize); + strm.avail_out = static_cast(nextBlockSize); + strm.next_out = &output[output.size() - nextBlockSize]; + const auto ret = deflate(&strm, flush); + if (ret == Z_STREAM_ERROR) + { + throw std::runtime_error("deflate failed with error " + std::to_string(ret)); + } + output.resize(output.size() - strm.avail_out); + } while (strm.avail_out == 0); + + src += nextBlockSize; + } while (flush != Z_FINISH); + deflateEnd(&strm); + return output; + } + + std::vector ungzip(const void* data, const size_t dataLen) + { + assert(data != nullptr); + + std::vector output; + z_stream strm{}; + strm.zalloc = Z_NULL; + strm.zfree = Z_NULL; + strm.opaque = Z_NULL; + + { + const auto ret = inflateInit2(&strm, 15 | 16); + if (ret != Z_OK) + { + throw std::runtime_error("inflateInit2 failed with error " + std::to_string(ret)); + } + } + + int flush = 0; + const auto* src = static_cast(data); + size_t srcRemaining = dataLen; + do + { + const auto nextBlockSize = std::min(srcRemaining, CHUNK); + srcRemaining -= nextBlockSize; + + flush = srcRemaining == 0 ? Z_FINISH : Z_NO_FLUSH; + strm.avail_in = static_cast(nextBlockSize); + strm.next_in = const_cast(src); + do + { + output.resize(output.size() + nextBlockSize); + strm.avail_out = static_cast(nextBlockSize); + strm.next_out = &output[output.size() - nextBlockSize]; + const auto ret = inflate(&strm, flush); + if (ret == Z_STREAM_ERROR) + { + throw std::runtime_error("deflate failed with error " + std::to_string(ret)); + } + output.resize(output.size() - strm.avail_out); + } while (strm.avail_out == 0); + + src += nextBlockSize; + } while (flush != Z_FINISH); + inflateEnd(&strm); + return output; + } +} // namespace OpenRCT2::Compression diff --git a/src/openrct2/core/Compression.h b/src/openrct2/core/Compression.h new file mode 100644 index 0000000000..999d05db9b --- /dev/null +++ b/src/openrct2/core/Compression.h @@ -0,0 +1,21 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include +#include +#include + +namespace OpenRCT2::Compression +{ + bool gzipCompress(FILE* source, FILE* dest); + std::vector gzip(const void* data, const size_t dataLen); + std::vector ungzip(const void* data, const size_t dataLen); +} // namespace OpenRCT2::Compression diff --git a/src/openrct2/core/OrcaStream.hpp b/src/openrct2/core/OrcaStream.hpp index 3a54b81039..257c8952a5 100644 --- a/src/openrct2/core/OrcaStream.hpp +++ b/src/openrct2/core/OrcaStream.hpp @@ -9,7 +9,7 @@ #pragma once -#include "../util/Util.h" +#include "../core/Compression.h" #include "../world/Location.hpp" #include "Crypt.h" #include "FileStream.h" @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,7 @@ namespace OpenRCT2 // Uncompress if (_header.Compression == COMPRESSION_GZIP) { - auto uncompressedData = Ungzip(_buffer.GetData(), _buffer.GetLength()); + auto uncompressedData = Compression::ungzip(_buffer.GetData(), _buffer.GetLength()); if (_header.UncompressedSize != uncompressedData.size()) { // Warning? @@ -135,7 +136,7 @@ namespace OpenRCT2 std::optional> compressedBytes; if (_header.Compression == COMPRESSION_GZIP) { - compressedBytes = Gzip(uncompressedData, uncompressedSize); + compressedBytes = Compression::gzip(uncompressedData, uncompressedSize); if (compressedBytes) { _header.CompressedSize = compressedBytes->size(); diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 74ea55ec6e..c1268858a1 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -186,6 +186,7 @@ + @@ -745,6 +746,7 @@ + diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index f5a0add067..6fb17cbdde 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -31,6 +31,7 @@ # include "../PlatformEnvironment.h" # include "../Version.h" # include "../config/Config.h" +# include "../core/Compression.h" # include "../core/Console.hpp" # include "../core/Guard.hpp" # include "../core/Path.hpp" @@ -139,7 +140,7 @@ static bool OnCrash( FILE* input = _wfopen(dumpFilePath, L"rb"); FILE* dest = _wfopen(dumpFilePathGZIP, L"wb"); - if (UtilGzipCompress(input, dest)) + if (Compression::gzipCompress(input, dest)) { // TODO: enable upload of gzip-compressed dumps once supported on // backtrace.io (uncomment the line below). For now leave compression diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index 0ac29fe1ef..b82533016b 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -16,7 +16,6 @@ #include "../interface/Window.h" #include "../platform/Platform.h" #include "../scenes/title/TitleScene.h" -#include "zlib.h" #include #include @@ -225,162 +224,6 @@ float UtilRandNormalDistributed() return _distributor(_prng); } -constexpr size_t CHUNK = 128 * 1024; - -// Compress the source to gzip-compatible stream, write to dest. -// Mainly used for compressing the crashdumps -bool UtilGzipCompress(FILE* source, FILE* dest) -{ - if (source == nullptr || dest == nullptr) - { - return false; - } - int ret, flush; - size_t have; - z_stream strm{}; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - unsigned char in[CHUNK]; - unsigned char out[CHUNK]; - int windowBits = 15; - int GZIP_ENCODING = 16; - ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, windowBits | GZIP_ENCODING, 8, Z_DEFAULT_STRATEGY); - if (ret != Z_OK) - { - LOG_ERROR("Failed to initialise stream"); - return false; - } - do - { - strm.avail_in = uInt(fread(in, 1, CHUNK, source)); - if (ferror(source)) - { - deflateEnd(&strm); - LOG_ERROR("Failed to read data from source"); - return false; - } - flush = feof(source) ? Z_FINISH : Z_NO_FLUSH; - strm.next_in = in; - do - { - strm.avail_out = CHUNK; - strm.next_out = out; - ret = deflate(&strm, flush); - if (ret == Z_STREAM_ERROR) - { - LOG_ERROR("Failed to compress data"); - return false; - } - have = CHUNK - strm.avail_out; - if (fwrite(out, 1, have, dest) != have || ferror(dest)) - { - deflateEnd(&strm); - LOG_ERROR("Failed to write data to destination"); - return false; - } - } while (strm.avail_out == 0); - } while (flush != Z_FINISH); - deflateEnd(&strm); - return true; -} - -std::vector Gzip(const void* data, const size_t dataLen) -{ - assert(data != nullptr); - - std::vector output; - z_stream strm{}; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - - { - const auto ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 15 | 16, 8, Z_DEFAULT_STRATEGY); - if (ret != Z_OK) - { - throw std::runtime_error("deflateInit2 failed with error " + std::to_string(ret)); - } - } - - int flush = 0; - const auto* src = static_cast(data); - size_t srcRemaining = dataLen; - do - { - const auto nextBlockSize = std::min(srcRemaining, CHUNK); - srcRemaining -= nextBlockSize; - - flush = srcRemaining == 0 ? Z_FINISH : Z_NO_FLUSH; - strm.avail_in = static_cast(nextBlockSize); - strm.next_in = const_cast(src); - do - { - output.resize(output.size() + nextBlockSize); - strm.avail_out = static_cast(nextBlockSize); - strm.next_out = &output[output.size() - nextBlockSize]; - const auto ret = deflate(&strm, flush); - if (ret == Z_STREAM_ERROR) - { - throw std::runtime_error("deflate failed with error " + std::to_string(ret)); - } - output.resize(output.size() - strm.avail_out); - } while (strm.avail_out == 0); - - src += nextBlockSize; - } while (flush != Z_FINISH); - deflateEnd(&strm); - return output; -} - -std::vector Ungzip(const void* data, const size_t dataLen) -{ - assert(data != nullptr); - - std::vector output; - z_stream strm{}; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - - { - const auto ret = inflateInit2(&strm, 15 | 16); - if (ret != Z_OK) - { - throw std::runtime_error("inflateInit2 failed with error " + std::to_string(ret)); - } - } - - int flush = 0; - const auto* src = static_cast(data); - size_t srcRemaining = dataLen; - do - { - const auto nextBlockSize = std::min(srcRemaining, CHUNK); - srcRemaining -= nextBlockSize; - - flush = srcRemaining == 0 ? Z_FINISH : Z_NO_FLUSH; - strm.avail_in = static_cast(nextBlockSize); - strm.next_in = const_cast(src); - do - { - output.resize(output.size() + nextBlockSize); - strm.avail_out = static_cast(nextBlockSize); - strm.next_out = &output[output.size() - nextBlockSize]; - const auto ret = inflate(&strm, flush); - if (ret == Z_STREAM_ERROR) - { - throw std::runtime_error("deflate failed with error " + std::to_string(ret)); - } - output.resize(output.size() - strm.avail_out); - } while (strm.avail_out == 0); - - src += nextBlockSize; - } while (flush != Z_FINISH); - inflateEnd(&strm); - return output; -} - uint8_t Lerp(uint8_t a, uint8_t b, float t) { if (t <= 0) diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index 3db5be95c2..94bea63235 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -38,10 +38,6 @@ char* SafeStrCat(char* destination, const char* source, size_t size); uint32_t UtilRand(); float UtilRandNormalDistributed(); -bool UtilGzipCompress(FILE* source, FILE* dest); -std::vector Gzip(const void* data, const size_t dataLen); -std::vector Ungzip(const void* data, const size_t dataLen); - template constexpr T AddClamp(T value, T valueToAdd) { From ece199176e1db93f97d55c33edec339c6e9bcfec Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 29 Oct 2024 11:27:00 +0100 Subject: [PATCH 3/5] Move UnitConversion from Util into its own compilation unit --- src/openrct2-ui/windows/InstallTrack.cpp | 2 +- src/openrct2-ui/windows/MapGen.cpp | 2 +- src/openrct2-ui/windows/Park.cpp | 2 +- src/openrct2-ui/windows/Ride.cpp | 1 + src/openrct2-ui/windows/TrackList.cpp | 1 + src/openrct2/core/UnitConversion.cpp | 78 +++++++++++++++++++ src/openrct2/core/UnitConversion.h | 27 +++++++ src/openrct2/libopenrct2.vcxproj | 2 + src/openrct2/localisation/Formatting.cpp | 2 +- src/openrct2/ride/RideRatings.cpp | 1 + src/openrct2/ride/TrackDesign.cpp | 1 + src/openrct2/scenario/Scenario.cpp | 1 + .../scripting/bindings/ride/ScRide.cpp | 1 + src/openrct2/util/Util.cpp | 65 ---------------- src/openrct2/util/Util.h | 12 --- 15 files changed, 117 insertions(+), 81 deletions(-) create mode 100644 src/openrct2/core/UnitConversion.cpp create mode 100644 src/openrct2/core/UnitConversion.h diff --git a/src/openrct2-ui/windows/InstallTrack.cpp b/src/openrct2-ui/windows/InstallTrack.cpp index ac0dc485ff..6636334a91 100644 --- a/src/openrct2-ui/windows/InstallTrack.cpp +++ b/src/openrct2-ui/windows/InstallTrack.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/src/openrct2-ui/windows/MapGen.cpp b/src/openrct2-ui/windows/MapGen.cpp index bfc7dc89a7..0fd661cb60 100644 --- a/src/openrct2-ui/windows/MapGen.cpp +++ b/src/openrct2-ui/windows/MapGen.cpp @@ -16,13 +16,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index cc951ae8a6..d238b16a40 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include namespace OpenRCT2::Ui::Windows diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index 90038c6eed..7825032de6 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2-ui/windows/TrackList.cpp b/src/openrct2-ui/windows/TrackList.cpp index 30da441681..60ef169386 100644 --- a/src/openrct2-ui/windows/TrackList.cpp +++ b/src/openrct2-ui/windows/TrackList.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/src/openrct2/core/UnitConversion.cpp b/src/openrct2/core/UnitConversion.cpp new file mode 100644 index 0000000000..2dcaf979ec --- /dev/null +++ b/src/openrct2/core/UnitConversion.cpp @@ -0,0 +1,78 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#include "UnitConversion.h" + +namespace OpenRCT2 +{ + int32_t SquaredMetresToSquaredFeet(int32_t squaredMetres) + { + // 1 metre squared = 10.7639104 feet squared + // RCT2 approximates as 11 + return squaredMetres * 11; + } + + int32_t MetresToFeet(int32_t metres) + { + // 1 metre = 3.2808399 feet + // RCT2 approximates as 3.28125 + return (metres * 840) / 256; + } + + int32_t FeetToMetres(int32_t feet) + { + return feet * 256 / 840; + } + + int32_t MphToKmph(int32_t mph) + { + // 1 mph = 1.60934 kmph + // RCT2 approximates as 1.609375 + return (mph * 1648) >> 10; + } + + int32_t MphToDmps(int32_t mph) + { + // 1 mph = 4.4704 decimeters/s + return (mph * 73243) >> 14; + } + + int32_t BaseZToMetres(int16_t baseZ) + { + return (baseZ / 2 - 7) * 1.5; + } + + uint8_t MetresToBaseZ(int16_t metres) + { + return ((metres / 1.5) + 7) * 2; + } + + int32_t HeightUnitsToMetres(int32_t heightUnit) + { + // 1 unit = 0.75 metres + return (heightUnit * 3) >> 2; + } + + int32_t ToHumanReadableSpeed(int32_t baseSpeed) + { + // Divide this value by 29127 to get the human-readable max speed + // (in RCT2, display_speed = (max_speed * 9) >> 18) + return (baseSpeed * 9) >> 18; + } + + uint16_t ToHumanReadableAirTime(uint16_t airTime) + { + return airTime * 3; + } + + int32_t ToHumanReadableRideLength(int32_t rideLength) + { + return rideLength >> 16; + } +} // namespace OpenRCT2 diff --git a/src/openrct2/core/UnitConversion.h b/src/openrct2/core/UnitConversion.h new file mode 100644 index 0000000000..89614ff0a0 --- /dev/null +++ b/src/openrct2/core/UnitConversion.h @@ -0,0 +1,27 @@ +/***************************************************************************** + * Copyright (c) 2014-2024 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include + +namespace OpenRCT2 +{ + int32_t SquaredMetresToSquaredFeet(int32_t squaredMetres); + int32_t MetresToFeet(int32_t metres); + int32_t FeetToMetres(int32_t feet); + int32_t MphToKmph(int32_t mph); + int32_t MphToDmps(int32_t mph); + int32_t BaseZToMetres(int16_t baseZ); + uint8_t MetresToBaseZ(int16_t metres); + int32_t HeightUnitsToMetres(int32_t heightUnit); + int32_t ToHumanReadableSpeed(int32_t baseSpeed); + uint16_t ToHumanReadableAirTime(uint16_t airTime); + int32_t ToHumanReadableRideLength(int32_t rideLength); +} // namespace OpenRCT2 diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index c1268858a1..95e2371cd2 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -232,6 +232,7 @@ + @@ -771,6 +772,7 @@ + diff --git a/src/openrct2/localisation/Formatting.cpp b/src/openrct2/localisation/Formatting.cpp index 10cc645550..0002d55fca 100644 --- a/src/openrct2/localisation/Formatting.cpp +++ b/src/openrct2/localisation/Formatting.cpp @@ -13,9 +13,9 @@ #include "../Diagnostic.h" #include "../config/Config.h" #include "../core/String.hpp" +#include "../core/UnitConversion.h" #include "../object/ObjectManager.h" #include "../object/PeepNamesObject.h" -#include "../util/Util.h" #include "Currency.h" #include "FormatCodes.h" #include "Formatter.h" diff --git a/src/openrct2/ride/RideRatings.cpp b/src/openrct2/ride/RideRatings.cpp index 20226b1a4c..2a0a4e2540 100644 --- a/src/openrct2/ride/RideRatings.cpp +++ b/src/openrct2/ride/RideRatings.cpp @@ -13,6 +13,7 @@ #include "../Context.h" #include "../GameState.h" #include "../OpenRCT2.h" +#include "../core/UnitConversion.h" #include "../interface/Window.h" #include "../localisation/Localisation.Date.h" #include "../profiling/Profiling.h" diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 677965d7ff..118283752a 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -35,6 +35,7 @@ #include "../core/File.h" #include "../core/Numerics.hpp" #include "../core/String.hpp" +#include "../core/UnitConversion.h" #include "../drawing/X8DrawingEngine.h" #include "../interface/Viewport.h" #include "../localisation/StringIds.h" diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index 5500175e3b..c99959915f 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -24,6 +24,7 @@ #include "../core/Guard.hpp" #include "../core/Path.hpp" #include "../core/Random.hpp" +#include "../core/UnitConversion.h" #include "../entity/Duck.h" #include "../entity/Guest.h" #include "../entity/Staff.h" diff --git a/src/openrct2/scripting/bindings/ride/ScRide.cpp b/src/openrct2/scripting/bindings/ride/ScRide.cpp index e50dda64a0..60566ead32 100644 --- a/src/openrct2/scripting/bindings/ride/ScRide.cpp +++ b/src/openrct2/scripting/bindings/ride/ScRide.cpp @@ -12,6 +12,7 @@ # include "ScRide.hpp" # include "../../../Context.h" +# include "../../../core/UnitConversion.h" # include "../../../ride/Ride.h" # include "../../../ride/RideData.h" # include "../../Duktape.hpp" diff --git a/src/openrct2/util/Util.cpp b/src/openrct2/util/Util.cpp index b82533016b..d6d24ac6ed 100644 --- a/src/openrct2/util/Util.cpp +++ b/src/openrct2/util/Util.cpp @@ -24,71 +24,6 @@ #include #include -int32_t SquaredMetresToSquaredFeet(int32_t squaredMetres) -{ - // 1 metre squared = 10.7639104 feet squared - // RCT2 approximates as 11 - return squaredMetres * 11; -} - -int32_t MetresToFeet(int32_t metres) -{ - // 1 metre = 3.2808399 feet - // RCT2 approximates as 3.28125 - return (metres * 840) / 256; -} - -int32_t FeetToMetres(int32_t feet) -{ - return feet * 256 / 840; -} - -int32_t MphToKmph(int32_t mph) -{ - // 1 mph = 1.60934 kmph - // RCT2 approximates as 1.609375 - return (mph * 1648) >> 10; -} - -int32_t MphToDmps(int32_t mph) -{ - // 1 mph = 4.4704 decimeters/s - return (mph * 73243) >> 14; -} - -int32_t BaseZToMetres(int16_t baseZ) -{ - return (baseZ / 2 - 7) * 1.5; -} - -uint8_t MetresToBaseZ(int16_t metres) -{ - return ((metres / 1.5) + 7) * 2; -} - -int32_t HeightUnitsToMetres(int32_t heightUnit) -{ - // 1 unit = 0.75 metres - return (heightUnit * 3) >> 2; -} - -int32_t ToHumanReadableSpeed(int32_t baseSpeed) -{ - // Divide this value by 29127 to get the human-readable max speed - // (in RCT2, display_speed = (max_speed * 9) >> 18) - return (baseSpeed * 9) >> 18; -} - -uint16_t ToHumanReadableAirTime(uint16_t airTime) -{ - return airTime * 3; -} - -int32_t ToHumanReadableRideLength(int32_t rideLength) -{ - return rideLength >> 16; -} - /* Case insensitive logical compare */ // Example: // - Guest 10 diff --git a/src/openrct2/util/Util.h b/src/openrct2/util/Util.h index 94bea63235..e4fff3a7bb 100644 --- a/src/openrct2/util/Util.h +++ b/src/openrct2/util/Util.h @@ -19,18 +19,6 @@ #include #include -int32_t SquaredMetresToSquaredFeet(int32_t squaredMetres); -int32_t MetresToFeet(int32_t metres); -int32_t FeetToMetres(int32_t feet); -int32_t MphToKmph(int32_t mph); -int32_t MphToDmps(int32_t mph); -int32_t BaseZToMetres(int16_t baseZ); -uint8_t MetresToBaseZ(int16_t metres); -int32_t HeightUnitsToMetres(int32_t heightUnit); -int32_t ToHumanReadableSpeed(int32_t baseSpeed); -uint16_t ToHumanReadableAirTime(uint16_t airTime); -int32_t ToHumanReadableRideLength(int32_t rideLength); - int32_t StrLogicalCmp(char const* a, char const* b); char* SafeStrCpy(char* destination, const char* source, size_t num); char* SafeStrCat(char* destination, const char* source, size_t size); From 43be4d1d924c2367049e40859a09ef2e487c6a1e Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 29 Oct 2024 13:12:25 +0100 Subject: [PATCH 4/5] Remove dependency on Drawing.h from Climate.h --- src/openrct2/world/Climate.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h index d8bb1354df..5d7860d249 100644 --- a/src/openrct2/world/Climate.h +++ b/src/openrct2/world/Climate.h @@ -9,8 +9,8 @@ #pragma once -#include "../drawing/Drawing.h" #include "../util/Util.h" +#include enum class ClimateType : uint8_t { @@ -78,6 +78,8 @@ void ClimateUpdateSound(); void ClimateStopWeatherSound(); void ClimateForceWeather(WeatherType weather); +enum class FilterPaletteID : int32_t; + bool ClimateIsRaining(); bool ClimateIsSnowing(); bool ClimateIsSnowingHeavily(); From d2e01dde4e7c061d3f4b9acab1feb01bcb8a8240 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 29 Oct 2024 13:12:52 +0100 Subject: [PATCH 5/5] Remove a bunch of Util.h includes --- src/openrct2-ui/ride/Construction.h | 1 + src/openrct2/Cheats.cpp | 1 - src/openrct2/CommandLineSprite.cpp | 1 - src/openrct2/Context.cpp | 1 - src/openrct2/actions/BannerSetStyleAction.cpp | 1 - src/openrct2/actions/NetworkModifyGroupAction.cpp | 1 - src/openrct2/actions/PeepPickupAction.cpp | 1 - src/openrct2/actions/ScenarioSetSettingAction.cpp | 1 - src/openrct2/actions/TrackRemoveAction.cpp | 1 - src/openrct2/entity/Balloon.cpp | 1 - src/openrct2/entity/Peep.h | 2 +- src/openrct2/entity/Staff.h | 1 + src/openrct2/management/NewsItem.cpp | 1 - src/openrct2/network/NetworkServerAdvertiser.cpp | 1 - src/openrct2/object/Object.h | 1 - src/openrct2/object/StringTable.cpp | 1 + src/openrct2/object/TerrainSurfaceObject.h | 1 + src/openrct2/peep/GuestPathfinding.cpp | 1 - src/openrct2/peep/PeepAnimationData.h | 1 + src/openrct2/platform/Crash.cpp | 1 - src/openrct2/platform/Platform.Posix.cpp | 1 - src/openrct2/ride/CableLift.cpp | 1 - src/openrct2/ride/RideConstruction.cpp | 1 - src/openrct2/ride/ShopItem.h | 2 +- src/openrct2/ride/Track.cpp | 1 - src/openrct2/ride/TrackData.cpp | 1 + src/openrct2/ride/TrackDesignRepository.cpp | 1 - src/openrct2/ride/TrackDesignSave.cpp | 1 - src/openrct2/ride/VehicleSubpositionData.h | 1 + src/openrct2/world/Climate.h | 1 - src/openrct2/world/Footpath.cpp | 1 - src/openrct2/world/MapGen.cpp | 1 - 32 files changed, 9 insertions(+), 25 deletions(-) diff --git a/src/openrct2-ui/ride/Construction.h b/src/openrct2-ui/ride/Construction.h index 9ffdd9cdc7..42d2f347c1 100644 --- a/src/openrct2-ui/ride/Construction.h +++ b/src/openrct2-ui/ride/Construction.h @@ -11,6 +11,7 @@ #include #include +#include namespace OpenRCT2 { diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index c0f94c984e..5a3d0a237d 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -16,7 +16,6 @@ #include "network/network.h" #include "ride/Ride.h" #include "scenario/Scenario.h" -#include "util/Util.h" #include "world/Climate.h" #include "world/Footpath.h" #include "world/Map.h" diff --git a/src/openrct2/CommandLineSprite.cpp b/src/openrct2/CommandLineSprite.cpp index 3fb3d96830..9bd58d2566 100644 --- a/src/openrct2/CommandLineSprite.cpp +++ b/src/openrct2/CommandLineSprite.cpp @@ -22,7 +22,6 @@ #include "object/ObjectLimits.h" #include "object/ObjectManager.h" #include "object/ObjectRepository.h" -#include "util/Util.h" #include #include diff --git a/src/openrct2/Context.cpp b/src/openrct2/Context.cpp index 9eff422afe..d19f79c02c 100644 --- a/src/openrct2/Context.cpp +++ b/src/openrct2/Context.cpp @@ -74,7 +74,6 @@ #include "scripting/ScriptEngine.h" #include "ui/UiContext.h" #include "ui/WindowManager.h" -#include "util/Util.h" #include "world/Park.h" #include diff --git a/src/openrct2/actions/BannerSetStyleAction.cpp b/src/openrct2/actions/BannerSetStyleAction.cpp index eaf2c9ca8d..5d23331a76 100644 --- a/src/openrct2/actions/BannerSetStyleAction.cpp +++ b/src/openrct2/actions/BannerSetStyleAction.cpp @@ -12,7 +12,6 @@ #include "../Context.h" #include "../Diagnostic.h" #include "../management/Finance.h" -#include "../util/Util.h" #include "../windows/Intent.h" #include "../world/Banner.h" #include "../world/tile_element/BannerElement.h" diff --git a/src/openrct2/actions/NetworkModifyGroupAction.cpp b/src/openrct2/actions/NetworkModifyGroupAction.cpp index d0ea39590c..b959e440b8 100644 --- a/src/openrct2/actions/NetworkModifyGroupAction.cpp +++ b/src/openrct2/actions/NetworkModifyGroupAction.cpp @@ -10,7 +10,6 @@ #include "NetworkModifyGroupAction.h" #include "../network/network.h" -#include "../util/Util.h" using namespace OpenRCT2; diff --git a/src/openrct2/actions/PeepPickupAction.cpp b/src/openrct2/actions/PeepPickupAction.cpp index f51675278b..b4ca9e897e 100644 --- a/src/openrct2/actions/PeepPickupAction.cpp +++ b/src/openrct2/actions/PeepPickupAction.cpp @@ -14,7 +14,6 @@ #include "../entity/EntityRegistry.h" #include "../entity/Peep.h" #include "../network/network.h" -#include "../util/Util.h" using namespace OpenRCT2; diff --git a/src/openrct2/actions/ScenarioSetSettingAction.cpp b/src/openrct2/actions/ScenarioSetSettingAction.cpp index fccd3b6305..a1dd6f7479 100644 --- a/src/openrct2/actions/ScenarioSetSettingAction.cpp +++ b/src/openrct2/actions/ScenarioSetSettingAction.cpp @@ -16,7 +16,6 @@ #include "../interface/Window.h" #include "../management/Finance.h" #include "../scenario/Scenario.h" -#include "../util/Util.h" #include "../world/Park.h" using namespace OpenRCT2; diff --git a/src/openrct2/actions/TrackRemoveAction.cpp b/src/openrct2/actions/TrackRemoveAction.cpp index d3ec9ef4c9..59e21498bf 100644 --- a/src/openrct2/actions/TrackRemoveAction.cpp +++ b/src/openrct2/actions/TrackRemoveAction.cpp @@ -16,7 +16,6 @@ #include "../ride/Track.h" #include "../ride/TrackData.h" #include "../ride/TrackDesign.h" -#include "../util/Util.h" #include "../world/Footpath.h" #include "../world/MapAnimation.h" #include "../world/tile_element/SurfaceElement.h" diff --git a/src/openrct2/entity/Balloon.cpp b/src/openrct2/entity/Balloon.cpp index 8d55d2047e..27145b92da 100644 --- a/src/openrct2/entity/Balloon.cpp +++ b/src/openrct2/entity/Balloon.cpp @@ -16,7 +16,6 @@ #include "../paint/Paint.h" #include "../profiling/Profiling.h" #include "../scenario/Scenario.h" -#include "../util/Util.h" #include "../world/tile_element/TrackElement.h" #include "EntityRegistry.h" diff --git a/src/openrct2/entity/Peep.h b/src/openrct2/entity/Peep.h index 35a7d84842..517961c5ca 100644 --- a/src/openrct2/entity/Peep.h +++ b/src/openrct2/entity/Peep.h @@ -14,11 +14,11 @@ #include "../localisation/StringIdType.h" #include "../ride/RideTypes.h" #include "../ride/Station.h" -#include "../util/Util.h" #include "../world/Location.hpp" #include #include +#include constexpr uint8_t kPeepMinEnergy = 32; constexpr uint8_t kPeepMaxEnergy = 128; diff --git a/src/openrct2/entity/Staff.h b/src/openrct2/entity/Staff.h index 1831002e8a..4e0cfdea5d 100644 --- a/src/openrct2/entity/Staff.h +++ b/src/openrct2/entity/Staff.h @@ -9,6 +9,7 @@ #pragma once +#include "../util/Util.h" #include "../world/Map.h" #include "Peep.h" diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index 85614b46a4..b0b58ef38b 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -26,7 +26,6 @@ #include "../profiling/Profiling.h" #include "../ride/Ride.h" #include "../ride/Vehicle.h" -#include "../util/Util.h" #include "../windows/Intent.h" #include "../world/Location.hpp" diff --git a/src/openrct2/network/NetworkServerAdvertiser.cpp b/src/openrct2/network/NetworkServerAdvertiser.cpp index f6ae41364d..e45bfa333f 100644 --- a/src/openrct2/network/NetworkServerAdvertiser.cpp +++ b/src/openrct2/network/NetworkServerAdvertiser.cpp @@ -23,7 +23,6 @@ # include "../localisation/Localisation.Date.h" # include "../management/Finance.h" # include "../platform/Platform.h" -# include "../util/Util.h" # include "../world/Map.h" # include "../world/Park.h" # include "Socket.h" diff --git a/src/openrct2/object/Object.h b/src/openrct2/object/Object.h index 367fd4701e..ed2005bac9 100644 --- a/src/openrct2/object/Object.h +++ b/src/openrct2/object/Object.h @@ -12,7 +12,6 @@ #include "../core/JsonFwd.hpp" #include "../core/StringTypes.h" #include "../drawing/ImageIndexType.h" -#include "../util/Util.h" #include "ImageTable.h" #include "ObjectAsset.h" #include "ObjectTypes.h" diff --git a/src/openrct2/object/StringTable.cpp b/src/openrct2/object/StringTable.cpp index 13eb669c22..db3c6310d5 100644 --- a/src/openrct2/object/StringTable.cpp +++ b/src/openrct2/object/StringTable.cpp @@ -16,6 +16,7 @@ #include "../core/String.hpp" #include "../localisation/LocalisationService.h" #include "../rct12/CSStringConverter.h" +#include "../util/Util.h" #include "Object.h" using namespace OpenRCT2; diff --git a/src/openrct2/object/TerrainSurfaceObject.h b/src/openrct2/object/TerrainSurfaceObject.h index 9b06c21855..1cfb4b5a87 100644 --- a/src/openrct2/object/TerrainSurfaceObject.h +++ b/src/openrct2/object/TerrainSurfaceObject.h @@ -9,6 +9,7 @@ #pragma once +#include "../core/Money.hpp" #include "Object.h" struct CoordsXY; diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index be3b10f1de..77e1652548 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -19,7 +19,6 @@ #include "../ride/Station.h" #include "../ride/Track.h" #include "../scenario/Scenario.h" -#include "../util/Util.h" #include "../world/Entrance.h" #include "../world/Footpath.h" #include "../world/tile_element/BannerElement.h" diff --git a/src/openrct2/peep/PeepAnimationData.h b/src/openrct2/peep/PeepAnimationData.h index c944a38631..3dadeb678d 100644 --- a/src/openrct2/peep/PeepAnimationData.h +++ b/src/openrct2/peep/PeepAnimationData.h @@ -1,6 +1,7 @@ #pragma once #include "../entity/Peep.h" +#include "../util/Util.h" #include diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 6fb17cbdde..b999eeb3de 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -43,7 +43,6 @@ # include "../park/ParkFile.h" # include "../scenario/Scenario.h" # include "../util/SawyerCoding.h" -# include "../util/Util.h" # include "Platform.h" # define WSZ(x) L"" x diff --git a/src/openrct2/platform/Platform.Posix.cpp b/src/openrct2/platform/Platform.Posix.cpp index 40db7f6f0c..f56fc144bd 100644 --- a/src/openrct2/platform/Platform.Posix.cpp +++ b/src/openrct2/platform/Platform.Posix.cpp @@ -16,7 +16,6 @@ # include "../core/Memory.hpp" # include "../core/Path.hpp" # include "../core/String.hpp" -# include "../util/Util.h" # include # include diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index 6dd960b5d3..a91c1c93eb 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -12,7 +12,6 @@ #include "../audio/audio.h" #include "../entity/EntityList.h" #include "../rct12/RCT12.h" -#include "../util/Util.h" #include "../world/tile_element/TileElement.h" #include "../world/tile_element/TrackElement.h" #include "Ride.h" diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index f5f57f7e5f..d310e5c3f1 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -28,7 +28,6 @@ #include "../network/network.h" #include "../ui/UiContext.h" #include "../ui/WindowManager.h" -#include "../util/Util.h" #include "../windows/Intent.h" #include "../world/Banner.h" #include "../world/Climate.h" diff --git a/src/openrct2/ride/ShopItem.h b/src/openrct2/ride/ShopItem.h index 23c706b7b3..3cbcca0b42 100644 --- a/src/openrct2/ride/ShopItem.h +++ b/src/openrct2/ride/ShopItem.h @@ -11,9 +11,9 @@ #include "../core/Money.hpp" #include "../entity/Litter.h" -#include "../util/Util.h" struct Ride; + enum class PeepThoughtType : uint8_t; enum class ShopItem : uint8_t diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index b03c3730c3..c432f8ca85 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -22,7 +22,6 @@ #include "../rct1/RCT1.h" #include "../ride/RideColour.h" #include "../util/SawyerCoding.h" -#include "../util/Util.h" #include "../world/Footpath.h" #include "../world/Map.h" #include "../world/MapAnimation.h" diff --git a/src/openrct2/ride/TrackData.cpp b/src/openrct2/ride/TrackData.cpp index ea93d8643d..8b7db7a82a 100644 --- a/src/openrct2/ride/TrackData.cpp +++ b/src/openrct2/ride/TrackData.cpp @@ -10,6 +10,7 @@ #include "TrackData.h" #include "../localisation/StringIds.h" +#include "../util/Util.h" #include "Track.h" #include "TrackPaint.h" diff --git a/src/openrct2/ride/TrackDesignRepository.cpp b/src/openrct2/ride/TrackDesignRepository.cpp index 20754ae482..8e4d30663a 100644 --- a/src/openrct2/ride/TrackDesignRepository.cpp +++ b/src/openrct2/ride/TrackDesignRepository.cpp @@ -21,7 +21,6 @@ #include "../localisation/LocalisationService.h" #include "../object/ObjectRepository.h" #include "../ride/RideData.h" -#include "../util/Util.h" #include "TrackDesign.h" #include diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index e793fc579e..11ea57859a 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -21,7 +21,6 @@ #include "../object/ObjectManager.h" #include "../rct2/RCT2.h" #include "../util/SawyerCoding.h" -#include "../util/Util.h" #include "../windows/Intent.h" #include "../world/Footpath.h" #include "../world/Scenery.h" diff --git a/src/openrct2/ride/VehicleSubpositionData.h b/src/openrct2/ride/VehicleSubpositionData.h index dd74c5cc24..cfb5f3538c 100644 --- a/src/openrct2/ride/VehicleSubpositionData.h +++ b/src/openrct2/ride/VehicleSubpositionData.h @@ -9,6 +9,7 @@ #pragma once +#include "../util/Util.h" #include "Track.h" #include diff --git a/src/openrct2/world/Climate.h b/src/openrct2/world/Climate.h index 5d7860d249..bf82d4daa8 100644 --- a/src/openrct2/world/Climate.h +++ b/src/openrct2/world/Climate.h @@ -9,7 +9,6 @@ #pragma once -#include "../util/Util.h" #include enum class ClimateType : uint8_t diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index cff8649020..a3f8a5ea6d 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -32,7 +32,6 @@ #include "../ride/RideData.h" #include "../ride/Track.h" #include "../ride/TrackData.h" -#include "../util/Util.h" #include "Location.hpp" #include "Map.h" #include "MapAnimation.h" diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 163fc9d467..aed07fb54d 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -24,7 +24,6 @@ #include "../object/TerrainEdgeObject.h" #include "../object/TerrainSurfaceObject.h" #include "../platform/Platform.h" -#include "../util/Util.h" #include "../world/tile_element/Slope.h" #include "../world/tile_element/SmallSceneryElement.h" #include "../world/tile_element/SurfaceElement.h"