1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-31 06:32:39 +00:00
OpenMW/apps/openmw/mwrender/landmanager.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.6 KiB
C++
Raw Normal View History

#include "landmanager.hpp"
#include <osg/Stats>
#include <components/resource/objectcache.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/esmstore.hpp"
namespace MWRender
{
LandManager::LandManager(int loadFlags)
: GenericResourceManager<ESM::ExteriorCellLocation>(nullptr)
, mLoadFlags(loadFlags)
{
}
osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellLocation cellIndex)
2022-09-22 21:26:05 +03:00
{
if (const std::optional<osg::ref_ptr<osg::Object>> obj = mCache->getRefFromObjectCacheOrNone(cellIndex))
return static_cast<ESMTerrain::LandObject*>(obj->get());
2023-08-18 19:06:08 +02:00
const MWBase::World& world = *MWBase::Environment::get().getWorld();
osg::ref_ptr<ESMTerrain::LandObject> landObj = nullptr;
2023-08-18 19:06:08 +02:00
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
{
const ESM4::Land* land = world.getStore().get<ESM4::Land>().search(cellIndex);
if (land != nullptr)
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
2023-08-18 19:06:08 +02:00
}
2022-09-22 21:26:05 +03:00
else
{
2023-08-18 19:06:08 +02:00
const ESM::Land* land = world.getStore().get<ESM::Land>().search(cellIndex.mX, cellIndex.mY);
if (land != nullptr)
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
}
mCache->addEntryToObjectCache(cellIndex, landObj.get());
return landObj;
2022-09-22 21:26:05 +03:00
}
2017-03-07 04:02:06 +01:00
void LandManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
2022-09-22 21:26:05 +03:00
{
stats->setAttribute(frameNumber, "Land", mCache->getCacheSize());
2022-09-22 21:26:05 +03:00
}
}