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".
openmw-35
dteviot 10 years ago
parent 595c08817f
commit 7aa0f887c0

@ -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.
// 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)
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.
// 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)
ptr.getRefData().setCount(1);

@ -1035,7 +1035,7 @@ namespace MWScript
msg << "Content file: ";
if (ptr.getCellRef().getRefNum().mContentFile == -1)
if (!ptr.getCellRef().hasContentFile())
msg << "[None]" << std::endl;
else
{

@ -10,10 +10,14 @@ namespace MWWorld
return mCellRef.mRefNum;
}
bool CellRef::hasContentFile() const
{
return getRefNum().hasContentFile();
}
void CellRef::unsetRefNum()
{
mCellRef.mRefNum.mContentFile = -1;
mCellRef.mRefNum.mIndex = 0;
getRefNum().unset();
}
std::string CellRef::getRefId() const

@ -28,6 +28,9 @@ namespace MWWorld
// Set RefNum to its default state.
void unsetRefNum();
/// Does the RefNum have a content file?
bool hasContentFile() const;
// Id of object being referenced
std::string getRefId() const;

@ -28,7 +28,7 @@ namespace MWWorld
{
for (typename List::iterator iter (mList.begin()); iter!=mList.end(); ++iter)
if (!iter->mData.isDeletedByContentFile()
&& (iter->mRef.getRefNum().mContentFile != -1 || iter->mData.getCount() > 0)
&& (iter->mRef.hasContentFile() || iter->mData.getCount() > 0)
&& iter->mRef.getRefId() == name)
return &*iter;

@ -72,12 +72,12 @@ namespace
iter (collection.mList.begin());
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
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
continue;
@ -102,7 +102,7 @@ namespace
state.load (reader);
// 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 =
contentFileMap.find (state.mRef.mRefNum.mContentFile);
@ -121,7 +121,7 @@ namespace
if (!record)
return;
if (state.mRef.mRefNum.mContentFile != -1)
if (state.mRef.mRefNum.hasContentFile())
{
for (typename MWWorld::CellRefList<T>::List::iterator iter (collection.mList.begin());
iter!=collection.mList.end(); ++iter)
@ -487,7 +487,7 @@ namespace MWWorld
mCell->restore (esm[index], i);
ESM::CellRef ref;
ref.mRefNum.mContentFile = -1;
ref.mRefNum.mContentFile = ESM::RefNum::RefNum_NoContentFile;
// Get each reference in turn
bool deleted = false;

@ -24,8 +24,7 @@ namespace MWWorld
const T* base = list.find(name);
ESM::CellRef cellRef;
cellRef.mRefNum.mIndex = 0;
cellRef.mRefNum.mContentFile = -1;
cellRef.mRefNum.unset();
cellRef.mRefID = name;
cellRef.mScale = 1;
cellRef.mFactionRank = 0;

@ -1089,7 +1089,7 @@ namespace MWWorld
void World::undeleteObject(const Ptr& ptr)
{
if (ptr.getCellRef().getRefNum().mContentFile == -1)
if (!ptr.getCellRef().hasContentFile())
return;
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.
// 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();
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()
{
mRefNum.mIndex = 0;
mRefNum.mContentFile = -1;
mRefNum.unset();
mRefID.clear();
mScale = 1;
mOwner.clear();

@ -13,8 +13,12 @@ namespace ESM
struct RefNum
{
int mIndex;
int mContentFile; // -1 no content file
unsigned int mIndex;
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

Loading…
Cancel
Save