From 2c2c031765bfbf5eb49a7a6b697e7877a50a8853 Mon Sep 17 00:00:00 2001 From: Kevin Ring Date: Tue, 1 Oct 2024 07:23:01 +1000 Subject: [PATCH] Cleaner std::move'ing of positions during height sampling. --- .../CesiumRuntime/Private/Cesium3DTileset.cpp | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/Source/CesiumRuntime/Private/Cesium3DTileset.cpp b/Source/CesiumRuntime/Private/Cesium3DTileset.cpp index 807d05781..f957ccabf 100644 --- a/Source/CesiumRuntime/Private/Cesium3DTileset.cpp +++ b/Source/CesiumRuntime/Private/Cesium3DTileset.cpp @@ -144,28 +144,31 @@ void ACesium3DTileset::SampleHeightMostDetailed( size_t count = positions.size(); - CesiumAsync::Future future = - this->_pTileset - ? this->_pTileset->sampleHeightMostDetailed(positions) - : getAsyncSystem().createResolvedFuture( - Cesium3DTilesSelection::SampleHeightResult{ - std::move(positions), - std::vector(count, false), - {"Could not sample heights from tileset because it has not " - "been created."}}); - - std::move(future) - .catchImmediately([positions = std::move(positions)]( - std::exception&& exception) mutable { - size_t count = positions.size(); - return Cesium3DTilesSelection::SampleHeightResult{ - std::move(positions), - std::vector(count, false), - {exception.what()}}; - }) - .thenImmediately([this, OnHeightsSampled = std::move(OnHeightsSampled)]( - Cesium3DTilesSelection::SampleHeightResult&& - result) { + auto sampleHeights = [this, &positions]() mutable { + if (this->_pTileset) { + return this->_pTileset->sampleHeightMostDetailed(positions) + .catchImmediately([positions = std::move(positions)]( + std::exception&& exception) mutable { + std::vector sampleSuccess(positions.size(), false); + return Cesium3DTilesSelection::SampleHeightResult{ + std::move(positions), + std::move(sampleSuccess), + {exception.what()}}; + }); + } else { + std::vector sampleSuccess(positions.size(), false); + return getAsyncSystem().createResolvedFuture( + Cesium3DTilesSelection::SampleHeightResult{ + std::move(positions), + std::move(sampleSuccess), + {"Could not sample heights from tileset because it has not " + "been created."}}); + } + }; + + sampleHeights().thenImmediately( + [this, OnHeightsSampled = std::move(OnHeightsSampled)]( + Cesium3DTilesSelection::SampleHeightResult&& result) { if (!IsValid(this)) return;