1
0
Fork 0

Merge branch 'next-2' into multiplayer-dev

# Conflicts:
#	src/AIModel/AIMultiplayer.cxx
#	src/MultiPlayer/multiplaymgr.cxx
This commit is contained in:
Richard Harrison 2017-02-20 03:38:51 +01:00
commit 4f04975508

View file

@ -70,16 +70,16 @@ FGODGauge::~FGODGauge()
* Used to remember the located groups that require modification * Used to remember the located groups that require modification
*/ */
typedef struct { typedef struct {
typedef osg::ref_ptr<osg::Group> GroupPtr; osg::ref_ptr<osg::Group> parent;
GroupPtr parent; osg::ref_ptr<osg::Geode> node;
GroupPtr node; unsigned int unit;
int unit;
}GroupListItem; }GroupListItem;
/** /**
* Replace a texture in the airplane model with the gauge texture. * Replace a texture in the airplane model with the gauge texture.
*/ */
class ReplaceStaticTextureVisitor: class ReplaceStaticTextureVisitor:
public osg::NodeVisitor public osg::NodeVisitor
{ {
public: public:
@ -134,10 +134,10 @@ class ReplaceStaticTextureVisitor:
virtual void apply(osg::Geode& node) virtual void apply(osg::Geode& node)
{ {
simgear::EffectGeode* eg = dynamic_cast<simgear::EffectGeode*>(&node); simgear::EffectGeode* effectGeode = dynamic_cast<simgear::EffectGeode*>(&node);
if( !eg ) if( !effectGeode )
return; return;
simgear::Effect* eff = eg->getEffect(); simgear::Effect* eff = effectGeode->getEffect();
if (!eff) if (!eff)
return; return;
osg::StateSet* ss = eff->getDefaultStateSet(); osg::StateSet* ss = eff->getDefaultStateSet();
@ -175,7 +175,7 @@ class ReplaceStaticTextureVisitor:
return; return;
} }
for( size_t unit = 0; unit < ss->getNumTextureAttributeLists(); ++unit ) for( unsigned int unit = 0; unit < ss->getNumTextureAttributeLists(); ++unit )
{ {
osg::Texture2D* tex = dynamic_cast<osg::Texture2D*> osg::Texture2D* tex = dynamic_cast<osg::Texture2D*>
( (
@ -195,41 +195,34 @@ class ReplaceStaticTextureVisitor:
/* /*
* remember this group for modification once the scenegraph has been traversed * remember this group for modification once the scenegraph has been traversed
*/ */
GroupListItem gli; groups_to_modify.push_back({ parent, &node, unit });
gli.node = eg; return;
gli.parent = parent;
gli.unit = unit;
groups_to_modify.push_back(gli);
return;
} }
} }
/* /*
* this section of code used to be in the apply method above, however to work this requires modification of the scenegraph nodes * this section of code used to be in the apply method above, however to work this requires modification of the scenegraph nodes
* that are currently iterating, so instead the apply method will locate the groups to be modified and when finished then the * that are currently iterating, so instead the apply method will locate the groups to be modified and when finished then the
* nodes can actually be modified safely. Initially found thanks to the debug RTL in MSVC2015 throwing an exception. * nodes can actually be modified safely. Initially found thanks to the debug RTL in MSVC2015 throwing an exception.
* should be called immediately after the visitor to ensure that the groups are still valid and that nothing else has modified these groups.
*/ */
void modify_groups() void modify_groups()
{ {
for (GroupList::iterator group_iterator = groups_to_modify.begin(); group_iterator != groups_to_modify.end(); group_iterator++) { for (auto g : groups_to_modify) {
GroupPtr eg = group_iterator->node; // insert a new group between the geode an it's parent which overrides
GroupPtr parent = group_iterator->parent;
int unit = group_iterator->unit;
// insert a new group between the geode an it's parent which overrides
// the texture // the texture
GroupPtr group = new osg::Group; GroupPtr group = new osg::Group;
group->setName("canvas texture group"); group->setName("canvas texture group");
group->addChild(eg); group->addChild(g.node);
parent->removeChild(eg); g.parent->removeChild(g.node);
parent->addChild(group); g.parent->addChild(group);
if (_cull_callback) if (_cull_callback)
group->setCullCallback(_cull_callback); group->setCullCallback(_cull_callback);
osg::StateSet* stateSet = group->getOrCreateStateSet(); osg::StateSet* stateSet = group->getOrCreateStateSet();
stateSet->setTextureAttribute(unit, _new_texture, stateSet->setTextureAttribute(g.unit, _new_texture,
osg::StateAttribute::OVERRIDE); osg::StateAttribute::OVERRIDE);
stateSet->setTextureMode(unit, GL_TEXTURE_2D, stateSet->setTextureMode(g.unit, GL_TEXTURE_2D,
osg::StateAttribute::ON); osg::StateAttribute::ON);
_placements.push_back(simgear::canvas::PlacementPtr( _placements.push_back(simgear::canvas::PlacementPtr(
@ -241,7 +234,7 @@ class ReplaceStaticTextureVisitor:
SG_GL, SG_GL,
SG_INFO, SG_INFO,
"Replaced texture '" << _tex_name << "'" "Replaced texture '" << _tex_name << "'"
<< " for object '" << parent->getName() << "'" << " for object '" << g.parent->getName() << "'"
<< (!_parent_name.empty() ? " with parent '" + _parent_name + "'" << (!_parent_name.empty() ? " with parent '" + _parent_name + "'"
: "") : "")
); );