1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-03 15:06:42 +00:00

Merge branch 'paged_refs_vector' into 'master'

Use std::vector to store paged ref nums

See merge request OpenMW/openmw!2245
This commit is contained in:
psi29a 2022-08-07 13:35:54 +00:00
commit e75d3285cf
6 changed files with 30 additions and 16 deletions

View file

@ -1,6 +1,7 @@
#include "objectpaging.hpp" #include "objectpaging.hpp"
#include <unordered_map> #include <unordered_map>
#include <vector>
#include <osg/LOD> #include <osg/LOD>
#include <osg/Switch> #include <osg/Switch>
@ -276,7 +277,7 @@ namespace MWRender
RefnumSet(){} RefnumSet(){}
RefnumSet(const RefnumSet& copy, const osg::CopyOp&) : mRefnums(copy.mRefnums) {} RefnumSet(const RefnumSet& copy, const osg::CopyOp&) : mRefnums(copy.mRefnums) {}
META_Object(MWRender, RefnumSet) META_Object(MWRender, RefnumSet)
std::set<ESM::RefNum> mRefnums; std::vector<ESM::RefNum> mRefnums;
}; };
class AnalyzeVisitor : public osg::NodeVisitor class AnalyzeVisitor : public osg::NodeVisitor
@ -554,7 +555,7 @@ namespace MWRender
if (cnode->getNumChildrenRequiringUpdateTraversal() > 0 || SceneUtil::hasUserDescription(cnode, Constants::NightDayLabel) || SceneUtil::hasUserDescription(cnode, Constants::HerbalismLabel)) if (cnode->getNumChildrenRequiringUpdateTraversal() > 0 || SceneUtil::hasUserDescription(cnode, Constants::NightDayLabel) || SceneUtil::hasUserDescription(cnode, Constants::HerbalismLabel))
continue; continue;
else else
refnumSet->mRefnums.insert(pair.first); refnumSet->mRefnums.push_back(pair.first);
} }
{ {
@ -727,6 +728,8 @@ namespace MWRender
osg::UserDataContainer* udc = group->getOrCreateUserDataContainer(); osg::UserDataContainer* udc = group->getOrCreateUserDataContainer();
if (activeGrid) if (activeGrid)
{ {
std::sort(refnumSet->mRefnums.begin(), refnumSet->mRefnums.end());
refnumSet->mRefnums.erase(std::unique(refnumSet->mRefnums.begin(), refnumSet->mRefnums.end()), refnumSet->mRefnums.end());
udc->addUserObject(refnumSet); udc->addUserObject(refnumSet);
group->addCullCallback(new SceneUtil::LightListCallback); group->addCullCallback(new SceneUtil::LightListCallback);
} }
@ -837,7 +840,7 @@ namespace MWRender
struct GetRefnumsFunctor struct GetRefnumsFunctor
{ {
GetRefnumsFunctor(std::set<ESM::RefNum>& output) : mOutput(output) {} GetRefnumsFunctor(std::vector<ESM::RefNum>& output) : mOutput(output) {}
void operator()(MWRender::ChunkId chunkId, osg::Object* obj) void operator()(MWRender::ChunkId chunkId, osg::Object* obj)
{ {
if (!std::get<2>(chunkId)) return; if (!std::get<2>(chunkId)) return;
@ -850,18 +853,20 @@ namespace MWRender
{ {
RefnumSet* refnums = dynamic_cast<RefnumSet*>(udc->getUserObject(0)); RefnumSet* refnums = dynamic_cast<RefnumSet*>(udc->getUserObject(0));
if (!refnums) return; if (!refnums) return;
mOutput.insert(refnums->mRefnums.begin(), refnums->mRefnums.end()); mOutput.insert(mOutput.end(), refnums->mRefnums.begin(), refnums->mRefnums.end());
} }
} }
osg::Vec4i mActiveGrid; osg::Vec4i mActiveGrid;
std::set<ESM::RefNum>& mOutput; std::vector<ESM::RefNum>& mOutput;
}; };
void ObjectPaging::getPagedRefnums(const osg::Vec4i &activeGrid, std::set<ESM::RefNum> &out) void ObjectPaging::getPagedRefnums(const osg::Vec4i &activeGrid, std::vector<ESM::RefNum>& out)
{ {
GetRefnumsFunctor grf(out); GetRefnumsFunctor grf(out);
grf.mActiveGrid = activeGrid; grf.mActiveGrid = activeGrid;
mCache->call(grf); mCache->call(grf);
std::sort(out.begin(), out.end());
out.erase(std::unique(out.begin(), out.end()), out.end());
} }
void ObjectPaging::reportStats(unsigned int frameNumber, osg::Stats *stats) const void ObjectPaging::reportStats(unsigned int frameNumber, osg::Stats *stats) const

View file

@ -47,7 +47,7 @@ namespace MWRender
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override; void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
void getPagedRefnums(const osg::Vec4i &activeGrid, std::set<ESM::RefNum> &out); void getPagedRefnums(const osg::Vec4i &activeGrid, std::vector<ESM::RefNum>& out);
private: private:
Resource::SceneManager* mSceneManager; Resource::SceneManager* mSceneManager;

View file

@ -1616,7 +1616,7 @@ namespace MWRender
} }
return false; return false;
} }
void RenderingManager::getPagedRefnums(const osg::Vec4i &activeGrid, std::set<ESM::RefNum> &out) void RenderingManager::getPagedRefnums(const osg::Vec4i &activeGrid, std::vector<ESM::RefNum>& out)
{ {
if (mObjectPaging) if (mObjectPaging)
mObjectPaging->getPagedRefnums(activeGrid, out); mObjectPaging->getPagedRefnums(activeGrid, out);

View file

@ -250,7 +250,7 @@ namespace MWRender
bool pagingEnableObject(int type, const MWWorld::ConstPtr& ptr, bool enabled); bool pagingEnableObject(int type, const MWWorld::ConstPtr& ptr, bool enabled);
void pagingBlacklistObject(int type, const MWWorld::ConstPtr &ptr); void pagingBlacklistObject(int type, const MWWorld::ConstPtr &ptr);
bool pagingUnlockCache(); bool pagingUnlockCache();
void getPagedRefnums(const osg::Vec4i &activeGrid, std::set<ESM::RefNum> &out); void getPagedRefnums(const osg::Vec4i &activeGrid, std::vector<ESM::RefNum>& out);
void updateProjectionMatrix(); void updateProjectionMatrix();

View file

@ -99,8 +99,8 @@ namespace
return model; return model;
} }
void addObject(const MWWorld::Ptr& ptr, const MWWorld::World& world, MWPhysics::PhysicsSystem& physics, void addObject(const MWWorld::Ptr& ptr, const MWWorld::World& world, const std::vector<ESM::RefNum>& pagedRefs,
MWRender::RenderingManager& rendering, std::set<ESM::RefNum>& pagedRefs) MWPhysics::PhysicsSystem& physics, MWRender::RenderingManager& rendering)
{ {
if (ptr.getRefData().getBaseNode() || physics.getActor(ptr)) if (ptr.getRefData().getBaseNode() || physics.getActor(ptr))
{ {
@ -112,7 +112,7 @@ namespace
const auto rotation = makeDirectNodeRotation(ptr); const auto rotation = makeDirectNodeRotation(ptr);
const ESM::RefNum& refnum = ptr.getCellRef().getRefNum(); const ESM::RefNum& refnum = ptr.getCellRef().getRefNum();
if (!refnum.hasContentFile() || pagedRefs.find(refnum) == pagedRefs.end()) if (!refnum.hasContentFile() || !std::binary_search(pagedRefs.begin(), pagedRefs.end(), refnum))
ptr.getClass().insertObjectRendering(ptr, model, rendering); ptr.getClass().insertObjectRendering(ptr, model, rendering);
else else
ptr.getRefData().setBaseNode(new SceneUtil::PositionAttitudeTransform); // FIXME remove this when physics code is fixed not to depend on basenode ptr.getRefData().setBaseNode(new SceneUtil::PositionAttitudeTransform); // FIXME remove this when physics code is fixed not to depend on basenode
@ -255,6 +255,15 @@ namespace
} }
return false; return false;
} }
bool removeFromSorted(const ESM::RefNum& refNum, std::vector<ESM::RefNum>& pagedRefs)
{
const auto it = std::lower_bound(pagedRefs.begin(), pagedRefs.end(), refNum);
if (it == pagedRefs.end() || *it != refNum)
return false;
pagedRefs.erase(it);
return true;
}
} }
@ -264,7 +273,7 @@ namespace MWWorld
void Scene::removeFromPagedRefs(const Ptr &ptr) void Scene::removeFromPagedRefs(const Ptr &ptr)
{ {
const ESM::RefNum& refnum = ptr.getCellRef().getRefNum(); const ESM::RefNum& refnum = ptr.getCellRef().getRefNum();
if (refnum.hasContentFile() && mPagedRefs.erase(refnum)) if (refnum.hasContentFile() && removeFromSorted(refnum, mPagedRefs))
{ {
if (!ptr.getRefData().getBaseNode()) return; if (!ptr.getRefData().getBaseNode()) return;
ptr.getClass().insertObjectRendering(ptr, getModel(ptr, mRendering.getResourceSystem()->getVFS()), mRendering); ptr.getClass().insertObjectRendering(ptr, getModel(ptr, mRendering.getResourceSystem()->getVFS()), mRendering);
@ -900,7 +909,7 @@ namespace MWWorld
{ {
InsertVisitor insertVisitor(cell, loadingListener); InsertVisitor insertVisitor(cell, loadingListener);
cell.forEach (insertVisitor); cell.forEach (insertVisitor);
insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, mWorld, *mPhysics, mRendering, mPagedRefs); }); insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, mWorld, mPagedRefs, *mPhysics, mRendering); });
insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, mWorld, *mPhysics, mNavigator); }); insertVisitor.insert([&] (const MWWorld::Ptr& ptr) { addObject(ptr, mWorld, *mPhysics, mNavigator); });
} }
@ -908,7 +917,7 @@ namespace MWWorld
{ {
try try
{ {
addObject(ptr, mWorld, *mPhysics, mRendering, mPagedRefs); addObject(ptr, mWorld, mPagedRefs, *mPhysics, mRendering);
addObject(ptr, mWorld, *mPhysics, mNavigator); addObject(ptr, mWorld, *mPhysics, mNavigator);
mWorld.scaleObject(ptr, ptr.getCellRef().getScale()); mWorld.scaleObject(ptr, ptr.getCellRef().getScale());
if (mCurrentCell != nullptr) if (mCurrentCell != nullptr)

View file

@ -104,7 +104,7 @@ namespace MWWorld
osg::Vec3f mLastPlayerPos; osg::Vec3f mLastPlayerPos;
std::set<ESM::RefNum> mPagedRefs; std::vector<ESM::RefNum> mPagedRefs;
std::vector<osg::ref_ptr<SceneUtil::WorkItem>> mWorkItems; std::vector<osg::ref_ptr<SceneUtil::WorkItem>> mWorkItems;