osg::UserDataContainer only accepts osg::Object, so four payloads that are pure game data inherited from it purely to get in the door: TextKeyMapHolder, MWRender::PtrHolder, RefnumMarker and RefnumSet. SceneUtil::UserData<T> takes that base on once so the payloads do not have to, which lets TextKeyMapHolder, PtrHolder and RefnumSet disappear entirely in favour of TextKeyMap, MWWorld::Ptr and std::vector<ESM::RefNum>, and leaves RefnumMarker a plain aggregate. The five hand-rolled dynamic_cast scans over the container collapse into findUserData and forEachUserData, which also drops the positional getUserObject(0) assumption in getPagedRefnums in favour of a lookup by type.
94 lines
3.1 KiB
C++
94 lines
3.1 KiB
C++
#ifndef OPENMW_MWRENDER_OBJECTPAGING_H
|
|
#define OPENMW_MWRENDER_OBJECTPAGING_H
|
|
|
|
#include <components/esm3/refnum.hpp>
|
|
#include <components/resource/resourcemanager.hpp>
|
|
#include <components/terrain/quadtreeworld.hpp>
|
|
|
|
#include <mutex>
|
|
|
|
namespace Resource
|
|
{
|
|
class SceneManager;
|
|
}
|
|
|
|
namespace MWRender
|
|
{
|
|
|
|
typedef std::tuple<osg::Vec2f, float, bool> ChunkId; // Center, Size, ActiveGrid
|
|
|
|
class ObjectPaging : public Resource::NodeResourceManager<ChunkId>, public Terrain::QuadTreeWorld::ChunkManager
|
|
{
|
|
public:
|
|
ObjectPaging(Resource::SceneManager* sceneManager, ESM::RefId worldspace);
|
|
~ObjectPaging() = default;
|
|
|
|
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;
|
|
|
|
osg::ref_ptr<osg::Node> createChunk(float size, const osg::Vec2f& center, bool activeGrid,
|
|
const osg::Vec3f& viewPoint, bool compile, unsigned char lod);
|
|
|
|
unsigned int getNodeMask() override;
|
|
|
|
/// @return true if view needs rebuild
|
|
bool enableObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled);
|
|
|
|
/// @return true if view needs rebuild
|
|
bool blacklistObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell);
|
|
|
|
void clear();
|
|
|
|
/// Must be called after clear() before rendering starts.
|
|
/// @return true if view needs rebuild
|
|
bool unlockCache();
|
|
|
|
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
|
|
|
|
void getPagedRefnums(const osg::Vec4i& activeGrid, std::vector<ESM::RefNum>& out);
|
|
|
|
private:
|
|
Resource::SceneManager* mSceneManager;
|
|
bool mActiveGrid;
|
|
bool mDebugBatches;
|
|
float mMergeFactor;
|
|
float mMinSize;
|
|
float mMinSizeMergeFactor;
|
|
float mMinSizeCostMultiplier;
|
|
|
|
std::mutex mRefTrackerMutex;
|
|
struct RefTracker
|
|
{
|
|
std::set<ESM::RefNum> mDisabled;
|
|
std::set<ESM::RefNum> mBlacklist;
|
|
bool operator==(const RefTracker& other) const
|
|
{
|
|
return mDisabled == other.mDisabled && mBlacklist == other.mBlacklist;
|
|
}
|
|
};
|
|
RefTracker mRefTracker;
|
|
RefTracker mRefTrackerNew;
|
|
bool mRefTrackerLocked;
|
|
|
|
const RefTracker& getRefTracker() const { return mRefTracker; }
|
|
RefTracker& getWritableRefTracker() { return mRefTrackerLocked ? mRefTrackerNew : mRefTracker; }
|
|
|
|
std::mutex mSizeCacheMutex;
|
|
typedef std::map<ESM::RefNum, float> SizeCache;
|
|
SizeCache mSizeCache;
|
|
|
|
std::mutex mLODNameCacheMutex;
|
|
typedef std::pair<std::string, unsigned char> LODNameCacheKey; // Key: mesh name, lod level
|
|
using LODNameCache = std::map<LODNameCacheKey, VFS::Path::Normalized>; // Cache: key, mesh name to use
|
|
LODNameCache mLODNameCache;
|
|
};
|
|
|
|
struct RefnumMarker
|
|
{
|
|
ESM::RefNum mRefnum;
|
|
unsigned int mNumVertices = 0;
|
|
};
|
|
}
|
|
|
|
#endif
|