From b733e97bfae25b2497420cb47910f1c00b62da01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Sat, 11 Sep 2021 19:53:14 +0300 Subject: [PATCH] Remove numerics from common.h and use it as needed --- src/openrct2/actions/TrackPlaceAction.cpp | 3 ++- src/openrct2/common.h | 12 ------------ src/openrct2/core/FileIndex.hpp | 3 ++- src/openrct2/core/FileScanner.cpp | 3 ++- src/openrct2/core/Numerics.hpp | 9 +++++++++ src/openrct2/drawing/TTF.cpp | 3 ++- src/openrct2/drawing/X8DrawingEngine.cpp | 3 ++- src/openrct2/object/ObjectRepository.cpp | 9 +++++---- .../paint/tile_element/Paint.LargeScenery.cpp | 3 ++- src/openrct2/paint/tile_element/Paint.Path.cpp | 9 +++++---- src/openrct2/paint/tile_element/Paint.Surface.cpp | 5 +++-- .../paint/tile_element/Paint.TileElement.cpp | 3 ++- src/openrct2/peep/Guest.cpp | 5 +++-- src/openrct2/rct12/SawyerChunkReader.cpp | 3 ++- src/openrct2/rct12/SawyerChunkWriter.cpp | 3 ++- src/openrct2/rct12/SawyerEncoding.cpp | 3 ++- src/openrct2/rct2/S6Exporter.cpp | 9 ++++++--- src/openrct2/rct2/S6Importer.cpp | 3 +++ src/openrct2/rct2/SeaDecrypt.cpp | 5 +++-- src/openrct2/ride/Ride.cpp | 9 +++++---- src/openrct2/ride/TrackDesign.cpp | 3 ++- src/openrct2/ride/gentle/Maze.cpp | 3 ++- src/openrct2/scenario/ScenarioRepository.cpp | 3 ++- src/openrct2/util/SawyerCoding.cpp | 13 +++++++------ src/openrct2/world/Park.h | 3 --- 25 files changed, 75 insertions(+), 55 deletions(-) diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index a3269cbe9a..f0fc1898cb 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -9,6 +9,7 @@ #include "TrackPlaceAction.h" +#include "../core/Numerics.hpp" #include "../management/Finance.h" #include "../ride/RideData.h" #include "../ride/Track.h" @@ -453,7 +454,7 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const // Remove walls in the directions this track intersects uint8_t intersectingDirections = wallEdges[blockIndex]; intersectingDirections ^= 0x0F; - intersectingDirections = rol4(intersectingDirections, _origin.direction); + intersectingDirections = Numerics::rol4(intersectingDirections, _origin.direction); for (int32_t i = 0; i < NumOrthogonalDirections; i++) { if (intersectingDirections & (1 << i)) diff --git a/src/openrct2/common.h b/src/openrct2/common.h index cc0e1d517a..5a5cae5ade 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -19,15 +19,12 @@ #endif #include "Diagnostic.h" -#include "core/Numerics.hpp" #include #include #include #include -using namespace Numerics; - using utf8 = char; using utf8string = utf8*; using const_utf8string = const utf8*; @@ -41,15 +38,6 @@ using const_utf8string = const utf8*; using codepoint_t = uint32_t; using colour_t = uint8_t; -const constexpr auto rol8 = rol; -const constexpr auto ror8 = ror; -const constexpr auto rol16 = rol; -const constexpr auto ror16 = ror; -const constexpr auto rol32 = rol; -const constexpr auto ror32 = ror; -const constexpr auto rol64 = rol; -const constexpr auto ror64 = ror; - namespace { [[maybe_unused]] constexpr bool is_power_of_2(int v) diff --git a/src/openrct2/core/FileIndex.hpp b/src/openrct2/core/FileIndex.hpp index 0e5d570a47..0d01da1e42 100644 --- a/src/openrct2/core/FileIndex.hpp +++ b/src/openrct2/core/FileIndex.hpp @@ -16,6 +16,7 @@ #include "FileScanner.h" #include "FileStream.h" #include "JobPool.h" +#include "Numerics.hpp" #include "Path.hpp" #include @@ -156,7 +157,7 @@ private: stats.TotalFileSize += fileInfo->Size; stats.FileDateModifiedChecksum ^= static_cast(fileInfo->LastModified >> 32) ^ static_cast(fileInfo->LastModified & 0xFFFFFFFF); - stats.FileDateModifiedChecksum = ror32(stats.FileDateModifiedChecksum, 5); + stats.FileDateModifiedChecksum = Numerics::ror32(stats.FileDateModifiedChecksum, 5); stats.PathChecksum += GetPathChecksum(path); files.push_back(std::move(path)); diff --git a/src/openrct2/core/FileScanner.cpp b/src/openrct2/core/FileScanner.cpp index 9c79c500f7..07662b1134 100644 --- a/src/openrct2/core/FileScanner.cpp +++ b/src/openrct2/core/FileScanner.cpp @@ -25,6 +25,7 @@ #include "FileScanner.h" #include "Memory.hpp" +#include "Numerics.hpp" #include "Path.hpp" #include "String.hpp" @@ -363,7 +364,7 @@ void Path::QueryDirectory(QueryDirectoryResult* result, const std::string& patte result->TotalFileSize += fileInfo->Size; result->FileDateModifiedChecksum ^= static_cast(fileInfo->LastModified >> 32) ^ static_cast(fileInfo->LastModified & 0xFFFFFFFF); - result->FileDateModifiedChecksum = ror32(result->FileDateModifiedChecksum, 5); + result->FileDateModifiedChecksum = Numerics::ror32(result->FileDateModifiedChecksum, 5); result->PathChecksum += GetPathChecksum(path); } } diff --git a/src/openrct2/core/Numerics.hpp b/src/openrct2/core/Numerics.hpp index 13c1b6a772..38855da2c4 100644 --- a/src/openrct2/core/Numerics.hpp +++ b/src/openrct2/core/Numerics.hpp @@ -68,4 +68,13 @@ namespace Numerics return (x >> shift | x << (4 - shift)) & 0x0F; } + const constexpr auto rol8 = rol; + const constexpr auto ror8 = ror; + const constexpr auto rol16 = rol; + const constexpr auto ror16 = ror; + const constexpr auto rol32 = rol; + const constexpr auto ror32 = ror; + const constexpr auto rol64 = rol; + const constexpr auto ror64 = ror; + } // namespace Numerics diff --git a/src/openrct2/drawing/TTF.cpp b/src/openrct2/drawing/TTF.cpp index 7887bb8e6f..c32039e870 100644 --- a/src/openrct2/drawing/TTF.cpp +++ b/src/openrct2/drawing/TTF.cpp @@ -19,6 +19,7 @@ # include "../OpenRCT2.h" # include "../config/Config.h" +# include "../core/Numerics.hpp" # include "../core/String.hpp" # include "../localisation/Localisation.h" # include "../localisation/LocalisationService.h" @@ -186,7 +187,7 @@ static uint32_t ttf_surface_cache_hash(TTF_Font* font, std::string_view text) uint32_t hash = static_cast(((reinterpret_cast(font) * 23) ^ 0xAAAAAAAA) & 0xFFFFFFFF); for (auto c : text) { - hash = ror32(hash, 3) ^ (c * 13); + hash = Numerics::ror32(hash, 3) ^ (c * 13); } return hash; } diff --git a/src/openrct2/drawing/X8DrawingEngine.cpp b/src/openrct2/drawing/X8DrawingEngine.cpp index 528e236892..3afc9e1bb2 100644 --- a/src/openrct2/drawing/X8DrawingEngine.cpp +++ b/src/openrct2/drawing/X8DrawingEngine.cpp @@ -13,6 +13,7 @@ #include "../Game.h" #include "../Intro.h" #include "../config/Config.h" +#include "../core/Numerics.hpp" #include "../interface/Screenshot.h" #include "../interface/Viewport.h" #include "../interface/Window.h" @@ -583,7 +584,7 @@ void X8DrawingContext::FillRect(uint32_t colour, int32_t left, int32_t top, int3 for (int32_t i = 0; i < height; i++) { uint8_t* nextdst = dst + dpi->width + dpi->pitch; - uint32_t p = ror32(crossPattern, 1); + uint32_t p = Numerics::ror32(crossPattern, 1); p = (p & 0xFFFF0000) | width; // Fill every other pixel with the colour diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index ea19c419bf..4c8329323e 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -21,6 +21,7 @@ #include "../core/IStream.hpp" #include "../core/Memory.hpp" #include "../core/MemoryStream.h" +#include "../core/Numerics.hpp" #include "../core/Path.hpp" #include "../core/String.hpp" #include "../localisation/Localisation.h" @@ -757,11 +758,11 @@ int32_t object_calculate_checksum(const rct_object_entry* entry, const void* dat uint32_t checksum = 0xF369A75B; checksum ^= entryBytePtr[0]; - checksum = rol32(checksum, 11); + checksum = Numerics::rol32(checksum, 11); for (int32_t i = 4; i < 12; i++) { checksum ^= entryBytePtr[i]; - checksum = rol32(checksum, 11); + checksum = Numerics::rol32(checksum, 11); } const uint8_t* dataBytes = reinterpret_cast(data); @@ -772,12 +773,12 @@ int32_t object_calculate_checksum(const rct_object_entry* entry, const void* dat { checksum ^= dataBytes[j]; } - checksum = rol32(checksum, 11); + checksum = Numerics::rol32(checksum, 11); } for (size_t i = dataLength32; i < dataLength; i++) { checksum ^= dataBytes[i]; - checksum = rol32(checksum, 11); + checksum = Numerics::rol32(checksum, 11); } return static_cast(checksum); diff --git a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp index 5a332d641e..4e806ce90a 100644 --- a/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp +++ b/src/openrct2/paint/tile_element/Paint.LargeScenery.cpp @@ -9,6 +9,7 @@ #include "../../Game.h" #include "../../config/Config.h" +#include "../../core/Numerics.hpp" #include "../../interface/Viewport.h" #include "../../localisation/Localisation.h" #include "../../object/LargeSceneryObject.h" @@ -278,7 +279,7 @@ void PaintLargeScenery(paint_session* session, uint8_t direction, uint16_t heigh if (edi & 0xF00) { edi &= 0xF000; - edi = rol16(edi, direction); + edi = Numerics::rol16(edi, direction); esi = (edi & 0xF) | (edi >> 12); } const CoordsXYZ bbOffset = { s98E3C4[esi].offset, height }; diff --git a/src/openrct2/paint/tile_element/Paint.Path.cpp b/src/openrct2/paint/tile_element/Paint.Path.cpp index 5f93c63949..33892bbe61 100644 --- a/src/openrct2/paint/tile_element/Paint.Path.cpp +++ b/src/openrct2/paint/tile_element/Paint.Path.cpp @@ -9,6 +9,7 @@ #include "../../Game.h" #include "../../config/Config.h" +#include "../../core/Numerics.hpp" #include "../../drawing/LightFX.h" #include "../../interface/Viewport.h" #include "../../localisation/Localisation.h" @@ -174,7 +175,7 @@ static void path_bit_bins_paint( // Edges have been rotated around the rotation to check addition status // this will also need to be rotated. - binIsFull = !(pathElement.GetAdditionStatus() & ror8(0x3, (2 * session->CurrentRotation))); + binIsFull = !(pathElement.GetAdditionStatus() & Numerics::ror8(0x3, (2 * session->CurrentRotation))); if (binIsFull) imageId += 8; } @@ -195,7 +196,7 @@ static void path_bit_bins_paint( // Edges have been rotated around the rotation to check addition status // this will also need to be rotated. - binIsFull = !(pathElement.GetAdditionStatus() & ror8(0xC, (2 * session->CurrentRotation))); + binIsFull = !(pathElement.GetAdditionStatus() & Numerics::ror8(0xC, (2 * session->CurrentRotation))); if (binIsFull) imageId += 8; } @@ -217,7 +218,7 @@ static void path_bit_bins_paint( // Edges have been rotated around the rotation to check addition status // this will also need to be rotated. - binIsFull = !(pathElement.GetAdditionStatus() & ror8(0x30, (2 * session->CurrentRotation))); + binIsFull = !(pathElement.GetAdditionStatus() & Numerics::ror8(0x30, (2 * session->CurrentRotation))); if (binIsFull) imageId += 8; } @@ -239,7 +240,7 @@ static void path_bit_bins_paint( // Edges have been rotated around the rotation to check addition status // this will also need to be rotated. - binIsFull = !(pathElement.GetAdditionStatus() & ror8(0xC0, (2 * session->CurrentRotation))); + binIsFull = !(pathElement.GetAdditionStatus() & Numerics::ror8(0xC0, (2 * session->CurrentRotation))); if (binIsFull) imageId += 8; } diff --git a/src/openrct2/paint/tile_element/Paint.Surface.cpp b/src/openrct2/paint/tile_element/Paint.Surface.cpp index fb6f601787..ba9f146089 100644 --- a/src/openrct2/paint/tile_element/Paint.Surface.cpp +++ b/src/openrct2/paint/tile_element/Paint.Surface.cpp @@ -14,6 +14,7 @@ #include "../../OpenRCT2.h" #include "../../config/Config.h" #include "../../core/Guard.hpp" +#include "../../core/Numerics.hpp" #include "../../drawing/Drawing.h" #include "../../interface/Colour.h" #include "../../interface/Viewport.h" @@ -950,7 +951,7 @@ static std::pair surface_get_height_above_water( } else { - localSurfaceShape = ror4(surfaceShape ^ TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK, 2); + localSurfaceShape = Numerics::ror4(surfaceShape ^ TILE_ELEMENT_SURFACE_RAISED_CORNERS_MASK, 2); } } } @@ -1340,7 +1341,7 @@ void PaintSurface(paint_session* session, uint8_t direction, uint16_t height, co // Owned land boundary fences session->InteractionType = ViewportInteractionItem::ParkEntrance; - uint8_t rotatedFences = rol4(tileElement.GetParkFences(), rotation); + uint8_t rotatedFences = Numerics::rol4(tileElement.GetParkFences(), rotation); for (const auto& fenceData : _tileSurfaceBoundaries) { diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index 98eb889f2b..c6fa7c74e9 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -12,6 +12,7 @@ #include "../../Game.h" #include "../../Input.h" #include "../../config/Config.h" +#include "../../core/Numerics.hpp" #include "../../drawing/Drawing.h" #include "../../interface/Viewport.h" #include "../../localisation/Localisation.h" @@ -427,7 +428,7 @@ void paint_util_set_segment_support_height(paint_session* session, int32_t segme uint16_t paint_util_rotate_segments(uint16_t segments, uint8_t rotation) { uint8_t temp = segments & 0xFF; - temp = rol8(temp, rotation * 2); + temp = Numerics::rol8(temp, rotation * 2); return (segments & 0xFF00) | temp; } diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 747b8670f4..2e3a2da226 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -13,6 +13,7 @@ #include "../audio/audio.h" #include "../config/Config.h" #include "../core/Guard.hpp" +#include "../core/Numerics.hpp" #include "../interface/Window_internal.h" #include "../localisation/Localisation.h" #include "../management/Finance.h" @@ -6001,7 +6002,7 @@ bool Guest::UpdateWalkingFindBin() uint8_t bin_quantities = pathElement->GetAdditionStatus(); // Rotate the bin to the correct edge. Makes it easier for next calc. - bin_quantities = ror8(ror8(bin_quantities, chosen_edge), chosen_edge); + bin_quantities = Numerics::ror8(Numerics::ror8(bin_quantities, chosen_edge), chosen_edge); for (uint8_t free_edge = 4; free_edge != 0; free_edge--) { @@ -6012,7 +6013,7 @@ bool Guest::UpdateWalkingFindBin() break; } chosen_edge = (chosen_edge + 1) & 0x3; - bin_quantities = ror8(bin_quantities, 2); + bin_quantities = Numerics::ror8(bin_quantities, 2); if ((free_edge - 1) == 0) return 0; } diff --git a/src/openrct2/rct12/SawyerChunkReader.cpp b/src/openrct2/rct12/SawyerChunkReader.cpp index 3ce28fadff..dee3fbfa20 100644 --- a/src/openrct2/rct12/SawyerChunkReader.cpp +++ b/src/openrct2/rct12/SawyerChunkReader.cpp @@ -10,6 +10,7 @@ #include "SawyerChunkReader.h" #include "../core/IStream.hpp" +#include "../core/Numerics.hpp" // malloc is very slow for large allocations in MSVC debug builds as it allocates // memory on a special debug heap and then initialises all the memory to 0xCC. @@ -295,7 +296,7 @@ size_t SawyerChunkReader::DecodeChunkRotate(void* dst, size_t dstCapacity, const uint8_t code = 1; for (size_t i = 0; i < srcLength; i++) { - dst8[i] = ror8(src8[i], code); + dst8[i] = Numerics::ror8(src8[i], code); code = (code + 2) % 8; } return srcLength; diff --git a/src/openrct2/rct12/SawyerChunkWriter.cpp b/src/openrct2/rct12/SawyerChunkWriter.cpp index 83a7dc944c..938a1176b3 100644 --- a/src/openrct2/rct12/SawyerChunkWriter.cpp +++ b/src/openrct2/rct12/SawyerChunkWriter.cpp @@ -10,6 +10,7 @@ #include "SawyerChunkWriter.h" #include "../core/IStream.hpp" +#include "../core/Numerics.hpp" #include "../util/SawyerCoding.h" // Maximum buffer size to store compressed data, maximum of 16 MiB @@ -99,7 +100,7 @@ void SawyerChunkWriter::WriteChunkTrack(const void* src, size_t length) { uint8_t newByte = ((checksum & 0xFF) + data[i]) & 0xFF; checksum = (checksum & 0xFFFFFF00) + newByte; - checksum = rol32(checksum, 3); + checksum = Numerics::rol32(checksum, 3); } checksum -= 0x1D4C1; diff --git a/src/openrct2/rct12/SawyerEncoding.cpp b/src/openrct2/rct12/SawyerEncoding.cpp index 0172d68d5b..758b6cb226 100644 --- a/src/openrct2/rct12/SawyerEncoding.cpp +++ b/src/openrct2/rct12/SawyerEncoding.cpp @@ -10,6 +10,7 @@ #include "SawyerEncoding.h" #include "../core/IStream.hpp" +#include "../core/Numerics.hpp" #include "RCT12.h" #include @@ -80,7 +81,7 @@ namespace SawyerEncoding { uint8_t newByte = ((checksum & 0xFF) + *data) & 0xFF; checksum = (checksum & 0xFFFFFF00) + newByte; - checksum = rol32(checksum, 3); + checksum = Numerics::rol32(checksum, 3); } uint32_t fileChecksum = stream->ReadValue(); diff --git a/src/openrct2/rct2/S6Exporter.cpp b/src/openrct2/rct2/S6Exporter.cpp index 2b155cc33f..8952fc624f 100644 --- a/src/openrct2/rct2/S6Exporter.cpp +++ b/src/openrct2/rct2/S6Exporter.cpp @@ -18,6 +18,7 @@ #include "../config/Config.h" #include "../core/FileStream.h" #include "../core/IStream.hpp" +#include "../core/Numerics.hpp" #include "../core/String.hpp" #include "../interface/Viewport.h" #include "../interface/Window.h" @@ -64,6 +65,8 @@ #include #include +#define ENCRYPT_MONEY(money) (static_cast(Numerics::ror32((money), 13) ^ 0xF4EC9621)) + S6Exporter::S6Exporter() { RemoveTracklessRides = false; @@ -597,11 +600,11 @@ uint32_t S6Exporter::GetLoanHash(money32 initialCash, money32 bankLoan, uint32_t { int32_t value = 0x70093A; value -= initialCash; - value = ror32(value, 5); + value = Numerics::ror32(value, 5); value -= bankLoan; - value = ror32(value, 7); + value = Numerics::ror32(value, 7); value += maxBankLoan; - value = ror32(value, 3); + value = Numerics::ror32(value, 3); return value; } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index bee403a492..b92b7ed13c 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -18,6 +18,7 @@ #include "../core/Console.hpp" #include "../core/FileStream.h" #include "../core/IStream.hpp" +#include "../core/Numerics.hpp" #include "../core/Path.hpp" #include "../core/Random.hpp" #include "../core/String.hpp" @@ -70,6 +71,8 @@ #include +#define DECRYPT_MONEY(money) (static_cast(Numerics::rol32((money) ^ 0xF4EC9621, 13))) + /** * Class to import RollerCoaster Tycoon 2 scenarios (*.SC6) and saved games (*.SV6). */ diff --git a/src/openrct2/rct2/SeaDecrypt.cpp b/src/openrct2/rct2/SeaDecrypt.cpp index 0d7e1bb837..5ca8c7f4de 100644 --- a/src/openrct2/rct2/SeaDecrypt.cpp +++ b/src/openrct2/rct2/SeaDecrypt.cpp @@ -9,6 +9,7 @@ #include "../common.h" #include "../core/File.h" +#include "../core/Numerics.hpp" #include "../core/Path.hpp" #include "RCT2.h" @@ -53,8 +54,8 @@ static std::vector CreateMask(const EncryptionKey& key) { uint32_t s0 = seed0; uint32_t s1 = seed1 ^ 0xF7654321; - seed0 = rol32(s1, 25) + s0; - seed1 = rol32(s0, 29); + seed0 = Numerics::rol32(s1, 25) + s0; + seed1 = Numerics::rol32(s0, 29); result[i + 0] = (s0 >> 3) & 0xFF; result[i + 1] = (s0 >> 11) & 0xFF; result[i + 2] = (s0 >> 19) & 0xFF; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index d39f418e69..9975a6b51e 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -24,6 +24,7 @@ #include "../config/Config.h" #include "../core/FixedVector.h" #include "../core/Guard.hpp" +#include "../core/Numerics.hpp" #include "../interface/Window.h" #include "../localisation/Date.h" #include "../localisation/Localisation.h" @@ -2234,7 +2235,7 @@ static void ride_shop_connected(Ride* ride) const auto& ted = GetTrackElementDescriptor(track_type); uint8_t entrance_directions = ted.SequenceProperties[0] & 0xF; uint8_t tile_direction = trackElement->GetDirection(); - entrance_directions = rol4(entrance_directions, tile_direction); + entrance_directions = Numerics::rol4(entrance_directions, tile_direction); // Now each bit in entrance_directions stands for an entrance direction to check if (entrance_directions == 0) @@ -3043,7 +3044,7 @@ static Vehicle* vehicle_create_car( vehicle->vehicle_type = vehicleEntryIndex; vehicle->SubType = carIndex == 0 ? Vehicle::Type::Head : Vehicle::Type::Tail; - vehicle->var_44 = ror32(vehicleEntry->spacing, 10) & 0xFFFF; + vehicle->var_44 = Numerics::ror32(vehicleEntry->spacing, 10) & 0xFFFF; auto edx = vehicleEntry->spacing >> 1; *remainingDistance -= edx; vehicle->remaining_distance = *remainingDistance; @@ -3666,9 +3667,9 @@ static bool ride_create_cable_lift(ride_id_t rideIndex, bool isApplying) uint32_t ebx = 0; for (int32_t i = 0; i < 5; i++) { - uint32_t edx = ror32(0x15478, 10); + uint32_t edx = Numerics::ror32(0x15478, 10); uint16_t var_44 = edx & 0xFFFF; - edx = rol32(edx, 10) >> 1; + edx = Numerics::rol32(edx, 10) >> 1; ebx -= edx; int32_t remaining_distance = ebx; ebx -= edx; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 747430bc7c..3cbc658e65 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -33,6 +33,7 @@ #include "../audio/audio.h" #include "../core/DataSerialiser.h" #include "../core/File.h" +#include "../core/Numerics.hpp" #include "../core/String.hpp" #include "../drawing/X8DrawingEngine.h" #include "../localisation/Localisation.h" @@ -1420,7 +1421,7 @@ static std::optional track_design_place_maze(TrackDesign* td6, const Co } break; default: - maze_entry = rol16(maze_element.maze_entry, rotation * 4); + maze_entry = Numerics::rol16(maze_element.maze_entry, rotation * 4); if (_trackDesignPlaceOperation == PTD_OPERATION_PLACE_TRACK_PREVIEW) { diff --git a/src/openrct2/ride/gentle/Maze.cpp b/src/openrct2/ride/gentle/Maze.cpp index 51d75f9d5d..b46e1e4268 100644 --- a/src/openrct2/ride/gentle/Maze.cpp +++ b/src/openrct2/ride/gentle/Maze.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "../../core/Numerics.hpp" #include "../../interface/Viewport.h" #include "../../paint/Paint.h" #include "../../paint/Supports.h" @@ -49,7 +50,7 @@ static void maze_paint_setup( const TrackElement& trackElement) { uint16_t maze_entry = trackElement.GetMazeEntry(); - maze_entry = rol16(maze_entry, direction * 4); + maze_entry = Numerics::rol16(maze_entry, direction * 4); uint32_t rotation = session->CurrentRotation; // draw ground diff --git a/src/openrct2/scenario/ScenarioRepository.cpp b/src/openrct2/scenario/ScenarioRepository.cpp index 822d884cf1..48b31d8d01 100644 --- a/src/openrct2/scenario/ScenarioRepository.cpp +++ b/src/openrct2/scenario/ScenarioRepository.cpp @@ -19,6 +19,7 @@ #include "../core/FileIndex.hpp" #include "../core/FileStream.h" #include "../core/MemoryStream.h" +#include "../core/Numerics.hpp" #include "../core/Path.hpp" #include "../core/String.hpp" #include "../localisation/Language.h" @@ -526,7 +527,7 @@ private: // Rotate each byte of mp.dat left by 4 bits to convert for (size_t i = 0; i < mpdat.size(); i++) { - mpdat[i] = rol8(mpdat[i], 4); + mpdat[i] = Numerics::rol8(mpdat[i], 4); } File::WriteAllBytes(dstPath, mpdat.data(), mpdat.size()); diff --git a/src/openrct2/util/SawyerCoding.cpp b/src/openrct2/util/SawyerCoding.cpp index b8c2fb586d..2c03a10910 100644 --- a/src/openrct2/util/SawyerCoding.cpp +++ b/src/openrct2/util/SawyerCoding.cpp @@ -9,6 +9,7 @@ #include "SawyerCoding.h" +#include "../core/Numerics.hpp" #include "../platform/platform.h" #include "../scenario/Scenario.h" #include "Util.h" @@ -113,10 +114,10 @@ size_t sawyercoding_decode_sc4(const uint8_t* src, uint8_t* dst, size_t length, for (size_t i = 0x60018; i <= std::min(decodedLength - 1, static_cast(0x1F8350)); i += 4) { - dst[i + 1] = ror8(dst[i + 1], 3); + dst[i + 1] = Numerics::ror8(dst[i + 1], 3); uint32_t* code = reinterpret_cast(&dst[i]); - *code = rol32(*code, 9); + *code = Numerics::rol32(*code, 9); } return decodedLength; @@ -148,7 +149,7 @@ size_t sawyercoding_encode_td6(const uint8_t* src, uint8_t* dst, size_t length) { uint8_t new_byte = ((checksum & 0xFF) + dst[i]) & 0xFF; checksum = (checksum & 0xFFFFFF00) + new_byte; - checksum = rol32(checksum, 3); + checksum = Numerics::rol32(checksum, 3); } checksum -= 0x1D4C1; @@ -167,7 +168,7 @@ int32_t sawyercoding_validate_track_checksum(const uint8_t* src, size_t length) { uint8_t new_byte = ((checksum & 0xFF) + src[i]) & 0xFF; checksum = (checksum & 0xFFFFFF00) + new_byte; - checksum = rol32(checksum, 3); + checksum = Numerics::rol32(checksum, 3); } if (checksum - 0x1D4C1 == file_checksum) @@ -383,7 +384,7 @@ static void encode_chunk_rotate(uint8_t* buffer, size_t length) uint8_t code = 1; for (i = 0; i < length; i++) { - buffer[i] = rol8(buffer[i], code); + buffer[i] = Numerics::rol8(buffer[i], code); code = (code + 2) % 8; } } @@ -401,7 +402,7 @@ int32_t sawyercoding_detect_file_type(const uint8_t* src, size_t length) for (i = 0; i < length - 4; i++) { actualChecksum = (actualChecksum & 0xFFFFFF00) | (((actualChecksum & 0xFF) + static_cast(src[i])) & 0xFF); - actualChecksum = rol32(actualChecksum, 3); + actualChecksum = Numerics::rol32(actualChecksum, 3); } return sawyercoding_detect_rct1_version(checksum - actualChecksum); diff --git a/src/openrct2/world/Park.h b/src/openrct2/world/Park.h index 786d122e10..7f27f77076 100644 --- a/src/openrct2/world/Park.h +++ b/src/openrct2/world/Park.h @@ -13,9 +13,6 @@ #include "../ride/Ride.h" #include "Map.h" -#define DECRYPT_MONEY(money) (static_cast(rol32((money) ^ 0xF4EC9621, 13))) -#define ENCRYPT_MONEY(money) (static_cast(ror32((money), 13) ^ 0xF4EC9621)) - #define MAX_ENTRANCE_FEE MONEY(200, 00) constexpr const uint8_t ParkRatingHistoryUndefined = std::numeric_limits::max();