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
|
|
|
|
|
// along with this program; if not, write to the Free Software
|
2006-02-21 01:16:04 +00:00
|
|
|
|
// 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
|
|
|
|
|
2004-04-25 02:06:55 +00:00
|
|
|
|
#include <simgear/sound/soundmgr_openal.hxx>
|
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>
|
2002-03-16 00:18:38 +00:00
|
|
|
|
|
2006-06-05 20:21:45 +00:00
|
|
|
|
#include <GUI/new_gui.hxx>
|
|
|
|
|
|
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
|
|
|
|
|
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() :
|
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( "" ),
|
2002-01-06 16:51:31 +00:00
|
|
|
|
#if defined(FX) && defined(XMESA)
|
|
|
|
|
fullscreen( true ),
|
|
|
|
|
#endif
|
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 ),
|
2004-01-31 19:47:45 +00:00
|
|
|
|
route_mgr( NULL ),
|
2003-03-31 08:25:00 +00:00
|
|
|
|
current_panel( NULL ),
|
2003-05-08 03:29:49 +00:00
|
|
|
|
soundmgr( NULL ),
|
2003-08-28 20:53:08 +00:00
|
|
|
|
airports( NULL ),
|
2002-12-11 21:07:30 +00:00
|
|
|
|
ATC_mgr( NULL ),
|
|
|
|
|
AI_mgr( NULL ),
|
|
|
|
|
controls( NULL ),
|
|
|
|
|
viewmgr( NULL ),
|
|
|
|
|
props( new SGPropertyNode ),
|
|
|
|
|
initial_state( NULL ),
|
|
|
|
|
locale( NULL ),
|
2007-01-04 12:48:21 +00:00
|
|
|
|
commands( SGCommandMgr::instance() ),
|
2003-05-15 21:35:51 +00:00
|
|
|
|
model_lib( NULL ),
|
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 ),
|
2004-05-26 18:15:19 +00:00
|
|
|
|
io( new FGIO ),
|
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 ),
|
|
|
|
|
mkrlist( NULL ),
|
2005-10-01 09:56:53 +00:00
|
|
|
|
tacanlist( NULL ),
|
|
|
|
|
carrierlist( NULL ),
|
2004-05-28 05:24:54 +00:00
|
|
|
|
fixlist( NULL )
|
2000-07-07 17:27:53 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
2001-01-12 15:37:40 +00:00
|
|
|
|
FGGlobals::~FGGlobals()
|
|
|
|
|
{
|
2004-04-25 02:06:55 +00:00
|
|
|
|
delete soundmgr;
|
|
|
|
|
delete subsystem_mgr;
|
|
|
|
|
delete event_mgr;
|
|
|
|
|
delete initial_state;
|
|
|
|
|
delete props;
|
2006-02-17 09:43:33 +00:00
|
|
|
|
delete io;
|
2006-06-05 20:21:45 +00:00
|
|
|
|
delete fontcache;
|
2004-09-20 13:21:51 +00:00
|
|
|
|
delete renderer;
|
2005-05-02 06:03:25 +00:00
|
|
|
|
delete initial_waypoints;
|
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;
|
|
|
|
|
|
|
|
|
|
// append /data to root if it exists
|
|
|
|
|
SGPath tmp( fg_root );
|
|
|
|
|
tmp.append( "data" );
|
|
|
|
|
tmp.append( "version" );
|
|
|
|
|
if ( ulFileExists( tmp.c_str() ) ) {
|
|
|
|
|
fg_root += "/data";
|
2006-01-09 03:47:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fgSetString("/sim/fg-root", fg_root.c_str());
|
2003-04-24 02:18:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-06-07 09:52:11 +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++) {
|
|
|
|
|
|
2004-07-16 20:02:36 +00:00
|
|
|
|
ulDir *d = ulOpenDir( path_list[i].c_str() );
|
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
|
|
|
|
if (d == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
ulCloseDir( d );
|
|
|
|
|
|
|
|
|
|
SGPath pt( path_list[i] ), po( path_list[i] );
|
|
|
|
|
pt.append("Terrain");
|
|
|
|
|
po.append("Objects");
|
|
|
|
|
|
|
|
|
|
ulDir *td = ulOpenDir( pt.c_str() );
|
|
|
|
|
ulDir *od = ulOpenDir( po.c_str() );
|
|
|
|
|
|
|
|
|
|
if (td == NULL && od == NULL)
|
|
|
|
|
fg_scenery.push_back( path_list[i] );
|
|
|
|
|
else {
|
|
|
|
|
if (td != NULL) {
|
|
|
|
|
fg_scenery.push_back( pt.str() );
|
|
|
|
|
ulCloseDir( td );
|
|
|
|
|
}
|
|
|
|
|
if (od != NULL) {
|
|
|
|
|
fg_scenery.push_back( po.str() );
|
|
|
|
|
ulCloseDir( od );
|
|
|
|
|
}
|
2004-06-07 09:52:11 +00:00
|
|
|
|
}
|
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("");
|
2004-06-07 09:52:11 +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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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 ()
|
|
|
|
|
{
|
|
|
|
|
delete initial_state;
|
|
|
|
|
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");
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SGPropertyNode *currentPresets = new SGPropertyNode;
|
|
|
|
|
SGPropertyNode *targetNode = fgGetNode( "/sim/presets" );
|
|
|
|
|
|
|
|
|
|
// stash the /sim/presets tree
|
|
|
|
|
if ( !copyProperties(targetNode, currentPresets) ) {
|
|
|
|
|
SG_LOG( SG_GENERAL, SG_ALERT, "Failed to save /sim/presets subtree" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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?)" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// recover the /sim/presets tree
|
|
|
|
|
if ( !copyProperties(currentPresets, targetNode) ) {
|
|
|
|
|
SG_LOG( SG_GENERAL, SG_ALERT,
|
|
|
|
|
"Failed to restore /sim/presets subtree" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete currentPresets;
|
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
|