mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-29 13:20:35 +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)
|
||||
{
|
||||
const osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(cellIndex);
|
||||
if (obj != nullptr)
|
||||
return static_cast<ESMTerrain::LandObject*>(obj.get());
|
||||
if (const std::optional<osg::ref_ptr<osg::Object>> obj = mCache->getRefFromObjectCacheOrNone(cellIndex))
|
||||
return static_cast<ESMTerrain::LandObject*>(obj->get());
|
||||
|
||||
const MWBase::World& world = *MWBase::Environment::get().getWorld();
|
||||
osg::ref_ptr<ESMTerrain::LandObject> landObj = nullptr;
|
||||
@ -29,16 +28,14 @@ namespace MWRender
|
||||
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
|
||||
{
|
||||
const ESM4::Land* land = world.getStore().get<ESM4::Land>().search(cellIndex);
|
||||
if (land == nullptr)
|
||||
return nullptr;
|
||||
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
||||
if (land != nullptr)
|
||||
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
||||
}
|
||||
else
|
||||
{
|
||||
const ESM::Land* land = world.getStore().get<ESM::Land>().search(cellIndex.mX, cellIndex.mY);
|
||||
if (land == nullptr)
|
||||
return nullptr;
|
||||
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
||||
if (land != nullptr)
|
||||
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
||||
}
|
||||
|
||||
mCache->addEntryToObjectCache(cellIndex, landObj.get());
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace osg
|
||||
@ -82,7 +83,8 @@ namespace Resource
|
||||
{
|
||||
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++);
|
||||
}
|
||||
else
|
||||
@ -127,6 +129,15 @@ namespace Resource
|
||||
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. */
|
||||
bool checkInObjectCache(const KeyType& key, double timeStamp)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user