1 // globals.hxx -- Global state that needs to be shared among the sim modules
3 // Written by Curtis Olson, started July 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <simgear/compiler.h>
28 #include <simgear/props/props.hxx>
29 #include <simgear/structure/subsystem_mgr.hxx>
30 #include <simgear/misc/sg_path.hxx>
35 typedef std::vector<std::string> string_list;
36 typedef std::vector<SGPath> PathList;
38 // Forward declarations
40 // This file is included, directly or indirectly, almost everywhere in
41 // FlightGear, so if any of its dependencies changes, most of the sim
42 // has to be recompiled. Using these forward declarations helps us to
43 // avoid including a lot of header files (and thus, a lot of
44 // dependencies). Since Most of the methods simply set or return
45 // pointers, we don't need to know anything about the class details
72 * Bucket for subsystem pointers representing the sim's state.
80 // properties, destroy last
81 SGPropertyNode_ptr props;
82 SGPropertyNode_ptr initial_state;
88 SGSubsystemMgr *subsystem_mgr;
89 SGEventMgr *event_mgr;
91 // Number of milliseconds elapsed since the start of the program.
94 // Root of FlightGear data tree
98 * locations to search for (non-scenery) data.
100 PathList additional_data_paths;
102 // Users home directory for data
105 // Roots of FlightGear scenery tree
106 string_list fg_scenery;
116 // Material properties library
117 SGSharedPtr<SGMaterialLib> matlib;
119 // Global autopilot "route"
120 FGRouteMgr *route_mgr;
125 // control input state
126 FGControls *controls;
131 SGCommandMgr *commands;
133 // list of serial port-like configurations
134 string_list *channel_options_list;
136 // A list of initial waypoints that are read from the command line
137 // and or flight-plan file during initialization
138 string_list *initial_waypoints;
140 // FlightGear scenery manager
141 SGSharedPtr<FGScenery> _scenery;
144 SGSharedPtr<FGTileMgr> _tile_mgr;
146 FGFontCache *fontcache;
149 FGTACANList *channellist;
151 /// roots of Aircraft trees
152 string_list fg_aircraft_dirs;
154 bool haveUserSettings;
156 SGPropertyNode_ptr positionLon, positionLat, positionAlt;
157 SGPropertyNode_ptr viewLon, viewLat, viewAlt;
158 SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
161 * helper to initialise standard properties on a new property tree
163 void initProperties();
165 SGSharedPtr<FGSampleQueue> _chatter_queue;
167 void cleanupListeners();
169 typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
170 SGPropertyChangeListenerVec _listeners_to_cleanup;
175 virtual ~FGGlobals();
177 virtual FGRenderer *get_renderer () const;
178 void set_renderer(FGRenderer* render);
180 virtual SGSubsystemMgr *get_subsystem_mgr () const;
182 virtual SGSubsystem *get_subsystem (const char * name);
184 virtual void add_subsystem (const char * name,
185 SGSubsystem * subsystem,
186 SGSubsystemMgr::GroupType
187 type = SGSubsystemMgr::GENERAL,
188 double min_time_sec = 0);
190 virtual SGEventMgr *get_event_mgr () const;
192 virtual SGSoundMgr *get_soundmgr () const;
194 inline double get_sim_time_sec () const { return sim_time_sec; }
195 inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
196 inline void set_sim_time_sec (double t) { sim_time_sec = t; }
198 inline const std::string &get_fg_root () const { return fg_root; }
199 void set_fg_root (const std::string &root);
202 * Get list of data locations. fg_root is always the final item in the
205 PathList get_data_paths() const;
208 * Get data locations which contain the file path suffix. Eg pass ing
209 * 'AI/Traffic' to get all data paths which define <path>/AI/Traffic subdir
211 PathList get_data_paths(const std::string& suffix) const;
213 void append_data_path(const SGPath& path);
216 * Given a path suffix (eg 'Textures' or 'AI/Traffic'), find the
217 * first data directory which defines it.
219 SGPath find_data_dir(const std::string& pathSuffix) const;
221 inline const std::string &get_fg_home () const { return fg_home; }
222 void set_fg_home (const std::string &home);
224 inline const string_list &get_fg_scenery () const { return fg_scenery; }
225 void append_fg_scenery (const std::string &scenery);
227 const string_list& get_aircraft_paths() const { return fg_aircraft_dirs; }
228 void append_aircraft_path(const std::string& path);
229 void append_aircraft_paths(const std::string& path);
232 * Given a path to an aircraft-related resource file, resolve it
233 * against the appropriate root. This means looking at the location
234 * defined by /sim/aircraft-dir, and then aircraft_path in turn,
235 * finishing with fg_root/Aircraft.
237 * if the path could not be resolved, an empty path is returned.
239 SGPath resolve_aircraft_path(const std::string& branch) const;
242 * Same as above, but test for non 'Aircraft/' branch paths, and
243 * always resolve them against fg_root.
245 SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
248 * Search in the following directories:
250 * 1. Root directory of current aircraft (defined by /sim/aircraft-dir)
251 * 2. All aircraft directories if branch starts with Aircraft/
252 * 3. fg_data directory
254 SGPath resolve_resource_path(const std::string& branch) const;
256 inline const std::string &get_browser () const { return browser; }
257 void set_browser (const std::string &b) { browser = b; }
259 long int get_warp() const;
260 void set_warp( long int w );
262 long int get_warp_delta() const;
263 void set_warp_delta( long int d );
265 inline SGTime *get_time_params() const { return time_params; }
266 inline void set_time_params( SGTime *t ) { time_params = t; }
268 inline SGEphemeris *get_ephem() const { return ephem; }
269 inline void set_ephem( SGEphemeris *e ) { ephem = e; }
271 inline SGMaterialLib *get_matlib() const { return matlib; }
272 void set_matlib( SGMaterialLib *m );
274 inline FGATISMgr *get_ATIS_mgr() const { return ATIS_mgr; }
275 inline void set_ATIS_mgr( FGATISMgr *a ) {ATIS_mgr = a; }
277 inline FGControls *get_controls() const { return controls; }
278 inline void set_controls( FGControls *c ) { controls = c; }
280 inline FGViewMgr *get_viewmgr() const { return viewmgr; }
281 inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; }
282 FGViewer *get_current_view() const;
284 inline SGPropertyNode *get_props () { return props; }
287 * @brief reset the property tree to new, empty tree. Ensure all
288 * subsystems are shutdown and unbound before call this.
290 void resetPropertyRoot();
292 inline FGLocale* get_locale () { return locale; }
294 inline SGCommandMgr *get_commands () { return commands; }
296 SGGeod get_aircraft_position() const;
298 SGVec3d get_aircraft_position_cart() const;
300 void get_aircraft_orientation(double& heading, double& pitch, double& roll);
302 SGGeod get_view_position() const;
304 SGVec3d get_view_position_cart() const;
306 inline string_list *get_channel_options_list () {
307 return channel_options_list;
309 inline void set_channel_options_list( string_list *l ) {
310 channel_options_list = l;
313 inline string_list *get_initial_waypoints () {
314 return initial_waypoints;
317 inline void set_initial_waypoints (string_list *list) {
318 initial_waypoints = list;
321 FGScenery * get_scenery () const;
322 void set_scenery ( FGScenery *s );
324 FGTileMgr * get_tile_mgr () const;
325 void set_tile_mgr ( FGTileMgr *t );
327 inline FGFontCache *get_fontcache() const { return fontcache; }
329 inline FGTACANList *get_channellist() const { return channellist; }
330 inline void set_channellist( FGTACANList *c ) { channellist = c; }
333 * Save the current state as the initial state.
335 void saveInitialState ();
339 * Restore the saved initial state, if any.
341 void restoreInitialState ();
344 * Load user settings from autosave.xml
346 void loadUserSettings(const SGPath& datapath);
349 * Save user settings in autosave.xml
351 void saveUserSettings();
353 FGSampleQueue* get_chatter_queue() const;
354 void set_chatter_queue(FGSampleQueue* queue);
356 void addListenerToCleanup(SGPropertyChangeListener* l);
360 extern FGGlobals *globals;
363 #endif // _GLOBALS_HXX