21 #include <Qt3DCore/QEntity>
25 QgsChunkNode::QgsChunkNode(
const QgsChunkNodeId &nodeId,
const QgsAABB &bbox,
float error, QgsChunkNode *parent )
31 , mLoaderQueueEntry( nullptr )
32 , mReplacementQueueEntry( nullptr )
35 , mUpdaterFactory( nullptr )
39 for (
int i = 0; i < 8; ++i )
40 mChildren[i] =
nullptr;
43 QgsChunkNode::~QgsChunkNode()
45 Q_ASSERT( mState == Skeleton );
46 Q_ASSERT( !mLoaderQueueEntry );
47 Q_ASSERT( !mReplacementQueueEntry );
50 Q_ASSERT( !mUpdater );
51 Q_ASSERT( !mUpdaterFactory );
53 for (
int i = 0; i < childCount(); ++i )
57 bool QgsChunkNode::allChildChunksResident( QTime currentTime )
const
59 Q_ASSERT( mChildCount != -1 );
60 for (
int i = 0; i < childCount(); ++i )
64 if ( mChildren[i]->mHasData && !mChildren[i]->mEntity )
66 Q_UNUSED( currentTime )
73 void QgsChunkNode::populateChildren(
const QVector<QgsChunkNode *> &children )
75 Q_ASSERT( mChildCount == -1 );
76 mChildCount = children.count();
77 for (
int i = 0; i < mChildCount; ++i )
78 mChildren[i] = children[i];
81 int QgsChunkNode::level()
const
84 QgsChunkNode *p = mParent;
93 QList<QgsChunkNode *> QgsChunkNode::descendants()
95 QList<QgsChunkNode *> lst;
98 for (
int i = 0; i < childCount(); ++i )
101 lst << mChildren[i]->descendants();
107 void QgsChunkNode::setQueuedForLoad( QgsChunkListEntry *entry )
109 Q_ASSERT( mState == Skeleton );
110 Q_ASSERT( !mLoaderQueueEntry );
111 Q_ASSERT( !mLoader );
113 mState = QgsChunkNode::QueuedForLoad;
114 mLoaderQueueEntry = entry;
117 void QgsChunkNode::cancelQueuedForLoad()
119 Q_ASSERT( mState == QueuedForLoad );
120 Q_ASSERT( mLoaderQueueEntry );
122 delete mLoaderQueueEntry;
123 mLoaderQueueEntry =
nullptr;
125 mState = QgsChunkNode::Skeleton;
128 void QgsChunkNode::setLoading( QgsChunkLoader *chunkLoader )
130 Q_ASSERT( mState == QueuedForLoad );
131 Q_ASSERT( !mLoader );
132 Q_ASSERT( mLoaderQueueEntry );
135 mLoader = chunkLoader;
136 mLoaderQueueEntry =
nullptr;
139 void QgsChunkNode::cancelLoading()
141 Q_ASSERT( mState == QgsChunkNode::Loading );
143 Q_ASSERT( !mLoaderQueueEntry );
144 Q_ASSERT( !mEntity );
145 Q_ASSERT( !mReplacementQueueEntry );
149 mState = QgsChunkNode::Skeleton;
152 void QgsChunkNode::setLoaded( Qt3DCore::QEntity *newEntity )
154 Q_ASSERT( mState == QgsChunkNode::Loading );
156 Q_ASSERT( !mLoaderQueueEntry );
157 Q_ASSERT( !mReplacementQueueEntry );
160 mEntityCreatedTime = QTime::currentTime();
164 mState = QgsChunkNode::Loaded;
165 mReplacementQueueEntry =
new QgsChunkListEntry(
this );
168 void QgsChunkNode::unloadChunk()
170 Q_ASSERT( mState == QgsChunkNode::Loaded );
172 Q_ASSERT( mReplacementQueueEntry );
177 delete mReplacementQueueEntry;
178 mReplacementQueueEntry =
nullptr;
179 mState = QgsChunkNode::Skeleton;
182 void QgsChunkNode::setQueuedForUpdate( QgsChunkListEntry *entry, QgsChunkQueueJobFactory *updateJobFactory )
184 Q_ASSERT( mState == QgsChunkNode::Loaded );
186 Q_ASSERT( mReplacementQueueEntry );
187 Q_ASSERT( !mLoaderQueueEntry );
188 Q_ASSERT( !mUpdater );
189 Q_ASSERT( !mUpdaterFactory );
191 mState = QueuedForUpdate;
192 mLoaderQueueEntry = entry;
193 mUpdaterFactory = updateJobFactory;
196 void QgsChunkNode::cancelQueuedForUpdate()
198 Q_ASSERT( mState == QueuedForUpdate );
200 Q_ASSERT( mLoaderQueueEntry );
201 Q_ASSERT( mUpdaterFactory );
202 Q_ASSERT( !mUpdater );
205 mUpdaterFactory =
nullptr;
207 delete mLoaderQueueEntry;
208 mLoaderQueueEntry =
nullptr;
211 void QgsChunkNode::setUpdating()
213 Q_ASSERT( mState == QgsChunkNode::QueuedForUpdate );
215 Q_ASSERT( mReplacementQueueEntry );
216 Q_ASSERT( mLoaderQueueEntry );
217 Q_ASSERT( !mUpdater );
218 Q_ASSERT( mUpdaterFactory );
221 mUpdater = mUpdaterFactory->createJob(
this );
222 mUpdaterFactory =
nullptr;
223 mLoaderQueueEntry =
nullptr;
226 void QgsChunkNode::cancelUpdating()
228 Q_ASSERT( mState == QgsChunkNode::Updating );
229 Q_ASSERT( mUpdater );
230 Q_ASSERT( !mLoaderQueueEntry );
237 void QgsChunkNode::setUpdated()
239 Q_ASSERT( mState == QgsChunkNode::Updating );
240 Q_ASSERT( mUpdater );
241 Q_ASSERT( !mLoaderQueueEntry );
242 Q_ASSERT( mReplacementQueueEntry );
246 mState = QgsChunkNode::Loaded;
249 void QgsChunkNode::setExactBbox(
const QgsAABB &box )