Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ecs/threading-and-reductions.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ struct KeyedSumScratch {
Adapted from `tests/src/ecs/KeyedReductions.cpp` (the `fixed_point_t` worker-count-invariance case):

```cpp
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/ecs/EcsThreadPool.hpp"
#include "openvic-simulation/ecs/Reductions.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"

using namespace OpenVic::ecs;
using OpenVic::fixed_point_t;
Expand Down
2 changes: 1 addition & 1 deletion misc/scripts/exp_lut_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def generate_exp_lut(divisor_base: int, divisor_power: int, exp_base: decimal.De
source += "}\n// clang-format on\n"

fixed_point_lut_path: str = os.path.join(
os.path.dirname(__file__), f"../../src/openvic-simulation/types/fixed_point/FixedPointLUT_{lut_identifier}.hpp"
os.path.dirname(__file__), f"../../src/openvic-simulation/core/object/FixedPoint/LUT_{lut_identifier}.hpp"
)
with open(fixed_point_lut_path, "w", newline="\n") as file:
file.write(source)
Expand Down
2 changes: 1 addition & 1 deletion misc/scripts/sin_lut_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def generate_sin_lut(precision: int, count_log2: int):
source += "}\n// clang-format on\n"

fixed_point_sin_path: str = os.path.join(
os.path.dirname(__file__), "../../src/openvic-simulation/types/fixed_point/FixedPointLUT_sin.hpp"
os.path.dirname(__file__), "../../src/openvic-simulation/core/object/FixedPoint/LUT_sin.hpp"
)
with open(fixed_point_sin_path, "w", newline="\n") as file:
file.write(source)
Expand Down
16 changes: 6 additions & 10 deletions src/openvic-simulation/core/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
#include <type_traits>

#include "openvic-simulation/core/Typedefs.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"

namespace OpenVic {
template<typename T>
[[nodiscard]] OV_SPEED_INLINE constexpr T abs(const T num);
class fixed_point_t;

template<typename T>
[[nodiscard]] constexpr T abs(const T num);

template<typename T>
requires std::integral<T> || std::floating_point<T>
Expand All @@ -22,13 +23,8 @@ namespace OpenVic {
}
}

template<>
[[nodiscard]] OV_SPEED_INLINE constexpr fixed_point_t abs(const fixed_point_t num) {
return num.abs();
}

template<typename T>
requires (!(std::integral<T> || std::floating_point<T> || std::is_same_v<T, fixed_point_t>))
template<typename T>
requires(!(std::integral<T> || std::floating_point<T> || std::same_as<T, fixed_point_t>))
[[nodiscard]] OV_SPEED_INLINE constexpr T abs(T const& num);

template<std::floating_point T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
#include <fmt/base.h>
#include <fmt/format.h>

#include "openvic-simulation/core/object/FixedPoint/String.hpp"
#include "openvic-simulation/core/Typedefs.hpp"
#include "openvic-simulation/utility/Logger.hpp"

#include "String.hpp"

/* Base e exponential lookup table */
#include "openvic-simulation/types/fixed_point/FixedPointLUT_2_16_EXP_e.hpp"
#include "openvic-simulation/core/object/FixedPoint/LUT_2_16_EXP_e.hpp"

/* Base 2001 exponential lookup table */
#include "openvic-simulation/types/fixed_point/FixedPointLUT_2_16_EXP_2001.hpp"
#include "openvic-simulation/core/object/FixedPoint/LUT_2_16_EXP_2001.hpp"

using namespace OpenVic;
static_assert(_detail::LUT::_2_16_EXP_e_DIVISOR == 1 << fixed_point_t::PRECISION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@

namespace OpenVic {
enum class midpoint_rounding { AWAY_ZERO, TO_ZERO };

template<typename T>
concept integral_max_size_4 = std::integral<T> && sizeof(T) <= 4;

struct fixed_point_t {
class fixed_point_t {
public:
/* PROPERTY generated getter functions will return fixed points by value, rather than const reference. */
using ov_return_by_value = void;
using value_type = int64_t;
Expand All @@ -40,6 +41,7 @@ namespace OpenVic {

private:
value_type value;

public:
[[nodiscard]] constexpr value_type const& get_raw_value() const {
return value;
Expand All @@ -48,6 +50,7 @@ namespace OpenVic {
OV_ALWAYS_INLINE constexpr fixed_point_t get_frac() const {
return parse_raw(value & FRAC_MASK);
}

private:
struct raw_value_t {
explicit raw_value_t() = default;
Expand Down Expand Up @@ -267,7 +270,7 @@ namespace OpenVic {

static fixed_point_t parse_capped(const int64_t value);
static fixed_point_t parse_capped(const uint64_t value);

template<std::integral T>
requires (sizeof(T) >= 4)
static fixed_point_t parse_capped(const T value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <atomic>

#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/Typedefs.hpp"

namespace std {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/types/fixed_point/Math.hpp"
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/object/FixedPoint/Math.hpp"
#include "openvic-simulation/core/Typedefs.hpp"

namespace OpenVic {
Expand All @@ -17,4 +17,4 @@ namespace OpenVic {
return fp::mul_div(lhs, rhs.numerator, rhs.denominator);
}
};
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
#pragma once

#include "FixedPoint.hpp"

#include <cassert>

#include "openvic-simulation/core/Math.hpp"
#include "openvic-simulation/core/MathSqrt.hpp"
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/template/Concepts.hpp"
#include "openvic-simulation/core/Typedefs.hpp"

/* Sin lookup table */
#include "openvic-simulation/types/fixed_point/FixedPointLUT_sin.hpp"
#include "openvic-simulation/core/object/FixedPoint/LUT_sin.hpp"

namespace OpenVic {
template<>
[[nodiscard]] OV_SPEED_INLINE constexpr fixed_point_t abs(const fixed_point_t num) {
return num.abs();
}
}

namespace OpenVic::fp {
static_assert(_detail::LUT::SIN_PRECISION == fixed_point_t::PRECISION);
static_assert(_detail::LUT::SIN_PRECISION == fixed_point_t::PRECISION);

OV_SPEED_INLINE static constexpr fixed_point_t sin(fixed_point_t const& v) {
using namespace _detail::LUT;
Expand All @@ -30,9 +37,7 @@ namespace OpenVic::fp {

const fixed_point_t::value_type fraction = (num - (index << SIN_SHIFT)) << SIN_COUNT_LOG2;
const fixed_point_t::value_type result = a + (((b - a) * fraction) >> SIN_PRECISION);
return fixed_point_t::parse_raw(
!negative ? result : -result
);
return fixed_point_t::parse_raw(!negative ? result : -result);
}

OV_SPEED_INLINE static constexpr fixed_point_t cos(fixed_point_t const& v) {
Expand All @@ -41,29 +46,28 @@ namespace OpenVic::fp {

OV_SPEED_INLINE static constexpr fixed_point_t sqrt(fixed_point_t const& v) {
return !v.is_negative()
? fixed_point_t::parse_raw(
OpenVic::sqrt(
static_cast<uint64_t>(v.get_raw_value()) << fixed_point_t::PRECISION
)
)
? fixed_point_t::parse_raw(OpenVic::sqrt(static_cast<uint64_t>(v.get_raw_value()) << fixed_point_t::PRECISION))
: fixed_point_t::_0;
}

//Preserves accuracy. Performing a normal multiplication of small values results in 0.
// Preserves accuracy. Performing a normal multiplication of small values results in 0.
template<std::integral T>
OV_SPEED_INLINE static constexpr fixed_point_t mul_div(fixed_point_t const& multiplier, T const& numerator, T const& denominator) {
OV_SPEED_INLINE static constexpr fixed_point_t
mul_div(fixed_point_t const& multiplier, T const& numerator, T const& denominator) {
return fixed_point_t::parse_raw(multiplier.get_raw_value() * numerator / denominator);
}

OV_SPEED_INLINE static constexpr fixed_point_t mul_div(fixed_point_t const& multiplier, fixed_point_t const& numerator, fixed_point_t const& denominator) {
OV_SPEED_INLINE static constexpr fixed_point_t
mul_div(fixed_point_t const& multiplier, fixed_point_t const& numerator, fixed_point_t const& denominator) {
return mul_div(multiplier, numerator.get_raw_value(), denominator.get_raw_value());
}

template<is_strongly_typed StrongType>
OV_SPEED_INLINE static constexpr fixed_point_t mul_div(fixed_point_t const& multiplier, StrongType const& numerator, StrongType const& denominator) {
OV_SPEED_INLINE static constexpr fixed_point_t
mul_div(fixed_point_t const& multiplier, StrongType const& numerator, StrongType const& denominator) {
return mul_div(multiplier, type_safe::get(numerator), type_safe::get(denominator));
}

template<std::integral T>
OV_SPEED_INLINE static constexpr T multiply_truncate(T const& integer, fixed_point_t const& v) {
return static_cast<T>(
Expand All @@ -73,33 +77,30 @@ namespace OpenVic::fp {

template<is_strongly_typed StrongType>
OV_SPEED_INLINE static constexpr StrongType multiply_truncate(StrongType const& integer, fixed_point_t const& v) {
return StrongType(multiply_truncate(
type_safe::get(integer),
v
));
return StrongType(multiply_truncate(type_safe::get(integer), v));
}

template<integral_max_size_4 TNumerator, integral_max_size_4 TDenominator>
OV_SPEED_INLINE static constexpr fixed_point_t from_fraction(const TNumerator numerator, const TDenominator denominator) {
return fixed_point_t::parse_raw(
(static_cast<fixed_point_t::value_type>(numerator) << fixed_point_t::PRECISION)
/ static_cast<fixed_point_t::value_type>(denominator)
(static_cast<fixed_point_t::value_type>(numerator) << fixed_point_t::PRECISION) /
static_cast<fixed_point_t::value_type>(denominator)
);
}

OV_SPEED_INLINE static constexpr fixed_point_t from_fraction(const int64_t numerator, const int64_t denominator) {
assert(numerator < 140737488355328LL); //2^47
assert(numerator < 140737488355328LL); // 2^47
assert(numerator >= -140737488355328LL); //- 2^47
return fixed_point_t::parse_raw((numerator << fixed_point_t::PRECISION) / denominator);
}

OV_SPEED_INLINE static constexpr fixed_point_t from_fraction(const uint64_t numerator, const uint64_t denominator) {
assert(numerator < 281474976710656ULL); //2^48
assert(numerator < 281474976710656ULL); // 2^48
return fixed_point_t::parse_raw((numerator << fixed_point_t::PRECISION) / denominator);
}

template<is_strongly_typed StrongType>
OV_SPEED_INLINE static constexpr fixed_point_t from_fraction(StrongType const& numerator, StrongType const& denominator) {
return from_fraction(type_safe::get(numerator), type_safe::get(denominator));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include <charconv>

#include "openvic-simulation/core/Math.hpp"
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/stl/containers/StackString.hpp"
#include "openvic-simulation/core/string/CharConv.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/utility/Logger.hpp"

namespace OpenVic::fp {
Expand Down Expand Up @@ -229,4 +229,4 @@ namespace OpenVic::fp {

return fixed_point_t::parse_raw(integer_value);
}
}
}
3 changes: 2 additions & 1 deletion src/openvic-simulation/core/object/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include <fmt/format.h>

#include "openvic-simulation/core/Math.hpp" // IWYU pragma: keep
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/object/FixedPoint/Math.hpp" // IWYU pragma: keep
#include "openvic-simulation/core/stl/BasicIterator.hpp" // IWYU pragma: keep
#include "openvic-simulation/core/template/Concepts.hpp" // IWYU pragma: keep
#include "openvic-simulation/core/Typedefs.hpp" // IWYU pragma: keep
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"

#define VEC_TYPE vec2_t
#define FOR_VEC_COMPONENTS(F, SEP) F(x) SEP F(y)
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/core/random/WeightedSampling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <limits>
#include <span>

#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/Typedefs.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"

namespace OpenVic {
OV_SPEED_INLINE static size_t sample_weighted_index(
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/country/CountryInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "openvic-simulation/core/error/ErrorMacros.hpp"
#include "openvic-simulation/core/object/Date.hpp"
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/object/FixedPoint/Math.hpp"
#include "openvic-simulation/core/object/Timespan.hpp"
#include "openvic-simulation/core/Typedefs.hpp"
#include "openvic-simulation/country/CountryDefinition.hpp"
Expand Down Expand Up @@ -48,8 +50,6 @@
#include "openvic-simulation/research/Invention.hpp"
#include "openvic-simulation/research/Technology.hpp"
#include "openvic-simulation/types/ClampedValue.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/types/fixed_point/Math.hpp"
#include "openvic-simulation/types/IndexedFlatMap.hpp"
#include "openvic-simulation/types/TypedIndices.hpp"
#include "openvic-simulation/types/UnitBranchType.hpp"
Expand Down Expand Up @@ -381,7 +381,7 @@
case BuildingRestrictionCategory::FACTORY:
return rule_set.may_invest_in_building_factory_abroad();
}
}

Check warning on line 384 in src/openvic-simulation/country/CountryInstance.cpp

View workflow job for this annotation

GitHub Actions / 🛠️ Build / 🐧 Linux Debug

control reaches end of non-void function [-Wreturn-type]

Check warning on line 384 in src/openvic-simulation/country/CountryInstance.cpp

View workflow job for this annotation

GitHub Actions / 🛠️ Build / 🏁 Windows Release

'OpenVic::CountryInstance::may_build_in': not all control paths return a value

Check warning on line 384 in src/openvic-simulation/country/CountryInstance.cpp

View workflow job for this annotation

GitHub Actions / 🛠️ Build / 🏁 Windows Debug

'OpenVic::CountryInstance::may_build_in': not all control paths return a value

CountryRelationManager::relation_value_type CountryInstance::get_relations_with(CountryInstance const& country) const {
return country_relations_manager.get_country_relation(this, &country);
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/country/CountryInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "openvic-simulation/core/memory/SmartPtr.hpp"
#include "openvic-simulation/core/memory/Vector.hpp"
#include "openvic-simulation/core/object/Date.hpp"
#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/object/FixedPoint/Atomic.hpp"
#include "openvic-simulation/core/object/Timespan.hpp"
#include "openvic-simulation/core/stl/containers/TypedSpan.hpp"
#include "openvic-simulation/core/thread/SpinMutex.hpp"
Expand All @@ -21,8 +23,6 @@
#include "openvic-simulation/population/PopsAggregate.hpp"
#include "openvic-simulation/research/TechnologyUnlockLevel.hpp"
#include "openvic-simulation/types/ClampedValue.hpp"
#include "openvic-simulation/types/fixed_point/Atomic.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/types/FlagStrings.hpp"
#include "openvic-simulation/types/HasIndex.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/country/SharedCountryValues.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/population/PopNeedsMacro.hpp"
#include "openvic-simulation/types/IndexedFlatMap.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/types/UnitBranchType.hpp"
#include "openvic-simulation/utility/reactive/MutableState.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/dataloader/NodeTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#include <range/v3/view/enumerate.hpp>

#include "openvic-simulation/core/object/Colour.hpp"
#include "openvic-simulation/core/object/FixedPoint/String.hpp"
#include "openvic-simulation/core/object/Timespan.hpp"
#include "openvic-simulation/core/object/Vector.hpp"
#include "openvic-simulation/core/ui/TextFormat.hpp"
#include "openvic-simulation/types/fixed_point/String.hpp"
#include "openvic-simulation/utility/Getters.hpp"

using namespace OpenVic;
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/defines/AIDefines.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/object/Timespan.hpp"
#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/utility/Getters.hpp"

namespace OpenVic {
Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/defines/CountryDefines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#include <cstddef>

#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/object/Timespan.hpp"
#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/map/LifeRating.hpp"
#include "openvic-simulation/utility/Getters.hpp"

Expand Down
2 changes: 1 addition & 1 deletion src/openvic-simulation/defines/DiplomacyDefines.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include "openvic-simulation/core/object/FixedPoint.hpp"
#include "openvic-simulation/core/object/Timespan.hpp"
#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
#include "openvic-simulation/utility/Getters.hpp"

namespace OpenVic {
Expand Down
Loading
Loading