]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.cxx
AI subsystem now does an orderly shutdown
[flightgear.git] / src / Main / globals.cxx
1 // globals.cxx -- Global state that needs to be shared among the sim modules
2 //
3 // Written by Curtis Olson, started July 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson - http://www.flightgear.org/~curt
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 // $Id$
22
23 #ifdef HAVE_CONFIG_H
24 #  include <config.h>
25 #endif
26
27 #include <boost/foreach.hpp>
28 #include <algorithm>
29
30 #include <osgViewer/Viewer>
31 #include <osgDB/Registry>
32
33 #include <simgear/structure/commands.hxx>
34 #include <simgear/misc/sg_path.hxx>
35 #include <simgear/misc/sg_dir.hxx>
36 #include <simgear/timing/sg_time.hxx>
37 #include <simgear/ephemeris/ephemeris.hxx>
38 #include <simgear/scene/material/matlib.hxx>
39 #include <simgear/structure/subsystem_mgr.hxx>
40 #include <simgear/structure/event_mgr.hxx>
41 #include <simgear/sound/soundmgr_openal.hxx>
42 #include <simgear/misc/ResourceManager.hxx>
43 #include <simgear/props/propertyObject.hxx>
44 #include <simgear/props/props_io.hxx>
45 #include <simgear/scene/model/modellib.hxx>
46 #include <simgear/package/Root.hxx>
47
48 #include <Aircraft/controls.hxx>
49 #include <Airports/runways.hxx>
50 #include <Autopilot/route_mgr.hxx>
51 #include <GUI/FGFontCache.hxx>
52 #include <GUI/gui.h>
53 #include <Scenery/scenery.hxx>
54 #include <Scenery/tilemgr.hxx>
55 #include <Navaids/navlist.hxx>
56 #include <Viewer/renderer.hxx>
57 #include <Viewer/viewmgr.hxx>
58 #include <Sound/sample_queue.hxx>
59
60 #include "globals.hxx"
61 #include "locale.hxx"
62
63 #include "fg_props.hxx"
64 #include "fg_io.hxx"
65
66 class AircraftResourceProvider : public simgear::ResourceProvider
67 {
68 public:
69   AircraftResourceProvider() :
70     simgear::ResourceProvider(simgear::ResourceManager::PRIORITY_HIGH)
71   {
72   }
73
74   virtual SGPath resolve(const std::string& aResource, SGPath&) const
75   {
76     string_list pieces(sgPathBranchSplit(aResource));
77     if ((pieces.size() < 3) || (pieces.front() != "Aircraft")) {
78       return SGPath(); // not an Aircraft path
79     }
80
81   // test against the aircraft-dir property
82     const char* aircraftDir = fgGetString("/sim/aircraft-dir");
83     string_list aircraftDirPieces(sgPathBranchSplit(aircraftDir));
84     if (!aircraftDirPieces.empty() && (aircraftDirPieces.back() == pieces[1])) {
85         // disable this warning for release builds
86 #if defined(ENABLE_DEV_WARNINGS)
87         SGPath betterPath;
88         for (unsigned int i=2; i<pieces.size(); ++i) {
89             betterPath.append(pieces[i]);
90         }
91         SG_LOG(SG_AIRCRAFT, SG_WARN, "resolved path:" << aResource << " using /sim/aircraft-dir.\n"
92                "This is legacy behaviour, change to an aircraft relative path:" << betterPath);
93 #endif
94
95         // current aircraft-dir matches resource aircraft
96         SGPath r(aircraftDir);
97         for (unsigned int i=2; i<pieces.size(); ++i) {
98           r.append(pieces[i]);
99         }
100
101         if (r.exists()) {
102           return r;
103         } else {
104           // Stop here, otherwise we could end up returning a resource that
105           // belongs to an unrelated version of the same aircraft (from a
106           // different aircraft directory).
107           return SGPath();
108         }
109     }
110
111   // try each aircraft dir in turn
112     std::string res(aResource, 9); // resource path with 'Aircraft/' removed
113     const string_list& dirs(globals->get_aircraft_paths());
114     string_list::const_iterator it = dirs.begin();
115     for (; it != dirs.end(); ++it) {
116       SGPath p(*it, res);
117       if (p.exists()) {
118         return p;
119       }
120     } // of aircraft path iteration
121
122     return SGPath(); // not found
123   }
124 };
125
126 class CurrentAircraftDirProvider : public simgear::ResourceProvider
127 {
128 public:
129   CurrentAircraftDirProvider() :
130     simgear::ResourceProvider(simgear::ResourceManager::PRIORITY_HIGH)
131   {
132   }
133
134   virtual SGPath resolve(const std::string& aResource, SGPath&) const
135   {
136     const char* aircraftDir = fgGetString("/sim/aircraft-dir");
137     SGPath p(aircraftDir);
138     p.append(aResource);
139     return p.exists() ? p : SGPath();
140   }
141 };
142
143 ////////////////////////////////////////////////////////////////////////
144 // Implementation of FGGlobals.
145 ////////////////////////////////////////////////////////////////////////
146
147 // global global :-)
148 FGGlobals *globals = NULL;
149
150
151 // Constructor
152 FGGlobals::FGGlobals() :
153     renderer( new FGRenderer ),
154     subsystem_mgr( new SGSubsystemMgr ),
155     event_mgr( new SGEventMgr ),
156     sim_time_sec( 0.0 ),
157     fg_root( "" ),
158     fg_home( "" ),
159     time_params( NULL ),
160     ephem( NULL ),
161     commands( SGCommandMgr::instance() ),
162     channel_options_list( NULL ),
163     initial_waypoints( NULL ),
164     fontcache ( new FGFontCache ),
165     channellist( NULL ),
166     haveUserSettings(false),
167     _chatter_queue(NULL)
168 {
169     SGPropertyNode* root = new SGPropertyNode;
170     props = SGPropertyNode_ptr(root);
171     locale = new FGLocale(props);
172
173     simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider);
174     simgear::ResourceManager::instance()->addProvider(new CurrentAircraftDirProvider);
175     initProperties();
176 }
177
178 void FGGlobals::initProperties()
179 {
180     simgear::PropertyObjectBase::setDefaultRoot(props);
181
182     positionLon = props->getNode("position/longitude-deg", true);
183     positionLat = props->getNode("position/latitude-deg", true);
184     positionAlt = props->getNode("position/altitude-ft", true);
185
186     viewLon = props->getNode("sim/current-view/viewer-lon-deg", true);
187     viewLat = props->getNode("sim/current-view/viewer-lat-deg", true);
188     viewAlt = props->getNode("sim/current-view/viewer-elev-ft", true);
189
190     orientPitch = props->getNode("orientation/pitch-deg", true);
191     orientHeading = props->getNode("orientation/heading-deg", true);
192     orientRoll = props->getNode("orientation/roll-deg", true);
193
194 }
195
196 // Destructor
197 FGGlobals::~FGGlobals()
198 {
199     // save user settings (unless already saved)
200     saveUserSettings();
201
202     // stop OSG threading first, to avoid thread races while we tear down
203     // scene-graph pieces
204
205     osg::ref_ptr<osgViewer::Viewer> vw(renderer->getViewer());
206     if (vw) {
207         // https://code.google.com/p/flightgear-bugs/issues/detail?id=1291
208         // explicitly stop trheading before we delete the renderer or
209         // viewMgr (which ultimately holds refs to the CameraGroup, and
210         // GraphicsContext)
211         vw->stopThreading();
212     }
213
214     subsystem_mgr->shutdown();
215     subsystem_mgr->unbind();
216
217     subsystem_mgr->remove(FGTileMgr::subsystemName());
218     // don't cancel the pager until after shutdown, since AIModels (and
219     // potentially others) can queue delete requests on the pager.
220     if (vw && vw->getDatabasePager()) {
221         vw->getDatabasePager()->cancel();
222         vw->getDatabasePager()->clear();
223     }
224
225     osgDB::Registry::instance()->clearObjectCache();
226     subsystem_mgr->remove(FGScenery::subsystemName());
227
228     // renderer touches subsystems during its destruction
229     set_renderer(NULL);
230     _chatter_queue.clear();
231
232     delete subsystem_mgr;
233     subsystem_mgr = NULL; // important so ::get_subsystem returns NULL
234     vw = 0; // don't delete the viewer until now
235
236     delete time_params;
237     set_matlib(NULL);
238
239     delete channel_options_list;
240     delete initial_waypoints;
241     delete fontcache;
242     delete channellist;
243
244     simgear::PropertyObjectBase::setDefaultRoot(NULL);
245     simgear::SGModelLib::resetPropertyRoot();
246
247     delete locale;
248     locale = NULL;
249
250     cleanupListeners();
251
252     props.clear();
253
254     delete commands;
255 }
256
257 // set the fg_root path
258 void FGGlobals::set_fg_root (const std::string &root) {
259     SGPath tmp(root);
260     fg_root = tmp.realpath();
261
262     // append /data to root if it exists
263     tmp.append( "data" );
264     tmp.append( "version" );
265     if ( tmp.exists() ) {
266         fgGetNode("BAD_FG_ROOT", true)->setStringValue(fg_root);
267         fg_root += "/data";
268         fgGetNode("GOOD_FG_ROOT", true)->setStringValue(fg_root);
269         SG_LOG(SG_GENERAL, SG_ALERT, "***\n***\n*** Warning: changing bad FG_ROOT/--fg-root to '"
270                 << fg_root << "'\n***\n***");
271     }
272
273     // deliberately not a tied property, for fgValidatePath security
274     // write-protect to avoid accidents
275     SGPropertyNode *n = fgGetNode("/sim", true);
276     n->removeChild("fg-root", 0);
277     n = n->getChild("fg-root", 0, true);
278     n->setStringValue(fg_root.c_str());
279     n->setAttribute(SGPropertyNode::WRITE, false);
280
281     simgear::ResourceManager::instance()->addBasePath(fg_root,
282       simgear::ResourceManager::PRIORITY_DEFAULT);
283 }
284
285 // set the fg_home path
286 void FGGlobals::set_fg_home (const std::string &home) {
287     SGPath tmp(home);
288     fg_home = tmp.realpath();
289 }
290
291 PathList FGGlobals::get_data_paths() const
292 {
293     PathList r(additional_data_paths);
294     r.push_back(SGPath(fg_root));
295     return r;
296 }
297
298 PathList FGGlobals::get_data_paths(const std::string& suffix) const
299 {
300     PathList r;
301     BOOST_FOREACH(SGPath p, get_data_paths()) {
302         p.append(suffix);
303         if (p.exists()) {
304             r.push_back(p);
305         }
306     }
307
308     return r;
309 }
310
311 void FGGlobals::append_data_path(const SGPath& path)
312 {
313     if (!path.exists()) {
314         SG_LOG(SG_GENERAL, SG_WARN, "adding non-existant data path:" << path);
315     }
316
317     additional_data_paths.push_back(path);
318 }
319
320 SGPath FGGlobals::find_data_dir(const std::string& pathSuffix) const
321 {
322     BOOST_FOREACH(SGPath p, additional_data_paths) {
323         p.append(pathSuffix);
324         if (p.exists()) {
325             return p;
326         }
327     }
328
329     SGPath rootPath(fg_root);
330     rootPath.append(pathSuffix);
331     if (rootPath.exists()) {
332         return rootPath;
333     }
334
335     SG_LOG(SG_GENERAL, SG_WARN, "dir not found in any data path:" << pathSuffix);
336     return SGPath();
337 }
338
339 void FGGlobals::append_fg_scenery (const std::string &paths, bool secure)
340 {
341     SGPropertyNode* sim = fgGetNode("/sim", true);
342
343   // find first unused fg-scenery property in /sim
344     int propIndex = 0;
345     while (sim->getChild("fg-scenery", propIndex) != NULL) {
346       ++propIndex;
347     }
348
349     BOOST_FOREACH(const SGPath& path, sgPathSplit( paths )) {
350         SGPath abspath(path.realpath());
351         if (!abspath.exists()) {
352           SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath.str());
353           continue;
354         }
355
356       // check for duplicates
357       string_list::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath.str());
358       if (ex != fg_scenery.end()) {
359         SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath.str());
360         continue;
361       }
362
363         simgear::Dir dir(abspath);
364         SGPath terrainDir(dir.file("Terrain"));
365         SGPath objectsDir(dir.file("Objects"));
366
367       // this code used to add *either* the base dir, OR add the
368       // Terrain and Objects subdirs, but the conditional logic was commented
369       // out, such that all three dirs are added. Unfortunately there's
370       // no information as to why the change was made.
371         fg_scenery.push_back(abspath.str());
372         if (secure) {
373           secure_fg_scenery.push_back(abspath.str());
374         }
375
376         if (terrainDir.exists()) {
377           fg_scenery.push_back(terrainDir.str());
378         }
379
380         if (objectsDir.exists()) {
381           fg_scenery.push_back(objectsDir.str());
382         }
383
384         // insert a marker for FGTileEntry::load(), so that
385         // FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
386         // "B/Terrain", "B/Objects", ""]
387         fg_scenery.push_back("");
388
389       // make scenery dirs available to Nasal
390         SGPropertyNode* n = sim->getChild("fg-scenery", propIndex++, true);
391         n->setStringValue(abspath.str());
392         n->setAttribute(SGPropertyNode::WRITE, false);
393
394         // temporary fix so these values survive reset
395         n->setAttribute(SGPropertyNode::PRESERVE, true);
396     } // of path list iteration
397 }
398
399 void FGGlobals::clear_fg_scenery()
400 {
401   fg_scenery.clear();
402   secure_fg_scenery.clear();
403   fgGetNode("/sim", true)->removeChildren("fg-scenery");
404
405 }
406
407 void FGGlobals::set_catalog_aircraft_path(const SGPath& path)
408 {
409     catalog_aircraft_dir = path;
410 }
411
412 string_list FGGlobals::get_aircraft_paths() const
413 {
414     string_list r;
415     if (!catalog_aircraft_dir.isNull()) {
416         r.push_back(catalog_aircraft_dir.str());
417     }
418
419     r.insert(r.end(), fg_aircraft_dirs.begin(), fg_aircraft_dirs.end());
420     return r;
421 }
422
423 void FGGlobals::append_aircraft_path(const std::string& path)
424 {
425   SGPath dirPath(path);
426   if (!dirPath.exists()) {
427     SG_LOG(SG_GENERAL, SG_ALERT, "aircraft path not found:" << path);
428     return;
429   }
430
431   SGPath acSubdir(dirPath);
432   acSubdir.append("Aircraft");
433   if (acSubdir.exists()) {
434       SG_LOG(
435         SG_GENERAL,
436         SG_WARN,
437         "Specified an aircraft-dir with an 'Aircraft' subdirectory:" << dirPath
438         << ", will instead use child directory:" << acSubdir
439       );
440       dirPath = acSubdir;
441   }
442
443   std::string abspath = dirPath.realpath();
444   fg_aircraft_dirs.push_back(abspath);
445 }
446
447 void FGGlobals::append_aircraft_paths(const std::string& path)
448 {
449   string_list paths = sgPathSplit(path);
450   for (unsigned int p = 0; p<paths.size(); ++p) {
451     append_aircraft_path(paths[p]);
452   }
453 }
454
455 SGPath FGGlobals::resolve_aircraft_path(const std::string& branch) const
456 {
457   return simgear::ResourceManager::instance()->findPath(branch);
458 }
459
460 SGPath FGGlobals::resolve_maybe_aircraft_path(const std::string& branch) const
461 {
462   return simgear::ResourceManager::instance()->findPath(branch);
463 }
464
465 SGPath FGGlobals::resolve_resource_path(const std::string& branch) const
466 {
467   return simgear::ResourceManager::instance()
468     ->findPath(branch, SGPath(fgGetString("/sim/aircraft-dir")));
469 }
470
471 FGRenderer *
472 FGGlobals::get_renderer () const
473 {
474    return renderer;
475 }
476
477 void FGGlobals::set_renderer(FGRenderer *render)
478 {
479     if (render == renderer) {
480         return;
481     }
482
483     delete renderer;
484     renderer = render;
485 }
486
487 SGSubsystemMgr *
488 FGGlobals::get_subsystem_mgr () const
489 {
490     return subsystem_mgr;
491 }
492
493 SGSubsystem *
494 FGGlobals::get_subsystem (const char * name) const
495 {
496     if (!subsystem_mgr) {
497         return NULL;
498     }
499
500     return subsystem_mgr->get_subsystem(name);
501 }
502
503 void
504 FGGlobals::add_subsystem (const char * name,
505                           SGSubsystem * subsystem,
506                           SGSubsystemMgr::GroupType type,
507                           double min_time_sec)
508 {
509     subsystem_mgr->add(name, subsystem, type, min_time_sec);
510 }
511
512 SGSoundMgr *
513 FGGlobals::get_soundmgr () const
514 {
515     return get_subsystem<SGSoundMgr>();
516 }
517
518 SGEventMgr *
519 FGGlobals::get_event_mgr () const
520 {
521     return event_mgr;
522 }
523
524 SGGeod
525 FGGlobals::get_aircraft_position() const
526 {
527   return SGGeod::fromDegFt(positionLon->getDoubleValue(),
528                            positionLat->getDoubleValue(),
529                            positionAlt->getDoubleValue());
530 }
531
532 SGVec3d
533 FGGlobals::get_aircraft_position_cart() const
534 {
535     return SGVec3d::fromGeod(get_aircraft_position());
536 }
537
538 void FGGlobals::get_aircraft_orientation(double& heading, double& pitch, double& roll)
539 {
540   heading = orientHeading->getDoubleValue();
541   pitch = orientPitch->getDoubleValue();
542   roll = orientRoll->getDoubleValue();
543 }
544
545 SGGeod
546 FGGlobals::get_view_position() const
547 {
548   return SGGeod::fromDegFt(viewLon->getDoubleValue(),
549                            viewLat->getDoubleValue(),
550                            viewAlt->getDoubleValue());
551 }
552
553 SGVec3d
554 FGGlobals::get_view_position_cart() const
555 {
556   return SGVec3d::fromGeod(get_view_position());
557 }
558
559 static void treeDumpRefCounts(int depth, SGPropertyNode* nd)
560 {
561     for (int i=0; i<nd->nChildren(); ++i) {
562         SGPropertyNode* cp = nd->getChild(i);
563         if (SGReferenced::count(cp) > 1) {
564             SG_LOG(SG_GENERAL, SG_INFO, "\t" << cp->getPath() << " refcount:" << SGReferenced::count(cp));
565         }
566
567         treeDumpRefCounts(depth + 1, cp);
568     }
569 }
570
571 static void treeClearAliases(SGPropertyNode* nd)
572 {
573     if (nd->isAlias()) {
574         nd->unalias();
575     }
576
577     for (int i=0; i<nd->nChildren(); ++i) {
578         SGPropertyNode* cp = nd->getChild(i);
579         treeClearAliases(cp);
580     }
581 }
582
583 void
584 FGGlobals::resetPropertyRoot()
585 {
586     delete locale;
587
588     cleanupListeners();
589
590     // we don't strictly need to clear these (they will be reset when we
591     // initProperties again), but trying to reduce false-positives when dumping
592     // ref-counts.
593     positionLon.clear();
594     positionLat.clear();
595     positionAlt.clear();
596     viewLon.clear();
597     viewLat.clear();
598     viewAlt.clear();
599     orientPitch.clear();
600     orientHeading.clear();
601     orientRoll.clear();
602
603     // clear aliases so ref-counts are accurate when dumped
604     treeClearAliases(props);
605
606     SG_LOG(SG_GENERAL, SG_INFO, "root props refcount:" << props.getNumRefs());
607     treeDumpRefCounts(0, props);
608
609     //BaseStackSnapshot::dumpAll(std::cout);
610
611     props = new SGPropertyNode;
612     initProperties();
613     locale = new FGLocale(props);
614
615     // remove /sim/fg-root before writing to prevent hijacking
616     SGPropertyNode *n = props->getNode("/sim", true);
617     n->removeChild("fg-root", 0);
618     n = n->getChild("fg-root", 0, true);
619     n->setStringValue(fg_root.c_str());
620     n->setAttribute(SGPropertyNode::WRITE, false);
621 }
622
623 static std::string autosaveName()
624 {
625     std::ostringstream os;
626     string_list versionParts = simgear::strutils::split(VERSION, ".");
627     if (versionParts.size() < 2) {
628         return "autosave.xml";
629     }
630
631     os << "autosave_" << versionParts[0] << "_" << versionParts[1] << ".xml";
632     return os.str();
633 }
634
635 // Load user settings from autosave.xml
636 void
637 FGGlobals::loadUserSettings(const SGPath& dataPath)
638 {
639     // remember that we have (tried) to load any existing autsave.xml
640     haveUserSettings = true;
641
642     SGPath autosaveFile = simgear::Dir(dataPath).file(autosaveName());
643     SGPropertyNode autosave;
644     if (autosaveFile.exists()) {
645       SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile.str());
646       try {
647           readProperties(autosaveFile.str(), &autosave, SGPropertyNode::USERARCHIVE);
648       } catch (sg_exception& e) {
649           SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
650             << "(from " << e.getOrigin() << ")");
651       }
652     }
653     copyProperties(&autosave, globals->get_props());
654 }
655
656 // Save user settings in autosave.xml
657 void
658 FGGlobals::saveUserSettings()
659 {
660     // only save settings when we have (tried) to load the previous
661     // settings (otherwise user data was lost)
662     if (!haveUserSettings)
663         return;
664
665     if (fgGetBool("/sim/startup/save-on-exit")) {
666       // don't save settings more than once on shutdown
667       haveUserSettings = false;
668
669       SGPath autosaveFile(globals->get_fg_home());
670       autosaveFile.append(autosaveName());
671       autosaveFile.create_dir( 0700 );
672       SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
673       try {
674         writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
675       } catch (const sg_exception &e) {
676         guiErrorMessage("Error writing autosave:", e);
677       }
678       SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
679     }
680 }
681
682 long int FGGlobals::get_warp() const
683 {
684   return fgGetInt("/sim/time/warp");
685 }
686
687 void FGGlobals::set_warp( long int w )
688 {
689   fgSetInt("/sim/time/warp", w);
690 }
691
692 long int FGGlobals::get_warp_delta() const
693 {
694   return fgGetInt("/sim/time/warp-delta");
695 }
696
697 void FGGlobals::set_warp_delta( long int d )
698 {
699   fgSetInt("/sim/time/warp-delta", d);
700 }
701
702 FGScenery* FGGlobals::get_scenery () const
703 {
704     return get_subsystem<FGScenery>();
705 }
706
707 FGTileMgr* FGGlobals::get_tile_mgr () const
708 {
709     return get_subsystem<FGTileMgr>();
710 }
711
712 FGViewMgr *FGGlobals::get_viewmgr() const
713 {
714     return get_subsystem<FGViewMgr>();
715 }
716
717 FGViewer* FGGlobals::get_current_view () const
718 {
719     FGViewMgr* vm = get_viewmgr();
720     return vm ? vm->get_current_view() : 0;
721 }
722
723 void FGGlobals::set_matlib( SGMaterialLib *m )
724 {
725     matlib = m;
726 }
727
728 FGControls *FGGlobals::get_controls() const
729 {
730     return get_subsystem<FGControls>();
731 }
732
733 FGSampleQueue* FGGlobals::get_chatter_queue() const
734 {
735     return _chatter_queue;
736 }
737
738 void FGGlobals::set_chatter_queue(FGSampleQueue* queue)
739 {
740     _chatter_queue = queue;
741 }
742
743 void FGGlobals::addListenerToCleanup(SGPropertyChangeListener* l)
744 {
745     _listeners_to_cleanup.push_back(l);
746 }
747
748 void FGGlobals::cleanupListeners()
749 {
750     SGPropertyChangeListenerVec::iterator i = _listeners_to_cleanup.begin();
751     for (; i != _listeners_to_cleanup.end(); ++i) {
752         delete *i;
753     }
754     _listeners_to_cleanup.clear();
755 }
756
757 simgear::pkg::Root* FGGlobals::packageRoot()
758 {
759   return _packageRoot.get();
760 }
761
762 void FGGlobals::setPackageRoot(const SGSharedPtr<simgear::pkg::Root>& p)
763 {
764   _packageRoot = p;
765 }
766
767 // end of globals.cxx