Move UnitConversion from Util into its own compilation unit

This commit is contained in:
Aaron van Geffen committed 2024-10-29 11:27:00 +01:00
1 parent 4e27bac292
commit ece199176e
15 files changed
+117 -81

No files matched your search

+1 -1
View File
@@ -18,6 +18,7 @@
#include <openrct2/audio/audio.h>
#include <openrct2/core/File.h>
#include <openrct2/core/Path.hpp>
#include <openrct2/core/UnitConversion.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/ride/RideConstruction.h>
@@ -25,7 +26,6 @@
#include <openrct2/ride/TrackDesign.h>
#include <openrct2/ride/TrackDesignRepository.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include <string>
#include <vector>
+1 -1
View File
@@ -16,13 +16,13 @@
#include <openrct2/Input.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/FileSystem.hpp>
#include <openrct2/core/UnitConversion.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Formatter.h>
#include <openrct2/object/ObjectManager.h>
#include <openrct2/object/TerrainEdgeObject.h>
#include <openrct2/object/TerrainSurfaceObject.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Map.h>
#include <openrct2/world/MapGen.h>
+1 -1
View File
@@ -24,6 +24,7 @@
#include <openrct2/actions/ParkSetEntranceFeeAction.h>
#include <openrct2/actions/ParkSetNameAction.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/UnitConversion.h>
#include <openrct2/localisation/Currency.h>
#include <openrct2/localisation/Formatting.h>
#include <openrct2/management/Award.h>
@@ -31,7 +32,6 @@
#include <openrct2/ride/RideData.h>
#include <openrct2/scenario/Scenario.h>
#include <openrct2/sprites.h>
#include <openrct2/util/Util.h>
#include <openrct2/world/Park.h>
namespace OpenRCT2::Ui::Windows
+1
View File
@@ -38,6 +38,7 @@
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/String.hpp>
#include <openrct2/core/UnitConversion.h>
#include <openrct2/entity/EntityList.h>
#include <openrct2/entity/Staff.h>
#include <openrct2/localisation/Currency.h>
+1
View File
@@ -16,6 +16,7 @@
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/core/String.hpp>
#include <openrct2/core/UnitConversion.h>
#include <openrct2/drawing/IDrawingEngine.h>
#include <openrct2/localisation/Formatting.h>
#include <openrct2/ride/RideConstruction.h>
+78
View File
@@ -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
+27
View File
@@ -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 <cstdint>
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
+2
View File
@@ -232,6 +232,7 @@
<ClInclude Include="core\Timer.hpp" />
<ClInclude Include="core\UTF8.h" />
<ClInclude Include="core\UnicodeChar.h" />
<ClInclude Include="core\UnitConversion.h" />
<ClInclude Include="core\Zip.h" />
<ClInclude Include="core\ZipStream.hpp" />
<ClInclude Include="Date.h" />
@@ -771,6 +772,7 @@
<ClCompile Include="core\StringBuilder.cpp" />
<ClCompile Include="core\StringReader.cpp" />
<ClCompile Include="core\UTF8.cpp" />
<ClCompile Include="core\UnitConversion.cpp" />
<ClCompile Include="core\Zip.cpp" />
<ClCompile Include="core\ZipAndroid.cpp" />
<ClCompile Include="Date.cpp" />
+1 -1
View File
@@ -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"
+1
View File
@@ -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"
+1
View File
@@ -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"
+1
View File
@@ -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"
@@ -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"
-65
View File
@@ -24,71 +24,6 @@
#include <ctime>
#include <random>
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
-12
View File
@@ -19,18 +19,6 @@
#include <type_traits>
#include <vector>
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);