mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 20:53:50 +00:00
Fix and simplify pathgrid update handling, only recreate geometry
once per frame, and a few naming changes.
This commit is contained in:
parent
d2d22e2f23
commit
a3363bc098
10 changed files with 96 additions and 118 deletions
|
@ -266,29 +266,14 @@ bool CSVRender::Cell::referenceAdded (const QModelIndex& parent, int start, int
|
|||
return addObjects (start, end);
|
||||
}
|
||||
|
||||
void CSVRender::Cell::pathgridAdded(const CSMWorld::Pathgrid& pathgrid)
|
||||
void CSVRender::Cell::pathgridModified()
|
||||
{
|
||||
mPathgrid->recreateGeometry();
|
||||
}
|
||||
|
||||
void CSVRender::Cell::pathgridRemoved()
|
||||
{
|
||||
mPathgrid->recreateGeometry();
|
||||
}
|
||||
|
||||
void CSVRender::Cell::pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
|
||||
{
|
||||
mPathgrid->recreateGeometry();
|
||||
}
|
||||
|
||||
void CSVRender::Cell::pathgridRowRemoved(const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
mPathgrid->recreateGeometry();
|
||||
}
|
||||
|
||||
void CSVRender::Cell::pathgridRowAdded(const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
mPathgrid->recreateGeometry();
|
||||
mPathgrid->removeGeometry();
|
||||
}
|
||||
|
||||
void CSVRender::Cell::setSelection (int elementMask, Selection mode)
|
||||
|
|
|
@ -111,16 +111,10 @@ namespace CSVRender
|
|||
/// this cell?
|
||||
bool referenceAdded (const QModelIndex& parent, int start, int end);
|
||||
|
||||
void pathgridAdded(const CSMWorld::Pathgrid& pathgrid);
|
||||
void pathgridModified();
|
||||
|
||||
void pathgridRemoved();
|
||||
|
||||
void pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
|
||||
void pathgridRowRemoved(const QModelIndex& parent, int start, int end);
|
||||
|
||||
void pathgridRowAdded(const QModelIndex& parent, int start, int end);
|
||||
|
||||
void setSelection (int elementMask, Selection mode);
|
||||
|
||||
// Select everything that references the same ID as at least one of the elements
|
||||
|
|
|
@ -280,38 +280,29 @@ void CSVRender::PagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& t
|
|||
{
|
||||
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();
|
||||
|
||||
int rowStart = -1;
|
||||
int rowEnd = -1;
|
||||
|
||||
if (topLeft.parent().isValid())
|
||||
{
|
||||
int row = topLeft.parent().row();
|
||||
rowStart = topLeft.parent().row();
|
||||
rowEnd = bottomRight.parent().row();
|
||||
}
|
||||
else
|
||||
{
|
||||
rowStart = topLeft.row();
|
||||
rowEnd = bottomRight.row();
|
||||
}
|
||||
|
||||
for (int row = rowStart; row <= rowEnd; ++row)
|
||||
{
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY);
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, Cell*>::iterator searchResult = mCells.find(coords);
|
||||
if (searchResult != mCells.end())
|
||||
{
|
||||
searchResult->second->pathgridDataChanged(topLeft, bottomRight);
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVRender::PagedWorldspaceWidget::pathgridRemoved (const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();
|
||||
|
||||
if (parent.isValid())
|
||||
{
|
||||
// Pathgrid data was modified
|
||||
int row = parent.row();
|
||||
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY);
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, Cell*>::iterator searchResult = mCells.find(coords);
|
||||
if (searchResult != mCells.end())
|
||||
{
|
||||
searchResult->second->pathgridRowRemoved(parent, start, end);
|
||||
searchResult->second->pathgridModified();
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
|
@ -345,7 +336,6 @@ void CSVRender::PagedWorldspaceWidget::pathgridAdded(const QModelIndex& parent,
|
|||
|
||||
if (!parent.isValid())
|
||||
{
|
||||
// Pathgrid added theoretically, unable to test until it is possible to add pathgrids
|
||||
for (int row = start; row <= end; ++row)
|
||||
{
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
|
@ -354,26 +344,11 @@ void CSVRender::PagedWorldspaceWidget::pathgridAdded(const QModelIndex& parent,
|
|||
std::map<CSMWorld::CellCoordinates, Cell*>::iterator searchResult = mCells.find(coords);
|
||||
if (searchResult != mCells.end())
|
||||
{
|
||||
searchResult->second->pathgridAdded(pathgrid);
|
||||
searchResult->second->pathgridModified();
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Pathgrid data was modified
|
||||
int row = parent.row();
|
||||
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY);
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, Cell*>::iterator searchResult = mCells.find(coords);
|
||||
if (searchResult != mCells.end())
|
||||
{
|
||||
searchResult->second->pathgridRowAdded(parent, start, end);
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -54,8 +54,6 @@ namespace CSVRender
|
|||
|
||||
virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
|
||||
virtual void pathgridRemoved (const QModelIndex& parent, int start, int end);
|
||||
|
||||
virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||
|
||||
virtual void pathgridAdded (const QModelIndex& parent, int start, int end);
|
||||
|
|
|
@ -18,6 +18,17 @@
|
|||
|
||||
namespace CSVRender
|
||||
{
|
||||
class PathgridNodeCallback : public osg::NodeCallback
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
|
||||
{
|
||||
PathgridTag* tag = dynamic_cast<PathgridTag*>(node->getUserData());
|
||||
tag->getPathgrid()->update();
|
||||
}
|
||||
};
|
||||
|
||||
PathgridTag::PathgridTag(Pathgrid* pathgrid)
|
||||
: TagBase(Mask_Pathgrid), mPathgrid(pathgrid)
|
||||
{
|
||||
|
@ -49,6 +60,8 @@ namespace CSVRender
|
|||
, mInterior(false)
|
||||
, mConnectionIndicator(false)
|
||||
, mConnectionNode(0)
|
||||
, mChangeGeometry(true)
|
||||
, mRemoveGeometry(false)
|
||||
, mParent(parent)
|
||||
, mPathgridGeometry(0)
|
||||
, mSelectedGeometry(0)
|
||||
|
@ -59,6 +72,7 @@ namespace CSVRender
|
|||
mBaseNode = new osg::PositionAttitudeTransform ();
|
||||
mBaseNode->setPosition(osg::Vec3f(mCoords.getX() * CoordScalar, mCoords.getY() * CoordScalar, 0.f));
|
||||
mBaseNode->setUserData(mTag);
|
||||
mBaseNode->setUpdateCallback(new PathgridNodeCallback());
|
||||
mBaseNode->setNodeMask(Mask_Pathgrid);
|
||||
mParent->addChild(mBaseNode);
|
||||
|
||||
|
@ -116,7 +130,7 @@ namespace CSVRender
|
|||
for (unsigned short i = 0; i < static_cast<unsigned short>(source->mPoints.size()); ++i)
|
||||
mSelected.push_back(i);
|
||||
|
||||
recreateSelectedGeometry(*source);
|
||||
createSelectedGeometry(*source);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -136,7 +150,7 @@ namespace CSVRender
|
|||
mSelected.push_back(node);
|
||||
}
|
||||
|
||||
recreateSelectedGeometry();
|
||||
createSelectedGeometry();
|
||||
}
|
||||
|
||||
void Pathgrid::invertSelected()
|
||||
|
@ -153,7 +167,7 @@ namespace CSVRender
|
|||
mSelected.push_back(i);
|
||||
}
|
||||
|
||||
recreateSelectedGeometry(*source);
|
||||
createSelectedGeometry(*source);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -176,7 +190,7 @@ namespace CSVRender
|
|||
{
|
||||
mConnectionIndicator = true;
|
||||
mConnectionNode = node;
|
||||
recreateSelectedGeometry();
|
||||
createSelectedGeometry();
|
||||
}
|
||||
|
||||
void Pathgrid::resetMove()
|
||||
|
@ -185,7 +199,7 @@ namespace CSVRender
|
|||
if (mConnectionIndicator)
|
||||
{
|
||||
mConnectionIndicator = false;
|
||||
recreateSelectedGeometry();
|
||||
createSelectedGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,7 +377,34 @@ namespace CSVRender
|
|||
|
||||
void Pathgrid::recreateGeometry()
|
||||
{
|
||||
// Make new
|
||||
mChangeGeometry = true;
|
||||
}
|
||||
|
||||
void Pathgrid::removeGeometry()
|
||||
{
|
||||
mRemoveGeometry = true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Pathgrid::update()
|
||||
{
|
||||
if (mRemoveGeometry)
|
||||
{
|
||||
removePathgridGeometry();
|
||||
removeSelectedGeometry();
|
||||
}
|
||||
else if (mChangeGeometry)
|
||||
{
|
||||
createGeometry();
|
||||
}
|
||||
|
||||
mChangeGeometry = false;
|
||||
mRemoveGeometry = false;
|
||||
}
|
||||
|
||||
void Pathgrid::createGeometry()
|
||||
{
|
||||
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||
if (source)
|
||||
{
|
||||
|
@ -371,21 +412,20 @@ namespace CSVRender
|
|||
mPathgridGeometry = SceneUtil::createPathgridGeometry(*source);
|
||||
mPathgridGeode->addDrawable(mPathgridGeometry);
|
||||
|
||||
recreateSelectedGeometry(*source);
|
||||
createSelectedGeometry(*source);
|
||||
}
|
||||
else
|
||||
{
|
||||
removePathgridGeometry();
|
||||
removeSelectedGeometry();
|
||||
removeGeometry();
|
||||
}
|
||||
}
|
||||
|
||||
void Pathgrid::recreateSelectedGeometry()
|
||||
void Pathgrid::createSelectedGeometry()
|
||||
{
|
||||
const CSMWorld::Pathgrid* source = getPathgridSource();
|
||||
if (source)
|
||||
{
|
||||
recreateSelectedGeometry(*source);
|
||||
createSelectedGeometry(*source);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -393,7 +433,7 @@ namespace CSVRender
|
|||
}
|
||||
}
|
||||
|
||||
void Pathgrid::recreateSelectedGeometry(const CSMWorld::Pathgrid& source)
|
||||
void Pathgrid::createSelectedGeometry(const CSMWorld::Pathgrid& source)
|
||||
{
|
||||
removeSelectedGeometry();
|
||||
|
||||
|
@ -438,7 +478,7 @@ namespace CSVRender
|
|||
const CSMWorld::Pathgrid* Pathgrid::getPathgridSource()
|
||||
{
|
||||
int index = mPathgridCollection.searchId(mId);
|
||||
if (index != -1)
|
||||
if (index != -1 && !mPathgridCollection.getRecord(index).isDeleted())
|
||||
{
|
||||
return &mPathgridCollection.getRecord(index).get();
|
||||
}
|
||||
|
|
|
@ -83,6 +83,9 @@ namespace CSVRender
|
|||
osg::ref_ptr<PathgridTag> getTag() const;
|
||||
|
||||
void recreateGeometry();
|
||||
void removeGeometry();
|
||||
|
||||
void update();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -96,6 +99,9 @@ namespace CSVRender
|
|||
bool mConnectionIndicator;
|
||||
unsigned short mConnectionNode;
|
||||
|
||||
bool mChangeGeometry;
|
||||
bool mRemoveGeometry;
|
||||
|
||||
osg::Group* mParent;
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
|
||||
osg::ref_ptr<osg::PositionAttitudeTransform> mSelectedNode;
|
||||
|
@ -106,8 +112,9 @@ namespace CSVRender
|
|||
|
||||
osg::ref_ptr<PathgridTag> mTag;
|
||||
|
||||
void recreateSelectedGeometry();
|
||||
void recreateSelectedGeometry(const CSMWorld::Pathgrid& source);
|
||||
void createGeometry();
|
||||
void createSelectedGeometry();
|
||||
void createSelectedGeometry(const CSMWorld::Pathgrid& source);
|
||||
void removePathgridGeometry();
|
||||
void removeSelectedGeometry();
|
||||
|
||||
|
|
|
@ -212,32 +212,28 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridDataChanged (const QModelIndex&
|
|||
{
|
||||
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();
|
||||
|
||||
int rowStart = -1;
|
||||
int rowEnd = -1;
|
||||
|
||||
if (topLeft.parent().isValid())
|
||||
{
|
||||
int row = topLeft.parent().row();
|
||||
rowStart = topLeft.parent().row();
|
||||
rowEnd = bottomRight.parent().row();
|
||||
}
|
||||
else
|
||||
{
|
||||
rowStart = topLeft.row();
|
||||
rowEnd = bottomRight.row();
|
||||
}
|
||||
|
||||
for (int row = rowStart; row <= rowEnd; ++row)
|
||||
{
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
if (mCellId == pathgrid.mId)
|
||||
{
|
||||
mCell->pathgridDataChanged(topLeft, bottomRight);
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVRender::UnpagedWorldspaceWidget::pathgridRemoved (const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();
|
||||
|
||||
if (parent.isValid()){
|
||||
// Pathgrid data was modified
|
||||
int row = parent.row();
|
||||
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
if (mCellId == pathgrid.mId)
|
||||
{
|
||||
mCell->pathgridRowRemoved(parent, start, end);
|
||||
mCell->pathgridModified();
|
||||
flagAsModified();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,6 +252,7 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridAboutToBeRemoved (const QModelI
|
|||
{
|
||||
mCell->pathgridRemoved();
|
||||
flagAsModified();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -267,29 +264,17 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridAdded (const QModelIndex& paren
|
|||
|
||||
if (!parent.isValid())
|
||||
{
|
||||
// Pathgrid added theoretically, unable to test until it is possible to add pathgrids
|
||||
for (int row = start; row <= end; ++row)
|
||||
{
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
if (mCellId == pathgrid.mId)
|
||||
{
|
||||
mCell->pathgridAdded(pathgrid);
|
||||
mCell->pathgridModified();
|
||||
flagAsModified();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Pathgrid data was modified
|
||||
int row = parent.row();
|
||||
|
||||
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
|
||||
if (mCellId == pathgrid.mId)
|
||||
{
|
||||
mCell->pathgridRowAdded(parent, start, end);
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (
|
||||
|
|
|
@ -91,8 +91,6 @@ namespace CSVRender
|
|||
|
||||
virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||
|
||||
virtual void pathgridRemoved (const QModelIndex& parent, int start, int end);
|
||||
|
||||
virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||
|
||||
virtual void pathgridAdded (const QModelIndex& parent, int start, int end);
|
||||
|
|
|
@ -63,8 +63,6 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg
|
|||
|
||||
connect (pathgrids, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
|
||||
this, SLOT (pathgridDataChanged (const QModelIndex&, const QModelIndex&)));
|
||||
connect (pathgrids, SIGNAL (rowsRemoved (const QModelIndex&, int, int)),
|
||||
this, SLOT (pathgridRemoved (const QModelIndex&, int, int)));
|
||||
connect (pathgrids, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
||||
this, SLOT (pathgridAboutToBeRemoved (const QModelIndex&, int, int)));
|
||||
connect (pathgrids, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
||||
|
|
|
@ -246,8 +246,6 @@ namespace CSVRender
|
|||
|
||||
virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) = 0;
|
||||
|
||||
virtual void pathgridRemoved (const QModelIndex& parent, int start, int end) = 0;
|
||||
|
||||
virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end) = 0;
|
||||
|
||||
virtual void pathgridAdded (const QModelIndex& parent, int start, int end) = 0;
|
||||
|
|
Loading…
Reference in a new issue