summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-02-08 18:11:23 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-02-08 18:11:23 +0000
commitca1a83e21d0cdb4b3443252b11789bd8ecff3c86 (patch)
treec62b1049e3823a7b129722bf10c791225361f367
parentSet height when reusing adjacent vertices (diff)
downloadilt-ca1a83e21d0cdb4b3443252b11789bd8ecff3c86.tar.bz2
ilt-ca1a83e21d0cdb4b3443252b11789bd8ecff3c86.tar.xz
ilt-ca1a83e21d0cdb4b3443252b11789bd8ecff3c86.zip
Improve logging and fault detection during mesh mutation
-rw-r--r--game/geoData.cpp34
-rw-r--r--game/geoData.h3
2 files changed, 31 insertions, 6 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index 4cfcf6d..816ce03 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -6,6 +6,9 @@
#include <maths.h>
#include <ranges>
#include <set>
+#ifndef NDEBUG
+# include <stream_support.h>
+#endif
GeoData
GeoData::loadFromAsciiGrid(const std::filesystem::path & input)
@@ -554,6 +557,7 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
}
return std::nullopt;
};
+ sanityCheck();
// Cut along each edge of triangleStrip AB, AC, BC, BD, CD, CE etc
std::map<VertexHandle, const Triangle<3> *> boundaryTriangles;
@@ -602,6 +606,16 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
})) {
continue;
}
+#ifndef NDEBUG
+ CLOG(start);
+ CLOG(startPoint);
+ CLOG(end);
+ CLOG(endPoint);
+ for (const auto v : vv_range(start)) {
+ CLOG(point(v));
+ }
+#endif
+ sanityCheck();
throw std::runtime_error(
std::format("Could not navigate to ({}, {}, {})", endPoint.x, endPoint.y, endPoint.z));
}
@@ -655,6 +669,7 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
}
done.insert(heh);
}
+ sanityCheck();
std::vector<FaceHandle> out;
auto surfaceStripWalk
@@ -686,11 +701,20 @@ GeoData::getGeneration() const
}
void
-GeoData::sanityCheck() const
+GeoData::sanityCheck(const std::source_location & loc) const
{
- if (!std::ranges::all_of(faces(), [this](const auto face) {
- return triangle<2>(face).isUp();
- })) {
- throw std::logic_error("Upside down faces detected");
+ if (const auto upSideDown = std::ranges::count_if(faces(), [this](const auto face) {
+ if (!triangle<2>(face).isUp()) {
+#ifndef NDEBUG
+ for (const auto v : fv_range(face)) {
+ CLOG(point(v));
+ }
+#endif
+ return true;
+ }
+ return false;
+ }) > 0) {
+ throw std::logic_error(std::format(
+ "{} upside down faces detected - checked from {}:{}", upSideDown, loc.function_name(), loc.line()));
}
}
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 <filesystem>
#include <glm/vec2.hpp>
#include <optional>
+#include <source_location>
#include <thirdparty/openmesh/glmcompat.h>
#include <thirdparty/openmesh/helpers.h>
@@ -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<glm::length_t Dim>