]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.cxx
Interim windows build fix
[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     // The AIModels manager performs a number of actions upon
203     // Shutdown that implicitly assume that other subsystems
204     // are still operational (Due to the dynamic allocation and
205     // deallocation of AIModel objects. To ensure we can safely
206     // shut down all subsystems, make sure we take down the
207     // AIModels system first.
208     SGSubsystemRef ai = subsystem_mgr->get_subsystem("ai-model");
209     if (ai) {
210         subsystem_mgr->remove("ai-model");
211         ai->unbind();
212         ai.clear(); // ensure AI is deleted now, not at end of this method
213     }
214
215     subsystem_mgr->shutdown();
216     subsystem_mgr->unbind();
217
218     subsystem_mgr->remove("aircraft-model");
219     subsystem_mgr->remove("model-manager");
220
221     subsystem_mgr->remove(FGTileMgr::subsystemName());
222
223     osg::ref_ptr<osgViewer::Viewer> vw(renderer->getViewer());
224     if (vw) {
225         // https://code.google.com/p/flightgear-bugs/issues/detail?id=1291
226         // explicitly stop trheading before we delete the renderer or
227         // viewMgr (which ultimately holds refs to the CameraGroup, and
228         // GraphicsContext)
229         vw->stopThreading();
230     }
231
232     // don't cancel the pager until after shutdown, since AIModels (and
233     // potentially others) can queue delete requests on the pager.
234     if (vw && vw->getDatabasePager()) {
235         vw->getDatabasePager()->cancel();
236         vw->getDatabasePager()->clear();
237     }
238
239     osgDB::Registry::instance()->clearObjectCache();
240     subsystem_mgr->remove(FGScenery::subsystemName());
241
242     // renderer touches subsystems during its destruction
243     set_renderer(NULL);
244     _chatter_queue.clear();
245
246     delete subsystem_mgr;
247     subsystem_mgr = NULL; // important so ::get_subsystem returns NULL
248     vw = 0; // don't delete the viewer until now
249
250     delete time_params;
251     set_matlib(NULL);
252
253     delete channel_options_list;
254     delete initial_waypoints;
255     delete fontcache;
256     delete channellist;
257
258     simgear::PropertyObjectBase::setDefaultRoot(NULL);
259     simgear::SGModelLib::resetPropertyRoot();
260
261     delete locale;
262     locale = NULL;
263
264     cleanupListeners();
265
266     props.clear();
267
268     delete commands;
269 }
270
271 // set the fg_root path
272 void FGGlobals::set_fg_root (const std::string &root) {
273     SGPath tmp(root);
274     fg_root = tmp.realpath();
275
276     // append /data to root if it exists
277     tmp.append( "data" );
278     tmp.append( "version" );
279     if ( tmp.exists() ) {
280         fgGetNode("BAD_FG_ROOT", true)->setStringValue(fg_root);
281         fg_root += "/data";
282         fgGetNode("GOOD_FG_ROOT", true)->setStringValue(fg_root);
283         SG_LOG(SG_GENERAL, SG_ALERT, "***\n***\n*** Warning: changing bad FG_ROOT/--fg-root to '"
284                 << fg_root << "'\n***\n***");
285     }
286
287     // deliberately not a tied property, for fgValidatePath security
288     // write-protect to avoid accidents
289     SGPropertyNode *n = fgGetNode("/sim", true);
290     n->removeChild("fg-root", 0);
291     n = n->getChild("fg-root", 0, true);
292     n->setStringValue(fg_root.c_str());
293     n->setAttribute(SGPropertyNode::WRITE, false);
294
295     simgear::ResourceManager::instance()->addBasePath(fg_root,
296       simgear::ResourceManager::PRIORITY_DEFAULT);
297 }
298
299 // set the fg_home path
300 void FGGlobals::set_fg_home (const std::string &home) {
301     SGPath tmp(home);
302     fg_home = tmp.realpath();
303 }
304
305 PathList FGGlobals::get_data_paths() const
306 {
307     PathList r(additional_data_paths);
308     r.push_back(SGPath(fg_root));
309     return r;
310 }
311
312 PathList FGGlobals::get_data_paths(const std::string& suffix) const
313 {
314     PathList r;
315     BOOST_FOREACH(SGPath p, get_data_paths()) {
316         p.append(suffix);
317         if (p.exists()) {
318             r.push_back(p);
319         }
320     }
321
322     return r;
323 }
324
325 void FGGlobals::append_data_path(const SGPath& path)
326 {
327     if (!path.exists()) {
328         SG_LOG(SG_GENERAL, SG_WARN, "adding non-existant data path:" << path);
329     }
330
331     additional_data_paths.push_back(path);
332 }
333
334 SGPath FGGlobals::find_data_dir(const std::string& pathSuffix) const
335 {
336     BOOST_FOREACH(SGPath p, additional_data_paths) {
337         p.append(pathSuffix);
338         if (p.exists()) {
339             return p;
340         }
341     }
342
343     SGPath rootPath(fg_root);
344     rootPath.append(pathSuffix);
345     if (rootPath.exists()) {
346         return rootPath;
347     }
348
349     SG_LOG(SG_GENERAL, SG_WARN, "dir not found in any data path:" << pathSuffix);
350     return SGPath();
351 }
352
353 void FGGlobals::append_fg_scenery (const std::string &paths, bool secure)
354 {
355     SGPropertyNode* sim = fgGetNode("/sim", true);
356
357   // find first unused fg-scenery property in /sim
358     int propIndex = 0;
359     while (sim->getChild("fg-scenery", propIndex) != NULL) {
360       ++propIndex;
361     }
362
363     BOOST_FOREACH(const SGPath& path, sgPathSplit( paths )) {
364         SGPath abspath(path.realpath());
365         if (!abspath.exists()) {
366           SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath.str());
367           continue;
368         }
369
370       // check for duplicates
371       string_list::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath.str());
372       if (ex != fg_scenery.end()) {
373         SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath.str());
374         continue;
375       }
376
377         simgear::Dir dir(abspath);
378         SGPath terrainDir(dir.file("Terrain"));
379         SGPath objectsDir(dir.file("Objects"));
380
381       // this code used to add *either* the base dir, OR add the
382       // Terrain and Objects subdirs, but the conditional logic was commented
383       // out, such that all three dirs are added. Unfortunately there's
384       // no information as to why the change was made.
385         fg_scenery.push_back(abspath.str());
386         if (secure) {
387           secure_fg_scenery.push_back(abspath.str());
388         }
389
390         if (terrainDir.exists()) {
391           fg_scenery.push_back(terrainDir.str());
392         }
393
394         if (objectsDir.exists()) {
395           fg_scenery.push_back(objectsDir.str());
396         }
397
398         // insert a marker for FGTileEntry::load(), so that
399         // FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
400         // "B/Terrain", "B/Objects", ""]
401         fg_scenery.push_back("");
402
403       // make scenery dirs available to Nasal
404         SGPropertyNode* n = sim->getChild("fg-scenery", propIndex++, true);
405         n->setStringValue(abspath.str());
406         n->setAttribute(SGPropertyNode::WRITE, false);
407
408         // temporary fix so these values survive reset
409         n->setAttribute(SGPropertyNode::PRESERVE, true);
410     } // of path list iteration
411 }
412
413 void FGGlobals::clear_fg_scenery()
414 {
415   fg_scenery.clear();
416   secure_fg_scenery.clear();
417   fgGetNode("/sim", true)->removeChildren("fg-scenery");
418
419 }
420
421 void FGGlobals::set_catalog_aircraft_path(const SGPath& path)
422 {
423     catalog_aircraft_dir = path;
424 }
425
426 string_list FGGlobals::get_aircraft_paths() const
427 {
428     string_list r;
429     if (!catalog_aircraft_dir.isNull()) {
430         r.push_back(catalog_aircraft_dir.str());
431     }
432
433     r.insert(r.end(), fg_aircraft_dirs.begin(), fg_aircraft_dirs.end());
434     return r;
435 }
436
437 void FGGlobals::append_aircraft_path(const std::string& path)
438 {
439   SGPath dirPath(path);
440   if (!dirPath.exists()) {
441     SG_LOG(SG_GENERAL, SG_ALERT, "aircraft path not found:" << path);
442     return;
443   }
444
445   SGPath acSubdir(dirPath);
446   acSubdir.append("Aircraft");
447   if (acSubdir.exists()) {
448       SG_LOG(
449         SG_GENERAL,
450         SG_WARN,
451         "Specified an aircraft-dir with an 'Aircraft' subdirectory:" << dirPath
452         << ", will instead use child directory:" << acSubdir
453       );
454       dirPath = acSubdir;
455   }
456
457   std::string abspath = dirPath.realpath();
458   fg_aircraft_dirs.push_back(abspath);
459 }
460
461 void FGGlobals::append_aircraft_paths(const std::string& path)
462 {
463   string_list paths = sgPathSplit(path);
464   for (unsigned int p = 0; p<paths.size(); ++p) {
465     append_aircraft_path(paths[p]);
466   }
467 }
468
469 SGPath FGGlobals::resolve_aircraft_path(const std::string& branch) const
470 {
471   return simgear::ResourceManager::instance()->findPath(branch);
472 }
473
474 SGPath FGGlobals::resolve_maybe_aircraft_path(const std::string& branch) const
475 {
476   return simgear::ResourceManager::instance()->findPath(branch);
477 }
478
479 SGPath FGGlobals::resolve_resource_path(const std::string& branch) const
480 {
481   return simgear::ResourceManager::instance()
482     ->findPath(branch, SGPath(fgGetString("/sim/aircraft-dir")));
483 }
484
485 FGRenderer *
486 FGGlobals::get_renderer () const
487 {
488    return renderer;
489 }
490
491 void FGGlobals::set_renderer(FGRenderer *render)
492 {
493     if (render == renderer) {
494         return;
495     }
496
497     delete renderer;
498     renderer = render;
499 }
500
501 SGSubsystemMgr *
502 FGGlobals::get_subsystem_mgr () const
503 {
504     return subsystem_mgr;
505 }
506
507 SGSubsystem *
508 FGGlobals::get_subsystem (const char * name) const
509 {
510     if (!subsystem_mgr) {
511         return NULL;
512     }
513
514     return subsystem_mgr->get_subsystem(name);
515 }
516
517 void
518 FGGlobals::add_subsystem (const char * name,
519                           SGSubsystem * subsystem,
520                           SGSubsystemMgr::GroupType type,
521                           double min_time_sec)
522 {
523     subsystem_mgr->add(name, subsystem, type, min_time_sec);
524 }
525
526 SGSoundMgr *
527 FGGlobals::get_soundmgr () const
528 {
529     return get_subsystem<SGSoundMgr>();
530 }
531
532 SGEventMgr *
533 FGGlobals::get_event_mgr () const
534 {
535     return event_mgr;
536 }
537
538 SGGeod
539 FGGlobals::get_aircraft_position() const
540 {
541   return SGGeod::fromDegFt(positionLon->getDoubleValue(),
542                            positionLat->getDoubleValue(),
543                            positionAlt->getDoubleValue());
544 }
545
546 SGVec3d
547 FGGlobals::get_aircraft_position_cart() const
548 {
549     return SGVec3d::fromGeod(get_aircraft_position());
550 }
551
552 void FGGlobals::get_aircraft_orientation(double& heading, double& pitch, double& roll)
553 {
554   heading = orientHeading->getDoubleValue();
555   pitch = orientPitch->getDoubleValue();
556   roll = orientRoll->getDoubleValue();
557 }
558
559 SGGeod
560 FGGlobals::get_view_position() const
561 {
562   return SGGeod::fromDegFt(viewLon->getDoubleValue(),
563                            viewLat->getDoubleValue(),
564                            viewAlt->getDoubleValue());
565 }
566
567 SGVec3d
568 FGGlobals::get_view_position_cart() const
569 {
570   return SGVec3d::fromGeod(get_view_position());
571 }
572
573 static void treeDumpRefCounts(int depth, SGPropertyNode* nd)
574 {
575     for (int i=0; i<nd->nChildren(); ++i) {
576         SGPropertyNode* cp = nd->getChild(i);
577         if (SGReferenced::count(cp) > 1) {
578             SG_LOG(SG_GENERAL, SG_INFO, "\t" << cp->getPath() << " refcount:" << SGReferenced::count(cp));
579         }
580
581         treeDumpRefCounts(depth + 1, cp);
582     }
583 }
584
585 static void treeClearAliases(SGPropertyNode* nd)
586 {
587     if (nd->isAlias()) {
588         nd->unalias();
589     }
590
591     for (int i=0; i<nd->nChildren(); ++i) {
592         SGPropertyNode* cp = nd->getChild(i);
593         treeClearAliases(cp);
594     }
595 }
596
597 void
598 FGGlobals::resetPropertyRoot()
599 {
600     delete locale;
601
602     cleanupListeners();
603
604     // we don't strictly need to clear these (they will be reset when we
605     // initProperties again), but trying to reduce false-positives when dumping
606     // ref-counts.
607     positionLon.clear();
608     positionLat.clear();
609     positionAlt.clear();
610     viewLon.clear();
611     viewLat.clear();
612     viewAlt.clear();
613     orientPitch.clear();
614     orientHeading.clear();
615     orientRoll.clear();
616
617     // clear aliases so ref-counts are accurate when dumped
618     treeClearAliases(props);
619
620     SG_LOG(SG_GENERAL, SG_INFO, "root props refcount:" << props.getNumRefs());
621     treeDumpRefCounts(0, props);
622
623     //BaseStackSnapshot::dumpAll(std::cout);
624
625     props = new SGPropertyNode;
626     initProperties();
627     locale = new FGLocale(props);
628
629     // remove /sim/fg-root before writing to prevent hijacking
630     SGPropertyNode *n = props->getNode("/sim", true);
631     n->removeChild("fg-root", 0);
632     n = n->getChild("fg-root", 0, true);
633     n->setStringValue(fg_root.c_str());
634     n->setAttribute(SGPropertyNode::WRITE, false);
635 }
636
637 static std::string autosaveName()
638 {
639     std::ostringstream os;
640     string_list versionParts = simgear::strutils::split(VERSION, ".");
641     if (versionParts.size() < 2) {
642         return "autosave.xml";
643     }
644
645     os << "autosave_" << versionParts[0] << "_" << versionParts[1] << ".xml";
646     return os.str();
647 }
648
649 // Load user settings from autosave.xml
650 void
651 FGGlobals::loadUserSettings(const SGPath& dataPath)
652 {
653     // remember that we have (tried) to load any existing autsave.xml
654     haveUserSettings = true;
655
656     SGPath autosaveFile = simgear::Dir(dataPath).file(autosaveName());
657     SGPropertyNode autosave;
658     if (autosaveFile.exists()) {
659       SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile.str());
660       try {
661           readProperties(autosaveFile.str(), &autosave, SGPropertyNode::USERARCHIVE);
662       } catch (sg_exception& e) {
663           SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
664             << "(from " << e.getOrigin() << ")");
665       }
666     }
667     copyProperties(&autosave, globals->get_props());
668 }
669
670 // Save user settings in autosave.xml
671 void
672 FGGlobals::saveUserSettings()
673 {
674     // only save settings when we have (tried) to load the previous
675     // settings (otherwise user data was lost)
676     if (!haveUserSettings)
677         return;
678
679     if (fgGetBool("/sim/startup/save-on-exit")) {
680       // don't save settings more than once on shutdown
681       haveUserSettings = false;
682
683       SGPath autosaveFile(globals->get_fg_home());
684       autosaveFile.append(autosaveName());
685       autosaveFile.create_dir( 0700 );
686       SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
687       try {
688         writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
689       } catch (const sg_exception &e) {
690         guiErrorMessage("Error writing autosave:", e);
691       }
692       SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
693     }
694 }
695
696 long int FGGlobals::get_warp() const
697 {
698   return fgGetInt("/sim/time/warp");
699 }
700
701 void FGGlobals::set_warp( long int w )
702 {
703   fgSetInt("/sim/time/warp", w);
704 }
705
706 long int FGGlobals::get_warp_delta() const
707 {
708   return fgGetInt("/sim/time/warp-delta");
709 }
710
711 void FGGlobals::set_warp_delta( long int d )
712 {
713   fgSetInt("/sim/time/warp-delta", d);
714 }
715
716 FGScenery* FGGlobals::get_scenery () const
717 {
718     return get_subsystem<FGScenery>();
719 }
720
721 FGTileMgr* FGGlobals::get_tile_mgr () const
722 {
723     return get_subsystem<FGTileMgr>();
724 }
725
726 FGViewMgr *FGGlobals::get_viewmgr() const
727 {
728     return get_subsystem<FGViewMgr>();
729 }
730
731 FGViewer* FGGlobals::get_current_view () const
732 {
733     FGViewMgr* vm = get_viewmgr();
734     return vm ? vm->get_current_view() : 0;
735 }
736
737 void FGGlobals::set_matlib( SGMaterialLib *m )
738 {
739     matlib = m;
740 }
741
742 FGControls *FGGlobals::get_controls() const
743 {
744     return get_subsystem<FGControls>();
745 }
746
747 FGSampleQueue* FGGlobals::get_chatter_queue() const
748 {
749     return _chatter_queue;
750 }
751
752 void FGGlobals::set_chatter_queue(FGSampleQueue* queue)
753 {
754     _chatter_queue = queue;
755 }
756
757 void FGGlobals::addListenerToCleanup(SGPropertyChangeListener* l)
758 {
759     _listeners_to_cleanup.push_back(l);
760 }
761
762 void FGGlobals::cleanupListeners()
763 {
764     SGPropertyChangeListenerVec::iterator i = _listeners_to_cleanup.begin();
765     for (; i != _listeners_to_cleanup.end(); ++i) {
766         delete *i;
767     }
768     _listeners_to_cleanup.clear();
769 }
770
771 simgear::pkg::Root* FGGlobals::packageRoot()
772 {
773   return _packageRoot.get();
774 }
775
776 void FGGlobals::setPackageRoot(const SGSharedPtr<simgear::pkg::Root>& p)
777 {
778   _packageRoot = p;
779 }
780
781 // end of globals.cxx