1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 15:29:55 +00:00

Replace const ESM::RefNum& -> ESM::RefNum

This commit is contained in:
Petr Mikheev 2023-09-15 19:38:09 +02:00
parent 551f424c80
commit c67b866a11
16 changed files with 28 additions and 32 deletions

View file

@ -103,8 +103,7 @@ namespace NavMeshTool
Log(Debug::Debug) << "Loaded " << cellRefs.size() << " cell refs"; Log(Debug::Debug) << "Loaded " << cellRefs.size() << " cell refs";
const auto getKey const auto getKey = [](const EsmLoader::Record<CellRef>& v) -> ESM::RefNum { return v.mValue.mRefNum; };
= [](const EsmLoader::Record<CellRef>& v) -> const ESM::RefNum& { return v.mValue.mRefNum; };
std::vector<CellRef> result = prepareRecords(cellRefs, getKey); std::vector<CellRef> result = prepareRecords(cellRefs, getKey);
Log(Debug::Debug) << "Prepared " << result.size() << " unique cell refs"; Log(Debug::Debug) << "Prepared " << result.size() << " unique cell refs";

View file

@ -87,7 +87,7 @@ namespace MWLua
void operator()(const OnNewExterior& event) const { mGlobalScripts.onNewExterior(GCell{ &event.mCell }); } void operator()(const OnNewExterior& event) const { mGlobalScripts.onNewExterior(GCell{ &event.mCell }); }
private: private:
MWWorld::Ptr getPtr(const ESM::RefNum& id) const MWWorld::Ptr getPtr(ESM::RefNum id) const
{ {
MWWorld::Ptr res = mWorldModel->getPtr(id); MWWorld::Ptr res = mWorldModel->getPtr(id);
if (res.isEmpty() && Settings::lua().mLuaDebug) if (res.isEmpty() && Settings::lua().mLuaDebug)
@ -103,7 +103,7 @@ namespace MWLua
return ptr.getRefData().getLuaScripts(); return ptr.getRefData().getLuaScripts();
} }
LocalScripts* getLocalScripts(const ESM::RefNum& id) const { return getLocalScripts(getPtr(id)); } LocalScripts* getLocalScripts(ESM::RefNum id) const { return getLocalScripts(getPtr(id)); }
GlobalScripts& mGlobalScripts; GlobalScripts& mGlobalScripts;
MWWorld::WorldModel* mWorldModel = MWBase::Environment::get().getWorldModel(); MWWorld::WorldModel* mWorldModel = MWBase::Environment::get().getWorldModel();

View file

@ -52,7 +52,7 @@ namespace MWLua
} }
template <typename Event> template <typename Event>
static void saveEvent(ESM::ESMWriter& esm, const ESM::RefNum& dest, const Event& event) static void saveEvent(ESM::ESMWriter& esm, ESM::RefNum dest, const Event& event)
{ {
esm.writeHNString("LUAE", event.mEventName); esm.writeHNString("LUAE", event.mEventName);
esm.writeFormId(dest, true); esm.writeFormId(dest, true);

View file

@ -16,7 +16,7 @@ namespace MWLua
// ObjectId is a unique identifier of a game object. // ObjectId is a unique identifier of a game object.
// It can change only if the order of content files was change. // It can change only if the order of content files was change.
using ObjectId = ESM::RefNum; using ObjectId = ESM::RefNum;
inline const ObjectId& getId(const MWWorld::Ptr& ptr) inline ObjectId getId(const MWWorld::Ptr& ptr)
{ {
return ptr.getCellRef().getRefNum(); return ptr.getCellRef().getRefNum();
} }

View file

@ -75,7 +75,7 @@ namespace MWLua
if (mChanged) if (mChanged)
{ {
mList->clear(); mList->clear();
for (const ObjectId& id : mSet) for (ObjectId id : mSet)
mList->push_back(id); mList->push_back(id);
mChanged = false; mChanged = false;
} }

View file

@ -52,7 +52,7 @@ namespace MWLua
{ {
std::vector<ESM::RefNum> buf; std::vector<ESM::RefNum> buf;
buf.reserve(objList->size()); buf.reserve(objList->size());
for (const ESM::RefNum& v : *objList) for (ESM::RefNum v : *objList)
buf.push_back({ Misc::toLittleEndian(v.mIndex), Misc::toLittleEndian(v.mContentFile) }); buf.push_back({ Misc::toLittleEndian(v.mIndex), Misc::toLittleEndian(v.mContentFile) });
append(out, sObjListTypeName, buf.data(), buf.size() * sizeof(ESM::RefNum)); append(out, sObjListTypeName, buf.data(), buf.size() * sizeof(ESM::RefNum));
} }

View file

@ -437,7 +437,7 @@ namespace MWRender
class AddRefnumMarkerVisitor : public osg::NodeVisitor class AddRefnumMarkerVisitor : public osg::NodeVisitor
{ {
public: public:
AddRefnumMarkerVisitor(const ESM::RefNum& refnum) AddRefnumMarkerVisitor(ESM::RefNum refnum)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
, mRefnum(refnum) , mRefnum(refnum)
{ {
@ -896,7 +896,7 @@ namespace MWRender
}; };
bool ObjectPaging::enableObject( bool ObjectPaging::enableObject(
int type, const ESM::RefNum& refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled) int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled)
{ {
if (!typeFilter(type, false)) if (!typeFilter(type, false))
return false; return false;
@ -923,8 +923,7 @@ namespace MWRender
return true; return true;
} }
bool ObjectPaging::blacklistObject( bool ObjectPaging::blacklistObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell)
int type, const ESM::RefNum& refnum, const osg::Vec3f& pos, const osg::Vec2i& cell)
{ {
if (!typeFilter(type, false)) if (!typeFilter(type, false))
return false; return false;

View file

@ -41,11 +41,10 @@ namespace MWRender
unsigned int getNodeMask() override; unsigned int getNodeMask() override;
/// @return true if view needs rebuild /// @return true if view needs rebuild
bool enableObject( bool enableObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled);
int type, const ESM::RefNum& refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled);
/// @return true if view needs rebuild /// @return true if view needs rebuild
bool blacklistObject(int type, const ESM::RefNum& refnum, const osg::Vec3f& pos, const osg::Vec2i& cell); bool blacklistObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell);
void clear(); void clear();

View file

@ -1644,7 +1644,7 @@ namespace MWRender
{ {
if (!ptr.isInCell() || !ptr.getCell()->isExterior() || !mObjectPaging) if (!ptr.isInCell() || !ptr.getCell()->isExterior() || !mObjectPaging)
return; return;
const ESM::RefNum& refnum = ptr.getCellRef().getRefNum(); ESM::RefNum refnum = ptr.getCellRef().getRefNum();
if (!refnum.hasContentFile()) if (!refnum.hasContentFile())
return; return;
if (mObjectPaging->blacklistObject(type, refnum, ptr.getCellRef().getPosition().asVec3(), if (mObjectPaging->blacklistObject(type, refnum, ptr.getCellRef().getPosition().asVec3(),

View file

@ -30,17 +30,17 @@ namespace MWWorld
{ {
} }
const ESM::RefNum& CellRef::getRefNum() const noexcept ESM::RefNum CellRef::getRefNum() const noexcept
{ {
return std::visit(ESM::VisitOverload{ return std::visit(ESM::VisitOverload{
[&](const ESM4::Reference& ref) -> const ESM::RefNum& { return ref.mId; }, [&](const ESM4::Reference& ref) -> ESM::RefNum { return ref.mId; },
[&](const ESM4::ActorCharacter& ref) -> const ESM::RefNum& { return ref.mId; }, [&](const ESM4::ActorCharacter& ref) -> ESM::RefNum { return ref.mId; },
[&](const ESM::CellRef& ref) -> const ESM::RefNum& { return ref.mRefNum; }, [&](const ESM::CellRef& ref) -> ESM::RefNum { return ref.mRefNum; },
}, },
mCellRef.mVariant); mCellRef.mVariant);
} }
const ESM::RefNum& CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum) ESM::RefNum CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum)
{ {
ESM::RefNum& refNum = std::visit(ESM::VisitOverload{ ESM::RefNum& refNum = std::visit(ESM::VisitOverload{
[&](ESM4::Reference& ref) -> ESM::RefNum& { return ref.mId; }, [&](ESM4::Reference& ref) -> ESM::RefNum& { return ref.mId; },

View file

@ -27,11 +27,11 @@ namespace MWWorld
explicit CellRef(const ESM4::ActorCharacter& ref); explicit CellRef(const ESM4::ActorCharacter& ref);
// Note: Currently unused for items in containers // Note: Currently unused for items in containers
const ESM::RefNum& getRefNum() const noexcept; ESM::RefNum getRefNum() const noexcept;
// Returns RefNum. // Returns RefNum.
// If RefNum is not set, assigns a generated one and changes the "lastAssignedRefNum" counter. // If RefNum is not set, assigns a generated one and changes the "lastAssignedRefNum" counter.
const ESM::RefNum& getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum); ESM::RefNum getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum);
void setRefNum(ESM::RefNum refNum); void setRefNum(ESM::RefNum refNum);

View file

@ -38,7 +38,7 @@ namespace MWWorld
} }
/// Remove all references with the given refNum from this list. /// Remove all references with the given refNum from this list.
void remove(const ESM::RefNum& refNum) void remove(ESM::RefNum refNum)
{ {
for (typename List::iterator it = mList.begin(); it != mList.end();) for (typename List::iterator it = mList.begin(); it != mList.end();)
{ {

View file

@ -660,10 +660,10 @@ namespace MWWorld
class RefNumSearchVisitor class RefNumSearchVisitor
{ {
const ESM::RefNum& mRefNum; ESM::RefNum mRefNum;
public: public:
RefNumSearchVisitor(const ESM::RefNum& refNum) RefNumSearchVisitor(ESM::RefNum refNum)
: mRefNum(refNum) : mRefNum(refNum)
{ {
} }

View file

@ -45,7 +45,7 @@ namespace MWWorld
void remove(const LiveCellRefBase& ref) noexcept void remove(const LiveCellRefBase& ref) noexcept
{ {
const ESM::RefNum& refNum = ref.mRef.getRefNum(); ESM::RefNum refNum = ref.mRef.getRefNum();
if (!refNum.isSet()) if (!refNum.isSet())
return; return;
auto it = mIndex.find(refNum); auto it = mIndex.find(refNum);

View file

@ -111,7 +111,7 @@ namespace
std::string model = getModel(ptr); std::string model = getModel(ptr);
const auto rotation = makeDirectNodeRotation(ptr); const auto rotation = makeDirectNodeRotation(ptr);
const ESM::RefNum& refnum = ptr.getCellRef().getRefNum(); ESM::RefNum refnum = ptr.getCellRef().getRefNum();
if (!refnum.hasContentFile() || !std::binary_search(pagedRefs.begin(), pagedRefs.end(), refnum)) if (!refnum.hasContentFile() || !std::binary_search(pagedRefs.begin(), pagedRefs.end(), refnum))
ptr.getClass().insertObjectRendering(ptr, model, rendering); ptr.getClass().insertObjectRendering(ptr, model, rendering);
else else
@ -259,7 +259,7 @@ namespace
return false; return false;
} }
bool removeFromSorted(const ESM::RefNum& refNum, std::vector<ESM::RefNum>& pagedRefs) bool removeFromSorted(ESM::RefNum refNum, std::vector<ESM::RefNum>& pagedRefs)
{ {
const auto it = std::lower_bound(pagedRefs.begin(), pagedRefs.end(), refNum); const auto it = std::lower_bound(pagedRefs.begin(), pagedRefs.end(), refNum);
if (it == pagedRefs.end() || *it != refNum) if (it == pagedRefs.end() || *it != refNum)
@ -274,7 +274,7 @@ namespace MWWorld
void Scene::removeFromPagedRefs(const Ptr& ptr) void Scene::removeFromPagedRefs(const Ptr& ptr)
{ {
const ESM::RefNum& refnum = ptr.getCellRef().getRefNum(); ESM::RefNum refnum = ptr.getCellRef().getRefNum();
if (refnum.hasContentFile() && removeFromSorted(refnum, mPagedRefs)) if (refnum.hasContentFile() && removeFromSorted(refnum, mPagedRefs))
{ {
if (!ptr.getRefData().getBaseNode()) if (!ptr.getRefData().getBaseNode())

View file

@ -79,8 +79,7 @@ namespace Resource
Log(Debug::Debug) << "Loaded " << cellRefs.size() << " cell refs"; Log(Debug::Debug) << "Loaded " << cellRefs.size() << " cell refs";
const auto getKey const auto getKey = [](const EsmLoader::Record<CellRef>& v) -> ESM::RefNum { return v.mValue.mRefNum; };
= [](const EsmLoader::Record<CellRef>& v) -> const ESM::RefNum& { return v.mValue.mRefNum; };
std::vector<CellRef> result = prepareRecords(cellRefs, getKey); std::vector<CellRef> result = prepareRecords(cellRefs, getKey);
Log(Debug::Debug) << "Prepared " << result.size() << " unique cell refs"; Log(Debug::Debug) << "Prepared " << result.size() << " unique cell refs";