Files
Bret Curtis 4addabaf95 Let the resource cache be told what it stores, and free its values from OSG
GenericObjectCache stored osg::ref_ptr<osg::Object>, so everything cached had to
derive from osg::Object whether that meant anything or not: NifFileHolder and
BgsmFileHolder existed for no other reason, Resource::BulletShape and
ESMTerrain::LandObject carried META_Object and a CopyOp constructor nothing ever
called, and every getter paid a static_cast on the way out. The cache and
MultiObjectCache now take their value type as a template parameter, ask "is
anything else holding this?" through a useCount overload rather than a base class
method, and constrain accept and releaseGLObjects so a value type with neither is
not an error. Both holders are deleted; BulletShape, BulletShapeInstance and
LandObject become plain classes held by std::shared_ptr across physics,
pathfinding, navmeshtool and terrain storage; MWPhysics::HeightField's
type-erased osg::Object keep-alive becomes the LandObject it was always holding;
every remaining manager names the type it actually caches through the
NodeResourceManager alias, which removes eight static_casts and stops
clang-format wrapping the declarations. The preloader needs two keep-alive sets
for now, because the render-owned entries are still osg::Object; they merge once
those move behind the render backend.
2026-09-18 16:10:18 +02:00

59 lines
2.0 KiB
C++

#include "landmanager.hpp"
#include <components/esm4/loadwrld.hpp>
#include <components/resource/objectcache.hpp>
#include <components/settings/values.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/esmstore.hpp"
namespace MWRender
{
LandManager::LandManager(int loadFlags)
: GenericResourceManager<ESM::ExteriorCellLocation, std::shared_ptr<const ESMTerrain::LandObject>>(
nullptr, Settings::cells().mCacheExpiryDelay)
, mLoadFlags(loadFlags)
{
}
std::shared_ptr<const ESMTerrain::LandObject> LandManager::getLand(ESM::ExteriorCellLocation cellIndex)
{
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;
}
if (const auto cached = mCache->getRefFromObjectCacheOrNone(cellIndex))
return *cached;
std::shared_ptr<const ESMTerrain::LandObject> landObj = nullptr;
if (ESM::isEsm4Ext(cellIndex.mWorldspace))
{
const ESM4::Land* land = world.getStore().get<ESM4::Land>().search(cellIndex);
if (land != nullptr)
landObj = std::make_shared<const ESMTerrain::LandObject>(*land, mLoadFlags);
}
else
{
const ESM::Land* land = world.getStore().get<ESM::Land>().search(cellIndex.mX, cellIndex.mY);
if (land != nullptr)
landObj = std::make_shared<const ESMTerrain::LandObject>(*land, mLoadFlags);
}
mCache->addEntryToObjectCache(cellIndex, landObj);
return landObj;
}
void LandManager::reportStats(unsigned int frameNumber, osg::Stats* stats) const
{
Resource::reportStats("Land", frameNumber, mCache->getStats(), *stats);
}
}