File: chunkmanager.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 (126 lines) | stat: -rw-r--r-- 3,578 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
114
115
116
117
118
119
120
121
122
123
124
125
126
#ifndef OPENMW_COMPONENTS_TERRAIN_CHUNKMANAGER_H
#define OPENMW_COMPONENTS_TERRAIN_CHUNKMANAGER_H

#include <tuple>

#include <components/resource/resourcemanager.hpp>

#include "buffercache.hpp"
#include "quadtreeworld.hpp"

namespace osg
{
    class Group;
    class Texture2D;
}

namespace Resource
{
    class SceneManager;
}

namespace Terrain
{

    class TextureManager;
    class CompositeMapRenderer;
    class Storage;
    class CompositeMap;
    class TerrainDrawable;

    struct TemplateKey
    {
        osg::Vec2f mCenter;
        unsigned char mLod;
    };

    inline auto tie(const TemplateKey& v)
    {
        return std::tie(v.mCenter, v.mLod);
    }

    inline bool operator<(const TemplateKey& l, const TemplateKey& r)
    {
        return tie(l) < tie(r);
    }

    inline bool operator==(const TemplateKey& l, const TemplateKey& r)
    {
        return tie(l) == tie(r);
    }

    struct ChunkKey
    {
        osg::Vec2f mCenter;
        unsigned char mLod;
        unsigned mLodFlags;
    };

    inline auto tie(const ChunkKey& v)
    {
        return std::tie(v.mCenter, v.mLod, v.mLodFlags);
    }

    inline bool operator<(const ChunkKey& l, const ChunkKey& r)
    {
        return tie(l) < tie(r);
    }

    inline bool operator<(const ChunkKey& l, const TemplateKey& r)
    {
        return TemplateKey{ .mCenter = l.mCenter, .mLod = l.mLod } < r;
    }

    /// @brief Handles loading and caching of terrain chunks
    class ChunkManager : public Resource::GenericResourceManager<ChunkKey>, public QuadTreeWorld::ChunkManager
    {
    public:
        explicit ChunkManager(Storage* storage, Resource::SceneManager* sceneMgr, TextureManager* textureManager,
            CompositeMapRenderer* renderer, ESM::RefId worldspace, double expiryDelay);

        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) override;

        void setCompositeMapSize(unsigned int size) { mCompositeMapSize = size; }
        void setCompositeMapLevel(float level) { mCompositeMapLevel = level; }
        void setMaxCompositeGeometrySize(float maxCompGeometrySize) { mMaxCompGeometrySize = maxCompGeometrySize; }

        void setNodeMask(unsigned int mask) { mNodeMask = mask; }
        unsigned int getNodeMask() override { return mNodeMask; }

        void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;

        void clearCache() override;

        void releaseGLObjects(osg::State* state) override;

    private:
        osg::ref_ptr<osg::Node> createChunk(float size, const osg::Vec2f& center, unsigned char lod,
            unsigned int lodFlags, bool compile, const TerrainDrawable* templateGeometry);

        osg::ref_ptr<osg::Texture2D> createCompositeMapRTT();

        void createCompositeMapGeometry(
            float chunkSize, const osg::Vec2f& chunkCenter, const osg::Vec4f& texCoords, CompositeMap& map);

        std::vector<osg::ref_ptr<osg::StateSet>> createPasses(
            float chunkSize, const osg::Vec2f& chunkCenter, bool forCompositeMap);

        Terrain::Storage* mStorage;
        Resource::SceneManager* mSceneManager;
        TextureManager* mTextureManager;
        CompositeMapRenderer* mCompositeMapRenderer;
        BufferCache mBufferCache;

        osg::ref_ptr<osg::StateSet> mMultiPassRoot;

        unsigned int mNodeMask;

        unsigned int mCompositeMapSize;
        float mCompositeMapLevel;
        float mMaxCompGeometrySize;
    };

}

#endif