1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 15:45:35 +00:00

Don't store member variables from document & use simpler and safer

inputs to cell constructor. Explicitly tell the constructor whether land
should be loaded or not
This commit is contained in:
Dave Corley 2024-02-22 05:42:02 -06:00
parent 9ca6dba2b6
commit 1cf029ec8d
4 changed files with 24 additions and 25 deletions

View file

@ -24,6 +24,7 @@
#include "cellwater.hpp" #include "cellwater.hpp"
#include "instancedragmodes.hpp" #include "instancedragmodes.hpp"
#include "mask.hpp" #include "mask.hpp"
#include "model/doc/document.hpp"
#include "object.hpp" #include "object.hpp"
#include "pathgrid.hpp" #include "pathgrid.hpp"
#include "terrainstorage.hpp" #include "terrainstorage.hpp"
@ -119,7 +120,7 @@ bool CSVRender::Cell::addObjects(int start, int end)
void CSVRender::Cell::updateLand() void CSVRender::Cell::updateLand()
{ {
if (!mUpdateLand || mLandDeleted || !mId.startsWith("#")) if (mLandDeleted)
return; return;
mUpdateLand = false; mUpdateLand = false;
@ -132,14 +133,6 @@ void CSVRender::Cell::updateLand()
} }
const CSMWorld::IdCollection<CSMWorld::Land>& land = mData.getLand(); const CSMWorld::IdCollection<CSMWorld::Land>& land = mData.getLand();
int landIndex = land.searchId(mId);
if (landIndex == -1)
{
CSMWorld::IdTable& landTable
= dynamic_cast<CSMWorld::IdTable&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Land));
mUndoStack.push(new CSMWorld::CreateCommand(landTable, mId.getRefIdString()));
}
if (land.getRecord(mId).isDeleted()) if (land.getRecord(mId).isDeleted())
return; return;
@ -176,14 +169,13 @@ void CSVRender::Cell::unloadLand()
} }
CSVRender::Cell::Cell( CSVRender::Cell::Cell(
CSMWorld::Data& data, QUndoStack& undoStack, osg::Group* rootNode, const std::string& id, bool deleted) CSMDoc::Document& document, osg::Group* rootNode, const std::string& id, bool deleted, bool isExterior)
: mData(data) : mData(document.getData())
, mUndoStack(undoStack)
, mId(ESM::RefId::stringRefId(id)) , mId(ESM::RefId::stringRefId(id))
, mDeleted(deleted) , mDeleted(deleted)
, mSubMode(0) , mSubMode(0)
, mSubModeElementMask(0) , mSubModeElementMask(0)
, mUpdateLand(true) , mUpdateLand(isExterior)
, mLandDeleted(false) , mLandDeleted(false)
{ {
std::pair<CSMWorld::CellCoordinates, bool> result = CSMWorld::CellCoordinates::fromId(id); std::pair<CSMWorld::CellCoordinates, bool> result = CSMWorld::CellCoordinates::fromId(id);
@ -209,7 +201,17 @@ CSVRender::Cell::Cell(
addObjects(0, rows - 1); addObjects(0, rows - 1);
if (mUpdateLand)
{
int landIndex = document.getData().getLand().searchId(mId);
if (landIndex == -1)
{
CSMWorld::IdTable& landTable
= dynamic_cast<CSMWorld::IdTable&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Land));
document.getUndoStack().push(new CSMWorld::CreateCommand(landTable, mId.getRefIdString()));
}
updateLand(); updateLand();
}
mPathgrid = std::make_unique<Pathgrid>(mData, mCellNode, mId.getRefIdString(), mCoordinates); mPathgrid = std::make_unique<Pathgrid>(mData, mCellNode, mId.getRefIdString(), mCoordinates);
mCellWater = std::make_unique<CellWater>(mData, mCellNode, mId.getRefIdString(), mCoordinates); mCellWater = std::make_unique<CellWater>(mData, mCellNode, mId.getRefIdString(), mCoordinates);

View file

@ -9,10 +9,9 @@
#include <osg/Vec3d> #include <osg/Vec3d>
#include <osg/ref_ptr> #include <osg/ref_ptr>
#include <QUndoStack>
#include "../../model/world/cellcoordinates.hpp" #include "../../model/world/cellcoordinates.hpp"
#include "instancedragmodes.hpp" #include "instancedragmodes.hpp"
#include "model/doc/document.hpp"
#include <components/esm/refid.hpp> #include <components/esm/refid.hpp>
#include <components/misc/algorithm.hpp> #include <components/misc/algorithm.hpp>
@ -48,7 +47,6 @@ namespace CSVRender
class Cell class Cell
{ {
CSMWorld::Data& mData; CSMWorld::Data& mData;
QUndoStack& mUndoStack;
ESM::RefId mId; ESM::RefId mId;
osg::ref_ptr<osg::Group> mCellNode; osg::ref_ptr<osg::Group> mCellNode;
std::map<std::string, Object*, Misc::StringUtils::CiComp> mObjects; std::map<std::string, Object*, Misc::StringUtils::CiComp> mObjects;
@ -92,8 +90,8 @@ namespace CSVRender
public: public:
/// \note Deleted covers both cells that are deleted and cells that don't exist in /// \note Deleted covers both cells that are deleted and cells that don't exist in
/// the first place. /// the first place.
Cell(CSMWorld::Data& data, QUndoStack& undoStack, osg::Group* rootNode, const std::string& id, Cell(CSMDoc::Document& document, osg::Group* rootNode, const std::string& id, bool deleted = false,
bool deleted = false); bool isExterior = false);
~Cell(); ~Cell();

View file

@ -86,8 +86,8 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells()
{ {
modified = true; modified = true;
auto cell = std::make_unique<Cell>(mDocument.getData(), mDocument.getUndoStack(), mRootNode, auto cell
iter->first.getId(mWorldspace), deleted); = std::make_unique<Cell>(mDocument, mRootNode, iter->first.getId(mWorldspace), deleted, true);
delete iter->second; delete iter->second;
iter->second = cell.release(); iter->second = cell.release();
@ -465,8 +465,7 @@ void CSVRender::PagedWorldspaceWidget::addCellToScene(const CSMWorld::CellCoordi
bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted; bool deleted = index == -1 || cells.getRecord(index).mState == CSMWorld::RecordBase::State_Deleted;
auto cell = std::make_unique<Cell>( auto cell = std::make_unique<Cell>(mDocument, mRootNode, coordinates.getId(mWorldspace), deleted, true);
mDocument.getData(), mDocument.getUndoStack(), mRootNode, coordinates.getId(mWorldspace), deleted);
EditMode* editMode = getEditMode(); EditMode* editMode = getEditMode();
cell->setSubMode(editMode->getSubMode(), editMode->getInteractionMask()); cell->setSubMode(editMode->getSubMode(), editMode->getInteractionMask());

View file

@ -79,7 +79,7 @@ CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget(
update(); update();
mCell = std::make_unique<Cell>(document.getData(), document.getUndoStack(), mRootNode, mCellId); mCell = std::make_unique<Cell>(document, mRootNode, mCellId);
} }
void CSVRender::UnpagedWorldspaceWidget::cellDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) void CSVRender::UnpagedWorldspaceWidget::cellDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
@ -127,7 +127,7 @@ bool CSVRender::UnpagedWorldspaceWidget::handleDrop(
mCellId = universalIdData.begin()->getId(); mCellId = universalIdData.begin()->getId();
mCell = std::make_unique<Cell>(getDocument().getData(), getDocument().getUndoStack(), mRootNode, mCellId); mCell = std::make_unique<Cell>(getDocument(), mRootNode, mCellId);
mCamPositionSet = false; mCamPositionSet = false;
mOrbitCamControl->reset(); mOrbitCamControl->reset();