1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 20:53:52 +00:00
openmw/components/terrain/quadtreeworld.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
3.5 KiB
C++
Raw Normal View History

#ifndef COMPONENTS_TERRAIN_QUADTREEWORLD_H
#define COMPONENTS_TERRAIN_QUADTREEWORLD_H
#include "terraingrid.hpp"
2022-07-18 16:40:26 +00:00
#include <atomic>
#include <memory>
2020-06-25 19:46:07 +00:00
#include <mutex>
2017-03-09 02:31:30 +00:00
#include <components/esm/refid.hpp>
namespace osg
{
class NodeVisitor;
class Group;
class Stats;
}
namespace Terrain
{
class RootNode;
2017-03-09 01:03:51 +00:00
class ViewDataMap;
class ViewData;
struct ViewDataEntry;
2022-09-22 18:26:05 +00:00
class DebugChunkManager;
/// @brief Terrain implementation that loads cells into a Quad Tree, with geometry LOD and texture LOD.
class QuadTreeWorld
: public TerrainGrid // note: derived from TerrainGrid is only to render default cells (see loadCell)
{
public:
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
~QuadTreeWorld();
void accept(osg::NodeVisitor& nv);
void enable(bool enabled) override;
2017-03-09 01:17:25 +00:00
void setViewDistance(float distance) override;
void cacheCell(View* view, int x, int y) override {}
/// @note Not thread safe.
void loadCell(int x, int y) override;
/// @note Not thread safe.
void unloadCell(int x, int y) override;
View* createView() override;
void preload(View* view, const osg::Vec3f& eyePoint, const osg::Vec4i& cellgrid, std::atomic<bool>& abort,
Loading::Reporter& reporter) override;
void rebuildViews() override;
void reportStats(unsigned int frameNumber, osg::Stats* stats) override;
class ChunkManager
{
public:
virtual ~ChunkManager() {}
ChunkManager() = default;
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;
virtual unsigned int getNodeMask() { return 0; }
void setViewDistance(float viewDistance) { mViewDistance = viewDistance; }
float getViewDistance() const { return mViewDistance; }
// 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
protected:
ESM::RefId mWorldspace = ESM::RefId();
private:
float mViewDistance = 0.f;
unsigned int mMaxLodLevel = ~0u;
};
void addChunkManager(ChunkManager*);
private:
2017-03-09 02:31:30 +00:00
void ensureQuadTreeBuilt();
void loadRenderingNode(
ViewDataEntry& entry, ViewData* vd, float cellWorldSize, const osg::Vec4i& gridbounds, bool compile);
2017-03-09 02:31:30 +00:00
osg::ref_ptr<RootNode> mRootNode;
2017-03-09 01:03:51 +00:00
osg::ref_ptr<ViewDataMap> mViewDataMap;
std::vector<ChunkManager*> mChunkManagers;
2020-06-25 19:46:07 +00:00
std::mutex mQuadTreeMutex;
bool mQuadTreeBuilt;
float mLodFactor;
2019-02-20 13:37:00 +00:00
int mVertexLodMod;
float mViewDistance;
2020-01-12 07:42:47 +00:00
float mMinSize;
bool mDebugTerrainChunks;
std::unique_ptr<DebugChunkManager> mDebugChunkManager;
};
}
#endif