2000-07-07 17:27:53 +00:00
|
|
|
// globals.cxx -- Global state that needs to be shared among the sim modules
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started July 2000.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
|
2000-07-07 17:27:53 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2009-10-24 08:31:37 +00:00
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-07-07 17:27:53 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
2005-10-22 11:22:05 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2000-07-07 17:27:53 +00:00
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
#include <simgear/structure/commands.hxx>
|
2003-04-24 02:18:12 +00:00
|
|
|
#include <simgear/misc/sg_path.hxx>
|
2010-07-05 07:31:09 +00:00
|
|
|
#include <simgear/misc/sg_dir.hxx>
|
2007-10-20 08:36:21 +00:00
|
|
|
#include <simgear/timing/sg_time.hxx>
|
|
|
|
#include <simgear/ephemeris/ephemeris.hxx>
|
|
|
|
#include <simgear/magvar/magvar.hxx>
|
|
|
|
#include <simgear/scene/material/matlib.hxx>
|
2008-07-31 12:04:32 +00:00
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
|
|
|
#include <simgear/structure/event_mgr.hxx>
|
2009-10-24 08:31:37 +00:00
|
|
|
#include <simgear/sound/soundmgr_openal.hxx>
|
2010-09-06 08:13:10 +00:00
|
|
|
#include <simgear/misc/ResourceManager.hxx>
|
2010-12-02 20:29:28 +00:00
|
|
|
#include <simgear/props/propertyObject.hxx>
|
2011-07-30 09:47:28 +00:00
|
|
|
#include <simgear/props/props_io.hxx>
|
2011-08-20 06:54:47 +00:00
|
|
|
#include <simgear/scene/model/placement.hxx>
|
2002-03-16 00:18:38 +00:00
|
|
|
|
2007-10-20 08:36:21 +00:00
|
|
|
#include <Aircraft/controls.hxx>
|
|
|
|
#include <Airports/runways.hxx>
|
2008-05-12 10:38:04 +00:00
|
|
|
#include <ATCDCL/ATCmgr.hxx>
|
2007-10-20 08:36:21 +00:00
|
|
|
#include <Autopilot/route_mgr.hxx>
|
|
|
|
#include <Cockpit/panel.hxx>
|
2011-11-19 20:25:51 +00:00
|
|
|
#include <GUI/FGFontCache.hxx>
|
2011-12-29 23:39:08 +00:00
|
|
|
#include <GUI/gui.h>
|
2007-10-20 08:36:21 +00:00
|
|
|
#include <Model/acmodel.hxx>
|
|
|
|
#include <Model/modelmgr.hxx>
|
|
|
|
#include <MultiPlayer/multiplaymgr.hxx>
|
|
|
|
#include <Scenery/scenery.hxx>
|
|
|
|
#include <Scenery/tilemgr.hxx>
|
2008-12-09 14:34:30 +00:00
|
|
|
#include <Navaids/navlist.hxx>
|
2006-06-05 20:21:45 +00:00
|
|
|
|
2000-07-07 17:27:53 +00:00
|
|
|
#include "globals.hxx"
|
2005-02-25 19:41:53 +00:00
|
|
|
#include "renderer.hxx"
|
2002-04-05 18:46:47 +00:00
|
|
|
#include "viewmgr.hxx"
|
|
|
|
|
2001-01-12 15:37:40 +00:00
|
|
|
#include "fg_props.hxx"
|
2002-08-25 20:56:16 +00:00
|
|
|
#include "fg_io.hxx"
|
2000-07-07 17:27:53 +00:00
|
|
|
|
2010-11-14 20:06:19 +00:00
|
|
|
class AircraftResourceProvider : public simgear::ResourceProvider
|
2010-09-06 08:13:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
AircraftResourceProvider() :
|
|
|
|
simgear::ResourceProvider(simgear::ResourceManager::PRIORITY_HIGH)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual SGPath resolve(const std::string& aResource, SGPath&) const
|
|
|
|
{
|
|
|
|
string_list pieces(sgPathBranchSplit(aResource));
|
|
|
|
if ((pieces.size() < 3) || (pieces.front() != "Aircraft")) {
|
|
|
|
return SGPath(); // not an Aircraft path
|
|
|
|
}
|
|
|
|
|
2010-09-08 10:01:26 +00:00
|
|
|
// test against the aircraft-dir property
|
2010-09-06 08:13:10 +00:00
|
|
|
const char* aircraftDir = fgGetString("/sim/aircraft-dir");
|
|
|
|
string_list aircraftDirPieces(sgPathBranchSplit(aircraftDir));
|
2010-11-14 20:06:19 +00:00
|
|
|
if (!aircraftDirPieces.empty() && (aircraftDirPieces.back() == pieces[1])) {
|
|
|
|
// current aircraft-dir matches resource aircraft
|
|
|
|
SGPath r(aircraftDir);
|
|
|
|
for (unsigned int i=2; i<pieces.size(); ++i) {
|
|
|
|
r.append(pieces[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r.exists()) {
|
2010-12-30 09:38:21 +00:00
|
|
|
SG_LOG(SG_IO, SG_DEBUG, "found path:" << aResource << " via /sim/aircraft-dir: " << r.str());
|
2010-11-14 20:06:19 +00:00
|
|
|
return r;
|
|
|
|
}
|
2010-09-08 10:01:26 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 20:06:19 +00:00
|
|
|
// try each aircraft dir in turn
|
2010-09-08 10:01:26 +00:00
|
|
|
std::string res(aResource, 9); // resource path with 'Aircraft/' removed
|
|
|
|
const string_list& dirs(globals->get_aircraft_paths());
|
|
|
|
string_list::const_iterator it = dirs.begin();
|
|
|
|
for (; it != dirs.end(); ++it) {
|
|
|
|
SGPath p(*it, res);
|
|
|
|
if (p.exists()) {
|
2010-12-30 09:38:21 +00:00
|
|
|
SG_LOG(SG_IO, SG_DEBUG, "found path:" << aResource << " in aircraft dir: " << *it);
|
2010-09-08 10:01:26 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
} // of aircraft path iteration
|
|
|
|
|
|
|
|
return SGPath(); // not found
|
2010-09-06 08:13:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-01-19 22:57:24 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Implementation of FGGlobals.
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2000-07-07 17:27:53 +00:00
|
|
|
// global global :-)
|
|
|
|
FGGlobals *globals;
|
|
|
|
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
FGGlobals::FGGlobals() :
|
2009-08-24 16:03:49 +00:00
|
|
|
props( new SGPropertyNode ),
|
|
|
|
initial_state( NULL ),
|
|
|
|
locale( NULL ),
|
2004-09-20 13:21:51 +00:00
|
|
|
renderer( new FGRenderer ),
|
2003-09-24 17:20:55 +00:00
|
|
|
subsystem_mgr( new SGSubsystemMgr ),
|
|
|
|
event_mgr( new SGEventMgr ),
|
2002-12-11 21:07:30 +00:00
|
|
|
sim_time_sec( 0.0 ),
|
|
|
|
fg_root( "" ),
|
|
|
|
time_params( NULL ),
|
|
|
|
ephem( NULL ),
|
|
|
|
mag( NULL ),
|
2007-12-10 19:17:57 +00:00
|
|
|
matlib( NULL ),
|
2004-01-31 19:47:45 +00:00
|
|
|
route_mgr( NULL ),
|
2003-03-31 08:25:00 +00:00
|
|
|
current_panel( NULL ),
|
2002-12-11 21:07:30 +00:00
|
|
|
ATC_mgr( NULL ),
|
|
|
|
controls( NULL ),
|
|
|
|
viewmgr( NULL ),
|
2007-01-04 12:48:21 +00:00
|
|
|
commands( SGCommandMgr::instance() ),
|
2002-12-11 21:07:30 +00:00
|
|
|
acmodel( NULL ),
|
|
|
|
model_mgr( NULL ),
|
|
|
|
channel_options_list( NULL ),
|
2004-06-14 18:47:21 +00:00
|
|
|
initial_waypoints( NULL ),
|
2002-12-11 21:07:30 +00:00
|
|
|
scenery( NULL ),
|
|
|
|
tile_mgr( NULL ),
|
2006-06-05 20:21:45 +00:00
|
|
|
fontcache ( new FGFontCache ),
|
2004-05-26 18:15:19 +00:00
|
|
|
navlist( NULL ),
|
2004-05-28 05:24:54 +00:00
|
|
|
loclist( NULL ),
|
|
|
|
gslist( NULL ),
|
|
|
|
dmelist( NULL ),
|
2005-10-01 09:56:53 +00:00
|
|
|
tacanlist( NULL ),
|
2007-12-10 19:17:57 +00:00
|
|
|
carrierlist( NULL ),
|
2011-12-29 23:39:08 +00:00
|
|
|
channellist( NULL ),
|
|
|
|
haveUserSettings(false)
|
2000-07-07 17:27:53 +00:00
|
|
|
{
|
2010-09-06 21:57:48 +00:00
|
|
|
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
|
2010-12-02 20:29:28 +00:00
|
|
|
simgear::PropertyObjectBase::setDefaultRoot(props);
|
2000-07-07 17:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destructor
|
2001-01-12 15:37:40 +00:00
|
|
|
FGGlobals::~FGGlobals()
|
2011-12-29 23:39:08 +00:00
|
|
|
{
|
|
|
|
// save user settings (unless already saved)
|
|
|
|
saveUserSettings();
|
|
|
|
|
|
|
|
// The AIModels manager performs a number of actions upon
|
2007-10-20 08:36:21 +00:00
|
|
|
// Shutdown that implicitly assume that other subsystems
|
|
|
|
// are still operational (Due to the dynamic allocation and
|
|
|
|
// deallocation of AIModel objects. To ensure we can safely
|
|
|
|
// shut down all subsystems, make sure we take down the
|
|
|
|
// AIModels system first.
|
2011-11-19 14:37:49 +00:00
|
|
|
SGSubsystem* ai = subsystem_mgr->remove("ai-model");
|
2010-10-30 22:36:54 +00:00
|
|
|
if (ai) {
|
|
|
|
ai->unbind();
|
|
|
|
delete ai;
|
|
|
|
}
|
2011-12-04 16:18:02 +00:00
|
|
|
SGSubsystem* sound = subsystem_mgr->remove("sound");
|
|
|
|
|
2010-11-06 07:22:37 +00:00
|
|
|
subsystem_mgr->shutdown();
|
2009-10-19 08:57:14 +00:00
|
|
|
subsystem_mgr->unbind();
|
2008-03-22 09:31:06 +00:00
|
|
|
delete subsystem_mgr;
|
2010-10-02 22:40:38 +00:00
|
|
|
|
2011-11-05 13:18:36 +00:00
|
|
|
delete renderer;
|
|
|
|
renderer = NULL;
|
|
|
|
|
2008-03-22 09:31:06 +00:00
|
|
|
delete time_params;
|
|
|
|
delete mag;
|
|
|
|
delete matlib;
|
|
|
|
delete route_mgr;
|
2012-04-11 22:03:16 +00:00
|
|
|
current_panel = NULL;
|
2008-03-22 09:31:06 +00:00
|
|
|
|
|
|
|
delete ATC_mgr;
|
2011-07-13 19:52:29 +00:00
|
|
|
|
|
|
|
if (controls)
|
|
|
|
{
|
|
|
|
controls->unbind();
|
|
|
|
delete controls;
|
|
|
|
}
|
2008-03-22 09:31:06 +00:00
|
|
|
|
|
|
|
delete channel_options_list;
|
|
|
|
delete initial_waypoints;
|
|
|
|
delete scenery;
|
|
|
|
delete fontcache;
|
2007-10-20 08:36:21 +00:00
|
|
|
|
|
|
|
delete navlist;
|
|
|
|
delete loclist;
|
|
|
|
delete gslist;
|
|
|
|
delete dmelist;
|
|
|
|
delete tacanlist;
|
|
|
|
delete carrierlist;
|
|
|
|
delete channellist;
|
2011-12-04 16:18:02 +00:00
|
|
|
delete sound;
|
2001-01-19 22:57:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-24 02:18:12 +00:00
|
|
|
// set the fg_root path
|
|
|
|
void FGGlobals::set_fg_root (const string &root) {
|
2012-01-12 21:06:40 +00:00
|
|
|
SGPath tmp(root);
|
|
|
|
fg_root = tmp.realpath();
|
2008-06-16 07:46:55 +00:00
|
|
|
|
2003-04-24 02:18:12 +00:00
|
|
|
// append /data to root if it exists
|
|
|
|
tmp.append( "data" );
|
|
|
|
tmp.append( "version" );
|
2011-11-19 20:25:51 +00:00
|
|
|
if ( tmp.exists() ) {
|
2009-01-30 17:55:14 +00:00
|
|
|
fgGetNode("BAD_FG_ROOT", true)->setStringValue(fg_root);
|
2003-04-24 02:18:12 +00:00
|
|
|
fg_root += "/data";
|
2009-01-30 17:55:14 +00:00
|
|
|
fgGetNode("GOOD_FG_ROOT", true)->setStringValue(fg_root);
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "***\n***\n*** Warning: changing bad FG_ROOT/--fg-root to '"
|
|
|
|
<< fg_root << "'\n***\n***");
|
2006-01-09 03:47:33 +00:00
|
|
|
}
|
|
|
|
|
2008-06-16 07:46:55 +00:00
|
|
|
// remove /sim/fg-root before writing to prevent hijacking
|
|
|
|
SGPropertyNode *n = fgGetNode("/sim", true);
|
|
|
|
n->removeChild("fg-root", 0, false);
|
|
|
|
n = n->getChild("fg-root", 0, true);
|
|
|
|
n->setStringValue(fg_root.c_str());
|
|
|
|
n->setAttribute(SGPropertyNode::WRITE, false);
|
2010-09-06 08:13:10 +00:00
|
|
|
|
|
|
|
simgear::ResourceManager::instance()->addBasePath(fg_root,
|
|
|
|
simgear::ResourceManager::PRIORITY_DEFAULT);
|
2003-04-24 02:18:12 +00:00
|
|
|
}
|
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
void FGGlobals::append_fg_scenery (const string &paths)
|
2010-07-05 07:31:09 +00:00
|
|
|
{
|
2011-10-16 17:35:40 +00:00
|
|
|
// fg_scenery.clear();
|
2011-05-24 23:03:51 +00:00
|
|
|
SGPropertyNode* sim = fgGetNode("/sim", true);
|
2011-10-16 17:35:40 +00:00
|
|
|
|
|
|
|
// find first unused fg-scenery property in /sim
|
|
|
|
int propIndex = 0;
|
|
|
|
while (sim->getChild("fg-scenery", propIndex) != NULL) {
|
|
|
|
++propIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_FOREACH(const SGPath& path, sgPathSplit( paths )) {
|
2012-01-12 21:06:40 +00:00
|
|
|
SGPath abspath(path.realpath());
|
|
|
|
if (!abspath.exists()) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << abspath.str());
|
2010-07-05 07:31:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-16 17:35:40 +00:00
|
|
|
// check for duplicates
|
2012-01-12 21:06:40 +00:00
|
|
|
string_list::const_iterator ex = std::find(fg_scenery.begin(), fg_scenery.end(), abspath.str());
|
2011-10-16 17:35:40 +00:00
|
|
|
if (ex != fg_scenery.end()) {
|
2012-01-12 21:06:40 +00:00
|
|
|
SG_LOG(SG_GENERAL, SG_INFO, "skipping duplicate add of scenery path:" << abspath.str());
|
2011-10-16 17:35:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-01-12 21:06:40 +00:00
|
|
|
simgear::Dir dir(abspath);
|
2010-07-05 07:31:09 +00:00
|
|
|
SGPath terrainDir(dir.file("Terrain"));
|
|
|
|
SGPath objectsDir(dir.file("Objects"));
|
|
|
|
|
|
|
|
// this code used to add *either* the base dir, OR add the
|
|
|
|
// Terrain and Objects subdirs, but the conditional logic was commented
|
|
|
|
// out, such that all three dirs are added. Unfortunately there's
|
|
|
|
// no information as to why the change was made.
|
2012-01-12 21:06:40 +00:00
|
|
|
fg_scenery.push_back(abspath.str());
|
2010-07-05 07:31:09 +00:00
|
|
|
|
|
|
|
if (terrainDir.exists()) {
|
|
|
|
fg_scenery.push_back(terrainDir.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (objectsDir.exists()) {
|
|
|
|
fg_scenery.push_back(objectsDir.str());
|
|
|
|
}
|
|
|
|
|
2005-12-03 10:20:35 +00:00
|
|
|
// insert a marker for FGTileEntry::load(), so that
|
|
|
|
// FG_SCENERY=A:B becomes list ["A/Terrain", "A/Objects", "",
|
|
|
|
// "B/Terrain", "B/Objects", ""]
|
|
|
|
fg_scenery.push_back("");
|
2011-05-24 23:03:51 +00:00
|
|
|
|
|
|
|
// make scenery dirs available to Nasal
|
2011-10-16 17:35:40 +00:00
|
|
|
SGPropertyNode* n = sim->getChild("fg-scenery", propIndex++, true);
|
2012-01-12 21:06:40 +00:00
|
|
|
n->setStringValue(abspath.str());
|
2011-05-24 23:03:51 +00:00
|
|
|
n->setAttribute(SGPropertyNode::WRITE, false);
|
2010-07-05 07:31:09 +00:00
|
|
|
} // of path list iteration
|
2004-06-07 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 12:21:30 +00:00
|
|
|
void FGGlobals::append_aircraft_path(const std::string& path)
|
|
|
|
{
|
|
|
|
SGPath dirPath(path);
|
|
|
|
if (!dirPath.exists()) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN, "aircraft path not found:" << path);
|
|
|
|
return;
|
|
|
|
}
|
2012-01-12 21:06:40 +00:00
|
|
|
std::string abspath = dirPath.realpath();
|
2010-07-18 12:21:30 +00:00
|
|
|
|
2010-08-16 10:00:54 +00:00
|
|
|
unsigned int index = fg_aircraft_dirs.size();
|
2012-01-12 21:06:40 +00:00
|
|
|
fg_aircraft_dirs.push_back(abspath);
|
2010-08-16 10:00:54 +00:00
|
|
|
|
|
|
|
// make aircraft dirs available to Nasal
|
|
|
|
SGPropertyNode* sim = fgGetNode("/sim", true);
|
|
|
|
sim->removeChild("fg-aircraft", index, false);
|
|
|
|
SGPropertyNode* n = sim->getChild("fg-aircraft", index, true);
|
2012-01-12 21:06:40 +00:00
|
|
|
n->setStringValue(abspath);
|
2010-08-16 10:00:54 +00:00
|
|
|
n->setAttribute(SGPropertyNode::WRITE, false);
|
2010-07-18 12:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGGlobals::append_aircraft_paths(const std::string& path)
|
|
|
|
{
|
|
|
|
string_list paths = sgPathSplit(path);
|
|
|
|
for (unsigned int p = 0; p<paths.size(); ++p) {
|
|
|
|
append_aircraft_path(paths[p]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SGPath FGGlobals::resolve_aircraft_path(const std::string& branch) const
|
|
|
|
{
|
2010-09-06 08:13:10 +00:00
|
|
|
return simgear::ResourceManager::instance()->findPath(branch);
|
2010-07-18 12:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SGPath FGGlobals::resolve_maybe_aircraft_path(const std::string& branch) const
|
|
|
|
{
|
2010-09-06 08:13:10 +00:00
|
|
|
return simgear::ResourceManager::instance()->findPath(branch);
|
2010-07-18 12:21:30 +00:00
|
|
|
}
|
2003-04-24 02:18:12 +00:00
|
|
|
|
2004-09-20 13:21:51 +00:00
|
|
|
FGRenderer *
|
|
|
|
FGGlobals::get_renderer () const
|
|
|
|
{
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
SGSubsystemMgr *
|
2003-01-16 16:01:26 +00:00
|
|
|
FGGlobals::get_subsystem_mgr () const
|
|
|
|
{
|
|
|
|
return subsystem_mgr;
|
|
|
|
}
|
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
SGSubsystem *
|
2003-01-16 16:01:26 +00:00
|
|
|
FGGlobals::get_subsystem (const char * name)
|
|
|
|
{
|
|
|
|
return subsystem_mgr->get_subsystem(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FGGlobals::add_subsystem (const char * name,
|
2003-09-24 17:20:55 +00:00
|
|
|
SGSubsystem * subsystem,
|
|
|
|
SGSubsystemMgr::GroupType type,
|
2003-01-16 16:01:26 +00:00
|
|
|
double min_time_sec)
|
|
|
|
{
|
|
|
|
subsystem_mgr->add(name, subsystem, type, min_time_sec);
|
|
|
|
}
|
|
|
|
|
2009-10-24 08:31:37 +00:00
|
|
|
SGSoundMgr *
|
|
|
|
FGGlobals::get_soundmgr () const
|
|
|
|
{
|
2011-11-20 15:20:05 +00:00
|
|
|
if (subsystem_mgr)
|
|
|
|
return (SGSoundMgr*) subsystem_mgr->get_subsystem("sound");
|
|
|
|
|
|
|
|
return NULL;
|
2009-10-24 08:31:37 +00:00
|
|
|
}
|
2003-01-16 16:01:26 +00:00
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
SGEventMgr *
|
|
|
|
FGGlobals::get_event_mgr () const
|
|
|
|
{
|
|
|
|
return event_mgr;
|
|
|
|
}
|
|
|
|
|
2011-08-20 06:54:47 +00:00
|
|
|
const SGGeod &
|
|
|
|
FGGlobals::get_aircraft_position() const
|
|
|
|
{
|
|
|
|
if( acmodel != NULL ) {
|
|
|
|
SGModelPlacement * mp = acmodel->get3DModel();
|
|
|
|
if( mp != NULL )
|
|
|
|
return mp->getPosition();
|
|
|
|
}
|
|
|
|
throw sg_exception("Can't get aircraft position", "FGGlobals::get_aircraft_position()" );
|
|
|
|
}
|
|
|
|
|
2011-10-30 09:31:41 +00:00
|
|
|
SGVec3d
|
2011-10-26 16:26:11 +00:00
|
|
|
FGGlobals::get_aircraft_positon_cart() const
|
|
|
|
{
|
|
|
|
return SGVec3d::fromGeod(get_aircraft_position());
|
|
|
|
}
|
2011-08-20 06:54:47 +00:00
|
|
|
|
2003-09-24 17:20:55 +00:00
|
|
|
|
2001-01-19 22:57:24 +00:00
|
|
|
// Save the current state as the initial state.
|
|
|
|
void
|
|
|
|
FGGlobals::saveInitialState ()
|
|
|
|
{
|
|
|
|
initial_state = new SGPropertyNode();
|
2003-09-24 17:20:55 +00:00
|
|
|
|
2011-06-12 18:31:56 +00:00
|
|
|
// copy properties which are READ/WRITEable - but not USERARCHIVEd or PRESERVEd
|
|
|
|
int checked = SGPropertyNode::READ+SGPropertyNode::WRITE+
|
|
|
|
SGPropertyNode::USERARCHIVE+SGPropertyNode::PRESERVE;
|
|
|
|
int expected = SGPropertyNode::READ+SGPropertyNode::WRITE;
|
|
|
|
if (!copyProperties(props, initial_state, expected, checked))
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT, "Error saving initial state");
|
2010-07-04 11:53:51 +00:00
|
|
|
|
|
|
|
// delete various properties from the initial state, since we want to
|
|
|
|
// preserve their values even if doing a restore
|
2011-06-12 18:31:56 +00:00
|
|
|
// => Properties should now use the PRESERVE flag to protect their values
|
|
|
|
// on sim-reset. Remove some specific properties for backward compatibility.
|
2010-07-04 11:53:51 +00:00
|
|
|
SGPropertyNode* sim = initial_state->getChild("sim");
|
|
|
|
SGPropertyNode* cameraGroupNode = sim->getNode("rendering/camera-group");
|
|
|
|
if (cameraGroupNode) {
|
|
|
|
cameraGroupNode->removeChild("camera");
|
|
|
|
cameraGroupNode->removeChild("gui");
|
|
|
|
}
|
2000-07-07 17:27:53 +00:00
|
|
|
}
|
|
|
|
|
2001-01-19 22:57:24 +00:00
|
|
|
|
|
|
|
// Restore the saved initial state, if any
|
|
|
|
void
|
|
|
|
FGGlobals::restoreInitialState ()
|
|
|
|
{
|
2002-11-18 21:31:33 +00:00
|
|
|
if ( initial_state == 0 ) {
|
|
|
|
SG_LOG(SG_GENERAL, SG_ALERT,
|
|
|
|
"No initial state available to restore!!!");
|
|
|
|
return;
|
|
|
|
}
|
2011-06-12 18:31:56 +00:00
|
|
|
// copy properties which are READ/WRITEable - but not USERARCHIVEd or PRESERVEd
|
|
|
|
int checked = SGPropertyNode::READ+SGPropertyNode::WRITE+
|
|
|
|
SGPropertyNode::USERARCHIVE+SGPropertyNode::PRESERVE;
|
|
|
|
int expected = SGPropertyNode::READ+SGPropertyNode::WRITE;
|
|
|
|
if ( copyProperties(initial_state, props, expected, checked)) {
|
2002-11-18 21:31:33 +00:00
|
|
|
SG_LOG( SG_GENERAL, SG_INFO, "Initial state restored successfully" );
|
|
|
|
} else {
|
|
|
|
SG_LOG( SG_GENERAL, SG_INFO,
|
|
|
|
"Some errors restoring initial state (read-only props?)" );
|
|
|
|
}
|
|
|
|
|
2001-01-19 22:57:24 +00:00
|
|
|
}
|
|
|
|
|
2011-12-29 23:39:08 +00:00
|
|
|
// Load user settings from autosave.xml
|
|
|
|
void
|
2011-12-30 00:01:15 +00:00
|
|
|
FGGlobals::loadUserSettings(const SGPath& dataPath)
|
2011-12-29 23:39:08 +00:00
|
|
|
{
|
2011-12-30 00:01:15 +00:00
|
|
|
// remember that we have (tried) to load any existing autsave.xml
|
2011-12-29 23:39:08 +00:00
|
|
|
haveUserSettings = true;
|
2011-12-30 00:01:15 +00:00
|
|
|
|
|
|
|
SGPath autosaveFile = simgear::Dir(dataPath).file("autosave.xml");
|
|
|
|
SGPropertyNode autosave;
|
|
|
|
if (autosaveFile.exists()) {
|
|
|
|
SG_LOG(SG_INPUT, SG_INFO, "Reading user settings from " << autosaveFile.str());
|
|
|
|
try {
|
|
|
|
readProperties(autosaveFile.str(), &autosave, SGPropertyNode::USERARCHIVE);
|
|
|
|
} catch (sg_exception& e) {
|
|
|
|
SG_LOG(SG_INPUT, SG_WARN, "failed to read user settings:" << e.getMessage()
|
|
|
|
<< "(from " << e.getOrigin() << ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
copyProperties(&autosave, globals->get_props());
|
2011-12-29 23:39:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save user settings in autosave.xml
|
|
|
|
void
|
|
|
|
FGGlobals::saveUserSettings()
|
|
|
|
{
|
|
|
|
// only save settings when we have (tried) to load the previous
|
|
|
|
// settings (otherwise user data was lost)
|
|
|
|
if (!haveUserSettings)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (fgGetBool("/sim/startup/save-on-exit")) {
|
|
|
|
// don't save settings more than once on shutdown
|
|
|
|
haveUserSettings = false;
|
|
|
|
|
|
|
|
SGPath autosaveFile(fgGetString("/sim/fg-home"));
|
|
|
|
autosaveFile.append( "autosave.xml" );
|
|
|
|
autosaveFile.create_dir( 0700 );
|
|
|
|
SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << autosaveFile.str());
|
|
|
|
try {
|
|
|
|
writeProperties(autosaveFile.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
|
|
|
|
} catch (const sg_exception &e) {
|
|
|
|
guiErrorMessage("Error writing autosave.xml: ", e);
|
|
|
|
}
|
|
|
|
SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-05 18:46:47 +00:00
|
|
|
FGViewer *
|
|
|
|
FGGlobals::get_current_view () const
|
|
|
|
{
|
|
|
|
return viewmgr->get_current_view();
|
|
|
|
}
|
2001-01-19 22:57:24 +00:00
|
|
|
|
2010-11-21 23:43:41 +00:00
|
|
|
long int FGGlobals::get_warp() const
|
|
|
|
{
|
|
|
|
return fgGetInt("/sim/time/warp");
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGGlobals::set_warp( long int w )
|
|
|
|
{
|
|
|
|
fgSetInt("/sim/time/warp", w);
|
|
|
|
}
|
|
|
|
|
|
|
|
long int FGGlobals::get_warp_delta() const
|
|
|
|
{
|
|
|
|
return fgGetInt("/sim/time/warp-delta");
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGGlobals::set_warp_delta( long int d )
|
|
|
|
{
|
|
|
|
fgSetInt("/sim/time/warp-delta", d);
|
|
|
|
}
|
2012-01-02 23:16:18 +00:00
|
|
|
|
|
|
|
void FGGlobals::set_current_panel( FGPanel *cp )
|
|
|
|
{
|
|
|
|
current_panel = cp;
|
|
|
|
// poke the renderer to rebuild the scene node as necessary
|
|
|
|
get_renderer()->panelChanged();
|
|
|
|
}
|
2010-11-21 23:43:41 +00:00
|
|
|
|
2001-01-19 22:57:24 +00:00
|
|
|
// end of globals.cxx
|