2017-03-06 19:04:17 +01:00
|
|
|
#include "landmanager.hpp"
|
|
|
|
|
2023-09-25 20:24:48 +03:00
|
|
|
#include <components/esm4/loadwrld.hpp>
|
2017-03-06 19:04:17 +01:00
|
|
|
#include <components/resource/objectcache.hpp>
|
2023-09-09 19:29:26 +02:00
|
|
|
#include <components/settings/values.hpp>
|
2017-03-06 19:04:17 +01:00
|
|
|
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwworld/esmstore.hpp"
|
|
|
|
|
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
|
|
|
|
LandManager::LandManager(int loadFlags)
|
2023-09-09 19:29:26 +02:00
|
|
|
: GenericResourceManager<ESM::ExteriorCellLocation>(nullptr, Settings::cells().mCacheExpiryDelay)
|
2017-03-06 19:04:17 +01:00
|
|
|
, mLoadFlags(loadFlags)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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-09-25 20:24:48 +03:00
|
|
|
const MWBase::World& world = *MWBase::Environment::get().getWorld();
|
|
|
|
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
|
|
|
|
{
|
|
|
|
const ESM4::World* worldspace = world.getStore().get<ESM4::World>().find(cellIndex.mWorldspace);
|
|
|
|
if (!worldspace->mParent.isZeroOrUnset() && worldspace->mParentUseFlags & ESM4::World::UseFlag_Land)
|
|
|
|
cellIndex.mWorldspace = worldspace->mParent;
|
|
|
|
}
|
|
|
|
|
2023-08-19 01:27:08 +02: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
|
|
|
|
2023-08-19 01:29:08 +02:00
|
|
|
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);
|
2023-08-19 01:27:08 +02:00
|
|
|
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);
|
2023-08-19 01:27:08 +02:00
|
|
|
if (land != nullptr)
|
|
|
|
landObj = new ESMTerrain::LandObject(*land, mLoadFlags);
|
2017-03-06 19:04:17 +01:00
|
|
|
}
|
2023-08-19 01:29:08 +02:00
|
|
|
|
|
|
|
mCache->addEntryToObjectCache(cellIndex, 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
|
|
|
{
|
2023-12-22 00:23:49 +01:00
|
|
|
Resource::reportStats("Land", frameNumber, mCache->getStats(), *stats);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2017-03-06 19:04:17 +01:00
|
|
|
|
|
|
|
}
|