1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00
OpenMW/apps/openmw/mwworld/ptr.cpp
2024-05-26 02:52:11 +02:00

35 lines
854 B
C++

#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())
{
}
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())
{
mPtr = worldModel.getPtr(mId);
mLastUpdate = worldModel.getPtrRegistryRevision();
}
}
}