mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-07 12:54:00 +00:00
35 lines
854 B
C++
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();
|
|
}
|
|
}
|
|
}
|