aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/Types.hpp
diff options
context:
space:
mode:
author Hop311 <hop3114@gmail.com>2023-08-10 12:32:53 +0200
committer Hop311 <hop3114@gmail.com>2023-08-10 12:32:53 +0200
commit170ee25469322d25931050813a779dfbc2eaa4b0 (patch)
tree42bc9cc4a0e33ff1f1a64ae5e23edc4a52ca4320 /src/openvic/Types.hpp
parent8a08be3e7e8477973e243716d431ad7117acfa43 (diff)
Added distributions for pop type and culture
Diffstat (limited to 'src/openvic/Types.hpp')
-rw-r--r--src/openvic/Types.hpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/openvic/Types.hpp b/src/openvic/Types.hpp
index 7740e17..d22f686 100644
--- a/src/openvic/Types.hpp
+++ b/src/openvic/Types.hpp
@@ -3,6 +3,7 @@
#include <algorithm>
#include <cstdint>
#include <map>
+#include <unordered_map>
#include <vector>
#include "utility/Logger.hpp"
@@ -25,6 +26,9 @@ namespace OpenVic {
constexpr colour_t float_to_alpha_value(float a) {
return float_to_colour_byte(a) << 24;
}
+ constexpr float colour_byte_to_float(colour_t colour) {
+ return std::clamp(static_cast<float>(colour) / 255.0f, 0.0f, 1.0f);
+ }
using index_t = uint16_t;
static constexpr index_t NULL_INDEX = 0, MAX_INDEX = 0xFFFF;
@@ -58,13 +62,13 @@ namespace OpenVic {
};
/*
- * Base class for objects with associated colour information
+ * Base class for objects with associated colour information.
*/
class HasColour {
const colour_t colour;
protected:
- HasColour(colour_t const new_colour, bool can_be_null);
+ HasColour(const colour_t new_colour, bool can_be_null);
public:
HasColour(HasColour const&) = delete;
@@ -78,6 +82,23 @@ namespace OpenVic {
};
/*
+ * Base class for objects with a unique string identifier
+ * and associated colour information.
+ */
+ class HasIdentifierAndColour : public HasIdentifier, public HasColour {
+ protected:
+ HasIdentifierAndColour(std::string const& new_identifier, const colour_t new_colour, bool can_be_null);
+
+ public:
+ HasIdentifierAndColour(HasIdentifierAndColour const&) = delete;
+ HasIdentifierAndColour(HasIdentifierAndColour&&) = default;
+ HasIdentifierAndColour& operator=(HasIdentifierAndColour const&) = delete;
+ HasIdentifierAndColour& operator=(HasIdentifierAndColour&&) = delete;
+ };
+
+ using distribution_t = std::unordered_map<HasIdentifierAndColour const*, float>;
+
+ /*
* Template for a list of objects with unique string identifiers that can
* be locked to prevent any further additions. The template argument T is
* the type of object that the registry will store, and the second part ensures