summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-11-16 00:32:18 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-11-16 00:32:18 +0000
commite75b8bc4b8494c1295a29dbafa6c7876a2bec0ce (patch)
treebaf7c085016d2fc111afcd74999c55e34b4d7f74 /game
parentReuse existing vertices when processing boundary parts (diff)
downloadilt-e75b8bc4b8494c1295a29dbafa6c7876a2bec0ce.tar.bz2
ilt-e75b8bc4b8494c1295a29dbafa6c7876a2bec0ce.tar.xz
ilt-e75b8bc4b8494c1295a29dbafa6c7876a2bec0ce.zip
Reuse existing vertices when processing strip vertices
Diffstat (limited to 'game')
-rw-r--r--game/geoData.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/game/geoData.cpp b/game/geoData.cpp
index fcaea64..f070391 100644
--- a/game/geoData.cpp
+++ b/game/geoData.cpp
@@ -481,9 +481,23 @@ GeoData::setHeights(const std::span<const GlobalPosition3D> triangleStrip, const
// New vertices for each vertex in triangleStrip
std::vector<VertexHandle> newVerts;
newVerts.reserve(newVerts.size());
- std::transform(
- triangleStrip.begin(), triangleStrip.end(), std::back_inserter(newVerts), [this](const auto tsPoint) {
- return split(findPoint(tsPoint), tsPoint);
+ std::transform(triangleStrip.begin(), triangleStrip.end(), std::back_inserter(newVerts),
+ [this, &newVerts](const auto tsPoint) {
+ const auto face = findPoint(tsPoint);
+ if (const auto nearest = std::ranges::min(std::views::iota(fv_begin(face), fv_end(face))
+ | std::views::filter([&newVerts](const auto v) {
+ return !std::ranges::contains(newVerts, *v);
+ })
+ | std::views::transform([this, &tsPoint](const auto v) {
+ return std::make_pair(
+ *v, glm::length(difference(this->point(*v).xy(), tsPoint.xy())));
+ }),
+ {}, &std::pair<VertexHandle, float>::second);
+ nearest.second < 500.F) {
+ point(nearest.first) = tsPoint;
+ return nearest.first;
+ }
+ return split(face, tsPoint);
});
// Create temporary triangles from triangleStrip