1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-26 23:10:24 +00:00

Fix and simplify pathgrid update handling, only recreate geometry

once per frame, and a few naming changes.
This commit is contained in:
Aesylwinn 2016-05-16 21:06:55 -04:00
parent d2d22e2f23
commit a3363bc098
10 changed files with 96 additions and 118 deletions

View file

@ -266,29 +266,14 @@ bool CSVRender::Cell::referenceAdded (const QModelIndex& parent, int start, int
return addObjects (start, end); return addObjects (start, end);
} }
void CSVRender::Cell::pathgridAdded(const CSMWorld::Pathgrid& pathgrid) void CSVRender::Cell::pathgridModified()
{ {
mPathgrid->recreateGeometry(); mPathgrid->recreateGeometry();
} }
void CSVRender::Cell::pathgridRemoved() void CSVRender::Cell::pathgridRemoved()
{ {
mPathgrid->recreateGeometry(); mPathgrid->removeGeometry();
}
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();
} }
void CSVRender::Cell::setSelection (int elementMask, Selection mode) void CSVRender::Cell::setSelection (int elementMask, Selection mode)

View file

@ -111,16 +111,10 @@ namespace CSVRender
/// this cell? /// this cell?
bool referenceAdded (const QModelIndex& parent, int start, int end); bool referenceAdded (const QModelIndex& parent, int start, int end);
void pathgridAdded(const CSMWorld::Pathgrid& pathgrid); void pathgridModified();
void pathgridRemoved(); 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); void setSelection (int elementMask, Selection mode);
// Select everything that references the same ID as at least one of the elements // Select everything that references the same ID as at least one of the elements

View file

@ -280,38 +280,29 @@ void CSVRender::PagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& t
{ {
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids(); const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();
int rowStart = -1;
int rowEnd = -1;
if (topLeft.parent().isValid()) 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(); const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY); CSMWorld::CellCoordinates coords = CSMWorld::CellCoordinates(pathgrid.mData.mX, pathgrid.mData.mY);
std::map<CSMWorld::CellCoordinates, Cell*>::iterator searchResult = mCells.find(coords); std::map<CSMWorld::CellCoordinates, Cell*>::iterator searchResult = mCells.find(coords);
if (searchResult != mCells.end()) if (searchResult != mCells.end())
{ {
searchResult->second->pathgridDataChanged(topLeft, bottomRight); searchResult->second->pathgridModified();
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);
flagAsModified(); flagAsModified();
} }
} }
@ -345,7 +336,6 @@ void CSVRender::PagedWorldspaceWidget::pathgridAdded(const QModelIndex& parent,
if (!parent.isValid()) if (!parent.isValid())
{ {
// Pathgrid added theoretically, unable to test until it is possible to add pathgrids
for (int row = start; row <= end; ++row) for (int row = start; row <= end; ++row)
{ {
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); 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); std::map<CSMWorld::CellCoordinates, Cell*>::iterator searchResult = mCells.find(coords);
if (searchResult != mCells.end()) if (searchResult != mCells.end())
{ {
searchResult->second->pathgridAdded(pathgrid); searchResult->second->pathgridModified();
flagAsModified(); 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();
}
}
} }

View file

@ -54,8 +54,6 @@ namespace CSVRender
virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); 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 pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end);
virtual void pathgridAdded (const QModelIndex& parent, int start, int end); virtual void pathgridAdded (const QModelIndex& parent, int start, int end);

View file

@ -18,6 +18,17 @@
namespace CSVRender 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) PathgridTag::PathgridTag(Pathgrid* pathgrid)
: TagBase(Mask_Pathgrid), mPathgrid(pathgrid) : TagBase(Mask_Pathgrid), mPathgrid(pathgrid)
{ {
@ -49,6 +60,8 @@ namespace CSVRender
, mInterior(false) , mInterior(false)
, mConnectionIndicator(false) , mConnectionIndicator(false)
, mConnectionNode(0) , mConnectionNode(0)
, mChangeGeometry(true)
, mRemoveGeometry(false)
, mParent(parent) , mParent(parent)
, mPathgridGeometry(0) , mPathgridGeometry(0)
, mSelectedGeometry(0) , mSelectedGeometry(0)
@ -59,6 +72,7 @@ namespace CSVRender
mBaseNode = new osg::PositionAttitudeTransform (); mBaseNode = new osg::PositionAttitudeTransform ();
mBaseNode->setPosition(osg::Vec3f(mCoords.getX() * CoordScalar, mCoords.getY() * CoordScalar, 0.f)); mBaseNode->setPosition(osg::Vec3f(mCoords.getX() * CoordScalar, mCoords.getY() * CoordScalar, 0.f));
mBaseNode->setUserData(mTag); mBaseNode->setUserData(mTag);
mBaseNode->setUpdateCallback(new PathgridNodeCallback());
mBaseNode->setNodeMask(Mask_Pathgrid); mBaseNode->setNodeMask(Mask_Pathgrid);
mParent->addChild(mBaseNode); mParent->addChild(mBaseNode);
@ -116,7 +130,7 @@ namespace CSVRender
for (unsigned short i = 0; i < static_cast<unsigned short>(source->mPoints.size()); ++i) for (unsigned short i = 0; i < static_cast<unsigned short>(source->mPoints.size()); ++i)
mSelected.push_back(i); mSelected.push_back(i);
recreateSelectedGeometry(*source); createSelectedGeometry(*source);
} }
else else
{ {
@ -136,7 +150,7 @@ namespace CSVRender
mSelected.push_back(node); mSelected.push_back(node);
} }
recreateSelectedGeometry(); createSelectedGeometry();
} }
void Pathgrid::invertSelected() void Pathgrid::invertSelected()
@ -153,7 +167,7 @@ namespace CSVRender
mSelected.push_back(i); mSelected.push_back(i);
} }
recreateSelectedGeometry(*source); createSelectedGeometry(*source);
} }
else else
{ {
@ -176,7 +190,7 @@ namespace CSVRender
{ {
mConnectionIndicator = true; mConnectionIndicator = true;
mConnectionNode = node; mConnectionNode = node;
recreateSelectedGeometry(); createSelectedGeometry();
} }
void Pathgrid::resetMove() void Pathgrid::resetMove()
@ -185,7 +199,7 @@ namespace CSVRender
if (mConnectionIndicator) if (mConnectionIndicator)
{ {
mConnectionIndicator = false; mConnectionIndicator = false;
recreateSelectedGeometry(); createSelectedGeometry();
} }
} }
@ -363,7 +377,34 @@ namespace CSVRender
void Pathgrid::recreateGeometry() 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(); const CSMWorld::Pathgrid* source = getPathgridSource();
if (source) if (source)
{ {
@ -371,21 +412,20 @@ namespace CSVRender
mPathgridGeometry = SceneUtil::createPathgridGeometry(*source); mPathgridGeometry = SceneUtil::createPathgridGeometry(*source);
mPathgridGeode->addDrawable(mPathgridGeometry); mPathgridGeode->addDrawable(mPathgridGeometry);
recreateSelectedGeometry(*source); createSelectedGeometry(*source);
} }
else else
{ {
removePathgridGeometry(); removeGeometry();
removeSelectedGeometry();
} }
} }
void Pathgrid::recreateSelectedGeometry() void Pathgrid::createSelectedGeometry()
{ {
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid* source = getPathgridSource();
if (source) if (source)
{ {
recreateSelectedGeometry(*source); createSelectedGeometry(*source);
} }
else else
{ {
@ -393,7 +433,7 @@ namespace CSVRender
} }
} }
void Pathgrid::recreateSelectedGeometry(const CSMWorld::Pathgrid& source) void Pathgrid::createSelectedGeometry(const CSMWorld::Pathgrid& source)
{ {
removeSelectedGeometry(); removeSelectedGeometry();
@ -438,7 +478,7 @@ namespace CSVRender
const CSMWorld::Pathgrid* Pathgrid::getPathgridSource() const CSMWorld::Pathgrid* Pathgrid::getPathgridSource()
{ {
int index = mPathgridCollection.searchId(mId); int index = mPathgridCollection.searchId(mId);
if (index != -1) if (index != -1 && !mPathgridCollection.getRecord(index).isDeleted())
{ {
return &mPathgridCollection.getRecord(index).get(); return &mPathgridCollection.getRecord(index).get();
} }

View file

@ -83,6 +83,9 @@ namespace CSVRender
osg::ref_ptr<PathgridTag> getTag() const; osg::ref_ptr<PathgridTag> getTag() const;
void recreateGeometry(); void recreateGeometry();
void removeGeometry();
void update();
private: private:
@ -96,6 +99,9 @@ namespace CSVRender
bool mConnectionIndicator; bool mConnectionIndicator;
unsigned short mConnectionNode; unsigned short mConnectionNode;
bool mChangeGeometry;
bool mRemoveGeometry;
osg::Group* mParent; osg::Group* mParent;
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode; osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
osg::ref_ptr<osg::PositionAttitudeTransform> mSelectedNode; osg::ref_ptr<osg::PositionAttitudeTransform> mSelectedNode;
@ -106,8 +112,9 @@ namespace CSVRender
osg::ref_ptr<PathgridTag> mTag; osg::ref_ptr<PathgridTag> mTag;
void recreateSelectedGeometry(); void createGeometry();
void recreateSelectedGeometry(const CSMWorld::Pathgrid& source); void createSelectedGeometry();
void createSelectedGeometry(const CSMWorld::Pathgrid& source);
void removePathgridGeometry(); void removePathgridGeometry();
void removeSelectedGeometry(); void removeSelectedGeometry();

View file

@ -212,32 +212,28 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridDataChanged (const QModelIndex&
{ {
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids(); const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();
int rowStart = -1;
int rowEnd = -1;
if (topLeft.parent().isValid()) 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(); const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
if (mCellId == pathgrid.mId) if (mCellId == pathgrid.mId)
{ {
mCell->pathgridDataChanged(topLeft, bottomRight); mCell->pathgridModified();
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);
flagAsModified(); flagAsModified();
return;
} }
} }
} }
@ -256,6 +252,7 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridAboutToBeRemoved (const QModelI
{ {
mCell->pathgridRemoved(); mCell->pathgridRemoved();
flagAsModified(); flagAsModified();
return;
} }
} }
} }
@ -267,29 +264,17 @@ void CSVRender::UnpagedWorldspaceWidget::pathgridAdded (const QModelIndex& paren
if (!parent.isValid()) if (!parent.isValid())
{ {
// Pathgrid added theoretically, unable to test until it is possible to add pathgrids
for (int row = start; row <= end; ++row) for (int row = start; row <= end; ++row)
{ {
const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get(); const CSMWorld::Pathgrid& pathgrid = pathgrids.getRecord(row).get();
if (mCellId == pathgrid.mId) if (mCellId == pathgrid.mId)
{ {
mCell->pathgridAdded(pathgrid); mCell->pathgridModified();
flagAsModified(); 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 ( void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (

View file

@ -91,8 +91,6 @@ namespace CSVRender
virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); 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 pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end);
virtual void pathgridAdded (const QModelIndex& parent, int start, int end); virtual void pathgridAdded (const QModelIndex& parent, int start, int end);

View file

@ -63,8 +63,6 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg
connect (pathgrids, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)), connect (pathgrids, SIGNAL (dataChanged (const QModelIndex&, const QModelIndex&)),
this, SLOT (pathgridDataChanged (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)), connect (pathgrids, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
this, SLOT (pathgridAboutToBeRemoved (const QModelIndex&, int, int))); this, SLOT (pathgridAboutToBeRemoved (const QModelIndex&, int, int)));
connect (pathgrids, SIGNAL (rowsInserted (const QModelIndex&, int, int)), connect (pathgrids, SIGNAL (rowsInserted (const QModelIndex&, int, int)),

View file

@ -246,8 +246,6 @@ namespace CSVRender
virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight) = 0; 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 pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end) = 0;
virtual void pathgridAdded (const QModelIndex& parent, int start, int end) = 0; virtual void pathgridAdded (const QModelIndex& parent, int start, int end) = 0;