Move money types into Money.hpp

This commit is contained in:
Aaron van Geffen 2024-05-14 16:35:00 +02:00
parent 9a4aa4bb94
commit 69c5e6ad9e
17 changed files with 80 additions and 60 deletions

View File

@ -9,7 +9,7 @@
#pragma once
#include <openrct2/common.h>
#include <openrct2/core/Money.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/world/Location.hpp>

View File

@ -9,7 +9,7 @@
#pragma once
#include "common.h"
#include "core/Money.hpp"
enum class StaffSpeedCheat
{

View File

@ -27,6 +27,7 @@
#include "core/Console.hpp"
#include "core/File.h"
#include "core/FileScanner.h"
#include "core/Money.hpp"
#include "core/Path.hpp"
#include "entity/EntityRegistry.h"
#include "entity/PatrolArea.h"

View File

@ -38,58 +38,6 @@ using datetime64 = uint64_t;
constexpr datetime64 DATETIME64_MIN = 0;
// Money is stored as a multiple of 0.10.
using money16 = fixed16_1dp;
using money32 = fixed32_1dp;
using money64 = fixed64_1dp;
// For a user defined floating point literal, the parameter type must be a
// `long double` which is problematic on ppc64el, as the architecture uses a
// pair of `doubles` to represent that type. This cannot be converted to a
// `constexpr`. As a workaround, statically cast the `long double` down to a
// `double`. All of the uses of _GBP constants fit just fine, and if anyone
// really tries to use a gigantic constant that can't fit in a double, they are
// probably going to be breaking other things anyways.
// For more details, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26374
constexpr money64 operator"" _GBP(long double money) noexcept
{
return static_cast<double>(money) * 10;
}
constexpr money64 ToMoney64FromGBP(int32_t money) noexcept
{
return money * 10;
}
constexpr money64 ToMoney64FromGBP(int64_t money) noexcept
{
return money * 10;
}
constexpr money64 ToMoney64FromGBP(double money) noexcept
{
return money * 10;
}
constexpr money16 kMoney16Undefined = static_cast<money16>(static_cast<uint16_t>(0xFFFF));
constexpr money32 kMoney32Undefined = static_cast<money32>(0x80000000);
constexpr money64 kMoney64Undefined = static_cast<money64>(0x8000000000000000);
constexpr money16 ToMoney16(money64 value)
{
return value == kMoney64Undefined ? kMoney16Undefined : value;
}
constexpr money64 ToMoney64(money32 value)
{
return value == kMoney32Undefined ? kMoney64Undefined : value;
}
constexpr money64 ToMoney64(money16 value)
{
return value == kMoney16Undefined ? kMoney64Undefined : value;
}
using StringId = uint16_t;
#define abstract = 0

View File

@ -0,0 +1,64 @@
/*****************************************************************************
* 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 "FixedPoint.hpp"
// Money is stored as a multiple of 0.10.
using money16 = fixed16_1dp;
using money32 = fixed32_1dp;
using money64 = fixed64_1dp;
// For a user defined floating point literal, the parameter type must be a
// `long double` which is problematic on ppc64el, as the architecture uses a
// pair of `doubles` to represent that type. This cannot be converted to a
// `constexpr`. As a workaround, statically cast the `long double` down to a
// `double`. All of the uses of _GBP constants fit just fine, and if anyone
// really tries to use a gigantic constant that can't fit in a double, they are
// probably going to be breaking other things anyways.
// For more details, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26374
constexpr money64 operator"" _GBP(long double money) noexcept
{
return static_cast<double>(money) * 10;
}
constexpr money64 ToMoney64FromGBP(int32_t money) noexcept
{
return money * 10;
}
constexpr money64 ToMoney64FromGBP(int64_t money) noexcept
{
return money * 10;
}
constexpr money64 ToMoney64FromGBP(double money) noexcept
{
return money * 10;
}
constexpr money16 kMoney16Undefined = static_cast<money16>(static_cast<uint16_t>(0xFFFF));
constexpr money32 kMoney32Undefined = static_cast<money32>(0x80000000);
constexpr money64 kMoney64Undefined = static_cast<money64>(0x8000000000000000);
constexpr money16 ToMoney16(money64 value)
{
return value == kMoney64Undefined ? kMoney16Undefined : value;
}
constexpr money64 ToMoney64(money32 value)
{
return value == kMoney32Undefined ? kMoney64Undefined : value;
}
constexpr money64 ToMoney64(money16 value)
{
return value == kMoney16Undefined ? kMoney64Undefined : value;
}

View File

@ -9,6 +9,7 @@
#pragma once
#include "../core/Money.hpp"
#include "EntityBase.h"
class DataSerialiser;

View File

@ -212,6 +212,7 @@
<ClInclude Include="core\Memory.hpp" />
<ClInclude Include="core\MemoryStream.h" />
<ClInclude Include="core\Meta.hpp" />
<ClInclude Include="core\Money.hpp" />
<ClInclude Include="core\Numerics.hpp" />
<ClInclude Include="core\OrcaStream.hpp" />
<ClInclude Include="core\Path.hpp" />

View File

@ -12,6 +12,7 @@
#include "../Identifiers.h"
#include "../common.h"
#include "../core/Guard.hpp"
#include "../core/Money.hpp"
#include "../core/String.hpp"
#include <array>

View File

@ -9,7 +9,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "Research.h"
enum class ExpenditureType : int32_t

View File

@ -10,6 +10,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "ObjectTypes.h"
enum

View File

@ -8,7 +8,8 @@
*****************************************************************************/
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "../world/Location.hpp"
#include "ObjectTypes.h"

View File

@ -9,7 +9,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "ObjectTypes.h"

View File

@ -9,7 +9,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "ObjectTypes.h"

View File

@ -9,7 +9,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "../interface/Cursors.h"
#include "ObjectTypes.h"

View File

@ -10,6 +10,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "../entity/Litter.h"
#include "../util/Util.h"

View File

@ -10,6 +10,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "../core/String.hpp"
#include <cstdio>

View File

@ -9,7 +9,7 @@
#pragma once
#include "../common.h"
#include "../core/Money.hpp"
#include "Location.hpp"
#include "ScenerySelection.h"