Skip to content

Commit

Permalink
Pathgrid rendering v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aesylwinn committed May 2, 2016
1 parent 93b2f09 commit 4dee960
Show file tree
Hide file tree
Showing 11 changed files with 804 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/opencs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ opencs_units (view/render

opencs_units_noqt (view/render
lighting lightingday lightingnight lightingbright object cell terrainstorage tagbase
cellarrow cellmarker cellborder cameracontroller
cellarrow cellmarker cellborder cameracontroller pathgrid
)

opencs_hdrs_noqt (view/render
Expand Down
46 changes: 46 additions & 0 deletions apps/opencs/view/render/cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "mask.hpp"
#include "terrainstorage.hpp"
#include "pathgrid.hpp"

bool CSVRender::Cell::removeObject (const std::string& id)
{
Expand Down Expand Up @@ -104,6 +105,11 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::st
mCellBorder->buildShape(esmLand);
}
}

const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mData.getPathgrids();
int pathgridIndex = pathgrids.searchId(mId);
if (pathgridIndex != -1)
mPathgrid.reset(new Pathgrid(mCellNode, pathgrids.getRecord(pathgridIndex).get(), mCoordinates));
}
}

Expand Down Expand Up @@ -254,6 +260,46 @@ bool CSVRender::Cell::referenceAdded (const QModelIndex& parent, int start, int
return addObjects (start, end);
}

void CSVRender::Cell::pathgridAdded(const CSMWorld::Pathgrid& pathgrid)
{
mPathgrid.reset(new Pathgrid(mCellNode, pathgrid, mCoordinates));
}

void CSVRender::Cell::pathgridRemoved()
{
mPathgrid.reset();
}

bool CSVRender::Cell::pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
if (mPathgrid.get() != 0)
{
return mPathgrid->dataChanged(topLeft, bottomRight);
}

return false;
}

bool CSVRender::Cell::pathgridRowAboutToBeRemoved(const QModelIndex& parent, int start, int end)
{
if (mPathgrid.get() != 0)
{
return mPathgrid->rowAboutToBeRemoved(parent, start, end);
}

return false;
}

bool CSVRender::Cell::pathgridRowAdded(const QModelIndex& parent, int start, int end)
{
if (mPathgrid.get() != 0)
{
return mPathgrid->rowAdded(parent, start, end);
}

return false;
}

void CSVRender::Cell::setSelection (int elementMask, Selection mode)
{
if (elementMask & Mask_Reference)
Expand Down
14 changes: 14 additions & 0 deletions apps/opencs/view/render/cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@ namespace CSMWorld
{
class Data;
class CellCoordinates;
class Pathgrid;
}

namespace CSVRender
{
class TagBase;

class Pathgrid;

class Cell
{
CSMWorld::Data& mData;
Expand All @@ -46,6 +49,7 @@ namespace CSVRender
std::auto_ptr<CellArrow> mCellArrows[4];
std::auto_ptr<CellMarker> mCellMarker;
std::auto_ptr<CellBorder> mCellBorder;
std::auto_ptr<Pathgrid> mPathgrid;
bool mDeleted;
int mSubMode;
unsigned int mSubModeElementMask;
Expand Down Expand Up @@ -103,6 +107,16 @@ namespace CSVRender
/// this cell?
bool referenceAdded (const QModelIndex& parent, int start, int end);

void pathgridAdded(const CSMWorld::Pathgrid& pathgrid);

void pathgridRemoved();

bool pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);

bool pathgridRowAboutToBeRemoved(const QModelIndex& parent, int start, int end);

bool 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
Expand Down
91 changes: 91 additions & 0 deletions apps/opencs/view/render/pagedworldspacewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,97 @@ void CSVRender::PagedWorldspaceWidget::referenceAdded (const QModelIndex& parent
flagAsModified();
}

void CSVRender::PagedWorldspaceWidget::pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight)
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();

if (topLeft.parent().isValid())
{
int row = topLeft.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->pathgridDataChanged(topLeft, bottomRight))
flagAsModified();
}
}

void CSVRender::PagedWorldspaceWidget::pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end)
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();

if (!parent.isValid())
{
// Pathgrid going to be deleted
for (int row = start; row <= end; ++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->pathgridRemoved();
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->pathgridRowAboutToBeRemoved(parent, start, end);
flagAsModified();
}
}
}

void CSVRender::PagedWorldspaceWidget::pathgridAdded(const QModelIndex& parent, int start, int end)
{
const CSMWorld::SubCellCollection<CSMWorld::Pathgrid>& pathgrids = mDocument.getData().getPathgrids();

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();
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->pathgridAdded(pathgrid);
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();
}
}
}

std::string CSVRender::PagedWorldspaceWidget::getStartupInstruction()
{
osg::Vec3d eye, center, up;
Expand Down
6 changes: 6 additions & 0 deletions apps/opencs/view/render/pagedworldspacewidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ namespace CSVRender

virtual void referenceAdded (const QModelIndex& index, int start, int end);

virtual void pathgridDataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);

virtual void pathgridAboutToBeRemoved (const QModelIndex& parent, int start, int end);

virtual void pathgridAdded (const QModelIndex& parent, int start, int end);

virtual std::string getStartupInstruction();

/// \note Does not update the view or any cell marker
Expand Down
Loading

0 comments on commit 4dee960

Please sign in to comment.