1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 21:32:42 +00:00

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
854 B
C++
Raw Normal View History

2023-03-05 21:47:49 +01:00
#include "ptr.hpp"
#include "apps/openmw/mwbase/environment.hpp"
#include "worldmodel.hpp"
namespace MWWorld
{
SafePtr::SafePtr(const Ptr& ptr)
: mId(ptr.getCellRef().getRefNum())
, mPtr(ptr)
, mLastUpdate(MWBase::Environment::get().getWorldModel()->getPtrRegistryRevision())
{
}
2023-03-05 21:47:49 +01:00
std::string SafePtr::toString() const
{
update();
if (mPtr.isEmpty())
return "object" + mId.toString() + " (not found)";
else
return mPtr.toString();
}
void SafePtr::update() const
{
const WorldModel& worldModel = *MWBase::Environment::get().getWorldModel();
if (mLastUpdate != worldModel.getPtrRegistryRevision())
2023-03-05 21:47:49 +01:00
{
mPtr = worldModel.getPtr(mId);
mLastUpdate = worldModel.getPtrRegistryRevision();
2023-03-05 21:47:49 +01:00
}
}
}