diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-03 12:04:14 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-04-03 12:04:14 +0100 |
| commit | 4d04572e48950493ce85255d181be43967f362fd (patch) | |
| tree | f74d055f151472cda3fa3fc0f760eb6219dd9fad /lib | |
| parent | Use std::chrono for worldTime (diff) | |
| parent | Fix direction of difference vector calculating railVehicle new position (diff) | |
| download | ilt-4d04572e48950493ce85255d181be43967f362fd.tar.bz2 ilt-4d04572e48950493ce85255d181be43967f362fd.tar.xz ilt-4d04572e48950493ce85255d181be43967f362fd.zip | |
Merge branch 'shared-locations'
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/location.cpp | 8 | ||||
| -rw-r--r-- | lib/location.h | 2 | ||||
| -rw-r--r-- | lib/util.cpp | 1 | ||||
| -rw-r--r-- | lib/util.h | 22 |
4 files changed, 32 insertions, 1 deletions
diff --git a/lib/location.cpp b/lib/location.cpp index 13acfde..2138f0a 100644 --- a/lib/location.cpp +++ b/lib/location.cpp @@ -2,6 +2,14 @@ #include "maths.h" #include <glm/gtx/transform.hpp> +Location +Location::operator+(RelativePosition3D offset) const +{ + Location ret {*this}; + ret.pos += offset; + return ret; +} + glm::mat3 Location::getRotationTransform() const { diff --git a/lib/location.h b/lib/location.h index 016aee7..e642b41 100644 --- a/lib/location.h +++ b/lib/location.h @@ -11,6 +11,8 @@ public: [[nodiscard]] glm::mat3 getRotationTransform() const; + Location operator+(RelativePosition3D) const; + GlobalPosition3D pos; Rotation3D rot; }; diff --git a/lib/util.cpp b/lib/util.cpp deleted file mode 100644 index 408a76a..0000000 --- a/lib/util.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "util.h" @@ -3,6 +3,7 @@ #include <algorithm> // IWYU pragma: keep #include <array> #include <cstddef> +#include <memory> #include <tuple> template<typename T, std::size_t N> @@ -33,3 +34,24 @@ template<size_t... N> inline constexpr auto Nth = GetNth<N...> {}; inline constexpr auto GetFirst = Nth<0>; inline constexpr auto GetSecond = Nth<1>; inline constexpr auto GetSwapped = Nth<0, 1>; + +template<typename T, typename M> struct Decompose { + consteval Decompose(M T::*) { } + + using ValueType = M; + using ContainerType = T; +}; + +template<auto MbrPtr> using MemberValueType = typename decltype(Decompose {MbrPtr})::ValueType; +template<auto MbrPtr> using ContainerType = typename decltype(Decompose {MbrPtr})::ContainerType; + +template<typename T> +bool +createIfRequired(std::shared_ptr<T> & instance, std::weak_ptr<T> & common) +{ + if (!instance && !(instance = common.lock())) { + common = instance = std::make_shared<T>(); + return true; + } + return false; +} |
