From 1cf029ec8dfdb6cd34320bebd9fe8c66c9bcb991 Mon Sep 17 00:00:00 2001 From: Dave Corley <smokydave@icloud.com> Date: Thu, 22 Feb 2024 05:42:02 -0600 Subject: [PATCH] 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 --- apps/opencs/view/render/cell.cpp | 30 ++++++++++--------- apps/opencs/view/render/cell.hpp | 8 ++--- .../view/render/pagedworldspacewidget.cpp | 7 ++--- .../view/render/unpagedworldspacewidget.cpp | 4 +-- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/apps/opencs/view/render/cell.cpp b/apps/opencs/view/render/cell.cpp index 3d70c21e3e..b20dc5445f 100644 --- a/apps/opencs/view/render/cell.cpp +++ b/apps/opencs/view/render/cell.cpp @@ -24,6 +24,7 @@ #include "cellwater.hpp" #include "instancedragmodes.hpp" #include "mask.hpp" +#include "model/doc/document.hpp" #include "object.hpp" #include "pathgrid.hpp" #include "terrainstorage.hpp" @@ -119,7 +120,7 @@ bool CSVRender::Cell::addObjects(int start, int end) void CSVRender::Cell::updateLand() { - if (!mUpdateLand || mLandDeleted || !mId.startsWith("#")) + if (mLandDeleted) return; mUpdateLand = false; @@ -132,14 +133,6 @@ void CSVRender::Cell::updateLand() } 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()) return; @@ -176,14 +169,13 @@ void CSVRender::Cell::unloadLand() } CSVRender::Cell::Cell( - CSMWorld::Data& data, QUndoStack& undoStack, osg::Group* rootNode, const std::string& id, bool deleted) - : mData(data) - , mUndoStack(undoStack) + CSMDoc::Document& document, osg::Group* rootNode, const std::string& id, bool deleted, bool isExterior) + : mData(document.getData()) , mId(ESM::RefId::stringRefId(id)) , mDeleted(deleted) , mSubMode(0) , mSubModeElementMask(0) - , mUpdateLand(true) + , mUpdateLand(isExterior) , mLandDeleted(false) { std::pair<CSMWorld::CellCoordinates, bool> result = CSMWorld::CellCoordinates::fromId(id); @@ -209,7 +201,17 @@ CSVRender::Cell::Cell( addObjects(0, rows - 1); - updateLand(); + 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(); + } mPathgrid = std::make_unique<Pathgrid>(mData, mCellNode, mId.getRefIdString(), mCoordinates); mCellWater = std::make_unique<CellWater>(mData, mCellNode, mId.getRefIdString(), mCoordinates); diff --git a/apps/opencs/view/render/cell.hpp b/apps/opencs/view/render/cell.hpp index e0672fa350..b894a69cf8 100644 --- a/apps/opencs/view/render/cell.hpp +++ b/apps/opencs/view/render/cell.hpp @@ -9,10 +9,9 @@ #include <osg/Vec3d> #include <osg/ref_ptr> -#include <QUndoStack> - #include "../../model/world/cellcoordinates.hpp" #include "instancedragmodes.hpp" +#include "model/doc/document.hpp" #include <components/esm/refid.hpp> #include <components/misc/algorithm.hpp> @@ -48,7 +47,6 @@ namespace CSVRender class Cell { CSMWorld::Data& mData; - QUndoStack& mUndoStack; ESM::RefId mId; osg::ref_ptr<osg::Group> mCellNode; std::map<std::string, Object*, Misc::StringUtils::CiComp> mObjects; @@ -92,8 +90,8 @@ namespace CSVRender public: /// \note Deleted covers both cells that are deleted and cells that don't exist in /// the first place. - Cell(CSMWorld::Data& data, QUndoStack& undoStack, osg::Group* rootNode, const std::string& id, - bool deleted = false); + Cell(CSMDoc::Document& document, osg::Group* rootNode, const std::string& id, bool deleted = false, + bool isExterior = false); ~Cell(); diff --git a/apps/opencs/view/render/pagedworldspacewidget.cpp b/apps/opencs/view/render/pagedworldspacewidget.cpp index c2b11c0247..3fd35b7740 100644 --- a/apps/opencs/view/render/pagedworldspacewidget.cpp +++ b/apps/opencs/view/render/pagedworldspacewidget.cpp @@ -86,8 +86,8 @@ bool CSVRender::PagedWorldspaceWidget::adjustCells() { modified = true; - auto cell = std::make_unique<Cell>(mDocument.getData(), mDocument.getUndoStack(), mRootNode, - iter->first.getId(mWorldspace), deleted); + auto cell + = std::make_unique<Cell>(mDocument, mRootNode, iter->first.getId(mWorldspace), deleted, true); delete iter->second; 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; - auto cell = std::make_unique<Cell>( - mDocument.getData(), mDocument.getUndoStack(), mRootNode, coordinates.getId(mWorldspace), deleted); + auto cell = std::make_unique<Cell>(mDocument, mRootNode, coordinates.getId(mWorldspace), deleted, true); EditMode* editMode = getEditMode(); cell->setSubMode(editMode->getSubMode(), editMode->getInteractionMask()); diff --git a/apps/opencs/view/render/unpagedworldspacewidget.cpp b/apps/opencs/view/render/unpagedworldspacewidget.cpp index 1a223ed41b..a7d8af0a62 100644 --- a/apps/opencs/view/render/unpagedworldspacewidget.cpp +++ b/apps/opencs/view/render/unpagedworldspacewidget.cpp @@ -79,7 +79,7 @@ CSVRender::UnpagedWorldspaceWidget::UnpagedWorldspaceWidget( 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) @@ -127,7 +127,7 @@ bool CSVRender::UnpagedWorldspaceWidget::handleDrop( 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; mOrbitCamControl->reset();