#include "landmanager.hpp" #include #include #include "../mwbase/environment.hpp" #include "../mwbase/world.hpp" #include "../mwworld/esmstore.hpp" namespace MWRender { LandManager::LandManager(int loadFlags) : GenericResourceManager(nullptr) , mLoadFlags(loadFlags) { } osg::ref_ptr LandManager::getLand(ESM::ExteriorCellLocation cellIndex) { const osg::ref_ptr obj = mCache->getRefFromObjectCache(cellIndex); if (obj != nullptr) return static_cast(obj.get()); const MWBase::World& world = *MWBase::Environment::get().getWorld(); if (ESM::isEsm4Ext(cellIndex.mWorldspace)) { const ESM4::Land* land = world.getStore().get().search(cellIndex); if (land == nullptr) return nullptr; osg::ref_ptr landObj(new ESMTerrain::LandObject(*land, mLoadFlags)); mCache->addEntryToObjectCache(cellIndex, landObj.get()); return landObj; } else { const ESM::Land* land = world.getStore().get().search(cellIndex.mX, cellIndex.mY); if (land == nullptr) return nullptr; osg::ref_ptr landObj(new ESMTerrain::LandObject(*land, mLoadFlags)); mCache->addEntryToObjectCache(cellIndex, landObj.get()); return landObj; } } void LandManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const { stats->setAttribute(frameNumber, "Land", mCache->getCacheSize()); } }