1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 09:09:43 +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 /// 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 setCurrentNodeToClosestAllowedNode(AiWanderStorage& storage);
void addNonPathGridAllowedPoints(const ESM::Pathgrid* pathGrid, int pointIndex, 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 mRegion = ESM::RefId::sEmpty; // Unimplemented for now
mFlags.hasWater = cell.mCellFlags & ESM4::CELL_HasWater; mFlags.mHasWater = cell.mCellFlags & ESM4::CELL_HasWater;
mFlags.isExterior = !(cell.mCellFlags & ESM4::CELL_Interior); mFlags.mIsExterior = !(cell.mCellFlags & ESM4::CELL_Interior);
mFlags.isQuasiExterior = cell.mCellFlags & ESM4::CELL_QuasiExt; mFlags.mIsQuasiExterior = cell.mCellFlags & ESM4::CELL_QuasiExt;
mFlags.noSleep = false; // No such notion in ESM4 mFlags.mNoSleep = false; // No such notion in ESM4
mCellId.mWorldspace = Misc::StringUtils::lowerCase(cell.mEditorId); mCellId.mWorldspace = Misc::StringUtils::lowerCase(cell.mEditorId);
mCellId.mWorld = ESM::RefId::sEmpty;
mCellId.mIndex.mX = cell.getGridX(); mCellId.mIndex.mX = cell.getGridX();
mCellId.mIndex.mX = cell.getGridY(); mCellId.mIndex.mX = cell.getGridY();
mCellId.mPaged = isExterior(); mCellId.mPaged = isExterior();
@ -44,10 +43,10 @@ namespace MWWorld
mRegion = ESM::RefId::sEmpty; // Unimplemented for now mRegion = ESM::RefId::sEmpty; // Unimplemented for now
mFlags.hasWater = cell.mData.mFlags & ESM::Cell::HasWater; mFlags.mHasWater = cell.mData.mFlags & ESM::Cell::HasWater;
mFlags.isExterior = !(cell.mData.mFlags & ESM::Cell::Interior); mFlags.mIsExterior = !(cell.mData.mFlags & ESM::Cell::Interior);
mFlags.isQuasiExterior = cell.mData.mFlags & ESM::Cell::QuasiEx; mFlags.mIsQuasiExterior = cell.mData.mFlags & ESM::Cell::QuasiEx;
mFlags.noSleep = cell.mData.mFlags & ESM::Cell::NoSleep; mFlags.mNoSleep = cell.mData.mFlags & ESM::Cell::NoSleep;
mCellId = cell.getCellId(); mCellId = cell.getCellId();

View file

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

View file

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

View file

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

View file

@ -382,17 +382,9 @@ namespace MWWorld
if (const X* ptr = store.search(ref.mBaseObj)) 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); LiveRef liveCellRef(ref, ptr);
if (deleted) if (deleted)
liveCellRef.mData.setDeletedByContentFile(true); liveCellRef.mData.setDeletedByContentFile(true);
/*if (iter != mList.end())
*iter = liveCellRef;
else
*/
mList.push_back(liveCellRef); mList.push_back(liveCellRef);
} }
else else

View file

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

View file

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

View file

@ -645,7 +645,8 @@ namespace MWWorld
if (!cell.isEsm4()) if (!cell.isEsm4())
{ {
const ESM::Region* region = mStore.get<ESM::Region>().search(cell.getEsm3().mRegion); 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(); 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) 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)); && (!left.mPaged || (left.mIndex.mX == right.mIndex.mX && left.mIndex.mY == right.mIndex.mY));
} }

View file

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