1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-19 15:39:49 +00:00

applied some review changes.

crashfix tests
This commit is contained in:
florent.teppe 2023-01-29 19:18:50 +01:00
parent 144e0197fb
commit 4e7cde5d72
11 changed files with 96 additions and 69 deletions

View file

@ -160,7 +160,6 @@ namespace MWMechanics
};
/// convert point from local (i.e. cell) to world coordinates
void ToWorldCoordinates(ESM::Pathgrid::Point& point, const ESM::CellCommon* cell);
void setCurrentNodeToClosestAllowedNode(AiWanderStorage& storage);
void addNonPathGridAllowedPoints(const ESM::Pathgrid* pathGrid, int pointIndex, AiWanderStorage& storage,

View file

@ -17,13 +17,12 @@ namespace MWWorld
mRegion = ESM::RefId::sEmpty; // Unimplemented for now
mFlags.hasWater = cell.mCellFlags & ESM4::CELL_HasWater;
mFlags.isExterior = !(cell.mCellFlags & ESM4::CELL_Interior);
mFlags.isQuasiExterior = cell.mCellFlags & ESM4::CELL_QuasiExt;
mFlags.noSleep = false; // No such notion in ESM4
mFlags.mHasWater = cell.mCellFlags & ESM4::CELL_HasWater;
mFlags.mIsExterior = !(cell.mCellFlags & ESM4::CELL_Interior);
mFlags.mIsQuasiExterior = cell.mCellFlags & ESM4::CELL_QuasiExt;
mFlags.mNoSleep = false; // No such notion in ESM4
mCellId.mWorldspace = Misc::StringUtils::lowerCase(cell.mEditorId);
mCellId.mWorld = ESM::RefId::sEmpty;
mCellId.mIndex.mX = cell.getGridX();
mCellId.mIndex.mX = cell.getGridY();
mCellId.mPaged = isExterior();
@ -44,10 +43,10 @@ namespace MWWorld
mRegion = ESM::RefId::sEmpty; // Unimplemented for now
mFlags.hasWater = cell.mData.mFlags & ESM::Cell::HasWater;
mFlags.isExterior = !(cell.mData.mFlags & ESM::Cell::Interior);
mFlags.isQuasiExterior = cell.mData.mFlags & ESM::Cell::QuasiEx;
mFlags.noSleep = cell.mData.mFlags & ESM::Cell::NoSleep;
mFlags.mHasWater = cell.mData.mFlags & ESM::Cell::HasWater;
mFlags.mIsExterior = !(cell.mData.mFlags & ESM::Cell::Interior);
mFlags.mIsQuasiExterior = cell.mData.mFlags & ESM::Cell::QuasiEx;
mFlags.mNoSleep = cell.mData.mFlags & ESM::Cell::NoSleep;
mCellId = cell.getCellId();

View file

@ -38,10 +38,10 @@ namespace MWWorld
int getGridX() const { return mGridPos.x(); }
int getGridY() const { return mGridPos.y(); }
bool isExterior() const { return mFlags.isExterior; }
bool isQuasiExterior() const { return mFlags.isQuasiExterior; }
bool hasWater() const { return mFlags.hasWater; }
bool noSleep() const { return mFlags.noSleep; }
bool isExterior() const { return mFlags.mIsExterior; }
bool isQuasiExterior() const { return mFlags.mIsQuasiExterior; }
bool hasWater() const { return mFlags.mHasWater; }
bool noSleep() const { return mFlags.mNoSleep; }
const ESM::CellId& getCellId() const { return mCellId; }
const ESM::RefId& getRegion() const { return mRegion; }
std::string_view getNameId() const { return mNameID; }
@ -52,10 +52,10 @@ namespace MWWorld
private:
struct
{
bool isExterior;
bool isQuasiExterior;
bool hasWater;
bool noSleep;
bool mIsExterior;
bool mIsQuasiExterior;
bool mHasWater;
bool mNoSleep;
} mFlags;
osg::Vec2i mGridPos;

View file

@ -20,29 +20,29 @@ namespace MWWorld
CellRef::CellRef(const ESM::CellRef& ref)
: mCellRef(ESM::ReferenceVariant(ref))
{
mChanged = false;
}
CellRef::CellRef(const ESM4::Reference& ref)
: mCellRef(ESM::ReferenceVariant(ref))
{
mChanged = false;
}
static const ESM::RefNum emptyRefNum = {};
const ESM::RefNum& CellRef::getRefNum() const
{
return std::visit(RefVisit{ [&](const ESM4::Reference& ref) -> const ESM::RefNum& { return emptyRefNum; },
[&](const ESM::CellRef& ref) -> const ESM::RefNum& { return ref.mRefNum; } },
return std::visit(RefVisit{
[&](const ESM4::Reference& /*ref*/) -> const ESM::RefNum& { return emptyRefNum; },
[&](const ESM::CellRef& ref) -> const ESM::RefNum& { return ref.mRefNum; },
},
mCellRef.mVariant);
}
const ESM::RefNum& CellRef::getOrAssignRefNum(ESM::RefNum& lastAssignedRefNum)
{
return std::visit(
RefVisit{ [&](ESM4::Reference& ref) -> const ESM::RefNum& { return emptyRefNum; },
RefVisit{
[&](ESM4::Reference& /*ref*/) -> const ESM::RefNum& { return emptyRefNum; },
[&](ESM::CellRef& ref) -> const ESM::RefNum& {
if (!ref.mRefNum.isSet())
{
@ -60,13 +60,17 @@ namespace MWWorld
mChanged = true;
}
return ref.mRefNum;
} },
},
},
mCellRef.mVariant);
}
void CellRef::unsetRefNum()
{
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mRefNum = emptyRefNum; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mRefNum = emptyRefNum; },
},
mCellRef.mVariant);
}
@ -94,8 +98,10 @@ namespace MWWorld
float CellRef::getEnchantmentCharge() const
{
return std::visit(RefVisit{ [&](const ESM4::Reference& ref) { return 0.f; },
[&](const ESM::CellRef& ref) { return ref.mEnchantmentCharge; } },
return std::visit(RefVisit{
[&](const ESM4::Reference& /*ref*/) { return 0.f; },
[&](const ESM::CellRef& ref) { return ref.mEnchantmentCharge; },
},
mCellRef.mVariant);
}
@ -121,21 +127,27 @@ namespace MWWorld
{
mChanged = true;
std::visit(
RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mEnchantmentCharge = charge; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mEnchantmentCharge = charge; },
},
mCellRef.mVariant);
}
}
void CellRef::setCharge(int charge)
{
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mChargeInt = charge; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mChargeInt = charge; },
},
mCellRef.mVariant);
}
void CellRef::applyChargeRemainderToBeSubtracted(float chargeRemainder)
{
std::visit(RefVisit{ [&](ESM4::Reference& ref) {},
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& cellRef3) {
cellRef3.mChargeIntRemainder += std::abs(chargeRemainder);
if (cellRef3.mChargeIntRemainder > 1.0f)
@ -152,21 +164,27 @@ namespace MWWorld
}
cellRef3.mChargeIntRemainder = newChargeRemainder;
}
} },
},
},
mCellRef.mVariant);
}
void CellRef::setChargeFloat(float charge)
{
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mChargeFloat = charge; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mChargeFloat = charge; },
},
mCellRef.mVariant);
}
const std::string& CellRef::getGlobalVariable() const
{
return std::visit(RefVisit{ [&](const ESM4::Reference& ref) -> const std::string& { return emptyString; },
[&](const ESM::CellRef& ref) -> const std::string& { return ref.mGlobalVariable; } },
return std::visit(RefVisit{
[&](const ESM4::Reference& /*ref*/) -> const std::string& { return emptyString; },
[&](const ESM::CellRef& ref) -> const std::string& { return ref.mGlobalVariable; },
},
mCellRef.mVariant);
}
@ -175,8 +193,10 @@ namespace MWWorld
if (!getGlobalVariable().empty())
{
mChanged = true;
std::visit(
RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mGlobalVariable.erase(); } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mGlobalVariable.erase(); },
},
mCellRef.mVariant);
}
}
@ -194,7 +214,10 @@ namespace MWWorld
{
if (owner != getOwner())
{
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mOwner = owner; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mOwner = owner; },
},
mCellRef.mVariant);
}
}
@ -204,7 +227,10 @@ namespace MWWorld
if (soul != getSoul())
{
mChanged = true;
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mSoul = soul; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mSoul = soul; },
},
mCellRef.mVariant);
}
}
@ -214,7 +240,10 @@ namespace MWWorld
if (faction != getFaction())
{
mChanged = true;
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mFaction = faction; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mFaction = faction; },
},
mCellRef.mVariant);
}
}
@ -246,7 +275,10 @@ namespace MWWorld
if (trap != getTrap())
{
mChanged = true;
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mTrap = trap; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mTrap = trap; },
},
mCellRef.mVariant);
}
}
@ -256,14 +288,20 @@ namespace MWWorld
if (value != getGoldValue())
{
mChanged = true;
std::visit(RefVisit{ [&](ESM4::Reference& ref) {}, [&](ESM::CellRef& ref) { ref.mGoldValue = value; } },
std::visit(RefVisit{
[&](ESM4::Reference& /*ref*/) {},
[&](ESM::CellRef& ref) { ref.mGoldValue = value; },
},
mCellRef.mVariant);
}
}
void CellRef::writeState(ESM::ObjectState& state) const
{
std::visit(RefVisit{ [&](const ESM4::Reference& ref) {}, [&](const ESM::CellRef& ref) { state.mRef = ref; } },
std::visit(RefVisit{
[&](const ESM4::Reference& /*ref*/) {},
[&](const ESM::CellRef& ref) { state.mRef = ref; },
},
mCellRef.mVariant);
}
}

View file

@ -20,9 +20,9 @@ namespace MWWorld
{
protected:
public:
CellRef(const ESM::CellRef& ref);
explicit CellRef(const ESM::CellRef& ref);
CellRef(const ESM4::Reference& ref);
explicit CellRef(const ESM4::Reference& ref);
// Note: Currently unused for items in containers
const ESM::RefNum& getRefNum() const;
@ -105,7 +105,7 @@ namespace MWWorld
struct Visitor
{
int operator()(const ESM::CellRef& ref) { return ref.mChargeInt; }
int operator()(const ESM4::Reference& ref) { return 0; }
int operator()(const ESM4::Reference& /*ref*/) { return 0; }
};
return std::visit(Visitor(), mCellRef.mVariant);
}
@ -114,7 +114,7 @@ namespace MWWorld
struct Visitor
{
float operator()(const ESM::CellRef& ref) { return ref.mChargeFloat; }
float operator()(const ESM4::Reference& ref) { return 0; }
float operator()(const ESM4::Reference& /*ref*/) { return 0; }
};
return std::visit(Visitor(), mCellRef.mVariant);
} // Implemented as union with int charge
@ -128,7 +128,7 @@ namespace MWWorld
struct Visitor
{
const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mOwner; }
const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; }
const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; }
};
return std::visit(Visitor(), mCellRef.mVariant);
}
@ -147,7 +147,7 @@ namespace MWWorld
struct Visitor
{
const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mSoul; }
const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; }
const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; }
};
return std::visit(Visitor(), mCellRef.mVariant);
}
@ -160,7 +160,7 @@ namespace MWWorld
struct Visitor
{
const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mFaction; }
const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; }
const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; }
};
return std::visit(Visitor(), mCellRef.mVariant);
}
@ -193,7 +193,7 @@ namespace MWWorld
struct Visitor
{
const ESM::RefId& operator()(const ESM::CellRef& ref) { return ref.mTrap; }
const ESM::RefId& operator()(const ESM4::Reference& ref) { return ESM::RefId::sEmpty; }
const ESM::RefId& operator()(const ESM4::Reference& /*ref*/) { return ESM::RefId::sEmpty; }
};
return std::visit(Visitor(), mCellRef.mVariant);
}
@ -205,7 +205,7 @@ namespace MWWorld
struct Visitor
{
int operator()(const ESM::CellRef& ref) { return ref.mGoldValue; }
int operator()(const ESM4::Reference& ref) { return 0; }
int operator()(const ESM4::Reference& /*ref*/) { return 0; }
};
return std::visit(Visitor(), mCellRef.mVariant);
}
@ -218,7 +218,7 @@ namespace MWWorld
bool hasChanged() const { return mChanged; }
private:
bool mChanged;
bool mChanged = false;
ESM::ReferenceVariant mCellRef;
};

View file

@ -382,17 +382,9 @@ namespace MWWorld
if (const X* ptr = store.search(ref.mBaseObj))
{
// typename std::list<LiveRef>::iterator iter = std::find(mList.begin(), mList.end(), ref.);
LiveRef liveCellRef(ref, ptr);
if (deleted)
liveCellRef.mData.setDeletedByContentFile(true);
/*if (iter != mList.end())
*iter = liveCellRef;
else
*/
mList.push_back(liveCellRef);
}
else

View file

@ -31,7 +31,7 @@ MWWorld::LiveCellRefBase::LiveCellRefBase(unsigned int type, const ESM4::Referen
void MWWorld::LiveCellRefBase::loadImp(const ESM::ObjectState& state)
{
mRef = state.mRef;
mRef = MWWorld::CellRef(state.mRef);
mData = RefData(state, mData.isDeletedByContentFile());
Ptr ptr(this);

View file

@ -317,8 +317,7 @@ namespace MWWorld
{
if (mActiveCells.find(cell) == mActiveCells.end())
return;
std::string description = cell->getCell()->getDescription();
Log(Debug::Info) << "Unloading cell " << description;
Log(Debug::Info) << "Unloading cell " << cell->getCell()->getDescription();
ListAndResetObjectsVisitor visitor;
@ -387,7 +386,7 @@ namespace MWWorld
const int cellX = cell->getCell()->getGridX();
const int cellY = cell->getCell()->getGridY();
auto cellVariant = *cell->getCell();
const MWWorld::Cell& cellVariant = *cell->getCell();
if (cellVariant.isExterior())
{

View file

@ -645,7 +645,8 @@ namespace MWWorld
if (!cell.isEsm4())
{
const ESM::Region* region = mStore.get<ESM::Region>().search(cell.getEsm3().mRegion);
return region->mName;
if (region)
return region->mName;
}
return mStore.get<ESM::GameSetting>().find("sDefaultCellname")->mValue.getString();

View file

@ -31,7 +31,7 @@ namespace ESM
bool operator==(const CellId& left, const CellId& right)
{
return left.mWorld == right.mWorld && left.mWorldspace == right.mWorldspace && left.mPaged == right.mPaged
return left.mWorldspace == right.mWorldspace && left.mPaged == right.mPaged
&& (!left.mPaged || (left.mIndex.mX == right.mIndex.mX && left.mIndex.mY == right.mIndex.mY));
}

View file

@ -17,7 +17,6 @@ namespace ESM
int mY;
};
ESM::RefId mWorld;
std::string mWorldspace;
CellIndex mIndex;
bool mPaged;