21 #include <Qt3DCore/QEntity>
25 QgsChunkNode::QgsChunkNode(
int x,
int y,
int z,
const QgsAABB &bbox,
float error, QgsChunkNode *parent )
33 , mLoaderQueueEntry( nullptr )
34 , mReplacementQueueEntry( nullptr )
37 , mUpdaterFactory( nullptr )
40 for (
int i = 0; i < 4; ++i )
41 mChildren[i] =
nullptr;
44 QgsChunkNode::~QgsChunkNode()
46 Q_ASSERT( mState == Skeleton );
47 Q_ASSERT( !mLoaderQueueEntry );
48 Q_ASSERT( !mReplacementQueueEntry );
51 Q_ASSERT( !mUpdater );
52 Q_ASSERT( !mUpdaterFactory );
53 for (
int i = 0; i < 4; ++i )
57 bool QgsChunkNode::allChildChunksResident( QTime currentTime )
const
59 for (
int i = 0; i < 4; ++i )
63 if ( mChildren[i]->mHasData && !mChildren[i]->mEntity )
65 Q_UNUSED( currentTime )
72 void QgsChunkNode::ensureAllChildrenExist()
74 float childError = mError / 2;
75 float xc = mBbox.xCenter(), zc = mBbox.zCenter();
76 float ymin = mBbox.yMin;
77 float ymax = mBbox.yMax;
80 mChildren[0] =
new QgsChunkNode( mTileX * 2 + 0, mTileY * 2 + 1, mTileZ + 1,
QgsAABB( mBbox.xMin, ymin, mBbox.zMin, xc, ymax, zc ), childError,
this );
83 mChildren[1] =
new QgsChunkNode( mTileX * 2 + 0, mTileY * 2 + 0, mTileZ + 1,
QgsAABB( mBbox.xMin, ymin, zc, xc, ymax, mBbox.zMax ), childError,
this );
86 mChildren[2] =
new QgsChunkNode( mTileX * 2 + 1, mTileY * 2 + 1, mTileZ + 1,
QgsAABB( xc, ymin, mBbox.zMin, mBbox.xMax, ymax, zc ), childError,
this );
89 mChildren[3] =
new QgsChunkNode( mTileX * 2 + 1, mTileY * 2 + 0, mTileZ + 1,
QgsAABB( xc, ymin, zc, mBbox.xMax, ymax, mBbox.zMax ), childError,
this );
92 int QgsChunkNode::level()
const
95 QgsChunkNode *p = mParent;
104 QList<QgsChunkNode *> QgsChunkNode::descendants()
106 QList<QgsChunkNode *> lst;
109 for (
int i = 0; i < 4; ++i )
112 lst << mChildren[i]->descendants();
118 void QgsChunkNode::setQueuedForLoad( QgsChunkListEntry *entry )
120 Q_ASSERT( mState == Skeleton );
121 Q_ASSERT( !mLoaderQueueEntry );
122 Q_ASSERT( !mLoader );
124 mState = QgsChunkNode::QueuedForLoad;
125 mLoaderQueueEntry = entry;
128 void QgsChunkNode::cancelQueuedForLoad()
130 Q_ASSERT( mState == QueuedForLoad );
131 Q_ASSERT( mLoaderQueueEntry );
133 delete mLoaderQueueEntry;
134 mLoaderQueueEntry =
nullptr;
136 mState = QgsChunkNode::Skeleton;
139 void QgsChunkNode::setLoading( QgsChunkLoader *chunkLoader )
141 Q_ASSERT( mState == QueuedForLoad );
142 Q_ASSERT( !mLoader );
143 Q_ASSERT( mLoaderQueueEntry );
146 mLoader = chunkLoader;
147 mLoaderQueueEntry =
nullptr;
150 void QgsChunkNode::cancelLoading()
152 Q_ASSERT( mState == QgsChunkNode::Loading );
154 Q_ASSERT( !mLoaderQueueEntry );
155 Q_ASSERT( !mEntity );
156 Q_ASSERT( !mReplacementQueueEntry );
160 mState = QgsChunkNode::Skeleton;
163 void QgsChunkNode::setLoaded( Qt3DCore::QEntity *newEntity )
165 Q_ASSERT( mState == QgsChunkNode::Loading );
167 Q_ASSERT( !mLoaderQueueEntry );
168 Q_ASSERT( !mReplacementQueueEntry );
171 mEntityCreatedTime = QTime::currentTime();
175 mState = QgsChunkNode::Loaded;
176 mReplacementQueueEntry =
new QgsChunkListEntry(
this );
179 void QgsChunkNode::unloadChunk()
181 Q_ASSERT( mState == QgsChunkNode::Loaded );
183 Q_ASSERT( mReplacementQueueEntry );
185 mEntity->deleteLater();
187 delete mReplacementQueueEntry;
188 mReplacementQueueEntry =
nullptr;
189 mState = QgsChunkNode::Skeleton;
192 void QgsChunkNode::setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory )
194 Q_ASSERT( mState == QgsChunkNode::Loaded );
196 Q_ASSERT( mReplacementQueueEntry );
197 Q_ASSERT( !mLoaderQueueEntry );
198 Q_ASSERT( !mUpdater );
199 Q_ASSERT( !mUpdaterFactory );
201 mState = QueuedForUpdate;
202 mLoaderQueueEntry = entry;
203 mUpdaterFactory = updateJobFactory;
206 void QgsChunkNode::cancelQueuedForUpdate()
208 Q_ASSERT( mState == QueuedForUpdate );
210 Q_ASSERT( mLoaderQueueEntry );
211 Q_ASSERT( mUpdaterFactory );
212 Q_ASSERT( !mUpdater );
215 mUpdaterFactory =
nullptr;
217 delete mLoaderQueueEntry;
218 mLoaderQueueEntry =
nullptr;
221 void QgsChunkNode::setUpdating()
223 Q_ASSERT( mState == QgsChunkNode::QueuedForUpdate );
225 Q_ASSERT( mReplacementQueueEntry );
226 Q_ASSERT( mLoaderQueueEntry );
227 Q_ASSERT( !mUpdater );
228 Q_ASSERT( mUpdaterFactory );
231 mUpdater = mUpdaterFactory->createJob(
this );
232 mUpdaterFactory =
nullptr;
233 mLoaderQueueEntry =
nullptr;
236 void QgsChunkNode::cancelUpdating()
238 Q_ASSERT( mState == QgsChunkNode::Updating );
239 Q_ASSERT( mUpdater );
240 Q_ASSERT( !mLoaderQueueEntry );
247 void QgsChunkNode::setUpdated()
249 Q_ASSERT( mState == QgsChunkNode::Updating );
250 Q_ASSERT( mUpdater );
251 Q_ASSERT( !mLoaderQueueEntry );
252 Q_ASSERT( mReplacementQueueEntry );
256 mState = QgsChunkNode::Loaded;
259 void QgsChunkNode::setExactBbox(
const QgsAABB &box )