1
0
Fork 0

Reset: listener cleanup

This commit is contained in:
James Turner 2013-12-04 09:11:26 +00:00
parent 8cd71ff1ef
commit 7ff9792b96
7 changed files with 77 additions and 9 deletions

View file

@ -232,6 +232,8 @@ FGGlobals::~FGGlobals()
delete locale;
locale = NULL;
cleanupListeners();
props.clear();
delete commands;
@ -525,9 +527,26 @@ FGGlobals::resetPropertyRoot()
{
delete locale;
cleanupListeners();
// we don't strictly need to clear these (they will be reset when we
// initProperties again), but trying to reduce false-positives when dumping
// ref-counts.
positionLon.clear();
positionLat.clear();
positionAlt.clear();
viewLon.clear();
viewLat.clear();
viewAlt.clear();
orientPitch.clear();
orientHeading.clear();
orientRoll.clear();
SG_LOG(SG_GENERAL, SG_INFO, "root props refcount:" << props.getNumRefs());
treeDumpRefCounts(0, props);
//BaseStackSnapshot::dumpAll(std::cout);
props = new SGPropertyNode;
initProperties();
locale = new FGLocale(props);
@ -709,4 +728,18 @@ void FGGlobals::set_chatter_queue(FGSampleQueue* queue)
_chatter_queue = queue;
}
void FGGlobals::addListenerToCleanup(SGPropertyChangeListener* l)
{
_listeners_to_cleanup.push_back(l);
}
void FGGlobals::cleanupListeners()
{
SGPropertyChangeListenerVec::iterator i = _listeners_to_cleanup.begin();
for (; i != _listeners_to_cleanup.end(); ++i) {
delete *i;
}
_listeners_to_cleanup.clear();
}
// end of globals.cxx

View file

@ -163,6 +163,12 @@ private:
void initProperties();
SGSharedPtr<FGSampleQueue> _chatter_queue;
void cleanupListeners();
typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
SGPropertyChangeListenerVec _listeners_to_cleanup;
public:
FGGlobals();
@ -346,6 +352,8 @@ public:
FGSampleQueue* get_chatter_queue() const;
void set_chatter_queue(FGSampleQueue* queue);
void addListenerToCleanup(SGPropertyChangeListener* l);
};

View file

@ -299,7 +299,9 @@ static void upper_case_property(const char *name)
else
assert(t == props::STRING);
}
p->addChangeListener(new FGMakeUpperCase);
SGPropertyChangeListener* muc = new FGMakeUpperCase;
globals->addListenerToCleanup(muc);
p->addChangeListener(muc);
}
// see http://code.google.com/p/flightgear-bugs/issues/detail?id=385

View file

@ -65,7 +65,8 @@ static bool fgSetTowerPosFromAirportID( const string& id) {
}
struct FGTowerLocationListener : SGPropertyChangeListener {
class FGTowerLocationListener : public SGPropertyChangeListener {
void valueChanged(SGPropertyNode* node) {
string id(node->getStringValue());
if (fgGetBool("/sim/tower/auto-position",true))
@ -82,7 +83,7 @@ struct FGTowerLocationListener : SGPropertyChangeListener {
}
};
struct FGClosestTowerLocationListener : SGPropertyChangeListener
class FGClosestTowerLocationListener : public SGPropertyChangeListener
{
void valueChanged(SGPropertyNode* )
{
@ -98,9 +99,14 @@ struct FGClosestTowerLocationListener : SGPropertyChangeListener
};
void initTowerLocationListener() {
SGPropertyChangeListener* tll = new FGTowerLocationListener();
globals->addListenerToCleanup(tll);
fgGetNode("/sim/tower/airport-id", true)
->addChangeListener( new FGTowerLocationListener(), true );
->addChangeListener( tll, true );
FGClosestTowerLocationListener* ntcl = new FGClosestTowerLocationListener();
globals->addListenerToCleanup(ntcl);
fgGetNode("/sim/airport/closest-airport-id", true)
->addChangeListener(ntcl , true );
fgGetNode("/sim/tower/auto-position", true)

View file

@ -286,7 +286,9 @@ void fgOSOpenWindow(bool stencil)
void fgOSResetProperties()
{
SGPropertyNode* osgLevel = fgGetNode("/sim/rendering/osg-notify-level", true);
osgLevel->addChangeListener(new NotifyLevelListener, true);
NotifyLevelListener* l = new NotifyLevelListener;
globals->addListenerToCleanup(l);
osgLevel->addChangeListener(l, true);
osg::Camera* guiCamera = getGUICamera(CameraGroup::getDefault());
if (guiCamera) {

View file

@ -430,6 +430,11 @@ FGRenderer::FGRenderer() :
FGRenderer::~FGRenderer()
{
SGPropertyChangeListenerVec::iterator i = _listeners.begin();
for (; i != _listeners.end(); ++i) {
delete *i;
}
DeletionManager::uninstall(mRealRoot.get());
#ifdef FG_JPEG_SERVER
jpgRenderFrame = NULL;
@ -498,6 +503,13 @@ public:
}
};
void
FGRenderer::addChangeListener(SGPropertyChangeListener* l, const char* path)
{
_listeners.push_back(l);
fgAddChangeListener(l, path);
}
void
FGRenderer::init( void )
{
@ -508,14 +520,14 @@ FGRenderer::init( void )
_classicalRenderer = !fgGetBool("/sim/rendering/rembrandt/enabled", false);
_shadowMapSize = fgGetInt( "/sim/rendering/shadows/map-size", 4096 );
fgAddChangeListener( new ShadowMapSizeListener, "/sim/rendering/shadows/map-size" );
fgAddChangeListener( new ShadowEnabledListener, "/sim/rendering/shadows/enabled" );
addChangeListener( new ShadowMapSizeListener, "/sim/rendering/shadows/map-size" );
addChangeListener( new ShadowEnabledListener, "/sim/rendering/shadows/enabled" );
ShadowRangeListener* srl = new ShadowRangeListener;
fgAddChangeListener(srl, "/sim/rendering/shadows/cascade-far-m[0]");
addChangeListener(srl, "/sim/rendering/shadows/cascade-far-m[0]");
fgAddChangeListener(srl, "/sim/rendering/shadows/cascade-far-m[1]");
fgAddChangeListener(srl, "/sim/rendering/shadows/cascade-far-m[2]");
fgAddChangeListener(srl, "/sim/rendering/shadows/cascade-far-m[3]");
fgAddChangeListener(new ShadowNumListener, "/sim/rendering/shadows/num-cascades");
addChangeListener(new ShadowNumListener, "/sim/rendering/shadows/num-cascades");
_numCascades = fgGetInt("/sim/rendering/shadows/num-cascades", 4);
_cascadeFar[0] = fgGetFloat("/sim/rendering/shadows/cascade-far-m[0]", 5.0f);
_cascadeFar[1] = fgGetFloat("/sim/rendering/shadows/cascade-far-m[1]", 50.0f);

View file

@ -138,6 +138,9 @@ protected:
float _cascadeFar[4];
bool _useColorForDepth;
typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
SGPropertyChangeListenerVec _listeners;
flightgear::CameraInfo* buildCameraFromRenderingPipeline(FGRenderingPipeline* rpipe, flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
const osg::Matrix& view, const osg::Matrix& projection, osg::GraphicsContext* gc);
@ -168,6 +171,8 @@ protected:
osg::ref_ptr<osg::Uniform> _depthInColor;
osg::ref_ptr<FGRenderingPipeline> _pipeline;
void addChangeListener(SGPropertyChangeListener* l, const char* path);
};
bool fgDumpSceneGraphToFile(const char* filename);