mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:23:52 +00:00
Minor changes to ESM::RefNum
1. Changed mIndex to unsigned, to solve potential implementation defined behavior with right shift. 2. Refactoring to minimize use of magic number -1 to indicate "no Content File".
This commit is contained in:
parent
595c08817f
commit
7aa0f887c0
11 changed files with 28 additions and 19 deletions
|
@ -872,7 +872,7 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
// Note we do not respawn moved references in the cell they were moved to. Instead they are respawned in the original cell.
|
// Note we do not respawn moved references in the cell they were moved to. Instead they are respawned in the original cell.
|
||||||
// This also means we cannot respawn dynamically placed references with no content file connection.
|
// This also means we cannot respawn dynamically placed references with no content file connection.
|
||||||
if (ptr.getCellRef().getRefNum().mContentFile != -1)
|
if (ptr.getCellRef().hasContentFile())
|
||||||
{
|
{
|
||||||
if (ptr.getRefData().getCount() == 0)
|
if (ptr.getRefData().getCount() == 0)
|
||||||
ptr.getRefData().setCount(1);
|
ptr.getRefData().setCount(1);
|
||||||
|
|
|
@ -1331,7 +1331,7 @@ namespace MWClass
|
||||||
{
|
{
|
||||||
// Note we do not respawn moved references in the cell they were moved to. Instead they are respawned in the original cell.
|
// Note we do not respawn moved references in the cell they were moved to. Instead they are respawned in the original cell.
|
||||||
// This also means we cannot respawn dynamically placed references with no content file connection.
|
// This also means we cannot respawn dynamically placed references with no content file connection.
|
||||||
if (ptr.getCellRef().getRefNum().mContentFile != -1)
|
if (ptr.getCellRef().hasContentFile())
|
||||||
{
|
{
|
||||||
if (ptr.getRefData().getCount() == 0)
|
if (ptr.getRefData().getCount() == 0)
|
||||||
ptr.getRefData().setCount(1);
|
ptr.getRefData().setCount(1);
|
||||||
|
|
|
@ -1035,7 +1035,7 @@ namespace MWScript
|
||||||
|
|
||||||
msg << "Content file: ";
|
msg << "Content file: ";
|
||||||
|
|
||||||
if (ptr.getCellRef().getRefNum().mContentFile == -1)
|
if (!ptr.getCellRef().hasContentFile())
|
||||||
msg << "[None]" << std::endl;
|
msg << "[None]" << std::endl;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,10 +10,14 @@ namespace MWWorld
|
||||||
return mCellRef.mRefNum;
|
return mCellRef.mRefNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CellRef::hasContentFile() const
|
||||||
|
{
|
||||||
|
return getRefNum().hasContentFile();
|
||||||
|
}
|
||||||
|
|
||||||
void CellRef::unsetRefNum()
|
void CellRef::unsetRefNum()
|
||||||
{
|
{
|
||||||
mCellRef.mRefNum.mContentFile = -1;
|
getRefNum().unset();
|
||||||
mCellRef.mRefNum.mIndex = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CellRef::getRefId() const
|
std::string CellRef::getRefId() const
|
||||||
|
|
|
@ -28,6 +28,9 @@ namespace MWWorld
|
||||||
// Set RefNum to its default state.
|
// Set RefNum to its default state.
|
||||||
void unsetRefNum();
|
void unsetRefNum();
|
||||||
|
|
||||||
|
/// Does the RefNum have a content file?
|
||||||
|
bool hasContentFile() const;
|
||||||
|
|
||||||
// Id of object being referenced
|
// Id of object being referenced
|
||||||
std::string getRefId() const;
|
std::string getRefId() const;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
for (typename List::iterator iter (mList.begin()); iter!=mList.end(); ++iter)
|
for (typename List::iterator iter (mList.begin()); iter!=mList.end(); ++iter)
|
||||||
if (!iter->mData.isDeletedByContentFile()
|
if (!iter->mData.isDeletedByContentFile()
|
||||||
&& (iter->mRef.getRefNum().mContentFile != -1 || iter->mData.getCount() > 0)
|
&& (iter->mRef.hasContentFile() || iter->mData.getCount() > 0)
|
||||||
&& iter->mRef.getRefId() == name)
|
&& iter->mRef.getRefId() == name)
|
||||||
return &*iter;
|
return &*iter;
|
||||||
|
|
||||||
|
|
|
@ -72,12 +72,12 @@ namespace
|
||||||
iter (collection.mList.begin());
|
iter (collection.mList.begin());
|
||||||
iter!=collection.mList.end(); ++iter)
|
iter!=collection.mList.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (!iter->mData.hasChanged() && !iter->mRef.hasChanged() && iter->mRef.getRefNum().mContentFile != -1)
|
if (!iter->mData.hasChanged() && !iter->mRef.hasChanged() && iter->mRef.hasContentFile())
|
||||||
{
|
{
|
||||||
// Reference that came from a content file and has not been changed -> ignore
|
// Reference that came from a content file and has not been changed -> ignore
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (iter->mData.getCount()==0 && iter->mRef.getRefNum().mContentFile==-1)
|
if (iter->mData.getCount()==0 && !iter->mRef.hasContentFile())
|
||||||
{
|
{
|
||||||
// Deleted reference that did not come from a content file -> ignore
|
// Deleted reference that did not come from a content file -> ignore
|
||||||
continue;
|
continue;
|
||||||
|
@ -102,7 +102,7 @@ namespace
|
||||||
state.load (reader);
|
state.load (reader);
|
||||||
|
|
||||||
// If the reference came from a content file, make sure this content file is loaded
|
// If the reference came from a content file, make sure this content file is loaded
|
||||||
if (state.mRef.mRefNum.mContentFile != -1)
|
if (state.mRef.mRefNum.hasContentFile())
|
||||||
{
|
{
|
||||||
std::map<int, int>::const_iterator iter =
|
std::map<int, int>::const_iterator iter =
|
||||||
contentFileMap.find (state.mRef.mRefNum.mContentFile);
|
contentFileMap.find (state.mRef.mRefNum.mContentFile);
|
||||||
|
@ -121,7 +121,7 @@ namespace
|
||||||
if (!record)
|
if (!record)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (state.mRef.mRefNum.mContentFile != -1)
|
if (state.mRef.mRefNum.hasContentFile())
|
||||||
{
|
{
|
||||||
for (typename MWWorld::CellRefList<T>::List::iterator iter (collection.mList.begin());
|
for (typename MWWorld::CellRefList<T>::List::iterator iter (collection.mList.begin());
|
||||||
iter!=collection.mList.end(); ++iter)
|
iter!=collection.mList.end(); ++iter)
|
||||||
|
@ -487,7 +487,7 @@ namespace MWWorld
|
||||||
mCell->restore (esm[index], i);
|
mCell->restore (esm[index], i);
|
||||||
|
|
||||||
ESM::CellRef ref;
|
ESM::CellRef ref;
|
||||||
ref.mRefNum.mContentFile = -1;
|
ref.mRefNum.mContentFile = ESM::RefNum::RefNum_NoContentFile;
|
||||||
|
|
||||||
// Get each reference in turn
|
// Get each reference in turn
|
||||||
bool deleted = false;
|
bool deleted = false;
|
||||||
|
|
|
@ -24,8 +24,7 @@ namespace MWWorld
|
||||||
const T* base = list.find(name);
|
const T* base = list.find(name);
|
||||||
|
|
||||||
ESM::CellRef cellRef;
|
ESM::CellRef cellRef;
|
||||||
cellRef.mRefNum.mIndex = 0;
|
cellRef.mRefNum.unset();
|
||||||
cellRef.mRefNum.mContentFile = -1;
|
|
||||||
cellRef.mRefID = name;
|
cellRef.mRefID = name;
|
||||||
cellRef.mScale = 1;
|
cellRef.mScale = 1;
|
||||||
cellRef.mFactionRank = 0;
|
cellRef.mFactionRank = 0;
|
||||||
|
|
|
@ -1089,7 +1089,7 @@ namespace MWWorld
|
||||||
|
|
||||||
void World::undeleteObject(const Ptr& ptr)
|
void World::undeleteObject(const Ptr& ptr)
|
||||||
{
|
{
|
||||||
if (ptr.getCellRef().getRefNum().mContentFile == -1)
|
if (!ptr.getCellRef().hasContentFile())
|
||||||
return;
|
return;
|
||||||
if (ptr.getRefData().isDeleted())
|
if (ptr.getRefData().isDeleted())
|
||||||
{
|
{
|
||||||
|
@ -3206,7 +3206,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
// Can't reset actors that were moved to a different cell, because we don't know what cell they came from.
|
// Can't reset actors that were moved to a different cell, because we don't know what cell they came from.
|
||||||
// This could be fixed once we properly track actor cell changes, but may not be desirable behaviour anyhow.
|
// This could be fixed once we properly track actor cell changes, but may not be desirable behaviour anyhow.
|
||||||
if (ptr.getClass().isActor() && ptr.getCellRef().getRefNum().mContentFile != -1)
|
if (ptr.getClass().isActor() && ptr.getCellRef().hasContentFile())
|
||||||
{
|
{
|
||||||
const ESM::Position& origPos = ptr.getCellRef().getPosition();
|
const ESM::Position& origPos = ptr.getCellRef().getPosition();
|
||||||
MWBase::Environment::get().getWorld()->moveObject(ptr, origPos.pos[0], origPos.pos[1], origPos.pos[2]);
|
MWBase::Environment::get().getWorld()->moveObject(ptr, origPos.pos[0], origPos.pos[1], origPos.pos[2]);
|
||||||
|
|
|
@ -129,8 +129,7 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons
|
||||||
|
|
||||||
void ESM::CellRef::blank()
|
void ESM::CellRef::blank()
|
||||||
{
|
{
|
||||||
mRefNum.mIndex = 0;
|
mRefNum.unset();
|
||||||
mRefNum.mContentFile = -1;
|
|
||||||
mRefID.clear();
|
mRefID.clear();
|
||||||
mScale = 1;
|
mScale = 1;
|
||||||
mOwner.clear();
|
mOwner.clear();
|
||||||
|
|
|
@ -13,8 +13,12 @@ namespace ESM
|
||||||
|
|
||||||
struct RefNum
|
struct RefNum
|
||||||
{
|
{
|
||||||
int mIndex;
|
unsigned int mIndex;
|
||||||
int mContentFile; // -1 no content file
|
int mContentFile;
|
||||||
|
|
||||||
|
enum { RefNum_NoContentFile = -1 };
|
||||||
|
inline bool hasContentFile() const { return mContentFile != RefNum_NoContentFile; }
|
||||||
|
inline void unset() { mIndex = 0; mContentFile = RefNum_NoContentFile; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Cell reference. This represents ONE object (of many) inside the
|
/* Cell reference. This represents ONE object (of many) inside the
|
||||||
|
|
Loading…
Reference in a new issue