mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-27 06:26:37 +00:00 
			
		
		
		
	This PR aims to solve all issues with `Groundcover` view distance handling in a satisfying way while preserving other optimisations that benefit other features. The main idea here is not to rely on `ViewData` updates for distance culling calculations because we can not accurately determine distance against lazily updated views. Instead, we perform an accurate measurement in a cull callback we can run every frame in `Groundcover` itself. While we do have to add some code to handle this feature, it is quite loosely coupled code that could be useful elsewhere in the future. These changes should address a performance regression @akortunov experienced.
		
			
				
	
	
		
			91 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			91 lines
		
	
	
	
		
			3.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| #ifndef COMPONENTS_TERRAIN_QUADTREEWORLD_H
 | |
| #define COMPONENTS_TERRAIN_QUADTREEWORLD_H
 | |
| 
 | |
| #include "world.hpp"
 | |
| #include "terraingrid.hpp"
 | |
| 
 | |
| #include <mutex>
 | |
| #include <memory>
 | |
| 
 | |
| namespace osg
 | |
| {
 | |
|     class NodeVisitor;
 | |
| }
 | |
| 
 | |
| namespace Terrain
 | |
| {
 | |
|     class RootNode;
 | |
|     class ViewDataMap;
 | |
|     class ViewData;
 | |
|     struct ViewDataEntry;
 | |
|     
 | |
|     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, bool debugChunks);
 | |
| 
 | |
|         ~QuadTreeWorld();
 | |
| 
 | |
|         void accept(osg::NodeVisitor& nv);
 | |
| 
 | |
|         void enable(bool enabled) override;
 | |
| 
 | |
|         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(){}
 | |
|             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; }
 | |
|         private:
 | |
|             float mViewDistance = 0.f;
 | |
|             unsigned int mMaxLodLevel = ~0u;
 | |
|         };
 | |
|         void addChunkManager(ChunkManager*);
 | |
| 
 | |
|     private:
 | |
|         void ensureQuadTreeBuilt();
 | |
|         void loadRenderingNode(ViewDataEntry& entry, ViewData* vd, float cellWorldSize, const osg::Vec4i &gridbounds, bool compile);
 | |
| 
 | |
|         osg::ref_ptr<RootNode> mRootNode;
 | |
| 
 | |
|         osg::ref_ptr<ViewDataMap> mViewDataMap;
 | |
| 
 | |
|         std::vector<ChunkManager*> mChunkManagers;
 | |
| 
 | |
|         std::mutex mQuadTreeMutex;
 | |
|         bool mQuadTreeBuilt;
 | |
|         float mLodFactor;
 | |
|         int mVertexLodMod;
 | |
|         float mViewDistance;
 | |
|         float mMinSize;
 | |
|         bool mDebugTerrainChunks;
 | |
|         std::unique_ptr<DebugChunkManager> mDebugChunkManager;
 | |
|     };
 | |
| 
 | |
| }
 | |
| 
 | |
| #endif
 |