2017-03-06 19:04:17 +01:00
|
|
|
#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)
|
2017-03-06 19:04:17 +01:00
|
|
|
, mLoadFlags(loadFlags)
|
|
|
|
{
|
2019-03-13 11:15:58 +04:00
|
|
|
mCache = new CacheType;
|
2017-03-06 19:04:17 +01:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:24:59 +02:00
|
|
|
osg::ref_ptr<ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellLocation cellIndex)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2023-05-09 22:08:17 +02:00
|
|
|
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
|
2023-04-24 21:20:07 +02:00
|
|
|
return osg::ref_ptr<ESMTerrain::LandObject>(nullptr);
|
2023-05-05 10:31:06 +02:00
|
|
|
int x = cellIndex.mX;
|
|
|
|
int y = cellIndex.mY;
|
2017-03-07 04:02:06 +01:00
|
|
|
osg::ref_ptr<osg::Object> obj = mCache->getRefFromObjectCache(std::make_pair(x, y));
|
2022-09-22 21:26:05 +03:00
|
|
|
if (obj)
|
2017-03-07 04:02:06 +01:00
|
|
|
return static_cast<ESMTerrain::LandObject*>(obj.get());
|
2022-09-22 21:26:05 +03:00
|
|
|
else
|
|
|
|
{
|
2017-03-07 04:02:06 +01:00
|
|
|
const auto world = MWBase::Environment::get().getWorld();
|
2022-03-03 20:24:52 +02:00
|
|
|
if (!world)
|
2017-03-06 19:04:17 +01:00
|
|
|
return nullptr;
|
|
|
|
const ESM::Land* land = world->getStore().get<ESM::Land>().search(x, y);
|
|
|
|
if (!land)
|
2018-10-09 10:21:12 +04:00
|
|
|
return nullptr;
|
2017-03-06 19:04:17 +01:00
|
|
|
osg::ref_ptr<ESMTerrain::LandObject> landObj(new ESMTerrain::LandObject(land, mLoadFlags));
|
|
|
|
mCache->addEntryToObjectCache(std::make_pair(x, y), landObj.get());
|
|
|
|
return landObj;
|
|
|
|
}
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2017-03-06 19:04:17 +01: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
|
|
|
{
|
2017-03-06 19:04:17 +01:00
|
|
|
stats->setAttribute(frameNumber, "Land", mCache->getCacheSize());
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2017-03-06 19:04:17 +01:00
|
|
|
|
|
|
|
}
|