mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-25 03:40:40 +00:00
Replace operator== for CellStore with pointer quality
Equality operator is confusing and redundant in this case. It should not be possible to have 2 CellStores for the same cell. There is no copy constructor defined so it's not possible to get a copy. It's possible to independently create second store when another one already exist but it would mean a bug. Explicitly delete CellStore copy and move constructors and assignment operators to enforce this.
This commit is contained in:
parent
599265eea7
commit
cfab425fb2
@ -549,7 +549,6 @@ namespace MWWorld
|
|||||||
}
|
}
|
||||||
|
|
||||||
CellStore::~CellStore() = default;
|
CellStore::~CellStore() = default;
|
||||||
CellStore::CellStore(CellStore&&) = default;
|
|
||||||
|
|
||||||
const MWWorld::Cell* CellStore::getCell() const
|
const MWWorld::Cell* CellStore::getCell() const
|
||||||
{
|
{
|
||||||
@ -1071,11 +1070,6 @@ namespace MWWorld
|
|||||||
requestMergedRefsUpdate();
|
requestMergedRefsUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CellStore::operator==(const CellStore& right) const
|
|
||||||
{
|
|
||||||
return right.mCellVariant.getId() == mCellVariant.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CellStore::setFog(std::unique_ptr<ESM::FogState>&& fog)
|
void CellStore::setFog(std::unique_ptr<ESM::FogState>&& fog)
|
||||||
{
|
{
|
||||||
mFogState = std::move(fog);
|
mFogState = std::move(fog);
|
||||||
|
@ -134,7 +134,15 @@ namespace MWWorld
|
|||||||
|
|
||||||
/// @param readerList The readers to use for loading of the cell on-demand.
|
/// @param readerList The readers to use for loading of the cell on-demand.
|
||||||
CellStore(MWWorld::Cell cell, const MWWorld::ESMStore& store, ESM::ReadersCache& readers);
|
CellStore(MWWorld::Cell cell, const MWWorld::ESMStore& store, ESM::ReadersCache& readers);
|
||||||
CellStore(CellStore&&);
|
|
||||||
|
CellStore(const CellStore&) = delete;
|
||||||
|
|
||||||
|
CellStore(CellStore&&) = delete;
|
||||||
|
|
||||||
|
CellStore& operator=(const CellStore&) = delete;
|
||||||
|
|
||||||
|
CellStore& operator=(CellStore&&) = delete;
|
||||||
|
|
||||||
~CellStore();
|
~CellStore();
|
||||||
|
|
||||||
const MWWorld::Cell* getCell() const;
|
const MWWorld::Cell* getCell() const;
|
||||||
@ -324,8 +332,6 @@ namespace MWWorld
|
|||||||
|
|
||||||
Ptr getPtr(ESM::RefId id);
|
Ptr getPtr(ESM::RefId id);
|
||||||
|
|
||||||
bool operator==(const CellStore& right) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend struct CellStoreImp;
|
friend struct CellStoreImp;
|
||||||
|
|
||||||
|
@ -877,7 +877,7 @@ namespace MWWorld
|
|||||||
loadingListener->setLabel("#{OMWEngine:LoadingInterior}");
|
loadingListener->setLabel("#{OMWEngine:LoadingInterior}");
|
||||||
Loading::ScopedLoad load(loadingListener);
|
Loading::ScopedLoad load(loadingListener);
|
||||||
|
|
||||||
if (mCurrentCell != nullptr && *mCurrentCell == cell)
|
if (mCurrentCell == &cell)
|
||||||
{
|
{
|
||||||
mWorld.moveObject(mWorld.getPlayerPtr(), position.asVec3());
|
mWorld.moveObject(mWorld.getPlayerPtr(), position.asVec3());
|
||||||
mWorld.rotateObject(mWorld.getPlayerPtr(), position.asRotationVec3());
|
mWorld.rotateObject(mWorld.getPlayerPtr(), position.asRotationVec3());
|
||||||
@ -1015,16 +1015,7 @@ namespace MWWorld
|
|||||||
|
|
||||||
bool Scene::isCellActive(const CellStore& cell)
|
bool Scene::isCellActive(const CellStore& cell)
|
||||||
{
|
{
|
||||||
CellStoreCollection::iterator active = mActiveCells.begin();
|
return mActiveCells.contains(&cell);
|
||||||
while (active != mActiveCells.end())
|
|
||||||
{
|
|
||||||
if (**active == cell)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
++active;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr Scene::searchPtrViaActorId(int actorId)
|
Ptr Scene::searchPtrViaActorId(int actorId)
|
||||||
|
@ -74,7 +74,7 @@ namespace MWWorld
|
|||||||
class Scene
|
class Scene
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using CellStoreCollection = std::set<CellStore*>;
|
using CellStoreCollection = std::set<CellStore*, std::less<>>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct ChangeCellGridRequest
|
struct ChangeCellGridRequest
|
||||||
|
@ -17,6 +17,22 @@
|
|||||||
#include "cellstore.hpp"
|
#include "cellstore.hpp"
|
||||||
#include "esmstore.hpp"
|
#include "esmstore.hpp"
|
||||||
|
|
||||||
|
namespace MWWorld
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
CellStore& emplaceCellStore(ESM::RefId id, const T& cell, ESMStore& store, ESM::ReadersCache& readers,
|
||||||
|
std::unordered_map<ESM::RefId, CellStore>& cells)
|
||||||
|
{
|
||||||
|
return cells
|
||||||
|
.emplace(std::piecewise_construct, std::forward_as_tuple(id),
|
||||||
|
std::forward_as_tuple(Cell(cell), store, readers))
|
||||||
|
.first->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MWWorld::CellStore& MWWorld::WorldModel::getOrInsertCellStore(const ESM::Cell& cell)
|
MWWorld::CellStore& MWWorld::WorldModel::getOrInsertCellStore(const ESM::Cell& cell)
|
||||||
{
|
{
|
||||||
const auto it = mCells.find(cell.mId);
|
const auto it = mCells.find(cell.mId);
|
||||||
@ -27,7 +43,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getOrInsertCellStore(const ESM::Cell& c
|
|||||||
|
|
||||||
MWWorld::CellStore& MWWorld::WorldModel::insertCellStore(const ESM::Cell& cell)
|
MWWorld::CellStore& MWWorld::WorldModel::insertCellStore(const ESM::Cell& cell)
|
||||||
{
|
{
|
||||||
CellStore& cellStore = mCells.emplace(cell.mId, CellStore(Cell(cell), mStore, mReaders)).first->second;
|
CellStore& cellStore = emplaceCellStore(cell.mId, cell, mStore, mReaders, mCells);
|
||||||
if (cell.mData.mFlags & ESM::Cell::Interior)
|
if (cell.mData.mFlags & ESM::Cell::Interior)
|
||||||
mInteriors.emplace(cell.mName, &cellStore);
|
mInteriors.emplace(cell.mName, &cellStore);
|
||||||
else
|
else
|
||||||
@ -112,8 +128,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellLocation c
|
|||||||
cell = mStore.insert(record);
|
cell = mStore.insert(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
CellStore* cellStore
|
CellStore* cellStore = &emplaceCellStore(cell->mId, *cell, mStore, mReaders, mCells);
|
||||||
= &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second;
|
|
||||||
result = mExteriors.emplace(cellIndex, cellStore).first;
|
result = mExteriors.emplace(cellIndex, cellStore).first;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -132,8 +147,7 @@ MWWorld::CellStore& MWWorld::WorldModel::getExterior(ESM::ExteriorCellLocation c
|
|||||||
record.mCellFlags = 0;
|
record.mCellFlags = 0;
|
||||||
cell = mStore.insert(record);
|
cell = mStore.insert(record);
|
||||||
}
|
}
|
||||||
CellStore* cellStore
|
CellStore* cellStore = &emplaceCellStore(cell->mId, *cell, mStore, mReaders, mCells);
|
||||||
= &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second;
|
|
||||||
result = mExteriors.emplace(cellIndex, cellStore).first;
|
result = mExteriors.emplace(cellIndex, cellStore).first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,10 +166,9 @@ MWWorld::CellStore* MWWorld::WorldModel::getInteriorOrNull(std::string_view name
|
|||||||
{
|
{
|
||||||
CellStore* newCellStore = nullptr;
|
CellStore* newCellStore = nullptr;
|
||||||
if (const ESM::Cell* cell = mStore.get<ESM::Cell>().search(name))
|
if (const ESM::Cell* cell = mStore.get<ESM::Cell>().search(name))
|
||||||
newCellStore = &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second;
|
newCellStore = &emplaceCellStore(cell->mId, *cell, mStore, mReaders, mCells);
|
||||||
else if (const ESM4::Cell* cell4 = mStore.get<ESM4::Cell>().searchCellName(name))
|
else if (const ESM4::Cell* cell4 = mStore.get<ESM4::Cell>().searchCellName(name))
|
||||||
newCellStore
|
newCellStore = &emplaceCellStore(cell4->mId, *cell4, mStore, mReaders, mCells);
|
||||||
= &mCells.emplace(cell4->mId, CellStore(MWWorld::Cell(*cell4), mStore, mReaders)).first->second;
|
|
||||||
if (!newCellStore)
|
if (!newCellStore)
|
||||||
return nullptr; // Cell not found
|
return nullptr; // Cell not found
|
||||||
result = mInteriors.emplace(name, newCellStore).first;
|
result = mInteriors.emplace(name, newCellStore).first;
|
||||||
@ -189,11 +202,11 @@ MWWorld::CellStore& MWWorld::WorldModel::getCell(const ESM::RefId& id, bool forc
|
|||||||
if (!cell4)
|
if (!cell4)
|
||||||
{
|
{
|
||||||
const ESM::Cell* cell = mStore.get<ESM::Cell>().find(id);
|
const ESM::Cell* cell = mStore.get<ESM::Cell>().find(id);
|
||||||
newCellStore = &mCells.emplace(cell->mId, CellStore(MWWorld::Cell(*cell), mStore, mReaders)).first->second;
|
newCellStore = &emplaceCellStore(cell->mId, *cell, mStore, mReaders, mCells);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newCellStore = &mCells.emplace(cell4->mId, CellStore(MWWorld::Cell(*cell4), mStore, mReaders)).first->second;
|
newCellStore = &emplaceCellStore(cell4->mId, *cell4, mStore, mReaders, mCells);
|
||||||
}
|
}
|
||||||
if (newCellStore->getCell()->isExterior())
|
if (newCellStore->getCell()->isExterior())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user