1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-12 22:14:42 +00:00

Define LiveCellRefBase functions inside MWWorld namespace block

This commit is contained in:
elsid 2024-06-15 00:31:43 +02:00
parent ca8869042b
commit 4565152b3d
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625
2 changed files with 83 additions and 83 deletions

View File

@ -15,104 +15,104 @@
#include "ptr.hpp"
#include "worldmodel.hpp"
MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM::CellRef& cref)
: mClass(&Class::get(type))
, mRef(cref)
, mData(cref)
namespace MWWorld
{
}
MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM4::Reference& cref)
: mClass(&Class::get(type))
, mRef(cref)
, mData(cref)
{
}
MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM4::ActorCharacter& cref)
: mClass(&Class::get(type))
, mRef(cref)
, mData(cref)
{
}
MWWorld::LiveCellRefBase::~LiveCellRefBase()
{
MWBase::Environment::get().getWorldModel()->deregisterLiveCellRef(*this);
}
void MWWorld::LiveCellRefBase::loadImp(const ESM::ObjectState& state)
{
mRef = MWWorld::CellRef(state.mRef);
mData = RefData(state, mData.isDeletedByContentFile());
Ptr ptr(this);
if (state.mHasLocals)
LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM::CellRef& cref)
: mClass(&Class::get(type))
, mRef(cref)
, mData(cref)
{
const ESM::RefId& scriptId = mClass->getScript(ptr);
// Make sure we still have a script. It could have been coming from a content file that is no longer active.
if (!scriptId.empty())
}
LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM4::Reference& cref)
: mClass(&Class::get(type))
, mRef(cref)
, mData(cref)
{
}
LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM4::ActorCharacter& cref)
: mClass(&Class::get(type))
, mRef(cref)
, mData(cref)
{
}
LiveCellRefBase::~LiveCellRefBase()
{
MWBase::Environment::get().getWorldModel()->deregisterLiveCellRef(*this);
}
void LiveCellRefBase::loadImp(const ESM::ObjectState& state)
{
mRef = CellRef(state.mRef);
mData = RefData(state, mData.isDeletedByContentFile());
Ptr ptr(this);
if (state.mHasLocals)
{
if (const ESM::Script* script
= MWBase::Environment::get().getESMStore()->get<ESM::Script>().search(scriptId))
const ESM::RefId& scriptId = mClass->getScript(ptr);
// Make sure we still have a script. It could have been coming from a content file that is no longer active.
if (!scriptId.empty())
{
try
if (const ESM::Script* script
= MWBase::Environment::get().getESMStore()->get<ESM::Script>().search(scriptId))
{
mData.setLocals(*script);
mData.getLocals().read(state.mLocals, scriptId);
}
catch (const std::exception& exception)
{
Log(Debug::Error) << "Error: failed to load state for local script " << scriptId
<< " because an exception has been thrown: " << exception.what();
try
{
mData.setLocals(*script);
mData.getLocals().read(state.mLocals, scriptId);
}
catch (const std::exception& exception)
{
Log(Debug::Error) << "Error: failed to load state for local script " << scriptId
<< " because an exception has been thrown: " << exception.what();
}
}
}
}
mClass->readAdditionalState(ptr, state);
if (!mRef.getSoul().empty()
&& !MWBase::Environment::get().getESMStore()->get<ESM::Creature>().search(mRef.getSoul()))
{
Log(Debug::Warning) << "Soul '" << mRef.getSoul() << "' not found, removing the soul from soul gem";
mRef.setSoul(ESM::RefId());
}
MWBase::Environment::get().getLuaManager()->loadLocalScripts(ptr, state.mLuaScripts);
}
mClass->readAdditionalState(ptr, state);
if (!mRef.getSoul().empty()
&& !MWBase::Environment::get().getESMStore()->get<ESM::Creature>().search(mRef.getSoul()))
void LiveCellRefBase::saveImp(ESM::ObjectState& state) const
{
Log(Debug::Warning) << "Soul '" << mRef.getSoul() << "' not found, removing the soul from soul gem";
mRef.setSoul(ESM::RefId());
mRef.writeState(state);
ConstPtr ptr(this);
mData.write(state, mClass->getScript(ptr));
MWBase::Environment::get().getLuaManager()->saveLocalScripts(
Ptr(const_cast<LiveCellRefBase*>(this)), state.mLuaScripts);
mClass->writeAdditionalState(ptr, state);
}
MWBase::Environment::get().getLuaManager()->loadLocalScripts(ptr, state.mLuaScripts);
}
bool LiveCellRefBase::checkStateImp(const ESM::ObjectState& state)
{
return true;
}
void MWWorld::LiveCellRefBase::saveImp(ESM::ObjectState& state) const
{
mRef.writeState(state);
unsigned int LiveCellRefBase::getType() const
{
return mClass->getType();
}
ConstPtr ptr(this);
bool LiveCellRefBase::isDeleted() const
{
return mData.isDeletedByContentFile() || mRef.getCount(false) == 0;
}
mData.write(state, mClass->getScript(ptr));
MWBase::Environment::get().getLuaManager()->saveLocalScripts(
Ptr(const_cast<LiveCellRefBase*>(this)), state.mLuaScripts);
mClass->writeAdditionalState(ptr, state);
}
bool MWWorld::LiveCellRefBase::checkStateImp(const ESM::ObjectState& state)
{
return true;
}
unsigned int MWWorld::LiveCellRefBase::getType() const
{
return mClass->getType();
}
bool MWWorld::LiveCellRefBase::isDeleted() const
{
return mData.isDeletedByContentFile() || mRef.getCount(false) == 0;
}
namespace MWWorld
{
std::string makeDynamicCastErrorMessage(const LiveCellRefBase* value, std::string_view recordType)
{
std::stringstream message;

View File

@ -29,7 +29,7 @@ namespace MWWorld
/** Information about this instance, such as 3D location and rotation
* and individual type-dependent data.
*/
MWWorld::CellRef mRef;
CellRef mRef;
/** runtime-data */
RefData mData;