Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathgrid rendering v2 #933

Merged
merged 13 commits into from
May 8, 2016
Prev Previous commit
Next Next commit
Remove code duplication.
  • Loading branch information
Aesylwinn committed May 3, 2016
commit 1f902ff0695d515673db07bc9e7518b2895640b9
56 changes: 18 additions & 38 deletions apps/opencs/view/render/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@ bool CSVRender::Cell::addObjects (int start, int end)
return modified;
}

void CSVRender::Cell::recreatePathgrid()
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mData.getPathgrids();
int pathgridIndex = pathgrids.searchId(mId);
if (pathgridIndex != -1)
{
mPathgridGeode->removeDrawable(mPathgridGeometry);
mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create(
pathgrids.getRecord(pathgridIndex).get());
mPathgridGeode->addDrawable(mPathgridGeometry);
}
}

CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::string& id,
bool deleted)
: mData (data), mId (Misc::StringUtils::lowerCase (id)), mDeleted (deleted), mSubMode (0),
Expand Down Expand Up @@ -120,14 +133,7 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::st
}
}

const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mData.getPathgrids();
int pathgridIndex = pathgrids.searchId(mId);
if (pathgridIndex != -1)
{
mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create(
pathgrids.getRecord(pathgridIndex).get());
mPathgridGeode->addDrawable(mPathgridGeometry);
}
recreatePathgrid();
}
}

Expand Down Expand Up @@ -280,9 +286,7 @@ bool CSVRender::Cell::referenceAdded (const QModelIndex& parent, int start, int

void CSVRender::Cell::pathgridAdded(const CSMWorld::Pathgrid& pathgrid)
{
mPathgridGeode->removeDrawable(mPathgridGeometry);
mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create(pathgrid);
mPathgridGeode->addDrawable(mPathgridGeometry);
recreatePathgrid();
}

void CSVRender::Cell::pathgridRemoved()
Expand All @@ -292,41 +296,17 @@ void CSVRender::Cell::pathgridRemoved()

void CSVRender::Cell::pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mData.getPathgrids();
int pathgridIndex = pathgrids.searchId(mId);
if (pathgridIndex != -1)
{
mPathgridGeode->removeDrawable(mPathgridGeometry);
mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create(
pathgrids.getRecord(pathgridIndex).get());
mPathgridGeode->addDrawable(mPathgridGeometry);
}
recreatePathgrid();
}

void CSVRender::Cell::pathgridRowRemoved(const QModelIndex& parent, int start, int end)
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mData.getPathgrids();
int pathgridIndex = pathgrids.searchId(mId);
if (pathgridIndex != -1)
{
mPathgridGeode->removeDrawable(mPathgridGeometry);
mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create(
pathgrids.getRecord(pathgridIndex).get());
mPathgridGeode->addDrawable(mPathgridGeometry);
}
recreatePathgrid();
}

void CSVRender::Cell::pathgridRowAdded(const QModelIndex& parent, int start, int end)
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mData.getPathgrids();
int pathgridIndex = pathgrids.searchId(mId);
if (pathgridIndex != -1)
{
mPathgridGeode->removeDrawable(mPathgridGeometry);
mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create(
pathgrids.getRecord(pathgridIndex).get());
mPathgridGeode->addDrawable(mPathgridGeometry);
}
recreatePathgrid();
}

void CSVRender::Cell::setSelection (int elementMask, Selection mode)
Expand Down
2 changes: 2 additions & 0 deletions apps/opencs/view/render/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ namespace CSVRender
/// \return Have any objects been added?
bool addObjects (int start, int end);

void recreatePathgrid();

public:

enum Selection
Expand Down