From a007ffeed3cfa6af2cbe1053c330ad11927d58de Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 18 Dec 2024 17:24:02 +0000 Subject: Add sanity checking logic to GeoData --- game/geoData.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 79924d3..01582a6 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -98,6 +98,8 @@ public: return property(surface, h); } + void sanityCheck() const; + protected: template [[nodiscard]] Triangle -- cgit v1.2.3 From 20308e0a8d62e575237310b7de919e9c7410a9d7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 22 Dec 2024 12:41:37 +0000 Subject: Store a generation number for GeoData --- game/geoData.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 01582a6..8eda99a 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -84,6 +84,7 @@ public: }; void setHeights(std::span triangleStrip, const SetHeightsOpts &); + [[nodiscard]] size_t getGeneration() const; [[nodiscard]] auto getExtents() const @@ -128,4 +129,5 @@ protected: private: GlobalPosition3D lowerExtent {}, upperExtent {}; + size_t generation {}; }; -- cgit v1.2.3 From 7a0121a612e901585fef39c1b599d53a21cb0afe Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 22 Dec 2024 12:58:57 +0000 Subject: SetHeightOptions surface changed to defaulted pointer --- game/geoData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 8eda99a..92b9b75 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -78,7 +78,7 @@ public: static constexpr auto DEFAULT_NEAR_NODE_TOLERANACE = 500.F; static constexpr auto DEFAULT_MAX_SLOPE = 0.5F; - const Surface & surface; + const Surface * surface = nullptr; RelativeDistance nearNodeTolerance = DEFAULT_NEAR_NODE_TOLERANACE; RelativeDistance maxSlope = DEFAULT_MAX_SLOPE; }; -- cgit v1.2.3 From eb4b851381453c1f60ccb56e966ca4e7b8e80b97 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 30 Dec 2024 13:30:48 +0000 Subject: Fix naming style of getSurface --- game/geoData.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 92b9b75..b3ef22a 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -94,9 +94,9 @@ public: template [[nodiscard]] auto - get_surface(const HandleT h) + getSurface(const HandleT handle) const { - return property(surface, h); + return property(surface, handle); } void sanityCheck() const; -- cgit v1.2.3 From 89068c56f3236b65e392cdc8794c5bc1977e5556 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 30 Dec 2024 17:18:26 +0000 Subject: Pass lots more information during GeoData::walk --- game/geoData.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index b3ef22a..68ce9a2 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -64,13 +64,23 @@ public: [[nodiscard]] IntersectionResult intersectRay(const Ray &) const; [[nodiscard]] IntersectionResult intersectRay(const Ray &, FaceHandle start) const; - void walk(const PointFace & from, const GlobalPosition2D to, const std::function & op) const; - void walkUntil(const PointFace & from, const GlobalPosition2D to, const std::function & op) const; + struct WalkStep { + FaceHandle current; + FaceHandle previous {}; + HalfedgeHandle exitHalfedge {}; + GlobalPosition2D exitPosition {}; + }; + + template using Consumer = const std::function &; + template using Tester = const std::function &; + + void walk(const PointFace & from, const GlobalPosition2D to, Consumer op) const; + void walkUntil(const PointFace & from, const GlobalPosition2D to, Tester op) const; - void boundaryWalk(const std::function &) const; - void boundaryWalk(const std::function &, HalfedgeHandle start) const; - void boundaryWalkUntil(const std::function &) const; - void boundaryWalkUntil(const std::function &, HalfedgeHandle start) const; + void boundaryWalk(Consumer) const; + void boundaryWalk(Consumer, HalfedgeHandle start) const; + void boundaryWalkUntil(Tester) const; + void boundaryWalkUntil(Tester, HalfedgeHandle start) const; [[nodiscard]] HalfedgeHandle findEntry(const GlobalPosition2D from, const GlobalPosition2D to) const; -- cgit v1.2.3 From ca3736b3a896557536c0aa4c0cee1f156e118b54 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 1 Jan 2025 12:53:43 +0000 Subject: Walk terrain along a curve - edge cases exist --- game/geoData.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 68ce9a2..e3fc313 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -74,8 +74,10 @@ public: template using Consumer = const std::function &; template using Tester = const std::function &; - void walk(const PointFace & from, const GlobalPosition2D to, Consumer op) const; - void walkUntil(const PointFace & from, const GlobalPosition2D to, Tester op) const; + void walk(const PointFace & from, GlobalPosition2D to, Consumer op) const; + void walkUntil(const PointFace & from, GlobalPosition2D to, Tester op) const; + void walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Consumer op) const; + void walkUntil(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Tester op) const; void boundaryWalk(Consumer) const; void boundaryWalk(Consumer, HalfedgeHandle start) const; -- cgit v1.2.3 From 917c081ddc1651381f83d8a9b0e095440419814a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Jan 2025 01:09:01 +0000 Subject: Helper to declare and add OpenMesh property declaratively --- game/geoData.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index e3fc313..11ba568 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -10,6 +10,7 @@ #include #include #include +#include struct GeoDataTraits : public OpenMesh::DefaultTraits { FaceAttributes(OpenMesh::Attributes::Status); @@ -22,9 +23,7 @@ struct GeoDataTraits : public OpenMesh::DefaultTraits { class GeoData : public OpenMesh::TriMesh_ArrayKernelT { private: - GeoData(); - - OpenMesh::FPropHandleT surface; + const OpenMesh::Helpers::Property surface {this}; public: static GeoData loadFromAsciiGrid(const std::filesystem::path &); -- cgit v1.2.3 From ee636e6c5da87e52e1d40e97ce95ed0765f9e819 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Jan 2025 11:59:24 +0000 Subject: Return surface face list from setHeights --- game/geoData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 11ba568..2bdc60d 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -94,7 +94,7 @@ public: RelativeDistance maxSlope = DEFAULT_MAX_SLOPE; }; - void setHeights(std::span triangleStrip, const SetHeightsOpts &); + std::vector setHeights(std::span triangleStrip, const SetHeightsOpts &); [[nodiscard]] size_t getGeneration() const; [[nodiscard]] auto -- cgit v1.2.3 From b5899aae753287805967ec5241bc0063f5c95a4d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Jan 2025 12:25:16 +0000 Subject: Include arc angle in curved terrain walk --- game/geoData.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 2bdc60d..7e4c28f 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -70,13 +70,18 @@ public: GlobalPosition2D exitPosition {}; }; + struct WalkStepCurve : public WalkStep { + Angle angle {}; + }; + template using Consumer = const std::function &; template using Tester = const std::function &; void walk(const PointFace & from, GlobalPosition2D to, Consumer op) const; void walkUntil(const PointFace & from, GlobalPosition2D to, Tester op) const; - void walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Consumer op) const; - void walkUntil(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Tester op) const; + void walk(const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Consumer op) const; + void walkUntil( + const PointFace & from, GlobalPosition2D to, GlobalPosition2D centre, Tester op) const; void boundaryWalk(Consumer) const; void boundaryWalk(Consumer, HalfedgeHandle start) const; -- cgit v1.2.3 From 1aba027462a861f2c1155672792dbbe555d7dc0a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 13 Jan 2025 01:45:43 +0000 Subject: Add distance helper Works with integer positions, first template param allows forcing to N dimensions --- game/geoData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 7e4c28f..390a443 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -136,7 +136,7 @@ protected: [[nodiscard]] HalfedgeHandle findBoundaryStart() const; [[nodiscard]] RelativePosition3D difference(const HalfedgeHandle) const; - [[nodiscard]] RelativeDistance length(const HalfedgeHandle) const; + template [[nodiscard]] RelativeDistance length(const HalfedgeHandle) const; [[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const; void updateAllVertexNormals(); -- cgit v1.2.3 From ca1a83e21d0cdb4b3443252b11789bd8ecff3c86 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 8 Feb 2025 18:11:23 +0000 Subject: Improve logging and fault detection during mesh mutation --- game/geoData.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 390a443..7c11b07 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -115,7 +116,7 @@ public: return property(surface, handle); } - void sanityCheck() const; + void sanityCheck(const std::source_location & = std::source_location::current()) const; protected: template -- cgit v1.2.3 From e608c8644bb9573c2e36a18a3f0404d6a284cfee Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 9 Feb 2025 12:52:37 +0000 Subject: Big of validation on getSurface --- game/geoData.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 7c11b07..03a2b3a 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -110,9 +110,11 @@ public: } template + requires(std::derived_from) [[nodiscard]] auto getSurface(const HandleT handle) const { + assert(handle.is_valid()); return property(surface, handle); } -- cgit v1.2.3 From ec29d7bb5e786549eaa960016ddf511fad010cc5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 9 Feb 2025 15:23:15 +0000 Subject: Split GeoData mesh basics into a subclass Declutters the class for terrain related things --- game/geoData.h | 74 +++------------------------------------------------------- 1 file changed, 3 insertions(+), 71 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 03a2b3a..d486f22 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -1,28 +1,12 @@ #pragma once #include "collections.h" // IWYU pragma: keep IterableCollection -#include "config/types.h" -#include "ray.h" +#include "geoDataMesh.h" #include "surface.h" -#include "triangle.h" -#include #include #include -#include -#include -#include -#include - -struct GeoDataTraits : public OpenMesh::DefaultTraits { - FaceAttributes(OpenMesh::Attributes::Status); - EdgeAttributes(OpenMesh::Attributes::Status); - VertexAttributes(OpenMesh::Attributes::Normal | OpenMesh::Attributes::Status); - HalfedgeAttributes(OpenMesh::Attributes::Status); - using Point = GlobalPosition3D; - using Normal = Normal3D; -}; -class GeoData : public OpenMesh::TriMesh_ArrayKernelT { +class GeoData : public GeoDataMesh { private: const OpenMesh::Helpers::Property surface {this}; @@ -30,35 +14,6 @@ public: static GeoData loadFromAsciiGrid(const std::filesystem::path &); static GeoData createFlat(GlobalPosition2D lower, GlobalPosition2D upper, GlobalDistance h); - struct PointFace { - // NOLINTNEXTLINE(hicpp-explicit-conversions) - PointFace(const GlobalPosition2D p) : point {p} { } - - PointFace(const GlobalPosition2D p, FaceHandle face) : point {p}, _face {face} { } - - PointFace(const GlobalPosition2D p, const GeoData *); - PointFace(const GlobalPosition2D p, const GeoData *, FaceHandle start); - - const GlobalPosition2D point; - [[nodiscard]] FaceHandle face(const GeoData *) const; - [[nodiscard]] FaceHandle face(const GeoData *, FaceHandle start) const; - - [[nodiscard]] bool - isLocated() const - { - return _face.is_valid(); - } - - private: - mutable FaceHandle _face {}; - }; - - template using Triangle = ::Triangle; - - [[nodiscard]] FaceHandle findPoint(GlobalPosition2D) const; - [[nodiscard]] FaceHandle findPoint(GlobalPosition2D, FaceHandle start) const; - - [[nodiscard]] GlobalPosition3D positionAt(const PointFace &) const; using IntersectionLocation = std::pair; using IntersectionResult = std::optional; [[nodiscard]] IntersectionResult intersectRay(const Ray &) const; @@ -89,7 +44,7 @@ public: void boundaryWalkUntil(Tester) const; void boundaryWalkUntil(Tester, HalfedgeHandle start) const; - [[nodiscard]] HalfedgeHandle findEntry(const GlobalPosition2D from, const GlobalPosition2D to) const; + [[nodiscard]] HalfedgeHandle findEntry(GlobalPosition2D from, GlobalPosition2D to) const; struct SetHeightsOpts { static constexpr auto DEFAULT_NEAR_NODE_TOLERANACE = 500.F; @@ -118,30 +73,7 @@ public: return property(surface, handle); } - void sanityCheck(const std::source_location & = std::source_location::current()) const; - protected: - template - [[nodiscard]] Triangle - triangle(FaceHandle face) const - { - Triangle triangle; - std::ranges::transform(fv_range(face), triangle.begin(), [this](auto vertex) { - return point(vertex); - }); - return triangle; - } - - [[nodiscard]] static bool triangleContainsPoint(const GlobalPosition2D, const Triangle<2> &); - [[nodiscard]] bool triangleContainsPoint(const GlobalPosition2D, FaceHandle) const; - [[nodiscard]] static bool triangleOverlapsTriangle(const Triangle<2> &, const Triangle<2> &); - [[nodiscard]] static bool triangleContainsTriangle(const Triangle<2> &, const Triangle<2> &); - [[nodiscard]] HalfedgeHandle findBoundaryStart() const; - [[nodiscard]] RelativePosition3D difference(const HalfedgeHandle) const; - - template [[nodiscard]] RelativeDistance length(const HalfedgeHandle) const; - [[nodiscard]] GlobalPosition3D centre(const HalfedgeHandle) const; - void updateAllVertexNormals(); template void updateAllVertexNormals(const R &); void updateVertexNormal(VertexHandle); -- cgit v1.2.3 From c9d9aedb9f29725e1106ce1f7ddbc1707400d105 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Feb 2025 20:07:46 +0000 Subject: Replace mesh generation counter with afterChange event --- game/geoData.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index d486f22..3d5ea5d 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -56,7 +56,6 @@ public: }; std::vector setHeights(std::span triangleStrip, const SetHeightsOpts &); - [[nodiscard]] size_t getGeneration() const; [[nodiscard]] auto getExtents() const @@ -77,8 +76,8 @@ protected: void updateAllVertexNormals(); template void updateAllVertexNormals(const R &); void updateVertexNormal(VertexHandle); + virtual void afterChange(); private: GlobalPosition3D lowerExtent {}, upperExtent {}; - size_t generation {}; }; -- cgit v1.2.3 From 4b175adffdf68f35589ed48c82baa15723a9af0a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Thu, 13 Feb 2025 19:57:41 +0000 Subject: Move basic setHeights lambdas into proper helper functions --- game/geoData.h | 1 + 1 file changed, 1 insertion(+) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 3d5ea5d..1a93d03 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -73,6 +73,7 @@ public: } protected: + [[nodiscard]] VertexHandle setPoint(GlobalPosition3D point, const SetHeightsOpts &); void updateAllVertexNormals(); template void updateAllVertexNormals(const R &); void updateVertexNormal(VertexHandle); -- cgit v1.2.3 From f3aa7850519bf022689192e7d52ff380daa9f2d1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 17 Feb 2025 18:45:30 +0000 Subject: Refactor GeoData::setHeights until a struct made of a logical breakdown of the process --- game/geoData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 1a93d03..586b48d 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -73,7 +73,7 @@ public: } protected: - [[nodiscard]] VertexHandle setPoint(GlobalPosition3D point, const SetHeightsOpts &); + [[nodiscard]] VertexHandle setPoint(GlobalPosition3D point, RelativeDistance nearNodeTolerance); void updateAllVertexNormals(); template void updateAllVertexNormals(const R &); void updateVertexNormal(VertexHandle); -- cgit v1.2.3 From 7c04c368fe0694b38e2ab46aca078d921c7d44b1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 24 Feb 2025 00:10:07 +0000 Subject: Don't rely on triangle centroid not already having a surface --- game/geoData.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'game/geoData.h') diff --git a/game/geoData.h b/game/geoData.h index 586b48d..b2a75bd 100644 --- a/game/geoData.h +++ b/game/geoData.h @@ -55,7 +55,7 @@ public: RelativeDistance maxSlope = DEFAULT_MAX_SLOPE; }; - std::vector setHeights(std::span triangleStrip, const SetHeightsOpts &); + std::set setHeights(std::span triangleStrip, const SetHeightsOpts &); [[nodiscard]] auto getExtents() const -- cgit v1.2.3