mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 14:59:54 +00:00
pagerebuild on disable
Signed-off-by: Bret Curtis <psi29a@gmail.com>
This commit is contained in:
parent
c1ebd9474b
commit
17637c6575
12 changed files with 91 additions and 16 deletions
|
@ -576,17 +576,52 @@ namespace MWRender
|
|||
return Mask_Static;
|
||||
}
|
||||
|
||||
void ObjectPaging::enableObject(const ESM::RefNum & refnum, bool enabled)
|
||||
struct ClearCacheFunctor
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mDisabledMutex);
|
||||
if (enabled) mDisabled.erase(refnum);
|
||||
else mDisabled.insert(refnum);
|
||||
void operator()(MWRender::ChunkId id, osg::Object* obj)
|
||||
{
|
||||
if (intersects(id, mPosition))
|
||||
mToClear.insert(id);
|
||||
}
|
||||
bool intersects(ChunkId id, osg::Vec3f pos)
|
||||
{
|
||||
pos /= ESM::Land::REAL_SIZE;
|
||||
osg::Vec2f center = std::get<0>(id);
|
||||
float halfSize = std::get<1>(id)/2;
|
||||
return pos.x() >= center.x()-halfSize && pos.y() >= center.y()-halfSize && pos.x() <= center.x()+halfSize && pos.y() <= center.y()+halfSize;
|
||||
}
|
||||
osg::Vec3f mPosition;
|
||||
std::set<MWRender::ChunkId> mToClear;
|
||||
};
|
||||
|
||||
bool ObjectPaging::enableObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, bool enabled)
|
||||
{
|
||||
if (!typeFilter(type, false))
|
||||
return false;
|
||||
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mDisabledMutex);
|
||||
if (enabled && !mDisabled.erase(refnum)) return false;
|
||||
if (!enabled && !mDisabled.insert(refnum).second) return false;
|
||||
}
|
||||
|
||||
ClearCacheFunctor ccf;
|
||||
ccf.mPosition = pos;
|
||||
mCache->call(ccf);
|
||||
for (auto chunk : ccf.mToClear)
|
||||
mCache->removeFromObjectCache(chunk);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ObjectPaging::clear()
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mDisabledMutex);
|
||||
mDisabled.clear();
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(mDisabledMutex);
|
||||
if (mDisabled.empty())
|
||||
return;
|
||||
mDisabled.clear();
|
||||
}
|
||||
mCache->clear();
|
||||
}
|
||||
|
||||
void ObjectPaging::reportStats(unsigned int frameNumber, osg::Stats *stats) const
|
||||
|
|
|
@ -33,7 +33,9 @@ namespace MWRender
|
|||
|
||||
virtual unsigned int getNodeMask() override;
|
||||
|
||||
void enableObject(const ESM::RefNum & refnum, bool enabled);
|
||||
/// @return true if something changed
|
||||
bool enableObject(int type, const ESM::RefNum & refnum, const osg::Vec3f& pos, bool enabled);
|
||||
|
||||
void clear();
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats* stats) const override;
|
||||
|
|
|
@ -1481,9 +1481,9 @@ namespace MWRender
|
|||
{
|
||||
mTerrain->setActiveGrid(grid);
|
||||
}
|
||||
void RenderingManager::pagingEnableObject(const ESM::RefNum & refnum, bool enabled)
|
||||
void RenderingManager::pagingEnableObject(int type, const MWWorld::ConstPtr& ptr, bool enabled)
|
||||
{
|
||||
if (mObjectPaging)
|
||||
mObjectPaging->enableObject(refnum, enabled);
|
||||
if (mObjectPaging && mObjectPaging->enableObject(type, ptr.getCellRef().getRefNum(), ptr.getRefData().getPosition().asVec3(), enabled))
|
||||
mTerrain->clearCachedViews(ptr.getRefData().getPosition().asVec3());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ namespace MWRender
|
|||
|
||||
void setActiveGrid(const osg::Vec4i &grid);
|
||||
|
||||
void pagingEnableObject(const ESM::RefNum & refnum, bool enabled);
|
||||
void pagingEnableObject(int type, const MWWorld::ConstPtr& ptr, bool enabled);
|
||||
|
||||
private:
|
||||
void updateProjectionMatrix();
|
||||
|
|
|
@ -815,7 +815,10 @@ namespace MWWorld
|
|||
mWorldScene->addObjectToScene (reference);
|
||||
|
||||
if (reference.getCellRef().getRefNum().hasContentFile())
|
||||
mRendering->pagingEnableObject(reference.getCellRef().getRefNum(), true);
|
||||
{
|
||||
int type = mStore.find(Misc::StringUtils::lowerCase(reference.getCellRef().getRefId()));
|
||||
mRendering->pagingEnableObject(type, reference, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -853,7 +856,10 @@ namespace MWWorld
|
|||
reference.getRefData().disable();
|
||||
|
||||
if (reference.getCellRef().getRefNum().hasContentFile())
|
||||
mRendering->pagingEnableObject(reference.getCellRef().getRefNum(), false);
|
||||
{
|
||||
int type = mStore.find(Misc::StringUtils::lowerCase(reference.getCellRef().getRefId()));
|
||||
mRendering->pagingEnableObject(type, reference, false);
|
||||
}
|
||||
|
||||
if(mWorldScene->getActiveCells().find (reference.getCell())!=mWorldScene->getActiveCells().end() && reference.getRefData().getCount())
|
||||
mWorldScene->removeObjectFromScene (reference);
|
||||
|
|
|
@ -161,13 +161,13 @@ class GenericObjectCache : public osg::Referenced
|
|||
}
|
||||
}
|
||||
|
||||
/** call operator()(osg::Object*) for each object in the cache. */
|
||||
/** call operator()(KeyType, osg::Object*) for each object in the cache. */
|
||||
template <class Functor>
|
||||
void call(Functor& f)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
for (typename ObjectCacheMap::iterator it = _objectCache.begin(); it != _objectCache.end(); ++it)
|
||||
f(it->second.first.get());
|
||||
f(it->first, it->second.first.get());
|
||||
}
|
||||
|
||||
/** Get the number of objects in the cache. */
|
||||
|
|
|
@ -574,4 +574,11 @@ void QuadTreeWorld::addChunkManager(QuadTreeWorld::ChunkManager* m)
|
|||
mTerrainRoot->setNodeMask(mTerrainRoot->getNodeMask()|m->getNodeMask());
|
||||
}
|
||||
|
||||
void QuadTreeWorld::clearCachedViews(const osg::Vec3f &pos)
|
||||
{
|
||||
//mViewDataMap->clear();
|
||||
osg::Vec3 pos_ = pos / mStorage->getCellWorldSize();
|
||||
mViewDataMap->clearCachedViews(pos_);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ namespace Terrain
|
|||
View* createView();
|
||||
void preload(View* view, const osg::Vec3f& eyePoint, const osg::Vec4i &cellgrid, std::atomic<bool>& abort, std::atomic<int>& progress, int& progressRange);
|
||||
void storeView(const View* view, double referenceTime);
|
||||
void clearCachedViews(const osg::Vec3f& pos) override;
|
||||
|
||||
void reportStats(unsigned int frameNumber, osg::Stats* stats);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ struct UpdateTextureFilteringFunctor
|
|||
}
|
||||
Resource::SceneManager* mSceneManager;
|
||||
|
||||
void operator()(osg::Object* obj)
|
||||
void operator()(std::string, osg::Object* obj)
|
||||
{
|
||||
mSceneManager->applyFilterSettings(static_cast<osg::Texture2D*>(obj));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "viewdata.hpp"
|
||||
|
||||
#include "quadtreenode.hpp"
|
||||
|
||||
namespace Terrain
|
||||
{
|
||||
|
||||
|
@ -99,6 +101,18 @@ bool ViewData::contains(QuadTreeNode *node)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool intersects(const osg::Vec2f& center, float halfSize, osg::Vec3f pos)
|
||||
{
|
||||
return (pos.x() >= center.x()-halfSize && pos.y() >= center.y()-halfSize && pos.x() <= center.x()+halfSize && pos.y() <= center.y()+halfSize);
|
||||
}
|
||||
|
||||
void ViewData::clearCache(const osg::Vec3f &cellPos)
|
||||
{
|
||||
for (Entry& entry : mEntries)
|
||||
if (entry.mNode && intersects(entry.mNode->getCenter(), entry.mNode->getSize()/2.f, cellPos))
|
||||
entry.mRenderingNode = nullptr;
|
||||
}
|
||||
|
||||
ViewData::Entry::Entry()
|
||||
: mNode(nullptr)
|
||||
, mLodFlags(0)
|
||||
|
@ -188,6 +202,12 @@ void ViewDataMap::clearUnusedViews(double referenceTime)
|
|||
}
|
||||
}
|
||||
|
||||
void ViewDataMap::clearCachedViews(const osg::Vec3f &cellPos)
|
||||
{
|
||||
for (auto pair : mViews)
|
||||
pair.second->clearCache(cellPos);
|
||||
}
|
||||
|
||||
void ViewDataMap::clear()
|
||||
{
|
||||
mViews.clear();
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Terrain
|
|||
void reset();
|
||||
|
||||
void clear();
|
||||
void clearCache(const osg::Vec3f &cellPos);
|
||||
|
||||
bool contains(QuadTreeNode* node);
|
||||
|
||||
|
@ -84,6 +85,7 @@ namespace Terrain
|
|||
ViewData* createOrReuseView();
|
||||
|
||||
void clearUnusedViews(double referenceTime);
|
||||
void clearCachedViews(const osg::Vec3f &cellPos);
|
||||
|
||||
void clear();
|
||||
|
||||
|
|
|
@ -153,6 +153,8 @@ namespace Terrain
|
|||
/// @note Not thread safe.
|
||||
virtual void storeView(const View* view, double referenceTime) {}
|
||||
|
||||
virtual void clearCachedViews(const osg::Vec3f& pos) {}
|
||||
|
||||
virtual void reportStats(unsigned int frameNumber, osg::Stats* stats) {}
|
||||
|
||||
virtual void setViewDistance(float distance) {}
|
||||
|
|
Loading…
Reference in a new issue