File: quadtreeworld.hpp

package info (click to toggle)
openmw 0.49.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,992 kB
  • sloc: cpp: 372,479; xml: 2,149; sh: 1,403; python: 797; makefile: 26
file content (113 lines) | stat: -rw-r--r-- 3,624 bytes parent folder | download
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef COMPONENTS_TERRAIN_QUADTREEWORLD_H
#define COMPONENTS_TERRAIN_QUADTREEWORLD_H

#include "terraingrid.hpp"

#include <atomic>
#include <memory>
#include <mutex>

#include <components/esm/refid.hpp>

namespace osg
{
    class NodeVisitor;
    class Group;
    class Stats;
}

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, ESM::RefId worldspace, double expiryDelay);

        ~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() {}
            ChunkManager() = default;
            ChunkManager(ESM::RefId worldspace)
                : ChunkManager()
            {
                mWorldspace = worldspace;
            }
            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; }

        protected:
            ESM::RefId mWorldspace = ESM::RefId();

        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