mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-09 21:44:54 +00:00
Cache absent land object
This allows to save on lookup in store.
This commit is contained in:
parent
eba553821b
commit
816d3772b9
@ -19,9 +19,8 @@ namespace MWRender
|
|||||||
|
|
||||||
osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellLocation cellIndex)
|
osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellLocation cellIndex)
|
||||||
{
|
{
|
||||||
const osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(cellIndex);
|
if (const std::optional<osg::ref_ptr<osg::Object>> obj = mCache->getRefFromObjectCacheOrNone(cellIndex))
|
||||||
if (obj != nullptr)
|
return static_cast<ESMTerrain::LandObject*>(obj->get());
|
||||||
return static_cast<ESMTerrain::LandObject*>(obj.get());
|
|
||||||
|
|
||||||
const MWBase::World& world = *MWBase::Environment::get().getWorld();
|
const MWBase::World& world = *MWBase::Environment::get().getWorld();
|
||||||
osg::ref_ptr<ESMTerrain::LandObject> landObj = nullptr;
|
osg::ref_ptr<ESMTerrain::LandObject> landObj = nullptr;
|
||||||
@ -29,16 +28,14 @@ namespace MWRender
|
|||||||
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
|
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
|
||||||
{
|
{
|
||||||
const ESM4::Land* land = world.getStore().get<ESM4::Land>().search(cellIndex);
|
const ESM4::Land* land = world.getStore().get<ESM4::Land>().search(cellIndex);
|
||||||
if (land == nullptr)
|
if (land != nullptr)
|
||||||
return nullptr;
|
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
||||||
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const ESM::Land* land = world.getStore().get<ESM::Land>().search(cellIndex.mX, cellIndex.mY);
|
const ESM::Land* land = world.getStore().get<ESM::Land>().search(cellIndex.mX, cellIndex.mY);
|
||||||
if (land == nullptr)
|
if (land != nullptr)
|
||||||
return nullptr;
|
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
||||||
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mCache->addEntryToObjectCache(cellIndex, landObj.get());
|
mCache->addEntryToObjectCache(cellIndex, landObj.get());
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace osg
|
namespace osg
|
||||||
@ -82,7 +83,8 @@ namespace Resource
|
|||||||
{
|
{
|
||||||
if (oitr->second.second <= expiryTime)
|
if (oitr->second.second <= expiryTime)
|
||||||
{
|
{
|
||||||
objectsToRemove.push_back(oitr->second.first);
|
if (oitr->second.first != nullptr)
|
||||||
|
objectsToRemove.push_back(oitr->second.first);
|
||||||
_objectCache.erase(oitr++);
|
_objectCache.erase(oitr++);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -127,6 +129,15 @@ namespace Resource
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<osg::ref_ptr<osg::Object>> getRefFromObjectCacheOrNone(const KeyType& key)
|
||||||
|
{
|
||||||
|
const std::lock_guard<std::mutex> lock(_objectCacheMutex);
|
||||||
|
const auto it = _objectCache.find(key);
|
||||||
|
if (it == _objectCache.end())
|
||||||
|
return std::nullopt;
|
||||||
|
return it->second.first;
|
||||||
|
}
|
||||||
|
|
||||||
/** Check if an object is in the cache, and if it is, update its usage time stamp. */
|
/** Check if an object is in the cache, and if it is, update its usage time stamp. */
|
||||||
bool checkInObjectCache(const KeyType& key, double timeStamp)
|
bool checkInObjectCache(const KeyType& key, double timeStamp)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user