]> git.mxchange.org Git - flightgear.git/blob - src/Main/globals.cxx
15c898998eacbebf1553a975152fc5b481fa1b9e
[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 - curt@flightgear.org
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
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22
23
24 #include <simgear/misc/commands.hxx>
25
26 #include <Environment/environment_mgr.hxx>
27
28 #include "globals.hxx"
29 #include "fg_props.hxx"
30
31
32 \f
33 ////////////////////////////////////////////////////////////////////////
34 // Implementation of FGGlobals.
35 ////////////////////////////////////////////////////////////////////////
36
37 // global global :-)
38 FGGlobals *globals;
39
40
41 // Constructor
42 FGGlobals::FGGlobals() :
43     elapsed_time_ms(0L),
44 #if defined(FX) && defined(XMESA)
45     fullscreen( true ),
46 #endif
47     warp( 0 ),
48     warp_delta( 0 ),
49     logger(0),
50     props(new SGPropertyNode),
51     initial_state(0),
52     commands(new SGCommandMgr)
53 {
54 }
55
56
57 // Destructor
58 FGGlobals::~FGGlobals() 
59 {
60   delete initial_state;
61   delete props;
62   delete commands;
63 }
64
65
66 // Save the current state as the initial state.
67 void
68 FGGlobals::saveInitialState ()
69 {
70   delete initial_state;
71   initial_state = new SGPropertyNode();
72   if (!copyProperties(props, initial_state))
73     SG_LOG(SG_GENERAL, SG_ALERT, "Error saving initial state");
74 }
75
76
77 // Restore the saved initial state, if any
78 void
79 FGGlobals::restoreInitialState ()
80 {
81   if (initial_state == 0) {
82     SG_LOG(SG_GENERAL, SG_ALERT, "No initial state available to restore!!!");
83   } else if (!copyProperties(initial_state, props)) {
84     SG_LOG(SG_GENERAL, SG_INFO,
85            "Some errors restoring initial state (probably just read-only props)");
86   } else {
87     SG_LOG(SG_GENERAL, SG_INFO, "Initial state restored successfully");
88   }
89 }
90
91 const FGEnvironment *
92 FGGlobals::get_environment () const
93 {
94   return environment_mgr->getEnvironment();
95 }
96
97 const FGEnvironment *
98 FGGlobals::get_environment (double lat, double lon, double alt) const
99 {
100   return environment_mgr->getEnvironment(lat, lon, alt);
101 }
102
103
104 // end of globals.cxx