aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openvic-simulation/Modifier.cpp1
-rw-r--r--src/openvic-simulation/Modifier.hpp1
-rw-r--r--src/openvic-simulation/types/Vector.cpp86
-rw-r--r--src/openvic-simulation/types/Vector.hpp35
-rw-r--r--src/openvic-simulation/utility/Logger.hpp4
5 files changed, 125 insertions, 2 deletions
diff --git a/src/openvic-simulation/Modifier.cpp b/src/openvic-simulation/Modifier.cpp
index ed32ee2..d2e21c6 100644
--- a/src/openvic-simulation/Modifier.cpp
+++ b/src/openvic-simulation/Modifier.cpp
@@ -10,6 +10,7 @@ bool ModifierEffect::get_positive_good() const {
}
ModifierValue::ModifierValue() = default;
+ModifierValue::ModifierValue(effect_map_t&& new_values) : values { std::move(new_values) } {}
ModifierValue::ModifierValue(ModifierValue const&) = default;
ModifierValue::ModifierValue(ModifierValue&&) = default;
diff --git a/src/openvic-simulation/Modifier.hpp b/src/openvic-simulation/Modifier.hpp
index e8c4c8b..eb63788 100644
--- a/src/openvic-simulation/Modifier.hpp
+++ b/src/openvic-simulation/Modifier.hpp
@@ -31,6 +31,7 @@ namespace OpenVic {
public:
ModifierValue();
+ ModifierValue(effect_map_t&& new_values);
ModifierValue(ModifierValue const&);
ModifierValue(ModifierValue&&);
diff --git a/src/openvic-simulation/types/Vector.cpp b/src/openvic-simulation/types/Vector.cpp
new file mode 100644
index 0000000..a5b8566
--- /dev/null
+++ b/src/openvic-simulation/types/Vector.cpp
@@ -0,0 +1,86 @@
+#include "Vector.hpp"
+
+#include <ostream>
+#include <tuple>
+
+using namespace OpenVic;
+
+template<typename T>
+constexpr vec2_t<T>::vec2_t() = default;
+
+template<typename T>
+constexpr vec2_t<T>::vec2_t(T new_val) : x { new_val }, y { new_val } {}
+
+template<typename T>
+constexpr vec2_t<T>::vec2_t(T new_x, T new_y) : x { new_x }, y { new_y } {}
+
+
+template<typename T>
+constexpr vec2_t<T> vec2_t<T>::abs() const {
+ return { };
+}
+
+template<typename T>
+constexpr T vec2_t<T>::length_squared() const {
+ return x * x + y * y;
+}
+
+template<typename T>
+constexpr T* vec2_t<T>::data() {
+ return reinterpret_cast<T*>(this);
+}
+
+template<typename T>
+constexpr T const* vec2_t<T>::data() const {
+ return reinterpret_cast<T const*>(this);
+}
+
+template<typename T>
+constexpr T& vec2_t<T>::operator[](size_t index) {
+ return data()[index & 1];
+}
+
+template<typename T>
+constexpr T const& vec2_t<T>::operator[](size_t index) const {
+ return data()[index & 1];
+}
+
+template<typename T>
+constexpr vec2_t<T> operator+(vec2_t<T> const& left, vec2_t<T> const& right) {
+ return { left.x + right.x, left.y + right.y };
+}
+
+template<typename T>
+constexpr vec2_t<T>& vec2_t<T>::operator+=(vec2_t const& right) {
+ x += right.x;
+ y += right.y;
+ return *this;
+}
+
+template<typename T>
+constexpr vec2_t<T> operator-(vec2_t<T> const& arg) {
+ return { -arg.x, -arg.y };
+}
+
+template<typename T>
+constexpr vec2_t<T> operator-(vec2_t<T> const& left, vec2_t<T> const& right) {
+ return { left.x - right.x, left.y - right.y };
+}
+
+template<typename T>
+constexpr vec2_t<T>& vec2_t<T>::operator-=(vec2_t const& right) {
+ x -= right.x;
+ y -= right.y;
+ return *this;
+}
+
+template<typename T>
+constexpr std::ostream& operator<<(std::ostream& stream, vec2_t<T> const& value) {
+ return stream << "(" << value.x << ", " << value.y << ")";
+}
+
+template struct vec2_t<int64_t>;
+template struct vec2_t<fixed_point_t>;
+
+static_assert(sizeof(ivec2_t) == 2 * sizeof(int64_t), "ivec2_t size does not equal the sum of its parts' sizes");
+static_assert(sizeof(fvec2_t) == 2 * sizeof(fixed_point_t), "fvec2_t size does not equal the sum of its parts' sizes");
diff --git a/src/openvic-simulation/types/Vector.hpp b/src/openvic-simulation/types/Vector.hpp
new file mode 100644
index 0000000..fdf7d70
--- /dev/null
+++ b/src/openvic-simulation/types/Vector.hpp
@@ -0,0 +1,35 @@
+#pragma once
+
+#include "openvic-simulation/types/fixed_point/FixedPoint.hpp"
+
+namespace OpenVic {
+
+ template<typename T>
+ struct vec2_t {
+ T x, y;
+
+ constexpr vec2_t();
+ constexpr vec2_t(T new_val);
+ constexpr vec2_t(T new_x, T new_y);
+
+ constexpr vec2_t abs() const;
+ constexpr T length_squared() const;
+
+ constexpr T* data();
+ constexpr T const* data() const;
+
+ constexpr T& operator[](size_t index);
+ constexpr T const& operator[](size_t index) const;
+
+ constexpr friend vec2_t operator+(vec2_t const& left, vec2_t const& right);
+ constexpr vec2_t& operator+=(vec2_t const& right);
+
+ constexpr friend vec2_t operator-(vec2_t const& arg);
+ constexpr friend vec2_t operator-(vec2_t const& left, vec2_t const& right);
+ constexpr vec2_t& operator-=(vec2_t const& right);
+ constexpr friend std::ostream& operator<<(std::ostream& stream, vec2_t const& value);
+ };
+
+ using ivec2_t = vec2_t<int64_t>;
+ using fvec2_t = vec2_t<fixed_point_t>;
+}
diff --git a/src/openvic-simulation/utility/Logger.hpp b/src/openvic-simulation/utility/Logger.hpp
index f9ebd5d..c7b8c51 100644
--- a/src/openvic-simulation/utility/Logger.hpp
+++ b/src/openvic-simulation/utility/Logger.hpp
@@ -70,13 +70,13 @@ namespace OpenVic {
static void set_##name##_func(log_func_t log_func) { \
name##_func = log_func; \
} \
- template <typename... Ts> \
+ template<typename... Ts> \
struct name { \
name(Ts&&... ts, source_location const& location = source_location::current()) { \
log<Ts...>{ name##_func, name##_queue, std::forward<Ts>(ts)..., location }; \
} \
}; \
- template <typename... Ts> \
+ template<typename... Ts> \
name(Ts&&...) -> name<Ts...>;
LOG_FUNC(info)