Skip to content

Commit

Permalink
Merge branch 'refnum_ref' into 'master'
Browse files Browse the repository at this point in the history
Replace `const ESM::RefNum&` -> `ESM::RefNum`

See merge request OpenMW/openmw!3432
  • Loading branch information
psi29a committed Sep 18, 2023
2 parents 18b6eba + c67b866 commit eb688b6
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 32 deletions.
3 changes: 1 addition & 2 deletions apps/navmeshtool/worldspacedata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ namespace NavMeshTool

Log(Debug::Debug) << "Loaded " << cellRefs.size() << " cell refs";

const auto getKey
= [](const EsmLoader::Record<CellRef>& v) -> const ESM::RefNum& { return v.mValue.mRefNum; };
const auto getKey = [](const EsmLoader::Record<CellRef>& v) -> ESM::RefNum { return v.mValue.mRefNum; };
std::vector<CellRef> result = prepareRecords(cellRefs, getKey);

Log(Debug::Debug) << "Prepared " << result.size() << " unique cell refs";
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwlua/engineevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace MWLua
void operator()(const OnNewExterior& event) const { mGlobalScripts.onNewExterior(GCell{ &event.mCell }); }

private:
MWWorld::Ptr getPtr(const ESM::RefNum& id) const
MWWorld::Ptr getPtr(ESM::RefNum id) const
{
MWWorld::Ptr res = mWorldModel->getPtr(id);
if (res.isEmpty() && Settings::lua().mLuaDebug)
Expand All @@ -103,7 +103,7 @@ namespace MWLua
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;
MWWorld::WorldModel* mWorldModel = MWBase::Environment::get().getWorldModel();
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwlua/luaevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace MWLua
}

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.writeFormId(dest, true);
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwlua/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace MWLua
// ObjectId is a unique identifier of a game object.
// It can change only if the order of content files was change.
using ObjectId = ESM::RefNum;
inline const ObjectId& getId(const MWWorld::Ptr& ptr)
inline ObjectId getId(const MWWorld::Ptr& ptr)
{
return ptr.getCellRef().getRefNum();
}
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwlua/objectlists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace MWLua
if (mChanged)
{
mList->clear();
for (const ObjectId& id : mSet)
for (ObjectId id : mSet)
mList->push_back(id);
mChanged = false;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwlua/userdataserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace MWLua
{
std::vector<ESM::RefNum> buf;
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) });
append(out, sObjListTypeName, buf.data(), buf.size() * sizeof(ESM::RefNum));
}
Expand Down
7 changes: 3 additions & 4 deletions apps/openmw/mwrender/objectpaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ namespace MWRender
class AddRefnumMarkerVisitor : public osg::NodeVisitor
{
public:
AddRefnumMarkerVisitor(const ESM::RefNum& refnum)
AddRefnumMarkerVisitor(ESM::RefNum refnum)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
, mRefnum(refnum)
{
Expand Down Expand Up @@ -896,7 +896,7 @@ namespace MWRender
};

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))
return false;
Expand All @@ -923,8 +923,7 @@ namespace MWRender
return true;
}

bool ObjectPaging::blacklistObject(
int type, const ESM::RefNum& refnum, const osg::Vec3f& pos, const osg::Vec2i& cell)
bool ObjectPaging::blacklistObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell)
{
if (!typeFilter(type, false))
return false;
Expand Down
5 changes: 2 additions & 3 deletions apps/openmw/mwrender/objectpaging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ namespace MWRender
unsigned int getNodeMask() override;

/// @return true if view needs rebuild
bool enableObject(
int type, const ESM::RefNum& refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled);
bool enableObject(int type, ESM::RefNum refnum, const osg::Vec3f& pos, const osg::Vec2i& cell, bool enabled);

/// @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();

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwrender/renderingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,7 @@ namespace MWRender
{
if (!ptr.isInCell() || !ptr.getCell()->isExterior() || !mObjectPaging)
return;
const ESM::RefNum& refnum = ptr.getCellRef().getRefNum();
ESM::RefNum refnum = ptr.getCellRef().getRefNum();
if (!refnum.hasContentFile())
return;
if (mObjectPaging->blacklistObject(type, refnum, ptr.getCellRef().getPosition().asVec3(),
Expand Down
10 changes: 5 additions & 5 deletions apps/openmw/mwworld/cellref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ namespace MWWorld
{
}

const ESM::RefNum& CellRef::getRefNum() const noexcept
ESM::RefNum CellRef::getRefNum() const noexcept
{
return std::visit(ESM::VisitOverload{
[&](const ESM4::Reference& ref) -> const ESM::RefNum& { return ref.mId; },
[&](const ESM4::ActorCharacter& ref) -> const ESM::RefNum& { return ref.mId; },
[&](const ESM::CellRef& ref) -> const ESM::RefNum& { return ref.mRefNum; },
[&](const ESM4::Reference& ref) -> ESM::RefNum { return ref.mId; },
[&](const ESM4::ActorCharacter& ref) -> ESM::RefNum { return ref.mId; },
[&](const ESM::CellRef& ref) -> ESM::RefNum { return ref.mRefNum; },
},
mCellRef.mVariant);
}

const ESM::RefNum& CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum)
ESM::RefNum CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum)
{
ESM::RefNum& refNum = std::visit(ESM::VisitOverload{
[&](ESM4::Reference& ref) -> ESM::RefNum& { return ref.mId; },
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwworld/cellref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace MWWorld
explicit CellRef(const ESM4::ActorCharacter& ref);

// Note: Currently unused for items in containers
const ESM::RefNum& getRefNum() const noexcept;
ESM::RefNum getRefNum() const noexcept;

// Returns RefNum.
// 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);

Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwworld/cellreflist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace MWWorld
}

/// 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();)
{
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwworld/cellstore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,10 @@ namespace MWWorld

class RefNumSearchVisitor
{
const ESM::RefNum& mRefNum;
ESM::RefNum mRefNum;

public:
RefNumSearchVisitor(const ESM::RefNum& refNum)
RefNumSearchVisitor(ESM::RefNum refNum)
: mRefNum(refNum)
{
}
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwworld/ptrregistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace MWWorld

void remove(const LiveCellRefBase& ref) noexcept
{
const ESM::RefNum& refNum = ref.mRef.getRefNum();
ESM::RefNum refNum = ref.mRef.getRefNum();
if (!refNum.isSet())
return;
auto it = mIndex.find(refNum);
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwworld/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace
std::string model = getModel(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))
ptr.getClass().insertObjectRendering(ptr, model, rendering);
else
Expand Down Expand Up @@ -259,7 +259,7 @@ namespace
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);
if (it == pagedRefs.end() || *it != refNum)
Expand All @@ -274,7 +274,7 @@ namespace MWWorld

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 (!ptr.getRefData().getBaseNode())
Expand Down
3 changes: 1 addition & 2 deletions components/resource/foreachbulletobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ namespace Resource

Log(Debug::Debug) << "Loaded " << cellRefs.size() << " cell refs";

const auto getKey
= [](const EsmLoader::Record<CellRef>& v) -> const ESM::RefNum& { return v.mValue.mRefNum; };
const auto getKey = [](const EsmLoader::Record<CellRef>& v) -> ESM::RefNum { return v.mValue.mRefNum; };
std::vector<CellRef> result = prepareRecords(cellRefs, getKey);

Log(Debug::Debug) << "Prepared " << result.size() << " unique cell refs";
Expand Down

0 comments on commit eb688b6

Please sign in to comment.