From 4565152b3d8538965821d2343a5419a8c745deb4 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 15 Jun 2024 00:31:43 +0200 Subject: [PATCH] Define LiveCellRefBase functions inside MWWorld namespace block --- apps/openmw/mwworld/livecellref.cpp | 164 ++++++++++++++-------------- apps/openmw/mwworld/livecellref.hpp | 2 +- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index 61b838bbf0..5623083de7 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -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().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().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().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().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(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(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; diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index c95dd589b2..5694e33642 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -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;