FlightGear next
globals.hxx
Go to the documentation of this file.
1// globals.hxx -- 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 - http://www.flightgear.org/~curt
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20//
21// $Id$
22
23
24#ifndef _GLOBALS_HXX
25#define _GLOBALS_HXX
26
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>
31
32#include <vector>
33#include <string>
34#include <memory>
35
36typedef std::vector<std::string> string_list;
37typedef std::vector<SGPath> PathList;
38
39// Forward declarations
40
41// This file is included, directly or indirectly, almost everywhere in
42// FlightGear, so if any of its dependencies changes, most of the sim
43// has to be recompiled. Using these forward declarations helps us to
44// avoid including a lot of header files (and thus, a lot of
45// dependencies). Since Most of the methods simply set or return
46// pointers, we don't need to know anything about the class details
47// anyway.
48
49class SGCommandMgr;
50class SGMaterialLib;
51class SGPropertyNode;
52class SGTime;
53class SGEventMgr;
54class SGSubsystemMgr;
55class SGSubsystem;
56
57class FGControls;
58class FGTACANList;
59class FGLocale;
60class FGRouteMgr;
61class FGScenery;
62class FGViewMgr;
63class FGRenderer;
64
65namespace simgear { namespace pkg {
66 class Root;
67}}
68
69namespace flightgear
70{
71 class View;
72}
73
77
79{
80
81private:
82
83 // properties, destroy last
84 SGPropertyNode_ptr props;
85
86 // localization
87 FGLocale* locale;
88
89 FGRenderer *renderer;
90 SGSubsystemMgr *subsystem_mgr;
91 SGEventMgr *event_mgr;
92
93 // Number of milliseconds elapsed since the start of the program.
94 double sim_time_sec;
95
96 // Root of FlightGear data tree
97 SGPath fg_root;
98
102 PathList additional_data_paths;
103
104 PathList _dataPathsAfterFGRoot;
105
106 // Users home directory for data
107 SGPath fg_home;
108
109 SGPath texture_cache_dir;
110 // Download directory
111 SGPath download_dir;
112 // Terrasync directory
113 SGPath terrasync_dir;
114
115 // Roots of FlightGear scenery tree
116 PathList fg_scenery;
117 // Paths Nasal is allowed to read
118 PathList extra_read_allowed_paths;
119
120 std::string browser;
121
122 // Time structure
123 SGTime *time_params;
124
125 // Material properties library
126 SGSharedPtr<SGMaterialLib> matlib;
127
128 SGCommandMgr *commands;
129
130 // list of serial port-like configurations
131 string_list *channel_options_list;
132
133 // A list of initial waypoints that are read from the command line
134 // and or flight-plan file during initialization
135 string_list *initial_waypoints;
136
137 // Navigational Aids
138 FGTACANList *channellist;
139
141 PathList fg_aircraft_dirs;
142 SGPath catalog_aircraft_dir;
143
144 bool haveUserSettings;
145
146 SGPropertyNode_ptr positionLon, positionLat, positionAlt;
147 SGPropertyNode_ptr viewLon, viewLat, viewAlt;
148 SGPropertyNode_ptr orientHeading, orientPitch, orientRoll;
149
150 SGPropertyNode_ptr referenceOffsetX, referenceOffsetY, referenceOffsetZ;
151
155 void initProperties();
156
157 void cleanupListeners();
158
159 typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
160 SGPropertyChangeListenerVec _listeners_to_cleanup;
161
162 SGSharedPtr<simgear::pkg::Root> _packageRoot;
163
164 SGSubsystem *get_subsystem (const char * name) const;
165
166public:
167
168 FGGlobals();
169 virtual ~FGGlobals();
170
171 virtual FGRenderer *get_renderer () const;
172 void set_renderer(FGRenderer* render);
173
174 SGSubsystemMgr *get_subsystem_mgr () const;
175
176 template<class T>
177 T* get_subsystem() const
178 {
179 return dynamic_cast<T*>(get_subsystem(T::staticSubsystemClassId()));
180 }
181
182
183 SGEventMgr *get_event_mgr () const;
184
185 inline double get_sim_time_sec () const { return sim_time_sec; }
186 inline void inc_sim_time_sec (double dt) { sim_time_sec += dt; }
187 inline void set_sim_time_sec (double t) { sim_time_sec = t; }
188
189 const SGPath &get_fg_root () const { return fg_root; }
190 void set_fg_root(const SGPath&root);
191 void set_texture_cache_dir(const SGPath&textureCache);
192
197 PathList get_data_paths() const;
198
203 PathList get_data_paths(const std::string& suffix) const;
204
205 void append_data_path(const SGPath& path, bool afterFGRoot = false);
206
211 SGPath findDataPath(const std::string& pathSuffix) const;
212
213 const SGPath &get_fg_home () const { return fg_home; }
214 void set_fg_home (const SGPath &home);
215
216 const SGPath &get_download_dir () const { return download_dir; }
217 // The 'path' argument to set_download_dir() must come from trustworthy
218 // code, because the method grants read permissions to Nasal code for many
219 // files beneath 'path'. In particular, don't call this method with a
220 // 'path' value taken from the property tree or any other Nasal-writable
221 // place.
222 void set_download_dir (const SGPath &path);
223
224 const SGPath &get_texture_cache_dir() const { return texture_cache_dir; }
225
226 const SGPath &get_terrasync_dir () const { return terrasync_dir; }
227 // The 'path' argument to set_terrasync_dir() must come from trustworthy
228 // code, because the method grants read permissions to Nasal code for all
229 // files beneath 'path'. In particular, don't call this method with a
230 // 'path' value taken from the property tree or any other Nasal-writable
231 // place.
232 void set_terrasync_dir (const SGPath &path);
233
234 const PathList &get_fg_scenery () const { return fg_scenery; }
235 const PathList &get_extra_read_allowed_paths () const { return extra_read_allowed_paths; }
243 void append_fg_scenery (const SGPath &scenery);
244
245 void append_fg_scenery (const PathList &scenery);
246
247 void clear_fg_scenery();
248
257 void append_read_allowed_paths (const SGPath &path);
258
264 void set_catalog_aircraft_path(const SGPath& path);
265
274 void append_aircraft_path(const SGPath& path);
275 void append_aircraft_paths(const PathList& path);
276
285 SGPath resolve_aircraft_path(const std::string& branch) const;
286
291 SGPath resolve_maybe_aircraft_path(const std::string& branch) const;
292
300 SGPath resolve_resource_path(const std::string& branch) const;
301
302 inline const std::string &get_browser () const { return browser; }
303 void set_browser (const std::string &b) { browser = b; }
304
305 long int get_warp() const;
306 void set_warp( long int w );
307
308 long int get_warp_delta() const;
309 void set_warp_delta( long int d );
310
311 inline SGTime *get_time_params() const { return time_params; }
312 inline void set_time_params( SGTime *t ) { time_params = t; }
313
314 inline SGMaterialLib *get_matlib() const
315 {
316 return matlib;
317 }
318 void set_matlib( SGMaterialLib *m );
319
320 inline SGPropertyNode *get_props () { return props; }
321
326 void resetPropertyRoot();
327
328 inline FGLocale* get_locale () { return locale; }
329
330 inline SGCommandMgr *get_commands () { return commands; }
331
332 SGGeod get_aircraft_position() const;
333
334 SGVec3d get_aircraft_position_cart() const;
335
336 void get_aircraft_orientation(double& heading, double& pitch, double& roll);
337
338 SGGeod get_view_position() const;
339
340 SGVec3d get_view_position_cart() const;
341
343
345 return channel_options_list;
346 }
348 channel_options_list = l;
349 }
350
352 return initial_waypoints;
353 }
354
355 inline void set_initial_waypoints (string_list *list) {
356 initial_waypoints = list;
357 }
358
359 FGViewMgr *get_viewmgr() const;
361
362 FGControls *get_controls() const;
363
364 FGScenery * get_scenery () const;
365
366 inline FGTACANList *get_channellist() const { return channellist; }
367 inline void set_channellist( FGTACANList *c ) { channellist = c; }
368
373 SGPath autosaveFilePath(SGPath userDataPath = SGPath()) const;
378 void loadUserSettings(SGPath userDatapath = SGPath());
379
391 void saveUserSettings(SGPath userDatapath = SGPath());
392
393 void addListenerToCleanup(SGPropertyChangeListener* l);
394
395 simgear::pkg::Root* packageRoot();
396 void setPackageRoot(const SGSharedPtr<simgear::pkg::Root>& p);
397
401 bool is_headless();
402 void set_headless(bool mode);
403};
404
405
406extern FGGlobals *globals;
407
408
409#endif // _GLOBALS_HXX
#define p(x)
Bucket for subsystem pointers representing the sim's state.
Definition globals.hxx:79
flightgear::View * get_current_view() const
Definition globals.cxx:960
void set_catalog_aircraft_path(const SGPath &path)
specify a path we'll prepend to the aircraft paths list if non-empty.
Definition globals.cxx:508
void setPackageRoot(const SGSharedPtr< simgear::pkg::Root > &p)
Definition globals.cxx:997
simgear::pkg::Root * packageRoot()
Definition globals.cxx:992
SGPath resolve_maybe_aircraft_path(const std::string &branch) const
Same as above, but test for non 'Aircraft/' branch paths, and always resolve them against fg_root.
Definition globals.cxx:560
void set_warp_delta(long int d)
Definition globals.cxx:945
void set_time_params(SGTime *t)
Definition globals.hxx:312
void set_channel_options_list(string_list *l)
Definition globals.hxx:347
long int get_warp() const
Definition globals.cxx:930
string_list * get_initial_waypoints()
Definition globals.hxx:351
PathList get_aircraft_paths() const
Definition globals.cxx:513
void set_warp(long int w)
Definition globals.cxx:935
SGVec3d get_view_position_cart() const
Definition globals.cxx:640
void append_aircraft_path(const SGPath &path)
Add an aircraft directory.
Definition globals.cxx:524
void set_renderer(FGRenderer *render)
Definition globals.cxx:577
virtual FGRenderer * get_renderer() const
Definition globals.cxx:572
const SGPath & get_texture_cache_dir() const
Definition globals.hxx:224
SGTime * get_time_params() const
Definition globals.hxx:311
void append_fg_scenery(const SGPath &scenery)
Add a scenery directory.
Definition globals.cxx:380
void set_initial_waypoints(string_list *list)
Definition globals.hxx:355
SGGeod get_aircraft_position() const
Definition globals.cxx:611
void clear_fg_scenery()
Definition globals.cxx:458
void set_matlib(SGMaterialLib *m)
Definition globals.cxx:966
const SGPath & get_download_dir() const
Definition globals.hxx:216
void get_aircraft_orientation(double &heading, double &pitch, double &roll)
Definition globals.cxx:624
PathList get_data_paths() const
Get list of data locations.
Definition globals.cxx:308
void append_aircraft_paths(const PathList &path)
Definition globals.cxx:548
SGEventMgr * get_event_mgr() const
Definition globals.cxx:605
SGPath resolve_aircraft_path(const std::string &branch) const
Given a path to an aircraft-related resource file, resolve it against the appropriate root.
Definition globals.cxx:555
void set_download_dir(const SGPath &path)
Definition globals.cxx:468
FGControls * get_controls() const
Definition globals.cxx:971
SGSubsystemMgr * get_subsystem_mgr() const
Definition globals.cxx:589
void resetPropertyRoot()
reset the property tree to new, empty tree.
Definition globals.cxx:685
SGPropertyNode * get_props()
Definition globals.hxx:320
SGVec3d get_aircraft_position_cart() const
Definition globals.cxx:619
string_list * get_channel_options_list()
Definition globals.hxx:344
void set_fg_home(const SGPath &home)
Definition globals.cxx:293
bool is_headless()
A runtime headless mode for running without a GUI.
Definition globals.cxx:1002
SGVec3d get_ownship_reference_position_cart() const
Definition globals.cxx:644
virtual ~FGGlobals()
Definition globals.cxx:194
void loadUserSettings(SGPath userDatapath=SGPath())
Load user settings from the autosave file under 'userDataPath', which defaults to $FG_HOME.
Definition globals.cxx:860
const PathList & get_fg_scenery() const
Definition globals.hxx:234
FGLocale * get_locale()
Definition globals.hxx:328
SGGeod get_view_position() const
Definition globals.cxx:632
void append_read_allowed_paths(const SGPath &path)
Allow Nasal to read a path.
Definition globals.cxx:448
SGPath resolve_resource_path(const std::string &branch) const
Search in the following directories:
Definition globals.cxx:565
FGTACANList * get_channellist() const
Definition globals.hxx:366
void append_data_path(const SGPath &path, bool afterFGRoot=false)
Definition globals.cxx:329
FGScenery * get_scenery() const
Definition globals.cxx:950
void addListenerToCleanup(SGPropertyChangeListener *l)
Definition globals.cxx:976
void set_sim_time_sec(double t)
Definition globals.hxx:187
void set_terrasync_dir(const SGPath &path)
Definition globals.cxx:489
const SGPath & get_fg_home() const
Definition globals.hxx:213
SGPath autosaveFilePath(SGPath userDataPath=SGPath()) const
Return an SGPath instance for the autosave file under 'userDataPath', which defaults to $FG_HOME.
Definition globals.cxx:739
double get_sim_time_sec() const
Definition globals.hxx:185
const SGPath & get_fg_root() const
Definition globals.hxx:189
void set_fg_root(const SGPath &root)
Definition globals.cxx:265
void inc_sim_time_sec(double dt)
Definition globals.hxx:186
SGCommandMgr * get_commands()
Definition globals.hxx:330
const std::string & get_browser() const
Definition globals.hxx:302
void saveUserSettings(SGPath userDatapath=SGPath())
Save user settings to the autosave file under 'userDataPath', which defaults to $FG_HOME.
Definition globals.cxx:902
SGMaterialLib * get_matlib() const
Definition globals.hxx:314
T * get_subsystem() const
Definition globals.hxx:177
long int get_warp_delta() const
Definition globals.cxx:940
const PathList & get_extra_read_allowed_paths() const
Definition globals.hxx:235
SGPath findDataPath(const std::string &pathSuffix) const
Given a path suffix (eg 'Textures' or 'AI/Traffic'), find the first data directory which defines it.
Definition globals.cxx:348
void set_browser(const std::string &b)
Definition globals.hxx:303
FGViewMgr * get_viewmgr() const
Definition globals.cxx:955
void set_headless(bool mode)
Definition globals.cxx:1007
void set_texture_cache_dir(const SGPath &textureCache)
Definition globals.cxx:298
void set_channellist(FGTACANList *c)
Definition globals.hxx:367
const SGPath & get_terrasync_dir() const
Definition globals.hxx:226
Top level route manager class.
Definition route_mgr.hxx:27
const char * name
FGGlobals * globals
Definition globals.cxx:142
std::vector< SGPath > PathList
Definition globals.hxx:37
std::vector< std::string > string_list
Definition globals.hxx:36
FlightPlan.hxx - defines a full flight-plan object, including departure, cruise, arrival information ...
Definition Addon.cxx:53