remove unnecessary object creation; replace deprecated geode with an appriopriate equivelent; clean up old style C++ in files and remove unnesed headers

just_say_no_to_geode
Bret Curtis 2 years ago
parent 776cae4c95
commit 917f738174

@ -1,9 +1,9 @@
#include "cell.hpp" #include "cell.hpp"
#include <osg/PositionAttitudeTransform> #include <osg/PositionAttitudeTransform>
#include <osg/Geode>
#include <osg/Group> #include <osg/Group>
#include <memory>
#include <components/misc/stringops.hpp> #include <components/misc/stringops.hpp>
#include <components/esm3/loadcell.hpp> #include <components/esm3/loadcell.hpp>
#include <components/esm3/loadland.hpp> #include <components/esm3/loadland.hpp>
@ -43,7 +43,7 @@ namespace CSVRender
void operator()(osg::Node* node, osg::NodeVisitor* nv) override void operator()(osg::Node* node, osg::NodeVisitor* nv) override
{ {
traverse(node, nv); traverse(node, nv);
CellNodeContainer* container = static_cast<CellNodeContainer*>(node->getUserData()); auto* container = dynamic_cast<CellNodeContainer*>(node->getUserData());
container->getCell()->updateLand(); container->getCell()->updateLand();
} }
}; };
@ -51,8 +51,7 @@ namespace CSVRender
bool CSVRender::Cell::removeObject (const std::string& id) bool CSVRender::Cell::removeObject (const std::string& id)
{ {
std::map<std::string, Object *>::iterator iter = auto iter = mObjects.find (Misc::StringUtils::lowerCase (id));
mObjects.find (Misc::StringUtils::lowerCase (id));
if (iter==mObjects.end()) if (iter==mObjects.end())
return false; return false;
@ -193,9 +192,8 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::st
CSVRender::Cell::~Cell() CSVRender::Cell::~Cell()
{ {
for (std::map<std::string, Object *>::iterator iter (mObjects.begin()); for (auto & mObject : mObjects)
iter!=mObjects.end(); ++iter) delete mObject.second;
delete iter->second;
mCellNode->getParent(0)->removeChild(mCellNode); mCellNode->getParent(0)->removeChild(mCellNode);
} }
@ -210,9 +208,8 @@ bool CSVRender::Cell::referenceableDataChanged (const QModelIndex& topLeft,
{ {
bool modified = false; bool modified = false;
for (std::map<std::string, Object *>::iterator iter (mObjects.begin()); for (auto & mObject : mObjects)
iter!=mObjects.end(); ++iter) if (mObject.second->referenceableDataChanged (topLeft, bottomRight))
if (iter->second->referenceableDataChanged (topLeft, bottomRight))
modified = true; modified = true;
return modified; return modified;
@ -226,9 +223,8 @@ bool CSVRender::Cell::referenceableAboutToBeRemoved (const QModelIndex& parent,
bool modified = false; bool modified = false;
for (std::map<std::string, Object *>::iterator iter (mObjects.begin()); for (auto & mObject : mObjects)
iter!=mObjects.end(); ++iter) if (mObject.second->referenceableAboutToBeRemoved (parent, start, end))
if (iter->second->referenceableAboutToBeRemoved (parent, start, end))
modified = true; modified = true;
return modified; return modified;
@ -269,13 +265,13 @@ bool CSVRender::Cell::referenceDataChanged (const QModelIndex& topLeft,
// perform update and remove where needed // perform update and remove where needed
bool modified = false; bool modified = false;
std::map<std::string, Object *>::iterator iter = mObjects.begin(); auto iter = mObjects.begin();
while (iter!=mObjects.end()) while (iter!=mObjects.end())
{ {
if (iter->second->referenceDataChanged (topLeft, bottomRight)) if (iter->second->referenceDataChanged (topLeft, bottomRight))
modified = true; modified = true;
std::map<std::string, bool>::iterator iter2 = ids.find (iter->first); auto iter2 = ids.find (iter->first);
if (iter2!=ids.end()) if (iter2!=ids.end())
{ {
@ -294,12 +290,12 @@ bool CSVRender::Cell::referenceDataChanged (const QModelIndex& topLeft,
} }
// add new objects // add new objects
for (std::map<std::string, bool>::iterator mapIter (ids.begin()); mapIter!=ids.end(); ++mapIter) for (auto & id : ids)
{ {
if (!mapIter->second) if (!id.second)
{ {
mObjects.insert (std::make_pair ( mObjects.insert (std::make_pair (
mapIter->first, new Object (mData, mCellNode, mapIter->first, false))); id.first, new Object (mData, mCellNode, id.first, false)));
modified = true; modified = true;
} }
@ -539,11 +535,11 @@ void CSVRender::Cell::setCellArrows (int mask)
{ {
for (int i=0; i<4; ++i) for (int i=0; i<4; ++i)
{ {
CellArrow::Direction direction = static_cast<CellArrow::Direction> (1<<i); auto direction = static_cast<CellArrow::Direction> (1<<i);
bool enable = mask & direction; bool enable = mask & direction;
if (enable!=(mCellArrows[i].get()!=nullptr)) if (enable!=(mCellArrows[i]!=nullptr))
{ {
if (enable) if (enable)
mCellArrows[i] = std::make_unique<CellArrow>(mCellNode, direction, mCoordinates); mCellArrows[i] = std::make_unique<CellArrow>(mCellNode, direction, mCoordinates);
@ -586,10 +582,9 @@ std::vector<osg::ref_ptr<CSVRender::TagBase> > CSVRender::Cell::getSelection (un
std::vector<osg::ref_ptr<TagBase> > result; std::vector<osg::ref_ptr<TagBase> > result;
if (elementMask & Mask_Reference) if (elementMask & Mask_Reference)
for (std::map<std::string, Object *>::const_iterator iter (mObjects.begin()); for (const auto & mObject : mObjects)
iter!=mObjects.end(); ++iter) if (mObject.second->getSelected())
if (iter->second->getSelected()) result.push_back (mObject.second->getTag());
result.push_back (iter->second->getTag());
if (mPathgrid && elementMask & Mask_Pathgrid) if (mPathgrid && elementMask & Mask_Pathgrid)
if (mPathgrid->isSelected()) if (mPathgrid->isSelected())
result.emplace_back(mPathgrid->getTag()); result.emplace_back(mPathgrid->getTag());
@ -602,10 +597,9 @@ std::vector<osg::ref_ptr<CSVRender::TagBase> > CSVRender::Cell::getEdited (unsig
std::vector<osg::ref_ptr<TagBase> > result; std::vector<osg::ref_ptr<TagBase> > result;
if (elementMask & Mask_Reference) if (elementMask & Mask_Reference)
for (std::map<std::string, Object *>::const_iterator iter (mObjects.begin()); for (const auto & mObject : mObjects)
iter!=mObjects.end(); ++iter) if (mObject.second->isEdited())
if (iter->second->isEdited()) result.push_back (mObject.second->getTag());
result.push_back (iter->second->getTag());
return result; return result;
} }

@ -18,7 +18,6 @@ namespace osg
{ {
class Group; class Group;
class Geometry; class Geometry;
class Geode;
} }
namespace CSMWorld namespace CSMWorld

@ -1,14 +1,12 @@
#include "cellarrow.hpp" #include "cellarrow.hpp"
#include <osg/Group> #include <osg/Group>
#include <osg/PositionAttitudeTransform> #include <osg/PositionAttitudeTransform>
#include <osg/Geode> #include <osg/Billboard>
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/PrimitiveSet> #include <osg/PrimitiveSet>
#include "../../model/prefs/state.hpp" #include "../../model/prefs/state.hpp"
#include "../../model/prefs/shortcutmanager.hpp"
#include <components/misc/constants.hpp> #include <components/misc/constants.hpp>
@ -96,7 +94,7 @@ void CSVRender::CellArrow::buildShape()
const int arrowLength = 1350; const int arrowLength = 1350;
const int arrowHeight = 300; const int arrowHeight = 300;
osg::Vec3Array *vertices = new osg::Vec3Array; auto *vertices = new osg::Vec3Array;
for (int i2=0; i2<2; ++i2) for (int i2=0; i2<2; ++i2)
for (int i=0; i<2; ++i) for (int i=0; i<2; ++i)
{ {
@ -108,7 +106,7 @@ void CSVRender::CellArrow::buildShape()
geometry->setVertexArray (vertices); geometry->setVertexArray (vertices);
osg::DrawElementsUShort *primitives = new osg::DrawElementsUShort (osg::PrimitiveSet::TRIANGLES, 0); auto *primitives = new osg::DrawElementsUShort (osg::PrimitiveSet::TRIANGLES, 0);
// top // top
primitives->push_back (0); primitives->push_back (0);
@ -148,7 +146,7 @@ void CSVRender::CellArrow::buildShape()
geometry->addPrimitiveSet (primitives); geometry->addPrimitiveSet (primitives);
osg::Vec4Array *colours = new osg::Vec4Array; auto *colours = new osg::Vec4Array;
for (int i=0; i<6; ++i) for (int i=0; i<6; ++i)
colours->push_back (osg::Vec4f (0.11f, 0.6f, 0.95f, 1.0f)); colours->push_back (osg::Vec4f (0.11f, 0.6f, 0.95f, 1.0f));
@ -159,10 +157,7 @@ void CSVRender::CellArrow::buildShape()
geometry->getOrCreateStateSet()->setMode (GL_LIGHTING, osg::StateAttribute::OFF); geometry->getOrCreateStateSet()->setMode (GL_LIGHTING, osg::StateAttribute::OFF);
osg::ref_ptr<osg::Geode> geode (new osg::Geode); mBaseNode->addChild (geometry);
geode->addDrawable (geometry);
mBaseNode->addChild (geode);
} }
CSVRender::CellArrow::CellArrow (osg::Group *cellNode, Direction direction, CSVRender::CellArrow::CellArrow (osg::Group *cellNode, Direction direction,

@ -2,20 +2,15 @@
#include <osg/AutoTransform> #include <osg/AutoTransform>
#include <osg/Material> #include <osg/Material>
#include <osg/Geode>
#include <osgText/Text> #include <osgText/Text>
#include <components/misc/constants.hpp> #include <components/misc/constants.hpp>
CSVRender::CellMarkerTag::CellMarkerTag(CellMarker *marker) CSVRender::CellMarkerTag::CellMarkerTag(CellMarker *marker)
: TagBase(Mask_CellMarker), mMarker(marker) : TagBase(Mask_CellMarker), mMarker(marker)
{} {}
CSVRender::CellMarker *CSVRender::CellMarkerTag::getCellMarker() const
{
return mMarker;
}
void CSVRender::CellMarker::buildMarker() void CSVRender::CellMarker::buildMarker()
{ {
const int characterSize = 20; const int characterSize = 20;
@ -44,9 +39,7 @@ void CSVRender::CellMarker::buildMarker()
markerText->setText(coordinatesText); markerText->setText(coordinatesText);
// Add text to marker node. // Add text to marker node.
osg::ref_ptr<osg::Geode> geode (new osg::Geode); mMarkerNode->addChild(markerText);
geode->addDrawable(markerText);
mMarkerNode->addChild(geode);
} }
void CSVRender::CellMarker::positionMarker() void CSVRender::CellMarker::positionMarker()

@ -1,6 +1,5 @@
#include "cellwater.hpp" #include "cellwater.hpp"
#include <osg/Geode>
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/Group> #include <osg/Group>
#include <osg/PositionAttitudeTransform> #include <osg/PositionAttitudeTransform>
@ -28,7 +27,7 @@ namespace CSVRender
, mId(id) , mId(id)
, mParentNode(cellNode) , mParentNode(cellNode)
, mWaterTransform(nullptr) , mWaterTransform(nullptr)
, mWaterNode(nullptr) , mWaterGroup(nullptr)
, mWaterGeometry(nullptr) , mWaterGeometry(nullptr)
, mDeleted(false) , mDeleted(false)
, mExterior(false) , mExterior(false)
@ -41,8 +40,8 @@ namespace CSVRender
mWaterTransform->setNodeMask(Mask_Water); mWaterTransform->setNodeMask(Mask_Water);
mParentNode->addChild(mWaterTransform); mParentNode->addChild(mWaterTransform);
mWaterNode = new osg::Geode(); mWaterGroup = new osg::Group();
mWaterTransform->addChild(mWaterNode); mWaterTransform->addChild(mWaterGroup);
int cellIndex = mData.getCells().searchId(mId); int cellIndex = mData.getCells().searchId(mId);
if (cellIndex > -1) if (cellIndex > -1)
@ -101,8 +100,8 @@ namespace CSVRender
{ {
const CSMWorld::Collection<CSMWorld::Cell>& cells = mData.getCells(); const CSMWorld::Collection<CSMWorld::Cell>& cells = mData.getCells();
int rowStart = -1; int rowStart;
int rowEnd = -1; int rowEnd;
if (topLeft.parent().isValid()) if (topLeft.parent().isValid())
{ {
@ -136,7 +135,7 @@ namespace CSVRender
if (mWaterGeometry) if (mWaterGeometry)
{ {
mWaterNode->removeDrawable(mWaterGeometry); mWaterGroup->removeChild(mWaterGeometry);
mWaterGeometry = nullptr; mWaterGeometry = nullptr;
} }
@ -177,6 +176,6 @@ namespace CSVRender
mWaterGeometry->getStateSet()->setTextureAttributeAndModes(0, waterTexture, osg::StateAttribute::ON); mWaterGeometry->getStateSet()->setTextureAttributeAndModes(0, waterTexture, osg::StateAttribute::ON);
mWaterNode->addDrawable(mWaterGeometry); mWaterGroup->addChild(mWaterGeometry);
} }
} }

@ -12,7 +12,6 @@
namespace osg namespace osg
{ {
class Geode;
class Geometry; class Geometry;
class Group; class Group;
class PositionAttitudeTransform; class PositionAttitudeTransform;
@ -60,7 +59,7 @@ namespace CSVRender
osg::Group* mParentNode; osg::Group* mParentNode;
osg::ref_ptr<osg::PositionAttitudeTransform> mWaterTransform; osg::ref_ptr<osg::PositionAttitudeTransform> mWaterTransform;
osg::ref_ptr<osg::Geode> mWaterNode; osg::ref_ptr<osg::Group> mWaterGroup;
osg::ref_ptr<osg::Geometry> mWaterGeometry; osg::ref_ptr<osg::Geometry> mWaterGeometry;
bool mDeleted; bool mDeleted;

@ -1,8 +1,8 @@
#include "object.hpp" #include "object.hpp"
#include <memory>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include <iostream>
#include <osg/Depth> #include <osg/Depth>
#include <osg/Group> #include <osg/Group>
@ -10,17 +10,13 @@
#include <osg/ShapeDrawable> #include <osg/ShapeDrawable>
#include <osg/Shape> #include <osg/Shape>
#include <osg/Geode>
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/PrimitiveSet> #include <osg/PrimitiveSet>
#include <osgFX/Scribe> #include <osgFX/Scribe>
#include "../../model/world/data.hpp" #include "../../model/world/data.hpp"
#include "../../model/world/ref.hpp"
#include "../../model/world/refidcollection.hpp"
#include "../../model/world/commands.hpp" #include "../../model/world/commands.hpp"
#include "../../model/world/universalid.hpp"
#include "../../model/world/commandmacro.hpp" #include "../../model/world/commandmacro.hpp"
#include "../../model/world/cellcoordinates.hpp" #include "../../model/world/cellcoordinates.hpp"
#include "../../model/prefs/state.hpp" #include "../../model/prefs/state.hpp"
@ -43,15 +39,15 @@ const float CSVRender::Object::MarkerHeadLength = 50;
namespace namespace
{ {
osg::ref_ptr<osg::Geode> createErrorCube() osg::ref_ptr<osg::Group> createErrorCube()
{ {
osg::ref_ptr<osg::Box> shape(new osg::Box(osg::Vec3f(0,0,0), 50.f)); osg::ref_ptr<osg::Box> shape(new osg::Box(osg::Vec3f(0,0,0), 50.f));
osg::ref_ptr<osg::ShapeDrawable> shapedrawable(new osg::ShapeDrawable); osg::ref_ptr<osg::ShapeDrawable> shapedrawable(new osg::ShapeDrawable);
shapedrawable->setShape(shape); shapedrawable->setShape(shape);
osg::ref_ptr<osg::Geode> geode (new osg::Geode); osg::ref_ptr<osg::Group> group (new osg::Group);
geode->addDrawable(shapedrawable); group->addChild(shapedrawable);
return geode; return group;
} }
} }
@ -217,7 +213,7 @@ osg::ref_ptr<osg::Node> CSVRender::Object::makeMoveOrScaleMarker (int axis)
float shaftLength = MarkerShaftBaseLength + mBaseNode->getBound().radius(); float shaftLength = MarkerShaftBaseLength + mBaseNode->getBound().radius();
// shaft // shaft
osg::Vec3Array *vertices = new osg::Vec3Array; auto *vertices = new osg::Vec3Array;
for (int i=0; i<2; ++i) for (int i=0; i<2; ++i)
{ {
@ -240,7 +236,7 @@ osg::ref_ptr<osg::Node> CSVRender::Object::makeMoveOrScaleMarker (int axis)
geometry->setVertexArray (vertices); geometry->setVertexArray (vertices);
osg::DrawElementsUShort *primitives = new osg::DrawElementsUShort (osg::PrimitiveSet::TRIANGLES, 0); auto *primitives = new osg::DrawElementsUShort (osg::PrimitiveSet::TRIANGLES, 0);
// shaft // shaft
for (int i=0; i<4; ++i) for (int i=0; i<4; ++i)
@ -282,7 +278,7 @@ osg::ref_ptr<osg::Node> CSVRender::Object::makeMoveOrScaleMarker (int axis)
geometry->addPrimitiveSet (primitives); geometry->addPrimitiveSet (primitives);
osg::Vec4Array *colours = new osg::Vec4Array; auto *colours = new osg::Vec4Array;
for (int i=0; i<8; ++i) for (int i=0; i<8; ++i)
colours->push_back (osg::Vec4f (axis==0 ? 1.0f : 0.2f, axis==1 ? 1.0f : 0.2f, colours->push_back (osg::Vec4f (axis==0 ? 1.0f : 0.2f, axis==1 ? 1.0f : 0.2f,
@ -296,10 +292,10 @@ osg::ref_ptr<osg::Node> CSVRender::Object::makeMoveOrScaleMarker (int axis)
setupCommonMarkerState(geometry); setupCommonMarkerState(geometry);
osg::ref_ptr<osg::Geode> geode (new osg::Geode); osg::ref_ptr<osg::Group> group (new osg::Group);
geode->addDrawable (geometry); group->addChild(geometry);
return geode; return group;
} }
osg::ref_ptr<osg::Node> CSVRender::Object::makeRotateMarker (int axis) osg::ref_ptr<osg::Node> CSVRender::Object::makeRotateMarker (int axis)
@ -370,9 +366,9 @@ osg::ref_ptr<osg::Node> CSVRender::Object::makeRotateMarker (int axis)
} }
size_t elementOffset = i * IndicesPerSegment; size_t elementOffset = i * IndicesPerSegment;
for (size_t j = 0; j < IndicesPerSegment; ++j) for (auto j : IndexPattern)
{ {
primitives->setElement(elementOffset++, indices[IndexPattern[j]]); primitives->setElement(elementOffset++, indices[j]);
} }
} }
@ -382,13 +378,13 @@ osg::ref_ptr<osg::Node> CSVRender::Object::makeRotateMarker (int axis)
setupCommonMarkerState(geometry); setupCommonMarkerState(geometry);
osg::ref_ptr<osg::Geode> geode = new osg::Geode(); osg::ref_ptr<osg::Group> group = new osg::Group();
geode->addDrawable (geometry); group->addChild(geometry);
return geode; return group;
} }
void CSVRender::Object::setupCommonMarkerState(osg::ref_ptr<osg::Geometry> geometry) void CSVRender::Object::setupCommonMarkerState(const osg::ref_ptr<osg::Geometry>& geometry)
{ {
osg::ref_ptr<osg::StateSet> state = geometry->getOrCreateStateSet(); osg::ref_ptr<osg::StateSet> state = geometry->getOrCreateStateSet();
state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
@ -401,12 +397,10 @@ osg::Vec3f CSVRender::Object::getMarkerPosition (float x, float y, float z, int
{ {
switch (axis) switch (axis)
{ {
case 2: return osg::Vec3f (x, y, z); case 0: return {z, x, y};
case 0: return osg::Vec3f (z, x, y); case 1: return {y, z, x};
case 1: return osg::Vec3f (y, z, x); case 2: return {x, y, z};
default: default:
throw std::logic_error ("invalid axis for marker geometry"); throw std::logic_error ("invalid axis for marker geometry");
} }
} }
@ -576,7 +570,7 @@ std::string CSVRender::Object::getReferenceableId() const
osg::ref_ptr<CSVRender::TagBase> CSVRender::Object::getTag() const osg::ref_ptr<CSVRender::TagBase> CSVRender::Object::getTag() const
{ {
return static_cast<CSVRender::TagBase *> (mBaseNode->getUserData()); return dynamic_cast<CSVRender::TagBase *> (mBaseNode->getUserData());
} }
bool CSVRender::Object::isEdited() const bool CSVRender::Object::isEdited() const

@ -20,7 +20,6 @@ namespace osg
class PositionAttitudeTransform; class PositionAttitudeTransform;
class Group; class Group;
class Node; class Node;
class Geode;
} }
namespace osgFX namespace osgFX
@ -94,7 +93,7 @@ namespace CSVRender
osg::Group* mParentNode; osg::Group* mParentNode;
Resource::ResourceSystem* mResourceSystem; Resource::ResourceSystem* mResourceSystem;
bool mForceBaseToZero; bool mForceBaseToZero;
ESM::Position mPositionOverride; ESM::Position mPositionOverride{};
float mScaleOverride; float mScaleOverride;
int mOverrideFlags; int mOverrideFlags;
osg::ref_ptr<osg::Node> mMarker[3]; osg::ref_ptr<osg::Node> mMarker[3];
@ -127,7 +126,7 @@ namespace CSVRender
osg::ref_ptr<osg::Node> makeRotateMarker (int axis); osg::ref_ptr<osg::Node> makeRotateMarker (int axis);
/// Sets up a stateset with properties common to all marker types. /// Sets up a stateset with properties common to all marker types.
void setupCommonMarkerState(osg::ref_ptr<osg::Geometry> geometry); void setupCommonMarkerState(const osg::ref_ptr<osg::Geometry>& geometry);
osg::Vec3f getMarkerPosition (float x, float y, float z, int axis); osg::Vec3f getMarkerPosition (float x, float y, float z, int axis);

@ -3,7 +3,6 @@
#include <algorithm> #include <algorithm>
#include <osg/Array> #include <osg/Array>
#include <osg/Geode>
#include <osg/Geometry> #include <osg/Geometry>
#include <osg/Group> #include <osg/Group>
#include <osg/PositionAttitudeTransform> #include <osg/PositionAttitudeTransform>
@ -11,7 +10,6 @@
#include <components/sceneutil/pathgridutil.hpp> #include <components/sceneutil/pathgridutil.hpp>
#include "../../model/world/cell.hpp"
#include "../../model/world/commands.hpp" #include "../../model/world/commands.hpp"
#include "../../model/world/commandmacro.hpp" #include "../../model/world/commandmacro.hpp"
#include "../../model/world/data.hpp" #include "../../model/world/data.hpp"
@ -26,7 +24,7 @@ namespace CSVRender
void operator()(osg::Node* node, osg::NodeVisitor* nv) override void operator()(osg::Node* node, osg::NodeVisitor* nv) override
{ {
PathgridTag* tag = static_cast<PathgridTag*>(node->getUserData()); auto* tag = dynamic_cast<PathgridTag*>(node->getUserData());
tag->getPathgrid()->update(); tag->getPathgrid()->update();
} }
}; };
@ -77,8 +75,8 @@ namespace CSVRender
mBaseNode->setNodeMask(Mask_Pathgrid); mBaseNode->setNodeMask(Mask_Pathgrid);
mParent->addChild(mBaseNode); mParent->addChild(mBaseNode);
mPathgridGeode = new osg::Geode(); mPathgridGroup = new osg::Group();
mBaseNode->addChild(mPathgridGeode); mBaseNode->addChild(mPathgridGroup);
recreateGeometry(); recreateGeometry();
@ -135,7 +133,7 @@ namespace CSVRender
void Pathgrid::toggleSelected(unsigned short node) void Pathgrid::toggleSelected(unsigned short node)
{ {
NodeList::iterator searchResult = std::find(mSelected.begin(), mSelected.end(), node); auto searchResult = std::find(mSelected.begin(), mSelected.end(), node);
if (searchResult != mSelected.end()) if (searchResult != mSelected.end())
{ {
mSelected.erase(searchResult); mSelected.erase(searchResult);
@ -222,7 +220,7 @@ namespace CSVRender
mUseOffset = false; mUseOffset = false;
mMoveOffset.set(0, 0, 0); mMoveOffset.set(0, 0, 0);
mPathgridGeode->removeDrawable(mDragGeometry); mPathgridGroup->removeChild(mDragGeometry);
mDragGeometry = nullptr; mDragGeometry = nullptr;
} }
@ -317,10 +315,10 @@ namespace CSVRender
QModelIndex parent = model->index(recordIndex, parentColumn); QModelIndex parent = model->index(recordIndex, parentColumn);
for (size_t i = 0; i < mSelected.size(); ++i) for (auto i : mSelected)
{ {
const CSMWorld::Pathgrid::Point& point = source->mPoints[mSelected[i]]; const CSMWorld::Pathgrid::Point& point = source->mPoints[i];
int row = static_cast<int>(mSelected[i]); int row = static_cast<int>(i);
commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent), commands.push(new CSMWorld::ModifyCommand(*model, model->index(row, posXColumn, parent),
clampToCell(point.mX + offsetX))); clampToCell(point.mX + offsetX)));
@ -348,9 +346,9 @@ namespace CSVRender
const CSMWorld::Pathgrid* source = getPathgridSource(); const CSMWorld::Pathgrid* source = getPathgridSource();
if (source) if (source)
{ {
for (size_t i = 0; i < mSelected.size(); ++i) for (unsigned short i : mSelected)
{ {
addEdge(commands, *source, node, mSelected[i]); addEdge(commands, *source, node, i);
} }
} }
} }
@ -363,18 +361,18 @@ namespace CSVRender
CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids)); CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids));
// Want to remove nodes from end of list first // Want to remove nodes from end of list first
std::sort(mSelected.begin(), mSelected.end(), std::greater<int>()); std::sort(mSelected.begin(), mSelected.end(), std::greater<>());
int recordIndex = mPathgridCollection.getIndex(mId); int recordIndex = mPathgridCollection.getIndex(mId);
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints); int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridPoints);
for (std::vector<unsigned short>::iterator row = mSelected.begin(); row != mSelected.end(); ++row) for (auto row : mSelected)
{ {
commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, static_cast<int>(*row), parentColumn)); commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, static_cast<int>(row), parentColumn));
} }
// Fix/remove edges // Fix/remove edges
std::set<int, std::greater<int> > edgeRowsToRemove; std::set<int, std::greater<>> edgeRowsToRemove;
parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges); parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges);
@ -392,9 +390,9 @@ namespace CSVRender
int adjustment1 = 0; int adjustment1 = 0;
// Determine necessary adjustment // Determine necessary adjustment
for (std::vector<unsigned short>::iterator point = mSelected.begin(); point != mSelected.end(); ++point) for (unsigned short & point : mSelected)
{ {
if (source->mEdges[edge].mV0 == *point || source->mEdges[edge].mV1 == *point) if (source->mEdges[edge].mV0 == point || source->mEdges[edge].mV1 == point)
{ {
edgeRowsToRemove.insert(static_cast<int>(edge)); edgeRowsToRemove.insert(static_cast<int>(edge));
@ -403,10 +401,10 @@ namespace CSVRender
break; break;
} }
if (source->mEdges[edge].mV0 > *point) if (source->mEdges[edge].mV0 > point)
--adjustment0; --adjustment0;
if (source->mEdges[edge].mV1 > *point) if (source->mEdges[edge].mV1 > point)
--adjustment1; --adjustment1;
} }
@ -425,7 +423,7 @@ namespace CSVRender
} }
} }
std::set<int, std::greater<int> >::iterator row; std::set<int, std::greater<> >::iterator row;
for (row = edgeRowsToRemove.begin(); row != edgeRowsToRemove.end(); ++row) for (row = edgeRowsToRemove.begin(); row != edgeRowsToRemove.end(); ++row)
{ {
commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, *row, parentColumn)); commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, *row, parentColumn));
@ -441,7 +439,7 @@ namespace CSVRender
if (source) if (source)
{ {
// Want to remove from end of row first // Want to remove from end of row first
std::set<int, std::greater<int> > rowsToRemove; std::set<int, std::greater<> > rowsToRemove;
for (size_t i = 0; i <= mSelected.size(); ++i) for (size_t i = 0; i <= mSelected.size(); ++i)
{ {
for (size_t j = i + 1; j < mSelected.size(); ++j) for (size_t j = i + 1; j < mSelected.size(); ++j)
@ -463,7 +461,7 @@ namespace CSVRender
CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids)); CSMWorld::IdTree* model = &dynamic_cast<CSMWorld::IdTree&>(*mData.getTableModel(CSMWorld::UniversalId::Type_Pathgrids));
int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges); int parentColumn = mPathgridCollection.findColumnIndex(CSMWorld::Columns::ColumnId_PathgridEdges);
std::set<int, std::greater<int> >::iterator row; std::set<int, std::greater<>>::iterator row;
for (row = rowsToRemove.begin(); row != rowsToRemove.end(); ++row) for (row = rowsToRemove.begin(); row != rowsToRemove.end(); ++row)
{ {
commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, *row, parentColumn)); commands.push(new CSMWorld::DeleteNestedCommand(*model, mId, *row, parentColumn));
@ -512,11 +510,11 @@ namespace CSVRender
{ {
temp = *source; temp = *source;
for (NodeList::iterator it = mSelected.begin(); it != mSelected.end(); ++it) for (auto it : mSelected)
{ {
temp.mPoints[*it].mX += mMoveOffset.x(); temp.mPoints[it].mX += mMoveOffset.x();
temp.mPoints[*it].mY += mMoveOffset.y(); temp.mPoints[it].mY += mMoveOffset.y();
temp.mPoints[*it].mZ += mMoveOffset.z(); temp.mPoints[it].mZ += mMoveOffset.z();
} }
source = &temp; source = &temp;
@ -524,7 +522,7 @@ namespace CSVRender
removePathgridGeometry(); removePathgridGeometry();
mPathgridGeometry = SceneUtil::createPathgridGeometry(*source); mPathgridGeometry = SceneUtil::createPathgridGeometry(*source);
mPathgridGeode->addDrawable(mPathgridGeometry); mPathgridGroup->addChild(mPathgridGeometry);
createSelectedGeometry(*source); createSelectedGeometry(*source);
} }
@ -553,14 +551,14 @@ namespace CSVRender
removeSelectedGeometry(); removeSelectedGeometry();
mSelectedGeometry = SceneUtil::createPathgridSelectedWireframe(source, mSelected); mSelectedGeometry = SceneUtil::createPathgridSelectedWireframe(source, mSelected);
mPathgridGeode->addDrawable(mSelectedGeometry); mPathgridGroup->addChild(mSelectedGeometry);
} }
void Pathgrid::removePathgridGeometry() void Pathgrid::removePathgridGeometry()
{ {
if (mPathgridGeometry) if (mPathgridGeometry)
{ {
mPathgridGeode->removeDrawable(mPathgridGeometry); mPathgridGroup->removeChild(mPathgridGeometry);
mPathgridGeometry = nullptr; mPathgridGeometry = nullptr;
} }
} }
@ -569,7 +567,7 @@ namespace CSVRender
{ {
if (mSelectedGeometry) if (mSelectedGeometry)
{ {
mPathgridGeode->removeDrawable(mSelectedGeometry); mPathgridGroup->removeChild(mSelectedGeometry);
mSelectedGeometry = nullptr; mSelectedGeometry = nullptr;
} }
} }
@ -577,7 +575,7 @@ namespace CSVRender
void Pathgrid::createDragGeometry(const osg::Vec3f& start, const osg::Vec3f& end, bool valid) void Pathgrid::createDragGeometry(const osg::Vec3f& start, const osg::Vec3f& end, bool valid)
{ {
if (mDragGeometry) if (mDragGeometry)
mPathgridGeode->removeDrawable(mDragGeometry); mPathgridGroup->removeChild(mDragGeometry);
mDragGeometry = new osg::Geometry(); mDragGeometry = new osg::Geometry();
@ -605,7 +603,7 @@ namespace CSVRender
mDragGeometry->addPrimitiveSet(indices); mDragGeometry->addPrimitiveSet(indices);
mDragGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); mDragGeometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
mPathgridGeode->addDrawable(mDragGeometry); mPathgridGroup->addChild(mDragGeometry);
} }
const CSMWorld::Pathgrid* Pathgrid::getPathgridSource() const CSMWorld::Pathgrid* Pathgrid::getPathgridSource()

@ -15,7 +15,6 @@
namespace osg namespace osg
{ {
class Geode;
class Geometry; class Geometry;
class Group; class Group;
class PositionAttitudeTransform; class PositionAttitudeTransform;
@ -107,7 +106,7 @@ namespace CSVRender
osg::Group* mParent; osg::Group* mParent;
osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode; osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
osg::ref_ptr<osg::Geode> mPathgridGeode; osg::ref_ptr<osg::Group> mPathgridGroup;
osg::ref_ptr<osg::Geometry> mPathgridGeometry; osg::ref_ptr<osg::Geometry> mPathgridGeometry;
osg::ref_ptr<osg::Geometry> mSelectedGeometry; osg::ref_ptr<osg::Geometry> mSelectedGeometry;
osg::ref_ptr<osg::Geometry> mDragGeometry; osg::ref_ptr<osg::Geometry> mDragGeometry;

@ -284,10 +284,10 @@ class Optimizer
FlattenStaticTransformsVisitor(Optimizer* optimizer=0): FlattenStaticTransformsVisitor(Optimizer* optimizer=0):
BaseOptimizerVisitor(optimizer, FLATTEN_STATIC_TRANSFORMS) {} BaseOptimizerVisitor(optimizer, FLATTEN_STATIC_TRANSFORMS) {}
void apply(osg::Node& geode) override; void apply(osg::Node& node) override;
void apply(osg::Geometry& drawable) override; void apply(osg::Geometry& drawable) override;
void apply(osg::Drawable& drawable) override; void apply(osg::Drawable& drawable) override;
void apply(osg::Billboard& geode) override; void apply(osg::Billboard& billboard) override;
void apply(osg::Transform& transform) override final; void apply(osg::Transform& transform) override final;
void apply(osg::MatrixTransform& transform) override; void apply(osg::MatrixTransform& transform) override;

@ -65,35 +65,35 @@ osg::ref_ptr<osg::Group> CellBorder::createBorderGeometry(float x, float y, floa
border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size())); border->addPrimitiveSet(new osg::DrawArrays(GL_LINE_STRIP,0,vertices->size()));
osg::ref_ptr<osg::Group> borderGeode = new osg::Group; osg::ref_ptr<osg::Group> borderGroup = new osg::Group;
borderGeode->addChild(border.get()); borderGroup->addChild(border.get());
osg::StateSet *stateSet = borderGeode->getOrCreateStateSet(); osg::StateSet *stateSet = borderGroup->getOrCreateStateSet();
osg::ref_ptr<osg::Material> material (new osg::Material); osg::ref_ptr<osg::Material> material (new osg::Material);
material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
stateSet->setAttribute(material); stateSet->setAttribute(material);
osg::PolygonMode* polygonmode = new osg::PolygonMode; auto* polygonmode = new osg::PolygonMode;
polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE); polygonmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE);
stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON); stateSet->setAttributeAndModes(polygonmode,osg::StateAttribute::ON);
sceneManager->recreateShaders(borderGeode, "debug"); sceneManager->recreateShaders(borderGroup, "debug");
borderGeode->setNodeMask(mask); borderGroup->setNodeMask(mask);
return borderGeode; return borderGroup;
} }
void CellBorder::createCellBorderGeometry(int x, int y) void CellBorder::createCellBorderGeometry(int x, int y)
{ {
auto borderGeode = createBorderGeometry(x, y, 1.f, mWorld->getStorage(), mSceneManager, mBorderMask); auto borderGroup = createBorderGeometry(x, y, 1.f, mWorld->getStorage(), mSceneManager, mBorderMask);
mRoot->addChild(borderGeode); mRoot->addChild(borderGroup);
mCellBorderNodes[std::make_pair(x,y)] = borderGeode; mCellBorderNodes[std::make_pair(x,y)] = borderGroup;
} }
void CellBorder::destroyCellBorderGeometry(int x, int y) void CellBorder::destroyCellBorderGeometry(int x, int y)
{ {
CellGrid::iterator it = mCellBorderNodes.find(std::make_pair(x,y)); auto it = mCellBorderNodes.find(std::make_pair(x,y));
if (it == mCellBorderNodes.end()) if (it == mCellBorderNodes.end())
return; return;

Loading…
Cancel
Save