mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Use std::vector to store paged ref nums
This commit is contained in:
parent
86a4d530c4
commit
dffb12ac05
@ -1,6 +1,7 @@
|
||||
#include "objectpaging.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <osg/LOD>
|
||||
#include <osg/Switch>
|
||||
@ -276,7 +277,7 @@ namespace MWRender
|
||||
RefnumSet(){}
|
||||
RefnumSet(const RefnumSet& copy, const osg::CopyOp&) : mRefnums(copy.mRefnums) {}
|
||||
META_Object(MWRender, RefnumSet)
|
||||
std::set<ESM::RefNum> mRefnums;
|
||||
std::vector<ESM::RefNum> mRefnums;
|
||||
};
|
||||
|
||||
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))
|
||||
continue;
|
||||
else
|
||||
refnumSet->mRefnums.insert(pair.first);
|
||||
refnumSet->mRefnums.push_back(pair.first);
|
||||
}
|
||||
|
||||
{
|
||||
@ -727,6 +728,8 @@ namespace MWRender
|
||||
osg::UserDataContainer* udc = group->getOrCreateUserDataContainer();
|
||||
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);
|
||||
group->addCullCallback(new SceneUtil::LightListCallback);
|
||||
}
|
||||
@ -837,7 +840,7 @@ namespace MWRender
|
||||
|
||||
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)
|
||||
{
|
||||
if (!std::get<2>(chunkId)) return;
|
||||
@ -850,18 +853,20 @@ namespace MWRender
|
||||
{
|
||||
RefnumSet* refnums = dynamic_cast<RefnumSet*>(udc->getUserObject(0));
|
||||
if (!refnums) return;
|
||||
mOutput.insert(refnums->mRefnums.begin(), refnums->mRefnums.end());
|
||||
mOutput.insert(mOutput.end(), refnums->mRefnums.begin(), refnums->mRefnums.end());
|
||||
}
|
||||
}
|
||||
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);
|
||||
grf.mActiveGrid = activeGrid;
|
||||
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
|
||||
|
@ -47,7 +47,7 @@ namespace MWRender
|
||||
|
||||
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:
|
||||
Resource::SceneManager* mSceneManager;
|
||||
|
@ -1616,7 +1616,7 @@ namespace MWRender
|
||||
}
|
||||
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)
|
||||
mObjectPaging->getPagedRefnums(activeGrid, out);
|
||||
|
@ -250,7 +250,7 @@ namespace MWRender
|
||||
bool pagingEnableObject(int type, const MWWorld::ConstPtr& ptr, bool enabled);
|
||||
void pagingBlacklistObject(int type, const MWWorld::ConstPtr &ptr);
|
||||
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();
|
||||
|
||||
|
@ -99,8 +99,8 @@ namespace
|
||||
return model;
|
||||
}
|
||||
|
||||
void addObject(const MWWorld::Ptr& ptr, const MWWorld::World& world, MWPhysics::PhysicsSystem& physics,
|
||||
MWRender::RenderingManager& rendering, std::set<ESM::RefNum>& pagedRefs)
|
||||
void addObject(const MWWorld::Ptr& ptr, const MWWorld::World& world, const std::vector<ESM::RefNum>& pagedRefs,
|
||||
MWPhysics::PhysicsSystem& physics, MWRender::RenderingManager& rendering)
|
||||
{
|
||||
if (ptr.getRefData().getBaseNode() || physics.getActor(ptr))
|
||||
{
|
||||
@ -112,7 +112,7 @@ namespace
|
||||
const auto rotation = makeDirectNodeRotation(ptr);
|
||||
|
||||
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);
|
||||
else
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const ESM::RefNum& refnum = ptr.getCellRef().getRefNum();
|
||||
if (refnum.hasContentFile() && mPagedRefs.erase(refnum))
|
||||
if (refnum.hasContentFile() && removeFromSorted(refnum, mPagedRefs))
|
||||
{
|
||||
if (!ptr.getRefData().getBaseNode()) return;
|
||||
ptr.getClass().insertObjectRendering(ptr, getModel(ptr, mRendering.getResourceSystem()->getVFS()), mRendering);
|
||||
@ -900,7 +909,7 @@ namespace MWWorld
|
||||
{
|
||||
InsertVisitor insertVisitor(cell, loadingListener);
|
||||
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); });
|
||||
}
|
||||
|
||||
@ -908,7 +917,7 @@ namespace MWWorld
|
||||
{
|
||||
try
|
||||
{
|
||||
addObject(ptr, mWorld, *mPhysics, mRendering, mPagedRefs);
|
||||
addObject(ptr, mWorld, mPagedRefs, *mPhysics, mRendering);
|
||||
addObject(ptr, mWorld, *mPhysics, mNavigator);
|
||||
mWorld.scaleObject(ptr, ptr.getCellRef().getScale());
|
||||
if (mCurrentCell != nullptr)
|
||||
|
@ -104,7 +104,7 @@ namespace MWWorld
|
||||
|
||||
osg::Vec3f mLastPlayerPos;
|
||||
|
||||
std::set<ESM::RefNum> mPagedRefs;
|
||||
std::vector<ESM::RefNum> mPagedRefs;
|
||||
|
||||
std::vector<osg::ref_ptr<SceneUtil::WorkItem>> mWorkItems;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user