2023-03-05 21:47:49 +01:00
|
|
|
#include "ptr.hpp"
|
|
|
|
|
|
|
|
#include "apps/openmw/mwbase/environment.hpp"
|
|
|
|
|
|
|
|
#include "worldmodel.hpp"
|
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
2023-03-22 01:27:22 +01:00
|
|
|
SafePtr::SafePtr(const Ptr& ptr)
|
|
|
|
: mId(ptr.getCellRef().getRefNum())
|
|
|
|
, mPtr(ptr)
|
2023-05-30 21:44:54 +02:00
|
|
|
, mLastUpdate(MWBase::Environment::get().getWorldModel()->getPtrRegistryRevision())
|
2023-03-22 01:27:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2023-05-30 21:44:54 +02:00
|
|
|
const WorldModel& worldModel = *MWBase::Environment::get().getWorldModel();
|
|
|
|
if (mLastUpdate != worldModel.getPtrRegistryRevision())
|
2023-03-05 21:47:49 +01:00
|
|
|
{
|
2023-05-30 21:44:54 +02:00
|
|
|
mPtr = worldModel.getPtr(mId);
|
|
|
|
mLastUpdate = worldModel.getPtrRegistryRevision();
|
2023-03-05 21:47:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|