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