@@ -17,14 +17,10 @@ class GltfModifier::NewVersionLoadRequester : public TileLoadRequester {
17
17
18
18
void notifyOfTrigger ();
19
19
20
- private:
21
- void addTilesToQueues ();
22
-
23
- GltfModifier* _pModifier;
24
- const Tile* _pRootTile;
25
- std::vector<Tile::ConstPointer> _workerThreadQueue;
26
- std::vector<Tile::ConstPointer> _mainThreadQueue;
27
- bool _running;
20
+ GltfModifier* pModifier;
21
+ const Tile* pRootTile;
22
+ std::vector<Tile::ConstPointer> workerThreadQueue;
23
+ std::vector<Tile::ConstPointer> mainThreadQueue;
28
24
};
29
25
30
26
GltfModifier::GltfModifier ()
@@ -48,6 +44,7 @@ CesiumAsync::Future<void> GltfModifier::onRegister(
48
44
TilesetContentManager& contentManager,
49
45
const TilesetMetadata& tilesetMetadata,
50
46
const Tile& rootTile) {
47
+ this ->_pNewVersionLoadRequester ->pRootTile = &rootTile;
51
48
contentManager.registerTileRequester (*this ->_pNewVersionLoadRequester );
52
49
53
50
const TilesetExternals& externals = contentManager.getExternals ();
@@ -68,111 +65,68 @@ CesiumAsync::Future<void> GltfModifier::onRegister(
68
65
return asyncSystem.createResolvedFuture ();
69
66
}
70
67
71
- GltfModifier::NewVersionLoadRequester::NewVersionLoadRequester (
72
- GltfModifier* pModifier)
73
- : _pModifier(pModifier),
74
- _pRootTile (nullptr ),
75
- _workerThreadQueue(),
76
- _mainThreadQueue(),
77
- _running(false ) {}
68
+ void GltfModifier::onOldVersionContentLoadingComplete (const Tile& tile) {
69
+ CESIUM_ASSERT (
70
+ tile.getState () == TileLoadState::ContentLoaded ||
71
+ tile.getState () == TileLoadState::Failed ||
72
+ tile.getState () == TileLoadState::FailedTemporarily);
73
+ if (tile.getState () == TileLoadState::ContentLoaded) {
74
+ // Tile just transitioned from ContentLoading -> ContentLoaded, but it did
75
+ // so based on the load version. Add it to the worker thread queue in order
76
+ // to re-run the GltfModifier on it.
77
+ this ->_pNewVersionLoadRequester ->workerThreadQueue .emplace_back (&tile);
78
+ }
79
+ }
78
80
79
- void GltfModifier::NewVersionLoadRequester::notifyOfTrigger () {
80
- this ->_running = true ;
81
- this ->addTilesToQueues ();
81
+ void GltfModifier::onWorkerThreadApplyComplete (const Tile& tile) {
82
+ // GltfModifier::apply just finished, so now we need to do the main-thread
83
+ // processing of the new version.
84
+ this ->_pNewVersionLoadRequester ->mainThreadQueue .emplace_back (&tile);
82
85
}
83
86
84
- void GltfModifier::NewVersionLoadRequester::addTilesToQueues () {
85
- CESIUM_ASSERT (this ->_pRootTile != nullptr );
86
- LoadedConstTileEnumerator enumerator (this ->_pRootTile );
87
+ GltfModifier::NewVersionLoadRequester::NewVersionLoadRequester (
88
+ GltfModifier* pModifier_)
89
+ : pModifier(pModifier_),
90
+ pRootTile (nullptr ),
91
+ workerThreadQueue(),
92
+ mainThreadQueue() {}
93
+
94
+ void GltfModifier::NewVersionLoadRequester::notifyOfTrigger () {
95
+ // Add all already-loaded tiles to this requester worker thread load queue.
96
+ // Tiles that are in ContentLoading will be added to this queue when they
97
+ // finish.
98
+ LoadedConstTileEnumerator enumerator (this ->pRootTile );
87
99
for (const Tile& tile : enumerator) {
88
100
TileLoadState state = tile.getState ();
89
-
90
- // Tiles that are already being loaded will need to finish loading, _then_
91
- // we'll have to apply the modification. Always add them to the queue.
92
- if (state == TileLoadState::ContentLoading) {
93
- this ->_workerThreadQueue .emplace_back (&tile);
94
- }
95
-
96
- // Tiles that are already loaded only need to be added to the queue if they
97
- // have a glTF and it is the wrong version.
98
- if (state != TileLoadState::ContentLoaded && state != TileLoadState::Done)
99
- continue ;
100
-
101
- const TileRenderContent* pRenderContent =
102
- tile.getContent ().getRenderContent ();
103
- if (!pRenderContent)
104
- continue ;
105
-
106
- if (pRenderContent->getModel ().version ==
107
- this ->_pModifier ->getCurrentVersion ()) {
108
- CESIUM_ASSERT (!pRenderContent->getModifiedModel ());
109
- continue ;
110
- }
111
-
112
- if (pRenderContent->getModifiedModel () &&
113
- pRenderContent->getModifiedModel ()->version ==
114
- this ->_pModifier ->getCurrentVersion ()) {
115
- // Worker thread GltfModifier::apply done, need to do main thread loading.
116
- this ->_mainThreadQueue .emplace_back (&tile);
117
- } else {
118
- this ->_workerThreadQueue .emplace_back (&tile);
101
+ if (state == TileLoadState::ContentLoaded || state == TileLoadState::Done) {
102
+ this ->workerThreadQueue .emplace_back (&tile);
119
103
}
120
104
}
121
105
}
122
106
123
107
bool GltfModifier::NewVersionLoadRequester::hasMoreTilesToLoadInWorkerThread ()
124
108
const {
125
- return !this ->_workerThreadQueue .empty ();
109
+ return !this ->workerThreadQueue .empty ();
126
110
}
127
111
128
112
const Tile*
129
113
GltfModifier::NewVersionLoadRequester::getNextTileToLoadInWorkerThread () {
130
- if (!this ->_running ) {
131
- CESIUM_ASSERT (this ->_workerThreadQueue .empty ());
132
- return nullptr ;
133
- }
134
-
135
- CESIUM_ASSERT (!this ->_workerThreadQueue .empty ());
136
- const Tile* pResult = this ->_workerThreadQueue .back ().get ();
137
- this ->_workerThreadQueue .pop_back ();
138
-
139
- if (this ->_workerThreadQueue .empty ()) {
140
- this ->addTilesToQueues ();
141
-
142
- // If both queues are still empty, we're done.
143
- if (this ->_workerThreadQueue .empty () && this ->_mainThreadQueue .empty ()) {
144
- this ->_running = false ;
145
- }
146
- }
147
-
114
+ CESIUM_ASSERT (!this ->workerThreadQueue .empty ());
115
+ const Tile* pResult = this ->workerThreadQueue .back ().get ();
116
+ this ->workerThreadQueue .pop_back ();
148
117
return pResult;
149
118
}
150
119
151
120
bool GltfModifier::NewVersionLoadRequester::hasMoreTilesToLoadInMainThread ()
152
121
const {
153
- return !this ->_mainThreadQueue .empty ();
122
+ return !this ->mainThreadQueue .empty ();
154
123
}
155
124
156
125
const Tile*
157
126
GltfModifier::NewVersionLoadRequester::getNextTileToLoadInMainThread () {
158
- if (!this ->_running ) {
159
- CESIUM_ASSERT (this ->_mainThreadQueue .empty ());
160
- return nullptr ;
161
- }
162
-
163
- CESIUM_ASSERT (!this ->_mainThreadQueue .empty ());
164
- const Tile* pResult = this ->_mainThreadQueue .back ().get ();
165
- this ->_mainThreadQueue .pop_back ();
166
-
167
- if (this ->_mainThreadQueue .empty ()) {
168
- this ->addTilesToQueues ();
169
-
170
- // If both queues are still empty, we're done.
171
- if (this ->_workerThreadQueue .empty () && this ->_mainThreadQueue .empty ()) {
172
- this ->_running = false ;
173
- }
174
- }
175
-
127
+ CESIUM_ASSERT (!this ->mainThreadQueue .empty ());
128
+ const Tile* pResult = this ->mainThreadQueue .back ().get ();
129
+ this ->mainThreadQueue .pop_back ();
176
130
return pResult;
177
131
}
178
132
0 commit comments