mirror of https://github.com/OpenMW/openmw.git
Merge branch 'master' of https://github.com/OpenMW/openmw into osg
Conflicts: extern/sdl4ogre/sdlwindowhelper.cpppull/638/head
commit
974fda5bde
@ -0,0 +1,151 @@
|
||||
#include "pathgridcheck.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../world/universalid.hpp"
|
||||
#include "../world/idcollection.hpp"
|
||||
#include "../world/subcellcollection.hpp"
|
||||
#include "../world/pathgrid.hpp"
|
||||
|
||||
CSMTools::PathgridCheckStage::PathgridCheckStage (const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids)
|
||||
: mPathgrids (pathgrids)
|
||||
{}
|
||||
|
||||
int CSMTools::PathgridCheckStage::setup()
|
||||
{
|
||||
return mPathgrids.getSize();
|
||||
}
|
||||
|
||||
void CSMTools::PathgridCheckStage::perform (int stage, CSMDoc::Messages& messages)
|
||||
{
|
||||
const CSMWorld::Record<CSMWorld::Pathgrid>& record = mPathgrids.getRecord (stage);
|
||||
|
||||
if (record.isDeleted())
|
||||
return;
|
||||
|
||||
const CSMWorld::Pathgrid& pathgrid = record.get();
|
||||
|
||||
CSMWorld::UniversalId id (CSMWorld::UniversalId::Type_Pathgrid, pathgrid.mId);
|
||||
|
||||
// check the number of pathgrid points
|
||||
if (pathgrid.mData.mS2 > static_cast<int>(pathgrid.mPoints.size()))
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + " has less points than expected"));
|
||||
else if (pathgrid.mData.mS2 > static_cast<int>(pathgrid.mPoints.size()))
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + " has more points than expected"));
|
||||
|
||||
std::vector<CSMTools::Point> pointList(pathgrid.mPoints.size());
|
||||
std::vector<int> duplList;
|
||||
|
||||
for (unsigned int i = 0; i < pathgrid.mEdges.size(); ++i)
|
||||
{
|
||||
if (pathgrid.mEdges[i].mV0 < static_cast<int>(pathgrid.mPoints.size()) && pathgrid.mEdges[i].mV0 >= 0)
|
||||
{
|
||||
pointList[pathgrid.mEdges[i].mV0].mConnectionNum++;
|
||||
// first check for duplicate edges
|
||||
unsigned int j = 0;
|
||||
for (; j < pointList[pathgrid.mEdges[i].mV0].mOtherIndex.size(); ++j)
|
||||
{
|
||||
if (pointList[pathgrid.mEdges[i].mV0].mOtherIndex[j] == pathgrid.mEdges[i].mV1)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << "has a duplicate edge between points" << pathgrid.mEdges[i].mV0
|
||||
<< " and " << pathgrid.mEdges[i].mV1;
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// only add if not a duplicate
|
||||
if (j == pointList[pathgrid.mEdges[i].mV0].mOtherIndex.size())
|
||||
pointList[pathgrid.mEdges[i].mV0].mOtherIndex.push_back(pathgrid.mEdges[i].mV1);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << " has an edge connecting a non-existent point " << pathgrid.mEdges[i].mV0;
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < pathgrid.mPoints.size(); ++i)
|
||||
{
|
||||
// check the connection number for each point matches the edge connections
|
||||
if (pathgrid.mPoints[i].mConnectionNum > pointList[i].mConnectionNum)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << " has has less edges than expected for point " << i;
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
|
||||
}
|
||||
else if (pathgrid.mPoints[i].mConnectionNum < pointList[i].mConnectionNum)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << " has has more edges than expected for point " << i;
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
|
||||
}
|
||||
|
||||
// check that edges are bidirectional
|
||||
bool foundReverse = false;
|
||||
for (unsigned int j = 0; j < pointList[i].mOtherIndex.size(); ++j)
|
||||
{
|
||||
for (unsigned int k = 0; k < pointList[pointList[i].mOtherIndex[j]].mOtherIndex.size(); ++k)
|
||||
{
|
||||
if (pointList[pointList[i].mOtherIndex[j]].mOtherIndex[k] == static_cast<int>(i))
|
||||
{
|
||||
foundReverse = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundReverse)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << " has a missing edge between points " << i << " and " << pointList[i].mOtherIndex[j];
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
|
||||
}
|
||||
}
|
||||
|
||||
// check duplicate points
|
||||
// FIXME: how to do this efficiently?
|
||||
for (unsigned int j = 0; j < pathgrid.mPoints.size(); ++j)
|
||||
{
|
||||
if (j == i)
|
||||
continue;
|
||||
|
||||
if (pathgrid.mPoints[i].mX == pathgrid.mPoints[j].mX &&
|
||||
pathgrid.mPoints[i].mY == pathgrid.mPoints[j].mY &&
|
||||
pathgrid.mPoints[i].mZ == pathgrid.mPoints[j].mZ)
|
||||
{
|
||||
std::vector<int>::const_iterator it = find(duplList.begin(), duplList.end(), i);
|
||||
if (it == duplList.end())
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << " has a duplicated point (" << i
|
||||
<< ") x=" << pathgrid.mPoints[i].mX
|
||||
<< ", y=" << pathgrid.mPoints[i].mY
|
||||
<< ", z=" << pathgrid.mPoints[i].mZ;
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
|
||||
|
||||
duplList.push_back(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check pathgrid points that are not connected to anything
|
||||
for (unsigned int i = 0; i < pointList.size(); ++i)
|
||||
{
|
||||
if (pointList[i].mConnectionNum == 0)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << " has an orphaned point (" << i
|
||||
<< ") x=" << pathgrid.mPoints[i].mX
|
||||
<< ", y=" << pathgrid.mPoints[i].mY
|
||||
<< ", z=" << pathgrid.mPoints[i].mZ;
|
||||
messages.push_back (std::make_pair (id, pathgrid.mId + ss.str()));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check whether there are disconnected graphs
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#ifndef CSM_TOOLS_PATHGRIDCHECK_H
|
||||
#define CSM_TOOLS_PATHGRIDCHECK_H
|
||||
|
||||
#include "../world/collection.hpp"
|
||||
|
||||
#include "../doc/stage.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
struct Pathgrid;
|
||||
template<typename T, typename AT>
|
||||
class SubCellCollection;
|
||||
}
|
||||
|
||||
namespace CSMTools
|
||||
{
|
||||
struct Point
|
||||
{
|
||||
unsigned char mConnectionNum;
|
||||
std::vector<int> mOtherIndex;
|
||||
Point() : mConnectionNum(0), mOtherIndex(0) {}
|
||||
};
|
||||
|
||||
class PathgridCheckStage : public CSMDoc::Stage
|
||||
{
|
||||
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid,
|
||||
CSMWorld::IdAccessor<CSMWorld::Pathgrid> >& mPathgrids;
|
||||
|
||||
public:
|
||||
|
||||
PathgridCheckStage (const CSMWorld::SubCellCollection<CSMWorld::Pathgrid,
|
||||
CSMWorld::IdAccessor<CSMWorld::Pathgrid> >& pathgrids);
|
||||
|
||||
virtual int setup();
|
||||
|
||||
virtual void perform (int stage, CSMDoc::Messages& messages);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSM_TOOLS_PATHGRIDCHECK_H
|
@ -0,0 +1,53 @@
|
||||
#include "dialoguespinbox.hpp"
|
||||
|
||||
#include <QWheelEvent>
|
||||
|
||||
CSVWorld::DialogueSpinBox::DialogueSpinBox(QWidget *parent) : QSpinBox(parent)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSpinBox::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
setFocusPolicy(Qt::WheelFocus);
|
||||
QSpinBox::focusInEvent(event);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSpinBox::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
QSpinBox::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueSpinBox::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (!hasFocus())
|
||||
event->ignore();
|
||||
else
|
||||
QSpinBox::wheelEvent(event);
|
||||
}
|
||||
|
||||
CSVWorld::DialogueDoubleSpinBox::DialogueDoubleSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueDoubleSpinBox::focusInEvent(QFocusEvent *event)
|
||||
{
|
||||
setFocusPolicy(Qt::WheelFocus);
|
||||
QDoubleSpinBox::focusInEvent(event);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueDoubleSpinBox::focusOutEvent(QFocusEvent *event)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
QDoubleSpinBox::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void CSVWorld::DialogueDoubleSpinBox::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (!hasFocus())
|
||||
event->ignore();
|
||||
else
|
||||
QDoubleSpinBox::wheelEvent(event);
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
#ifndef CSV_WORLD_DIALOGUESPINBOX_H
|
||||
#define CSV_WORLD_DIALOGUESPINBOX_H
|
||||
|
||||
#include <QSpinBox>
|
||||
#include <QDoubleSpinBox>
|
||||
|
||||
namespace CSVWorld
|
||||
{
|
||||
class DialogueSpinBox : public QSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
DialogueSpinBox (QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void focusInEvent(QFocusEvent *event);
|
||||
virtual void focusOutEvent(QFocusEvent *event);
|
||||
virtual void wheelEvent(QWheelEvent *event);
|
||||
};
|
||||
|
||||
class DialogueDoubleSpinBox : public QDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
DialogueDoubleSpinBox (QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void focusInEvent(QFocusEvent *event);
|
||||
virtual void focusOutEvent(QFocusEvent *event);
|
||||
virtual void wheelEvent(QWheelEvent *event);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // CSV_WORLD_DIALOGUESPINBOX_H
|
Loading…
Reference in New Issue