1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00
OpenMW/apps/openmw/mwrender/landmanager.cpp

44 lines
1.1 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)
2019-03-13 11:15:58 +04:00
: GenericResourceManager<std::pair<int, int> >(nullptr)
, mLoadFlags(loadFlags)
{
2019-03-13 11:15:58 +04:00
mCache = new CacheType;
}
osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(int x, int y)
{
2019-03-13 11:15:58 +04:00
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(std::make_pair(x,y));
if (obj)
return static_cast<ESMTerrain::LandObject*>(obj.get());
else
{
const ESM::Land* land = MWBase::Environment::get().getWorld()->getStore().get<ESM::Land>().search(x,y);
if (!land)
2018-10-09 10:21:12 +04:00
return nullptr;
osg::ref_ptr<ESMTerrain::LandObject> landObj (new ESMTerrain::LandObject(land, mLoadFlags));
2019-03-13 11:15:58 +04:00
mCache->addEntryToObjectCache(std::make_pair(x,y), landObj.get());
return landObj;
}
}
2017-03-07 04:02:06 +01:00
void LandManager::reportStats(unsigned int frameNumber, osg::Stats *stats) const
{
stats->setAttribute(frameNumber, "Land", mCache->getCacheSize());
}
}