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
|
|
|
|
|
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>
|
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>
|
2006-06-05 20:21:45 +00:00
|
|
|
|
#include <GUI/new_gui.hxx>
|
2007-10-20 08:36:21 +00:00
|
|
|
|
#include <Model/acmodel.hxx>
|
|
|
|
|
#include <Model/modelmgr.hxx>
|
|
|
|
|
#include <MultiPlayer/multiplaymgr.hxx>
|
|
|
|
|
#include <Navaids/awynet.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-09-06 08:13:10 +00:00
|
|
|
|
class AircraftResourceProvider : public simgear::ResourceProvider
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* aircraftDir = fgGetString("/sim/aircraft-dir");
|
|
|
|
|
string_list aircraftDirPieces(sgPathBranchSplit(aircraftDir));
|
|
|
|
|
if (aircraftDirPieces.empty() || (aircraftDirPieces.back() != pieces[1])) {
|
|
|
|
|
return SGPath(); // current aircraft-dir does not match resource aircraft
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SGPath r(aircraftDir);
|
|
|
|
|
for (unsigned int i=2; i<pieces.size(); ++i) {
|
|
|
|
|
r.append(pieces[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.exists() ? r : SGPath();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
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 ),
|
2009-10-24 08:31:37 +00:00
|
|
|
|
soundmgr( new SGSoundMgr ),
|
2002-12-11 21:07:30 +00:00
|
|
|
|
sim_time_sec( 0.0 ),
|
|
|
|
|
fg_root( "" ),
|
2000-07-07 17:27:53 +00:00
|
|
|
|
warp( 0 ),
|
2001-01-19 22:57:24 +00:00
|
|
|
|
warp_delta( 0 ),
|
2002-12-11 21:07:30 +00:00
|
|
|
|
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 ),
|
|
|
|
|
channellist( NULL ),
|
|
|
|
|
airwaynet( NULL ),
|
|
|
|
|
multiplayer_mgr( NULL )
|
2000-07-07 17:27:53 +00:00
|
|
|
|
{
|
2010-09-06 21:57:48 +00:00
|
|
|
|
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
|
2000-07-07 17:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
2001-01-12 15:37:40 +00:00
|
|
|
|
FGGlobals::~FGGlobals()
|
|
|
|
|
{
|
2004-09-20 13:21:51 +00:00
|
|
|
|
delete renderer;
|
2007-10-20 08:36:21 +00:00
|
|
|
|
// The AIModels manager performs a number of actions upon
|
|
|
|
|
// 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.
|
|
|
|
|
subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("ai_model");
|
2009-09-04 05:42:58 +00:00
|
|
|
|
// FGInput (FGInputEvent) and FGDialog calls get_subsystem() in their destructors,
|
|
|
|
|
// which is not safe since some subsystem are already deleted but can be referred.
|
|
|
|
|
// So these subsystems must be deleted prior to deleting subsystem_mgr unless
|
|
|
|
|
// ~SGSubsystemGroup and SGSubsystemMgr::get_subsystem are changed not to refer to
|
|
|
|
|
// deleted subsystems.
|
|
|
|
|
subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("input");
|
|
|
|
|
subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("gui");
|
2009-10-19 08:57:14 +00:00
|
|
|
|
subsystem_mgr->unbind();
|
2008-03-22 09:31:06 +00:00
|
|
|
|
delete subsystem_mgr;
|
|
|
|
|
delete event_mgr;
|
|
|
|
|
delete time_params;
|
|
|
|
|
delete mag;
|
|
|
|
|
delete matlib;
|
|
|
|
|
delete route_mgr;
|
|
|
|
|
delete current_panel;
|
|
|
|
|
|
|
|
|
|
delete ATC_mgr;
|
|
|
|
|
delete controls;
|
|
|
|
|
delete viewmgr;
|
|
|
|
|
|
2007-10-20 08:36:21 +00:00
|
|
|
|
// delete commands;
|
2008-03-22 09:31:06 +00:00
|
|
|
|
delete acmodel;
|
|
|
|
|
delete model_mgr;
|
|
|
|
|
delete channel_options_list;
|
|
|
|
|
delete initial_waypoints;
|
|
|
|
|
delete tile_mgr;
|
|
|
|
|
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;
|
|
|
|
|
delete airwaynet;
|
|
|
|
|
delete multiplayer_mgr;
|
2009-10-24 08:31:37 +00:00
|
|
|
|
|
|
|
|
|
soundmgr->unbind();
|
|
|
|
|
delete soundmgr;
|
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) {
|
|
|
|
|
fg_root = root;
|
2008-06-16 07:46:55 +00:00
|
|
|
|
|
2003-04-24 02:18:12 +00:00
|
|
|
|
// append /data to root if it exists
|
|
|
|
|
SGPath tmp( fg_root );
|
|
|
|
|
tmp.append( "data" );
|
|
|
|
|
tmp.append( "version" );
|
|
|
|
|
if ( ulFileExists( tmp.c_str() ) ) {
|
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
|
|
|
|
}
|
|
|
|
|
|
2010-07-05 07:31:09 +00:00
|
|
|
|
void FGGlobals::set_fg_scenery (const string &scenery)
|
|
|
|
|
{
|
Melchior FRANZ:
Wouldn't it be better to prepare the whole list of paths (or two
separate ones for Terrain/Objects if necessary) in FGGlobals::set_fg_scenery,
and to pass the vector<string>s to FGTileEntry::load? It doesn't seem to make
a lot of sense to split the path up, modify it, mount it together to one string
again, and then let FGTileEntry::load split it up again.
Here we go:
Main/globals.cxx
================
As fg_scenery is now a string_list, we don't need initialization. Furthermore,
this list is cleared with every set_fg_scenery() call.
ctor: create default dir from fg_root if necessary. Otherwise check all paths
of --fg-scenery/FG_SCENERY: If the path doesn't exist, ignore it. If it contains
a dir Terrain and/or Objects, then only add that to the list. If it contains
neither, then use the path as is.
Scenery/tileentry.cxx
=====================
Trivial: don't split a "base path", but use the given path_list as is.
(I considered a variable name "path_list" better suited than "search".)
Scenery/FGTileLoader.cxx
========================
No more fiddling with sub-paths. This has to be delivered by get_fg_scenery
already.
2004-06-08 15:32:09 +00:00
|
|
|
|
SGPath s;
|
|
|
|
|
if (scenery.empty()) {
|
|
|
|
|
s.set( fg_root );
|
|
|
|
|
s.append( "Scenery" );
|
|
|
|
|
} else
|
|
|
|
|
s.set( scenery );
|
|
|
|
|
|
|
|
|
|
string_list path_list = sgPathSplit( s.str() );
|
|
|
|
|
fg_scenery.clear();
|
|
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < path_list.size(); i++) {
|
2010-07-05 07:31:09 +00:00
|
|
|
|
SGPath path(path_list[i]);
|
|
|
|
|
if (!path.exists()) {
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN, "scenery path not found:" << path.str());
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
simgear::Dir dir(path);
|
|
|
|
|
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.
|
|
|
|
|
fg_scenery.push_back(path.str());
|
|
|
|
|
|
|
|
|
|
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("");
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-16 10:00:54 +00:00
|
|
|
|
unsigned int index = fg_aircraft_dirs.size();
|
2010-07-18 12:21:30 +00:00
|
|
|
|
fg_aircraft_dirs.push_back(path);
|
2010-08-16 10:00:54 +00:00
|
|
|
|
|
2010-09-06 08:13:10 +00:00
|
|
|
|
simgear::ResourceManager::instance()->addBasePath(path,
|
|
|
|
|
simgear::ResourceManager::PRIORITY_NORMAL);
|
|
|
|
|
|
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);
|
|
|
|
|
n->setStringValue(path);
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
return soundmgr;
|
|
|
|
|
}
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!copyProperties(props, initial_state))
|
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
|
|
|
|
|
|
|
|
|
|
SGPropertyNode* sim = initial_state->getChild("sim");
|
|
|
|
|
sim->removeChild("presets");
|
|
|
|
|
SGPropertyNode* simStartup = sim->getChild("startup");
|
|
|
|
|
simStartup->removeChild("xsize");
|
|
|
|
|
simStartup->removeChild("ysize");
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( copyProperties(initial_state, props) ) {
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
// end of globals.cxx
|