This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
/
GeometryUpdateTask.cpp
99 lines (82 loc) · 3.13 KB
/
GeometryUpdateTask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
Copyright (C) 2009 Erik Ogenvik <erik@ogenvik.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "GeometryUpdateTask.h"
#include <utility>
#include "TerrainPage.h"
#include "TerrainHandler.h"
#include "TerrainShaderUpdateTask.h"
#include "TerrainPageGeometry.h"
#include "HeightMapUpdateTask.h"
#include "ITerrainPageBridge.h"
#include "framework/tasks/TaskExecutionContext.h"
namespace Ember {
namespace OgreView {
namespace Terrain {
GeometryUpdateTask::GeometryUpdateTask(BridgeBoundGeometryPtrVector pages,
std::vector<WFMath::AxisBox<2>> areas,
TerrainHandler& handler,
std::vector<const Terrain::TerrainShader*> shaders,
HeightMapBufferProvider& heightMapBufferProvider,
HeightMap& heightMap) :
mGeometry(std::move(pages)),
mAreas(std::move(areas)),
mHandler(handler),
mShaders(std::move(shaders)),
mHeightMapBufferProvider(heightMapBufferProvider),
mHeightMap(heightMap) {
}
void GeometryUpdateTask::executeTaskInBackgroundThread(Tasks::TaskExecutionContext& context) {
std::vector<Mercator::Segment*> segments;
//first populate the geometry for all pages, and then regenerate the shaders
for (const auto& geometryEntry : mGeometry) {
auto& geometry = geometryEntry.first;
geometry->repopulate();
const SegmentVector& segmentVector = geometry->getValidSegments();
for (const auto& entry : segmentVector) {
segments.push_back(entry.segment);
}
GeometryPtrVector geometries;
geometries.push_back(geometry);
context.executeTask(std::make_unique<TerrainShaderUpdateTask>(geometries, mShaders, mAreas, mHandler.EventLayerUpdated, mHandler.EventTerrainMaterialRecompiled));
}
context.executeTask(std::make_unique<HeightMapUpdateTask>(mHeightMapBufferProvider, mHeightMap, segments));
for (const auto& geometryEntry : mGeometry) {
const TerrainPageGeometryPtr& geometry = geometryEntry.first;
const ITerrainPageBridgePtr& bridge = geometryEntry.second;
if (bridge) {
bridge->updateTerrain(*geometry);
mBridgesToNotify.insert(bridge);
}
}
for (const auto& geometryEntry : mGeometry) {
TerrainPage* page = &(geometryEntry.first)->getPage();
mPages.insert(page);
}
//Release Segment references as soon as we can
mGeometry.clear();
}
bool GeometryUpdateTask::executeTaskInMainThread() {
if (!mBridgesToNotify.empty()) {
auto I = mBridgesToNotify.begin();
(*I)->terrainPageReady();
mBridgesToNotify.erase(I);
return false;
}
mHandler.EventAfterTerrainUpdate(mAreas, mPages);
return true;
}
}
}
}