2017-03-08 00:53:13 +00:00
|
|
|
#ifndef COMPONENTS_TERRAIN_QUADTREEWORLD_H
|
|
|
|
#define COMPONENTS_TERRAIN_QUADTREEWORLD_H
|
|
|
|
|
2019-02-28 18:19:48 +00:00
|
|
|
#include "terraingrid.hpp"
|
2017-03-08 00:53:13 +00:00
|
|
|
|
2022-07-18 16:40:26 +00:00
|
|
|
#include <atomic>
|
2021-09-27 19:25:39 +00:00
|
|
|
#include <memory>
|
2020-06-25 19:46:07 +00:00
|
|
|
#include <mutex>
|
2017-03-09 02:31:30 +00:00
|
|
|
|
2023-05-14 18:00:02 +00:00
|
|
|
#include <components/esm/refid.hpp>
|
|
|
|
|
2017-03-08 00:53:13 +00:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class NodeVisitor;
|
2022-07-18 16:11:37 +00:00
|
|
|
class Group;
|
|
|
|
class Stats;
|
2017-03-08 00:53:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace Terrain
|
|
|
|
{
|
|
|
|
class RootNode;
|
2017-03-09 01:03:51 +00:00
|
|
|
class ViewDataMap;
|
2021-10-31 11:59:34 +00:00
|
|
|
class ViewData;
|
|
|
|
struct ViewDataEntry;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2021-09-27 19:25:39 +00:00
|
|
|
class DebugChunkManager;
|
2017-03-08 00:53:13 +00:00
|
|
|
|
2019-02-20 13:37:00 +00:00
|
|
|
/// @brief Terrain implementation that loads cells into a Quad Tree, with geometry LOD and texture LOD.
|
2019-02-28 18:19:48 +00:00
|
|
|
class QuadTreeWorld
|
|
|
|
: public TerrainGrid // note: derived from TerrainGrid is only to render default cells (see loadCell)
|
2017-03-08 00:53:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-09-29 15:10:58 +00:00
|
|
|
QuadTreeWorld(osg::Group* parent, osg::Group* compileRoot, Resource::ResourceSystem* resourceSystem,
|
|
|
|
Storage* storage, unsigned int nodeMask, unsigned int preCompileMask, unsigned int borderMask,
|
|
|
|
int compMapResolution, float comMapLevel, float lodFactor, int vertexLodMod, float maxCompGeometrySize,
|
2023-10-28 13:14:00 +00:00
|
|
|
bool debugChunks, ESM::RefId worldspace, double expiryDelay);
|
2019-02-20 13:37:00 +00:00
|
|
|
|
2017-03-08 00:53:13 +00:00
|
|
|
~QuadTreeWorld();
|
|
|
|
|
|
|
|
void accept(osg::NodeVisitor& nv);
|
|
|
|
|
2020-06-16 11:31:50 +00:00
|
|
|
void enable(bool enabled) override;
|
2017-03-09 01:17:25 +00:00
|
|
|
|
2021-10-31 11:59:34 +00:00
|
|
|
void setViewDistance(float distance) override;
|
2019-02-20 13:37:00 +00:00
|
|
|
|
2020-06-16 11:31:50 +00:00
|
|
|
void cacheCell(View* view, int x, int y) override {}
|
2019-02-28 18:19:48 +00:00
|
|
|
/// @note Not thread safe.
|
2020-06-16 11:31:50 +00:00
|
|
|
void loadCell(int x, int y) override;
|
2019-02-28 18:19:48 +00:00
|
|
|
/// @note Not thread safe.
|
2020-06-16 11:31:50 +00:00
|
|
|
void unloadCell(int x, int y) override;
|
2017-03-09 20:05:25 +00:00
|
|
|
|
2020-06-16 11:31:50 +00:00
|
|
|
View* createView() override;
|
2021-09-05 15:43:46 +00:00
|
|
|
void preload(View* view, const osg::Vec3f& eyePoint, const osg::Vec4i& cellgrid, std::atomic<bool>& abort,
|
|
|
|
Loading::Reporter& reporter) override;
|
2020-05-08 13:37:00 +00:00
|
|
|
void rebuildViews() override;
|
2017-03-09 03:17:25 +00:00
|
|
|
|
2020-06-16 11:31:50 +00:00
|
|
|
void reportStats(unsigned int frameNumber, osg::Stats* stats) override;
|
2017-03-09 18:52:30 +00:00
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
class ChunkManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ChunkManager() {}
|
2023-05-19 22:31:38 +00:00
|
|
|
ChunkManager() = default;
|
2023-05-14 18:00:02 +00:00
|
|
|
ChunkManager(ESM::RefId worldspace)
|
|
|
|
: ChunkManager()
|
|
|
|
{
|
|
|
|
mWorldspace = worldspace;
|
|
|
|
}
|
2020-01-12 07:42:47 +00:00
|
|
|
virtual osg::ref_ptr<osg::Node> getChunk(float size, const osg::Vec2f& center, unsigned char lod,
|
|
|
|
unsigned int lodFlags, bool activeGrid, const osg::Vec3f& viewPoint, bool compile)
|
|
|
|
= 0;
|
2019-06-13 13:37:00 +00:00
|
|
|
virtual unsigned int getNodeMask() { return 0; }
|
2021-09-09 21:10:22 +00:00
|
|
|
|
|
|
|
void setViewDistance(float viewDistance) { mViewDistance = viewDistance; }
|
|
|
|
float getViewDistance() const { return mViewDistance; }
|
2021-11-08 09:27:42 +00:00
|
|
|
|
|
|
|
// Automatically set by addChunkManager based on getViewDistance()
|
|
|
|
unsigned int getMaxLodLevel() const { return mMaxLodLevel; }
|
|
|
|
void setMaxLodLevel(unsigned int level) { mMaxLodLevel = level; }
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2023-05-14 18:00:02 +00:00
|
|
|
protected:
|
2023-05-19 22:31:38 +00:00
|
|
|
ESM::RefId mWorldspace = ESM::RefId();
|
2023-05-14 18:00:02 +00:00
|
|
|
|
2021-09-09 21:10:22 +00:00
|
|
|
private:
|
2023-05-19 22:31:38 +00:00
|
|
|
float mViewDistance = 0.f;
|
|
|
|
unsigned int mMaxLodLevel = ~0u;
|
2019-06-13 13:37:00 +00:00
|
|
|
};
|
|
|
|
void addChunkManager(ChunkManager*);
|
|
|
|
|
2017-03-08 00:53:13 +00:00
|
|
|
private:
|
2017-03-09 02:31:30 +00:00
|
|
|
void ensureQuadTreeBuilt();
|
2021-11-08 09:27:42 +00:00
|
|
|
void loadRenderingNode(
|
|
|
|
ViewDataEntry& entry, ViewData* vd, float cellWorldSize, const osg::Vec4i& gridbounds, bool compile);
|
2017-03-09 02:31:30 +00:00
|
|
|
|
2017-03-08 00:53:13 +00:00
|
|
|
osg::ref_ptr<RootNode> mRootNode;
|
|
|
|
|
2017-03-09 01:03:51 +00:00
|
|
|
osg::ref_ptr<ViewDataMap> mViewDataMap;
|
|
|
|
|
2019-06-13 13:37:00 +00:00
|
|
|
std::vector<ChunkManager*> mChunkManagers;
|
|
|
|
|
2020-06-25 19:46:07 +00:00
|
|
|
std::mutex mQuadTreeMutex;
|
2017-03-08 00:53:13 +00:00
|
|
|
bool mQuadTreeBuilt;
|
2019-02-27 15:41:07 +00:00
|
|
|
float mLodFactor;
|
2019-02-20 13:37:00 +00:00
|
|
|
int mVertexLodMod;
|
2019-02-20 13:37:00 +00:00
|
|
|
float mViewDistance;
|
2020-01-12 07:42:47 +00:00
|
|
|
float mMinSize;
|
2021-09-06 19:10:03 +00:00
|
|
|
bool mDebugTerrainChunks;
|
2021-09-27 19:25:39 +00:00
|
|
|
std::unique_ptr<DebugChunkManager> mDebugChunkManager;
|
2017-03-08 00:53:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|