Skip to content

Commit

Permalink
Cleaner std::move'ing of positions during height sampling.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Sep 30, 2024
1 parent 1a9ff05 commit 2c2c031
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions Source/CesiumRuntime/Private/Cesium3DTileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,31 @@ void ACesium3DTileset::SampleHeightMostDetailed(

size_t count = positions.size();

CesiumAsync::Future<Cesium3DTilesSelection::SampleHeightResult> future =
this->_pTileset
? this->_pTileset->sampleHeightMostDetailed(positions)
: getAsyncSystem().createResolvedFuture(
Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::vector<bool>(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<bool>(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<bool> sampleSuccess(positions.size(), false);
return Cesium3DTilesSelection::SampleHeightResult{
std::move(positions),
std::move(sampleSuccess),
{exception.what()}};
});
} else {
std::vector<bool> 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;

Expand Down

0 comments on commit 2c2c031

Please sign in to comment.