diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cache.h | 1 | ||||
-rw-r--r-- | lib/collections.h | 3 | ||||
-rw-r--r-- | lib/enumDetails.h | 6 | ||||
-rw-r--r-- | lib/geometricPlane.cpp | 4 | ||||
-rw-r--r-- | lib/geometricPlane.h | 10 | ||||
-rw-r--r-- | lib/glArrays.h | 3 | ||||
-rw-r--r-- | lib/glContainer.h | 6 | ||||
-rw-r--r-- | lib/gl_traits.h | 12 | ||||
-rw-r--r-- | lib/jsonParse-persistence.cpp | 3 | ||||
-rw-r--r-- | lib/location.cpp | 4 | ||||
-rw-r--r-- | lib/location.h | 12 | ||||
-rw-r--r-- | lib/maths.cpp | 46 | ||||
-rw-r--r-- | lib/maths.h | 61 | ||||
-rw-r--r-- | lib/persistence.cpp | 1 | ||||
-rw-r--r-- | lib/persistence.h | 9 | ||||
-rw-r--r-- | lib/ptr.h | 1 | ||||
-rw-r--r-- | lib/ray.cpp | 8 | ||||
-rw-r--r-- | lib/ray.h | 15 | ||||
-rw-r--r-- | lib/resource.h | 1 | ||||
-rw-r--r-- | lib/saxParse-persistence.h | 1 | ||||
-rw-r--r-- | lib/stdTypeDefs.h | 4 | ||||
-rw-r--r-- | lib/unicode.h | 2 | ||||
-rw-r--r-- | lib/worker.h | 3 |
23 files changed, 140 insertions, 76 deletions
diff --git a/lib/cache.h b/lib/cache.h index 2c3975b..f5fd227 100644 --- a/lib/cache.h +++ b/lib/cache.h @@ -35,4 +35,5 @@ public: private: std::map<Key, Ptr, std::less<>> cached; }; + // IWYU pragma: no_forward_declare Cache diff --git a/lib/collections.h b/lib/collections.h index 7d78ef9..943b986 100644 --- a/lib/collections.h +++ b/lib/collections.h @@ -149,11 +149,14 @@ template<typename T> struct pair_range { { return pair.first; } + constexpr auto & end() const noexcept { return pair.second; } + const std::pair<T, T> & pair; }; + template<typename T> pair_range(std::pair<T, T>) -> pair_range<T>; diff --git a/lib/enumDetails.h b/lib/enumDetails.h index 5966be2..b6ff046 100644 --- a/lib/enumDetails.h +++ b/lib/enumDetails.h @@ -26,11 +26,13 @@ template<typename E> struct EnumTypeDetails : EnumDetailsBase { protected: #endif constexpr static std::string_view SEARCH_TYPE {"E = "}; + constexpr static auto typeraw() { return std::string_view {__PRETTY_FUNCTION__}; }; + constexpr static auto typeNameStart {typeraw().find(SEARCH_TYPE) + SEARCH_TYPE.length()}; constexpr static auto typeNameEnd {typeraw().find_first_of("];", typeNameStart)}; constexpr static auto typeNameLen {typeNameEnd - typeNameStart}; @@ -47,11 +49,13 @@ template<auto value> struct EnumValueDetails : public EnumTypeDetails<decltype(v private: #endif using T = EnumTypeDetails<decltype(value)>; + constexpr static auto raw() { return std::string_view {__PRETTY_FUNCTION__}; }; + constexpr static auto nameStart {raw().find_last_of(": ") + 1}; constexpr static auto nameEnd {raw().find_first_of("];", nameStart)}; constexpr static auto nameLen {nameEnd - nameStart}; @@ -84,12 +88,14 @@ private: return std::array {EnumValueDetails<static_cast<E>(n)>::valid...}; #pragma GCC diagnostic pop } + template<auto... n> constexpr static auto get_values(std::integer_sequence<int, n...>) { return std::array {EnumValueDetails<static_cast<E>(n)>::raw_value...}; } + template<auto... n> constexpr static auto get_valueNames(std::integer_sequence<int, n...>) diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp index ea4f02d..567f98a 100644 --- a/lib/geometricPlane.cpp +++ b/lib/geometricPlane.cpp @@ -4,10 +4,10 @@ #include <glm/gtx/intersect.hpp> GeometricPlane::PlaneRelation -GeometricPlane::getRelation(glm::vec3 p) const +GeometricPlane::getRelation(Position3D p) const { const auto d = glm::dot(normal, p - origin); - return d < 0.f ? PlaneRelation::Below : d > 0.f ? PlaneRelation::Above : PlaneRelation::On; + return d < 0.F ? PlaneRelation::Below : d > 0.F ? PlaneRelation::Above : PlaneRelation::On; } bool diff --git a/lib/geometricPlane.h b/lib/geometricPlane.h index dc8df50..c74beff 100644 --- a/lib/geometricPlane.h +++ b/lib/geometricPlane.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include <glm/vec3.hpp> #include <optional> @@ -9,14 +10,15 @@ class GeometricPlane { public: struct DistAndPosition { float dist; - glm::vec3 position; + Position3D position; }; enum class PlaneRelation { Above, Below, On }; - glm::vec3 origin, normal; + Position3D origin; + Normal3D normal; - PlaneRelation getRelation(glm::vec3 point) const; - std::optional<DistAndPosition> getRayIntersectPosition(const Ray &) const; + [[nodiscard]] PlaneRelation getRelation(Position3D point) const; + [[nodiscard]] std::optional<DistAndPosition> getRayIntersectPosition(const Ray &) const; static bool isIntersect(PlaneRelation a, PlaneRelation b); }; diff --git a/lib/glArrays.h b/lib/glArrays.h index 86385d9..787ea17 100644 --- a/lib/glArrays.h +++ b/lib/glArrays.h @@ -15,7 +15,8 @@ public: CUSTOM_MOVE(glArraysBase); // NOLINTNEXTLINE(hicpp-explicit-conversions) - inline operator GLuint() const + inline + operator GLuint() const { static_assert(N == 1, "Implicit cast only if N == 1"); return ids.front(); diff --git a/lib/glContainer.h b/lib/glContainer.h index 993170e..8177618 100644 --- a/lib/glContainer.h +++ b/lib/glContainer.h @@ -9,6 +9,7 @@ template<typename I, typename Direction> class basic_glContainer_iterator { public: explicit basic_glContainer_iterator(I * i) : i {i} { } + template<typename OtherI> basic_glContainer_iterator(const basic_glContainer_iterator<OtherI, Direction> & other) : i {&*other} { @@ -20,17 +21,20 @@ public: i = Direction {}(i, 1); return *this; } + auto operator++(int) noexcept { return basic_glContainer_iterator<I, Direction> {std::exchange(i, Direction {}(i, 1))}; } + auto & operator--() noexcept { i = Direction {}(i, -1); return *this; } + auto operator--(int) noexcept { @@ -76,6 +80,7 @@ public: { return this->i == other.i; } + [[nodiscard]] bool operator!=(const basic_glContainer_iterator & other) const noexcept { @@ -87,6 +92,7 @@ public: { return i; } + [[nodiscard]] auto & operator*() const noexcept { diff --git a/lib/gl_traits.h b/lib/gl_traits.h index a930eba..934b505 100644 --- a/lib/gl_traits.h +++ b/lib/gl_traits.h @@ -6,9 +6,11 @@ #include <glm/fwd.hpp> template<typename T> struct gl_traits; + struct gl_traits_base { static constexpr GLint size {1}; }; + struct gl_traits_float : public gl_traits_base { static constexpr auto vertexAttribFunc { [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { @@ -16,6 +18,7 @@ struct gl_traits_float : public gl_traits_base { return 1; }}; }; + struct gl_traits_longfloat : public gl_traits_base { static constexpr auto vertexAttribFunc { [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { @@ -23,6 +26,7 @@ struct gl_traits_longfloat : public gl_traits_base { return 1; }}; }; + struct gl_traits_integer : public gl_traits_base { static constexpr auto vertexAttribFunc { [](GLuint index, GLint size, GLenum type, GLsizei stride, const void * pointer) -> GLuint { @@ -30,27 +34,35 @@ struct gl_traits_integer : public gl_traits_base { return 1; }}; }; + template<> struct gl_traits<glm::f32> : public gl_traits_float { static constexpr GLenum type {GL_FLOAT}; }; + template<> struct gl_traits<glm::f64> : public gl_traits_longfloat { static constexpr GLenum type {GL_DOUBLE}; }; + template<> struct gl_traits<glm::int8> : public gl_traits_integer { static constexpr GLenum type {GL_BYTE}; }; + template<> struct gl_traits<glm::int16> : public gl_traits_integer { static constexpr GLenum type {GL_SHORT}; }; + template<> struct gl_traits<glm::int32> : public gl_traits_integer { static constexpr GLenum type {GL_INT}; }; + template<> struct gl_traits<glm::uint8> : public gl_traits_integer { static constexpr GLenum type {GL_UNSIGNED_BYTE}; }; + template<> struct gl_traits<glm::uint16> : public gl_traits_integer { static constexpr GLenum type {GL_UNSIGNED_SHORT}; }; + template<> struct gl_traits<glm::uint32> : public gl_traits_integer { static constexpr GLenum type {GL_UNSIGNED_INT}; }; diff --git a/lib/jsonParse-persistence.cpp b/lib/jsonParse-persistence.cpp index fe8bf8d..5c0011a 100644 --- a/lib/jsonParse-persistence.cpp +++ b/lib/jsonParse-persistence.cpp @@ -93,17 +93,20 @@ namespace Persistence { { strm.put(ch); } + static inline void wrh(std::ostream & strm, char ch) { using namespace std::literals; strm << R"(\u)"sv << std::setw(4) << std::hex << static_cast<int>(ch) << std::setw(1); } + static inline void wre(std::ostream & strm, char e) { strm << '\\' << e; } + template<char E> static inline void wre(std::ostream & strm, char) diff --git a/lib/location.cpp b/lib/location.cpp index 732dd6d..ff7cfa6 100644 --- a/lib/location.cpp +++ b/lib/location.cpp @@ -3,7 +3,7 @@ #include <glm/gtx/transform.hpp> glm::mat4 -Location::getTransform() const +Location::getRotationTransform() const { - return glm::translate(pos) * rotate_ypr(rot); + return rotate_ypr(rot); } diff --git a/lib/location.h b/lib/location.h index 078f5d3..8570fc2 100644 --- a/lib/location.h +++ b/lib/location.h @@ -1,14 +1,16 @@ #pragma once +#include "config/types.h" #include <glm/mat4x4.hpp> -#include <glm/vec3.hpp> class Location { public: - explicit Location(glm::vec3 pos = {}, glm::vec3 rot = {}) : pos {pos}, rot {rot} { } +#ifndef __cpp_aggregate_paren_init + explicit Location(GlobalPosition3D pos = {}, Rotation3D rot = {}) : pos {pos}, rot {rot} { } +#endif - glm::mat4 getTransform() const; + [[nodiscard]] glm::mat4 getRotationTransform() const; - glm::vec3 pos; - glm::vec3 rot; + GlobalPosition3D pos; + Rotation3D rot; }; diff --git a/lib/maths.cpp b/lib/maths.cpp index b8dbd34..5430ef6 100644 --- a/lib/maths.cpp +++ b/lib/maths.cpp @@ -6,7 +6,7 @@ #include <stdexcept> glm::mat4 -flat_orientation(const glm::vec3 & diff) +flat_orientation(const Direction3D & diff) { static const auto oneeighty {glm::rotate(pi, up)}; const auto flatdiff {glm::normalize(!!diff)}; @@ -16,17 +16,17 @@ flat_orientation(const glm::vec3 & diff) } // Helper to lookup into a matrix given an xy vector coordinate -template<typename M> +template<typename M, typename I> inline auto & -operator^(M & m, glm::ivec2 xy) +operator^(M & m, glm::vec<2, I> xy) { return m[xy.x][xy.y]; } // Create a matrix for the angle, given the targets into the matrix -template<typename M> +template<typename M, typename I> inline auto -rotation(typename M::value_type a, glm::ivec2 c1, glm::ivec2 s1, glm::ivec2 c2, glm::ivec2 ms2) +rotation(typename M::value_type a, glm::vec<2, I> c1, glm::vec<2, I> s1, glm::vec<2, I> c2, glm::vec<2, I> ms2) { M m(1); sincosf(a, m ^ s1, m ^ c1); @@ -39,51 +39,51 @@ rotation(typename M::value_type a, glm::ivec2 c1, glm::ivec2 s1, glm::ivec2 c2, glm::mat2 rotate_flat(float a) { - return rotation<glm::mat2>(a, {0, 0}, {0, 1}, {1, 1}, {1, 0}); + return rotation<glm::mat2, glm::length_t>(a, {0, 0}, {0, 1}, {1, 1}, {1, 0}); } // Create a yaw transformation matrix glm::mat4 rotate_yaw(float a) { - return rotation<glm::mat4>(a, {0, 0}, {1, 0}, {1, 1}, {0, 1}); + return rotation<glm::mat4, glm::length_t>(a, {0, 0}, {1, 0}, {1, 1}, {0, 1}); } // Create a roll transformation matrix glm::mat4 rotate_roll(float a) { - return rotation<glm::mat4>(a, {0, 0}, {2, 0}, {2, 2}, {0, 2}); + return rotation<glm::mat4, glm::length_t>(a, {0, 0}, {2, 0}, {2, 2}, {0, 2}); } // Create a pitch transformation matrix glm::mat4 rotate_pitch(float a) { - return rotation<glm::mat4>(a, {1, 1}, {1, 2}, {2, 2}, {2, 1}); + return rotation<glm::mat4, glm::length_t>(a, {1, 1}, {1, 2}, {2, 2}, {2, 1}); } // Create a combined yaw, pitch, roll transformation matrix glm::mat4 -rotate_ypr(glm::vec3 a) +rotate_ypr(Rotation3D a) { return rotate_yaw(a.y) * rotate_pitch(a.x) * rotate_roll(a.z); } glm::mat4 -rotate_yp(glm::vec2 a) +rotate_yp(Rotation2D a) { return rotate_yaw(a.y) * rotate_pitch(a.x); } float -vector_yaw(const glm::vec3 & diff) +vector_yaw(const Direction3D & diff) { return std::atan2(diff.x, diff.y); } float -vector_pitch(const glm::vec3 & diff) +vector_pitch(const Direction3D & diff) { return std::atan(diff.z); } @@ -106,7 +106,7 @@ normalize(float ang) return ang; } -Arc::Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p) : +Arc::Arc(const Position3D & centre3, const Position3D & e0p, const Position3D & e1p) : Arc([&]() -> Arc { const auto diffa = e0p - centre3; const auto diffb = e1p - centre3; @@ -120,8 +120,8 @@ Arc::Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p { } -std::pair<glm::vec2, bool> -find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye) +std::pair<Position2D, bool> +find_arc_centre(Position2D as, float entrys, Position2D bs, float entrye) { if (as == bs) { return {as, false}; @@ -129,8 +129,8 @@ find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye) return find_arc_centre(as, sincosf(entrys + half_pi), bs, sincosf(entrye - half_pi)); } -std::pair<glm::vec2, bool> -find_arc_centre(glm::vec2 as, glm::vec2 ad, glm::vec2 bs, glm::vec2 bd) +std::pair<Position2D, bool> +find_arc_centre(Position2D as, Position2D ad, Position2D bs, Position2D bd) { const auto det = bd.x * ad.y - bd.y * ad.x; if (det != 0) { // near parallel line will yield noisy results @@ -142,7 +142,7 @@ find_arc_centre(glm::vec2 as, glm::vec2 ad, glm::vec2 bs, glm::vec2 bd) } std::pair<float, float> -find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye) +find_arcs_radius(Position2D start, float entrys, Position2D end, float entrye) { const auto getrad = [&](float leftOrRight) { return find_arcs_radius(start, sincosf(entrys + leftOrRight), end, sincosf(entrye + leftOrRight)); @@ -151,7 +151,7 @@ find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye) } float -find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd) +find_arcs_radius(Position2D start, Position2D ad, Position2D end, Position2D bd) { // Short name functions for big forula auto sqrt = [](float v) { @@ -177,12 +177,14 @@ find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd) / (2 * (sq(X) - 2 * X * Z + sq(Z) + sq(Y) - 2 * Y * W + sq(W) - 4)); } -float operator"" _mph(const long double v) +float +operator"" _mph(const long double v) { return static_cast<float>(mph_to_ms(v)); } -float operator"" _kph(const long double v) +float +operator"" _kph(const long double v) { return static_cast<float>(kph_to_ms(v)); } diff --git a/lib/maths.h b/lib/maths.h index b95b706..67b2a15 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -1,5 +1,6 @@ #pragma once +#include "config/types.h" #include <cmath> #include <glm/glm.hpp> #include <glm/gtc/constants.hpp> @@ -9,7 +10,7 @@ struct Arc : public std::pair<float, float> { using std::pair<float, float>::pair; - Arc(const glm::vec3 & centre3, const glm::vec3 & e0p, const glm::vec3 & e1p); + Arc(const Position3D & centre3, const Position3D & e0p, const Position3D & e1p); float operator[](unsigned int i) const @@ -18,19 +19,19 @@ struct Arc : public std::pair<float, float> { } }; -constexpr const glm::vec3 origin {0, 0, 0}; -constexpr const glm::vec3 up {0, 0, 1}; -constexpr const glm::vec3 down {0, 0, -1}; -constexpr const glm::vec3 north {0, 1, 0}; -constexpr const glm::vec3 south {0, -1, 0}; -constexpr const glm::vec3 east {1, 0, 0}; -constexpr const glm::vec3 west {-1, 0, 0}; +constexpr const Position3D origin {0, 0, 0}; +constexpr const Position3D up {0, 0, 1}; +constexpr const Position3D down {0, 0, -1}; +constexpr const Position3D north {0, 1, 0}; +constexpr const Position3D south {0, -1, 0}; +constexpr const Position3D east {1, 0, 0}; +constexpr const Position3D west {-1, 0, 0}; constexpr auto half_pi {glm::half_pi<float>()}; constexpr auto quarter_pi {half_pi / 2}; constexpr auto pi {glm::pi<float>()}; constexpr auto two_pi {glm::two_pi<float>()}; -glm::mat4 flat_orientation(const glm::vec3 & diff); +glm::mat4 flat_orientation(const Rotation3D & diff); // C++ wrapper for C's sincosf, but with references, not pointers inline auto @@ -39,10 +40,10 @@ sincosf(float a, float & s, float & c) return sincosf(a, &s, &c); } -inline glm::vec2 +inline Rotation2D sincosf(float a) { - glm::vec2 sc; + Rotation2D sc; sincosf(a, sc.x, sc.y); return sc; } @@ -51,11 +52,11 @@ glm::mat2 rotate_flat(float); glm::mat4 rotate_roll(float); glm::mat4 rotate_yaw(float); glm::mat4 rotate_pitch(float); -glm::mat4 rotate_yp(glm::vec2); -glm::mat4 rotate_ypr(glm::vec3); +glm::mat4 rotate_yp(Rotation2D); +glm::mat4 rotate_ypr(Rotation3D); -float vector_yaw(const glm::vec3 & diff); -float vector_pitch(const glm::vec3 & diff); +float vector_yaw(const Direction3D & diff); +float vector_pitch(const Direction3D & diff); float round_frac(const float & v, const float & frac); @@ -87,26 +88,26 @@ perspective_divide(glm::vec<4, T, Q> v) return v / v.w; } -constexpr inline glm::vec2 -operator!(const glm::vec3 & v) +constexpr inline Position2D +operator!(const Position3D & v) { return {v.x, v.y}; } -constexpr inline glm::vec3 -operator^(const glm::vec2 & v, float z) +constexpr inline Position3D +operator^(const Position2D & v, float z) { return {v.x, v.y, z}; } constexpr inline glm::vec4 -operator^(const glm::vec3 & v, float w) +operator^(const Position3D & v, float w) { return {v.x, v.y, v.z, w}; } -constexpr inline glm::vec3 -operator!(const glm::vec2 & v) +constexpr inline Position3D +operator!(const Position2D & v) { return v ^ 0.F; } @@ -125,15 +126,15 @@ operator||(const glm::vec<L, T, Q> v1, const T v2) return {v1, v2}; } -inline glm::vec3 -operator%(const glm::vec3 & p, const glm::mat4 & mutation) +inline Position3D +operator%(const Position3D & p, const glm::mat4 & mutation) { const auto p2 = mutation * (p ^ 1); return p2 / p2.w; } -inline glm::vec3 -operator%=(glm::vec3 & p, const glm::mat4 & mutation) +inline Position3D +operator%=(Position3D & p, const glm::mat4 & mutation) { return p = p % mutation; } @@ -146,10 +147,10 @@ arc_length(const Arc & arc) float normalize(float ang); -std::pair<glm::vec2, bool> find_arc_centre(glm::vec2 start, float entrys, glm::vec2 end, float entrye); -std::pair<glm::vec2, bool> find_arc_centre(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd); -std::pair<float, float> find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye); -float find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd); +std::pair<Position2D, bool> find_arc_centre(Position2D start, float entrys, Position2D end, float entrye); +std::pair<Position2D, bool> find_arc_centre(Position2D start, Position2D ad, Position2D end, Position2D bd); +std::pair<float, float> find_arcs_radius(Position2D start, float entrys, Position2D end, float entrye); +float find_arcs_radius(Position2D start, Position2D ad, Position2D end, Position2D bd); template<typename T> auto diff --git a/lib/persistence.cpp b/lib/persistence.cpp index e22d74d..38e2ac6 100644 --- a/lib/persistence.cpp +++ b/lib/persistence.cpp @@ -167,6 +167,7 @@ namespace Persistence { { throw std::logic_error("Default write op shouldn't ever get called"); } + /// LCOV_EXCL_STOP ParseBase::ParseBase() : sharedObjectsInstance {std::make_shared<SharedObjects>()} diff --git a/lib/persistence.h b/lib/persistence.h index 5d71d4c..92f3052 100644 --- a/lib/persistence.h +++ b/lib/persistence.h @@ -153,6 +153,7 @@ namespace Persistence { }; struct Persistable; + struct PersistenceStore { using SelectionFactory = std::function<SelectionPtr()>; PersistenceStore() = default; @@ -163,6 +164,7 @@ namespace Persistence { enum class NameAction { Push, HandleAndContinue, Ignore }; using NameActionSelection = std::pair<NameAction, SelectionPtr>; + template<typename Helper, typename T> [[nodiscard]] inline bool persistValue(const std::string_view key, T & value) @@ -267,6 +269,7 @@ namespace Persistence { template<glm::length_t L, typename T, glm::qualifier Q> struct SelectionT<glm::vec<L, T, Q>> : public SelectionT<std::span<T>> { SelectionT(glm::vec<L, T, Q> & v) : SelectionT<std::span<T>> {spn}, spn {&v[0], L} { } + std::span<T> spn; }; @@ -316,6 +319,7 @@ namespace Persistence { MapByMember(Map & m) : Persistence::SelectionT<Type> {s}, map {m} { } using Persistence::SelectionT<Type>::SelectionT; + void endObject(Persistence::Stack & stk) override { @@ -332,7 +336,9 @@ namespace Persistence { template<typename Container, typename Type = typename Container::value_type> struct Appender : public Persistence::SelectionT<Type> { Appender(Container & c) : Persistence::SelectionT<Type> {s}, container {c} { } + using Persistence::SelectionT<Type>::SelectionT; + void endObject(Persistence::Stack & stk) override { @@ -407,6 +413,7 @@ namespace Persistence { { return std::dynamic_pointer_cast<T>(Persistence::ParseBase::sharedObjects.lock()->at(k)); } + template<typename... T> static auto emplaceShared(T &&... v) @@ -421,6 +428,7 @@ namespace Persistence { inline static thread_local SharedObjectsWPtr sharedObjects; SharedObjectsPtr sharedObjectsInstance; }; + // TODO Move these using SeenSharedObjects = std::map<void *, std::string>; inline SeenSharedObjects seenSharedObjects; @@ -428,6 +436,7 @@ namespace Persistence { template<typename Ptr> struct SelectionPtrBase : public SelectionV<Ptr> { static constexpr auto shared = std::is_copy_assignable_v<Ptr>; using T = typename Ptr::element_type; + struct SelectionObj : public SelectionV<Ptr> { struct MakeObjectByTypeName : public SelectionV<Ptr> { using SelectionV<Ptr>::SelectionV; @@ -55,6 +55,7 @@ public: protected: explicit wrapped_ptr(Obj * o) : obj {o} { } + Obj * obj; }; diff --git a/lib/ray.cpp b/lib/ray.cpp index c4e0d8c..9fb3648 100644 --- a/lib/ray.cpp +++ b/lib/ray.cpp @@ -2,13 +2,13 @@ #include <algorithm> Ray -Ray::fromPoints(glm::vec3 start, glm::vec3 p) +Ray::fromPoints(Position3D start, Position3D p) { return {start, glm::normalize(p - start)}; } float -Ray::distanceToLine(const glm::vec3 & p1, const glm::vec3 & e1) const +Ray::distanceToLine(const Position3D & p1, const Position3D & e1) const { // https://en.wikipedia.org/wiki/Skew_lines const auto diff = p1 - e1; @@ -25,10 +25,10 @@ Ray::distanceToLine(const glm::vec3 & p1, const glm::vec3 & e1) const } bool -Ray::passesCloseToEdges(const std::span<const glm::vec3> positions, float distance) const +Ray::passesCloseToEdges(const std::span<const Position3D> positions, float distance) const { return std::adjacent_find(positions.begin(), positions.end(), - [this, distance](const glm::vec3 & a, const glm::vec3 & b) { + [this, distance](const Position3D & a, const Position3D & b) { return distanceToLine(a, b) <= distance; }) != positions.end(); @@ -1,17 +1,20 @@ #pragma once +#include "config/types.h" #include <glm/glm.hpp> #include <span> class Ray { public: - Ray(glm::vec3 start, glm::vec3 direction) : start {start}, direction {direction} { } +#ifndef __cpp_aggregate_paren_init + Ray(Position3D start, Direction3D direction) : start {start}, direction {direction} { } +#endif - static Ray fromPoints(glm::vec3, glm::vec3); + static Ray fromPoints(Position3D, Position3D); - glm::vec3 start; - glm::vec3 direction; + Position3D start; + Direction3D direction; - float distanceToLine(const glm::vec3 & a, const glm::vec3 & b) const; - bool passesCloseToEdges(const std::span<const glm::vec3> positions, float distance) const; + [[nodiscard]] float distanceToLine(const Position3D & a, const Position3D & b) const; + [[nodiscard]] bool passesCloseToEdges(const std::span<const Position3D> positions, float distance) const; }; diff --git a/lib/resource.h b/lib/resource.h index 37dd657..9af3632 100644 --- a/lib/resource.h +++ b/lib/resource.h @@ -16,5 +16,6 @@ public: Resource::setBasePath(RESDIR); } }; + BOOST_GLOBAL_FIXTURE(SetResourcePath); #endif diff --git a/lib/saxParse-persistence.h b/lib/saxParse-persistence.h index 6043b25..bd5db57 100644 --- a/lib/saxParse-persistence.h +++ b/lib/saxParse-persistence.h @@ -10,6 +10,7 @@ namespace Persistence { private: template<typename T> struct Root : public Persistable { T t {}; + bool persist(PersistenceStore & store) { diff --git a/lib/stdTypeDefs.h b/lib/stdTypeDefs.h index 317cdb3..beab630 100644 --- a/lib/stdTypeDefs.h +++ b/lib/stdTypeDefs.h @@ -6,18 +6,22 @@ template<typename T> struct AnyPtr { // cppcheck-suppress noExplicitConstructor AnyPtr(T * p) : ptr {p} { } + // cppcheck-suppress noExplicitConstructor template<typename S> AnyPtr(const S & p) : ptr {p.get()} { } + auto get() const { return ptr; } + auto operator->() const { return ptr; } + auto & operator*() const { diff --git a/lib/unicode.h b/lib/unicode.h index f69c43c..bc491f3 100644 --- a/lib/unicode.h +++ b/lib/unicode.h @@ -50,6 +50,7 @@ struct utf8_string_view { constexpr utf8_string_view(const Str & str) : begin_ {str.data()}, end_ {str.data() + str.length()} { } + // cppcheck-suppress noExplicitConstructor; NOLINTNEXTLINE(hicpp-explicit-conversions) constexpr utf8_string_view(const char * const str) : utf8_string_view {std::string_view {str}} { } @@ -70,6 +71,7 @@ struct utf8_string_view { private: const char *begin_, *end_; }; + template<> struct std::iterator_traits<utf8_string_view::iter> { using difference_type = size_t; using value_type = uint32_t; diff --git a/lib/worker.h b/lib/worker.h index 0d15ca2..95bb4ec 100644 --- a/lib/worker.h +++ b/lib/worker.h @@ -16,6 +16,7 @@ public: class WorkItem { protected: WorkItem(Worker * worker) : worker {worker} { } + virtual ~WorkItem() = default; NO_MOVE(WorkItem); NO_COPY(WorkItem); @@ -25,6 +26,7 @@ public: { worker->assist(); } + Worker * worker; public: @@ -57,6 +59,7 @@ public: { return instance.addWorkImpl(std::forward<Params>(params)...); } + template<typename T> using WorkPtrT = std::shared_ptr<WorkItemT<T>>; private: |