/
chunkedentity.h
96 lines (71 loc) · 2.6 KB
/
chunkedentity.h
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
#ifndef CHUNKEDENTITY_H
#define CHUNKEDENTITY_H
#include <Qt3DCore/QEntity>
class AABB;
class ChunkNode;
class ChunkList;
class ChunkQueueJob;
class ChunkLoaderFactory;
class ChunkBoundsEntity;
class ChunkQueueJobFactory;
#include <QVector3D>
#include <QMatrix4x4>
//! Records some bits about the scene
class SceneState
{
public:
QVector3D cameraPos;
float cameraFov;
int screenSizePx;
QMatrix4x4 viewProjectionMatrix; //!< For frustum culling
};
#include <QTime>
//! Implementation of entity that handles chunks of data organized in quadtree with loading data when necessary
//! based on data error and unloading of data when data are not necessary anymore
class ChunkedEntity : public Qt3DCore::QEntity
{
Q_OBJECT
public:
ChunkedEntity( const AABB &rootBbox, float rootError, float tau, int maxLevel, ChunkLoaderFactory *loaderFactory, Qt3DCore::QNode *parent = nullptr );
~ChunkedEntity();
//!< Called when e.g. camera changes and entity may need updated
void update( const SceneState &state );
bool needsUpdate; //!< A chunk has been loaded recently - let's display it!
void setShowBoundingBoxes( bool enabled );
//! update already loaded nodes (add to the queue)
void updateNodes( const QList<ChunkNode *> &nodes, ChunkQueueJobFactory *updateJobFactory );
QList<ChunkNode *> getActiveNodes() const { return activeNodes; }
ChunkNode *getRootNode() const { return rootNode; }
protected:
void cancelActiveJob();
private:
void update( ChunkNode *node, const SceneState &state );
//! make sure that the chunk will be loaded soon (if not loaded yet) and not unloaded anytime soon (if loaded already)
void requestResidency( ChunkNode *node );
void startJob();
private slots:
void onActiveJobFinished();
protected:
//! root node of the quadtree hierarchy
ChunkNode *rootNode;
//! max. allowed screen space error
float tau;
//! maximum allowed depth of quad tree
int maxLevel;
//! factory that creates loaders for individual chunk nodes
ChunkLoaderFactory *chunkLoaderFactory;
//! queue of chunks to be loaded
ChunkList *chunkLoaderQueue;
//! queue of chunk to be eventually replaced
ChunkList *replacementQueue;
QList<ChunkNode *> activeNodes;
int frustumCulled;
// TODO: max. length for loading queue
QTime currentTime;
//! max. length for replacement queue
int maxLoadedChunks;
ChunkBoundsEntity *bboxesEntity;
//! job that is currently being processed (asynchronously in a worker thread)
ChunkQueueJob *activeJob = nullptr;
};
#endif // CHUNKEDENTITY_H