]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
672065f45a2d0e69339ea0568d2b74789c0e1e95
[flightgear.git] / src / Main / fg_commands.cxx
1 // fg_commands.cxx - internal FGFS commands.
2
3 #ifdef HAVE_CONFIG_H
4 #  include "config.h"
5 #endif
6
7 #include <string.h>             // strcmp()
8
9 #include <simgear/compiler.h>
10
11 #include <string>
12 #include <fstream>
13
14 #include <simgear/sg_inlines.h>
15 #include <simgear/debug/logstream.hxx>
16 #include <simgear/math/sg_random.h>
17 #include <simgear/scene/material/mat.hxx>
18 #include <simgear/scene/material/matlib.hxx>
19 #include <simgear/structure/exception.hxx>
20 #include <simgear/structure/commands.hxx>
21 #include <simgear/props/props.hxx>
22 #include <simgear/structure/event_mgr.hxx>
23 #include <simgear/sound/soundmgr_openal.hxx>
24 #include <simgear/timing/sg_time.hxx>
25
26 #include <Cockpit/panel.hxx>
27 #include <Cockpit/panel_io.hxx>
28 #include <FDM/flight.hxx>
29 #include <GUI/gui.h>
30 #include <GUI/new_gui.hxx>
31 #include <GUI/dialog.hxx>
32 #include <Aircraft/replay.hxx>
33 #include <Scenery/scenery.hxx>
34 #include <Scripting/NasalSys.hxx>
35 #include <Sound/sample_queue.hxx>
36 #include <Time/sunsolver.hxx>
37
38 #include "fg_init.hxx"
39 #include "fg_io.hxx"
40 #include "fg_os.hxx"
41 #include "fg_commands.hxx"
42 #include "fg_props.hxx"
43 #include "globals.hxx"
44 #include "logger.hxx"
45 #include "util.hxx"
46 #include "viewmgr.hxx"
47 #include "main.hxx"
48 #include <Main/viewer.hxx>
49 #include <Environment/presets.hxx>
50
51 using std::string;
52 using std::ifstream;
53 using std::ofstream;
54
55
56 \f
57 ////////////////////////////////////////////////////////////////////////
58 // Static helper functions.
59 ////////////////////////////////////////////////////////////////////////
60
61
62 static inline SGPropertyNode *
63 get_prop (const SGPropertyNode * arg)
64 {
65     return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
66 }
67
68 static inline SGPropertyNode *
69 get_prop2 (const SGPropertyNode * arg)
70 {
71     return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
72 }
73
74
75 /**
76  * Get a double value and split it as required.
77  */
78 static void
79 split_value (double full_value, const char * mask,
80              double * unmodifiable, double * modifiable)
81 {
82     if (!strcmp("integer", mask)) {
83         *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
84         *unmodifiable = full_value - *modifiable;
85     } else if (!strcmp("decimal", mask)) {
86         *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
87         *modifiable = full_value - *unmodifiable;
88     } else {
89         if (strcmp("all", mask))
90             SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
91                    << " assuming 'all'");
92         *unmodifiable = 0;
93         *modifiable = full_value;
94     }
95 }
96
97
98 /**
99  * Clamp or wrap a value as specified.
100  */
101 static void
102 limit_value (double * value, const SGPropertyNode * arg)
103 {
104     const SGPropertyNode * min_node = arg->getChild("min");
105     const SGPropertyNode * max_node = arg->getChild("max");
106
107     bool wrap = arg->getBoolValue("wrap");
108
109     if (min_node == 0 || max_node == 0)
110         wrap = false;
111   
112     if (wrap) {                 // wrap such that min <= x < max
113         double min_val = min_node->getDoubleValue();
114         double max_val = max_node->getDoubleValue();
115         double resolution = arg->getDoubleValue("resolution");
116         if (resolution > 0.0) {
117             // snap to (min + N*resolution), taking special care to handle imprecision
118             int n = (int)floor((*value - min_val) / resolution + 0.5);
119             int steps = (int)floor((max_val - min_val) / resolution + 0.5);
120             SG_NORMALIZE_RANGE(n, 0, steps);
121             *value = min_val + resolution * n;
122         } else {
123             // plain circular wrapping
124             SG_NORMALIZE_RANGE(*value, min_val, max_val);
125         }
126     } else {                    // clamp such that min <= x <= max
127         if ((min_node != 0) && (*value < min_node->getDoubleValue()))
128             *value = min_node->getDoubleValue();
129         else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
130             *value = max_node->getDoubleValue();
131     }
132 }
133
134 static bool
135 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
136 {
137     switch (value1->getType()) {
138     case simgear::props::BOOL:
139         return (value1->getBoolValue() == value2->getBoolValue());
140     case simgear::props::INT:
141         return (value1->getIntValue() == value2->getIntValue());
142     case simgear::props::LONG:
143         return (value1->getLongValue() == value2->getLongValue());
144     case simgear::props::FLOAT:
145         return (value1->getFloatValue() == value2->getFloatValue());
146     case simgear::props::DOUBLE:
147         return (value1->getDoubleValue() == value2->getDoubleValue());
148     default:
149         return !strcmp(value1->getStringValue(), value2->getStringValue());
150     }
151 }
152
153
154 \f
155 ////////////////////////////////////////////////////////////////////////
156 // Command implementations.
157 ////////////////////////////////////////////////////////////////////////
158
159
160 /**
161  * Built-in command: do nothing.
162  */
163 static bool
164 do_null (const SGPropertyNode * arg)
165 {
166   return true;
167 }
168
169 /**
170  * Built-in command: run a Nasal script.
171  */
172 static bool
173 do_nasal (const SGPropertyNode * arg)
174 {
175     return ((FGNasalSys*)globals->get_subsystem("nasal"))->handleCommand(arg);
176 }
177
178 /**
179  * Built-in command: exit FlightGear.
180  *
181  * status: the exit status to return to the operating system (defaults to 0)
182  */
183 static bool
184 do_exit (const SGPropertyNode * arg)
185 {
186     SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
187     fgSetBool("/sim/signals/exit", true);
188
189     if (fgGetBool("/sim/startup/save-on-exit")) {
190 #ifdef _WIN32
191         char* envp = ::getenv( "APPDATA" );
192         if ( envp != NULL ) {
193             SGPath config( envp );
194             config.append( "flightgear.org" );
195 #else
196         if ( homedir != NULL ) {
197             SGPath config( homedir );
198             config.append( ".fgfs" );
199 #endif
200             config.append( "autosave.xml" );
201             config.create_dir( 0700 );
202             SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << config.str());
203             try {
204                 writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE);
205             } catch (const sg_exception &e) {
206                 guiErrorMessage("Error writing autosave.xml: ", e);
207             }
208
209             SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings");
210         }
211     }
212     
213     fgOSExit(arg->getIntValue("status", 0));
214     return true;
215 }
216
217
218 /**
219  * Reset FlightGear (Shift-Escape or Menu->File->Reset)
220  */
221 static bool
222 do_reset (const SGPropertyNode * arg)
223 {
224     fgReInitSubsystems();
225     return true;
226 }
227
228
229 /**
230  * Built-in command: reinitialize one or more subsystems.
231  *
232  * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
233  * none is specified, reinitialize all of them.
234  */
235 static bool
236 do_reinit (const SGPropertyNode * arg)
237 {
238     bool result = true;
239
240     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
241     if (subsystems.size() == 0) {
242         globals->get_subsystem_mgr()->reinit();
243     } else {
244         for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
245             const char * name = subsystems[i]->getStringValue();
246             SGSubsystem * subsystem = globals->get_subsystem(name);
247             if (subsystem == 0) {
248                 result = false;
249                 SG_LOG( SG_GENERAL, SG_ALERT,
250                         "Subsystem " << name << " not found" );
251             } else {
252                 subsystem->reinit();
253             }
254         }
255     }
256
257     globals->get_event_mgr()->reinit();
258
259     return result;
260 }
261
262 #if 0
263   //
264   // these routines look useful ??? but are never used in the code ???
265   //
266
267 /**
268  * Built-in command: suspend one or more subsystems.
269  *
270  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
271  */
272 static bool
273 do_suspend (const SGPropertyNode * arg)
274 {
275     bool result = true;
276
277     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
278     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
279         const char * name = subsystems[i]->getStringValue();
280         SGSubsystem * subsystem = globals->get_subsystem(name);
281         if (subsystem == 0) {
282             result = false;
283             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
284         } else {
285             subsystem->suspend();
286         }
287     }
288     return result;
289 }
290
291 /**
292  * Built-in command: suspend one or more subsystems.
293  *
294  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
295  */
296 static bool
297 do_resume (const SGPropertyNode * arg)
298 {
299     bool result = true;
300
301     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
302     for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
303         const char * name = subsystems[i]->getStringValue();
304         SGSubsystem * subsystem = globals->get_subsystem(name);
305         if (subsystem == 0) {
306             result = false;
307             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
308         } else {
309             subsystem->resume();
310         }
311     }
312     return result;
313 }
314
315 #endif
316
317 static bool
318 do_pause (const SGPropertyNode * arg)
319 {
320     bool paused = fgGetBool("/sim/freeze/master",true);
321     fgSetBool("/sim/freeze/master",!paused);
322     fgSetBool("/sim/freeze/clock",!paused);
323     if (fgGetBool("/sim/freeze/replay-state",false))
324         fgSetBool("/sim/replay/disable",true);
325 }
326
327 /**
328  * Built-in command: load flight.
329  *
330  * file (optional): the name of the file to load (relative to current
331  *   directory).  Defaults to "fgfs.sav"
332  */
333 static bool
334 do_load (const SGPropertyNode * arg)
335 {
336     string file = arg->getStringValue("file", "fgfs.sav");
337     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
338         file += ".sav";
339
340     if (!fgValidatePath(file.c_str(), false)) {
341         SG_LOG(SG_IO, SG_ALERT, "load: reading '" << file << "' denied "
342                 "(unauthorized access)");
343         return false;
344     }
345
346     ifstream input(file.c_str());
347     if (input.good() && fgLoadFlight(input)) {
348         input.close();
349         SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
350         return true;
351     } else {
352         SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file);
353         return false;
354     }
355 }
356
357
358 /**
359  * Built-in command: save flight.
360  *
361  * file (optional): the name of the file to save (relative to the
362  * current directory).  Defaults to "fgfs.sav".
363  */
364 static bool
365 do_save (const SGPropertyNode * arg)
366 {
367     string file = arg->getStringValue("file", "fgfs.sav");
368     if (file.size() < 4 || file.substr(file.size() - 4) != ".sav")
369         file += ".sav";
370
371     if (!fgValidatePath(file.c_str(), false)) {
372         SG_LOG(SG_IO, SG_ALERT, "save: writing '" << file << "' denied "
373                 "(unauthorized access)");
374         return false;
375     }
376
377     bool write_all = arg->getBoolValue("write-all", false);
378     SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
379     ofstream output(file.c_str());
380     if (output.good() && fgSaveFlight(output, write_all)) {
381         output.close();
382         SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
383         return true;
384     } else {
385         SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
386         return false;
387     }
388 }
389
390
391 /**
392  * Built-in command: (re)load the panel.
393  *
394  * path (optional): the file name to load the panel from 
395  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
396  * and if that's unspecified, to "Panels/Default/default.xml".
397  */
398 static bool
399 do_panel_load (const SGPropertyNode * arg)
400 {
401   string panel_path =
402     arg->getStringValue("path", fgGetString("/sim/panel/path"));
403   if (panel_path.empty()) {
404     return false;
405   }
406   
407   FGPanel * new_panel = fgReadPanel(panel_path);
408   if (new_panel == 0) {
409     SG_LOG(SG_INPUT, SG_ALERT,
410            "Error reading new panel from " << panel_path);
411     return false;
412   }
413   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
414   globals->get_current_panel()->unbind();
415   delete globals->get_current_panel();
416   globals->set_current_panel( new_panel );
417   globals->get_current_panel()->bind();
418   return true;
419 }
420
421
422 /**
423  * Built-in command: pass a mouse click to the panel.
424  *
425  * button: the mouse button number, zero-based.
426  * is-down: true if the button is down, false if it is up.
427  * x-pos: the x position of the mouse click.
428  * y-pos: the y position of the mouse click.
429  */
430 static bool
431 do_panel_mouse_click (const SGPropertyNode * arg)
432 {
433   if (globals->get_current_panel() != 0)
434     return globals->get_current_panel()
435       ->doMouseAction(arg->getIntValue("button"),
436                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
437                       arg->getIntValue("x-pos"),
438                       arg->getIntValue("y-pos"));
439   else
440     return false;
441 }
442
443
444 /**
445  * Built-in command: (re)load preferences.
446  *
447  * path (optional): the file name to load the panel from (relative
448  * to FG_ROOT). Defaults to "preferences.xml".
449  */
450 static bool
451 do_preferences_load (const SGPropertyNode * arg)
452 {
453   try {
454     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
455                 globals->get_props());
456   } catch (const sg_exception &e) {
457     guiErrorMessage("Error reading global preferences: ", e);
458     return false;
459   }
460   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
461   return true;
462 }
463
464 static void
465 do_view_next( bool )
466 {
467     globals->get_current_view()->setHeadingOffset_deg(0.0);
468     globals->get_viewmgr()->next_view();
469 }
470
471 static void
472 do_view_prev( bool )
473 {
474     globals->get_current_view()->setHeadingOffset_deg(0.0);
475     globals->get_viewmgr()->prev_view();
476 }
477
478 /**
479  * Built-in command: cycle view.
480  */
481 static bool
482 do_view_cycle (const SGPropertyNode * arg)
483 {
484   globals->get_current_view()->setHeadingOffset_deg(0.0);
485   globals->get_viewmgr()->next_view();
486   return true;
487 }
488
489 /**
490  * Built-in command: capture screen.
491  */
492 static bool
493 do_screen_capture (const SGPropertyNode * arg)
494 {
495   return fgDumpSnapShot();
496 }
497
498 static bool
499 do_reload_shaders (const SGPropertyNode*)
500 {
501     simgear::reload_shaders();
502     return true;
503 }
504
505 static bool
506 do_dump_scene_graph (const SGPropertyNode*)
507 {
508     fgDumpSceneGraph();
509     return true;
510 }
511
512 static bool
513 do_dump_terrain_branch (const SGPropertyNode*)
514 {
515     fgDumpTerrainBranch();
516
517     double lon_deg = fgGetDouble("/position/longitude-deg");
518     double lat_deg = fgGetDouble("/position/latitude-deg");
519     SGGeod geodPos = SGGeod::fromDegFt(lon_deg, lat_deg, 0.0);
520     SGVec3d zero = SGVec3d::fromGeod(geodPos);
521
522     SG_LOG(SG_INPUT, SG_INFO, "Model parameters:");
523     SG_LOG(SG_INPUT, SG_INFO, "Center: " << zero.x() << ", " << zero.y() << ", " << zero.z() );
524     SG_LOG(SG_INPUT, SG_INFO, "Rotation: " << lat_deg << ", " << lon_deg );
525
526     return true;
527 }
528
529 static bool
530 do_print_visible_scene_info(const SGPropertyNode*)
531 {
532     fgPrintVisibleSceneInfoCommand();
533     return true;
534 }
535
536 /**
537  * Built-in command: hires capture screen.
538  */
539 static bool
540 do_hires_screen_capture (const SGPropertyNode * arg)
541 {
542   fgHiResDump();
543   return true;
544 }
545
546
547 /**
548  * Reload the tile cache.
549  */
550 static bool
551 do_tile_cache_reload (const SGPropertyNode * arg)
552 {
553     static const SGPropertyNode *master_freeze
554         = fgGetNode("/sim/freeze/master");
555     bool freeze = master_freeze->getBoolValue();
556     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
557     if ( !freeze ) {
558         fgSetBool("/sim/freeze/master", true);
559     }
560
561     globals->get_subsystem("tile-manager")->reinit();
562
563     if ( !freeze ) {
564         fgSetBool("/sim/freeze/master", false);
565     }
566     return true;
567 }
568
569
570 #if 0
571 These do_set_(some-environment-parameters) are deprecated and no longer 
572 useful/functional - Torsten Dreyer, January 2011
573 /**
574  * Set the sea level outside air temperature and assigning that to all
575  * boundary and aloft environment layers.
576  */
577 static bool
578 do_set_sea_level_degc ( double temp_sea_level_degc)
579 {
580     SGPropertyNode *node, *child;
581
582     // boundary layers
583     node = fgGetNode( "/environment/config/boundary" );
584     if ( node != NULL ) {
585       int i = 0;
586       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
587         child->setDoubleValue( "temperature-sea-level-degc",
588                                temp_sea_level_degc );
589         ++i;
590       }
591     }
592
593     // aloft layers
594     node = fgGetNode( "/environment/config/aloft" );
595     if ( node != NULL ) {
596       int i = 0;
597       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
598         child->setDoubleValue( "temperature-sea-level-degc",
599                                temp_sea_level_degc );
600         ++i;
601       }
602     }
603
604     return true;
605 }
606
607 static bool
608 do_set_sea_level_degc (const SGPropertyNode * arg)
609 {
610     return do_set_sea_level_degc( arg->getDoubleValue("temp-degc", 15.0) );
611 }
612
613
614 /**
615  * Set the outside air temperature at the "current" altitude by first
616  * calculating the corresponding sea level temp, and assigning that to
617  * all boundary and aloft environment layers.
618  */
619 static bool
620 do_set_oat_degc (const SGPropertyNode * arg)
621 {
622     double oat_degc = arg->getDoubleValue("temp-degc", 15.0);
623     // check for an altitude specified in the arguments, otherwise use
624     // current aircraft altitude.
625     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
626     if ( altitude_ft == NULL ) {
627         altitude_ft = fgGetNode("/position/altitude-ft");
628     }
629
630     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
631     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
632     dummy.set_temperature_degc( oat_degc );
633     return do_set_sea_level_degc( dummy.get_temperature_sea_level_degc());
634 }
635
636 /**
637  * Set the sea level outside air dewpoint and assigning that to all
638  * boundary and aloft environment layers.
639  */
640 static bool
641 do_set_dewpoint_sea_level_degc (double dewpoint_sea_level_degc)
642 {
643
644     SGPropertyNode *node, *child;
645
646     // boundary layers
647     node = fgGetNode( "/environment/config/boundary" );
648     if ( node != NULL ) {
649       int i = 0;
650       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
651         child->setDoubleValue( "dewpoint-sea-level-degc",
652                                dewpoint_sea_level_degc );
653         ++i;
654       }
655     }
656
657     // aloft layers
658     node = fgGetNode( "/environment/config/aloft" );
659     if ( node != NULL ) {
660       int i = 0;
661       while ( ( child = node->getNode( "entry", i ) ) != NULL ) {
662         child->setDoubleValue( "dewpoint-sea-level-degc",
663                                dewpoint_sea_level_degc );
664         ++i;
665       }
666     }
667
668     return true;
669 }
670
671 static bool
672 do_set_dewpoint_sea_level_degc (const SGPropertyNode * arg)
673 {
674     return do_set_dewpoint_sea_level_degc(arg->getDoubleValue("dewpoint-degc", 5.0));
675 }
676
677 /**
678  * Set the outside air dewpoint at the "current" altitude by first
679  * calculating the corresponding sea level dewpoint, and assigning
680  * that to all boundary and aloft environment layers.
681  */
682 static bool
683 do_set_dewpoint_degc (const SGPropertyNode * arg)
684 {
685     double dewpoint_degc = arg->getDoubleValue("dewpoint-degc", 5.0);
686
687     // check for an altitude specified in the arguments, otherwise use
688     // current aircraft altitude.
689     const SGPropertyNode *altitude_ft = arg->getChild("altitude-ft");
690     if ( altitude_ft == NULL ) {
691         altitude_ft = fgGetNode("/position/altitude-ft");
692     }
693
694     FGEnvironment dummy;        // instantiate a dummy so we can leech a method
695     dummy.set_elevation_ft( altitude_ft->getDoubleValue() );
696     dummy.set_dewpoint_degc( dewpoint_degc );
697     return do_set_dewpoint_sea_level_degc(dummy.get_dewpoint_sea_level_degc());
698 }
699 #endif
700 /**
701  * Update the lighting manually.
702  */
703 static bool
704 do_timeofday (const SGPropertyNode * arg)
705 {
706     const string &offset_type = arg->getStringValue("timeofday", "noon");
707
708     static const SGPropertyNode *longitude
709         = fgGetNode("/position/longitude-deg");
710     static const SGPropertyNode *latitude
711         = fgGetNode("/position/latitude-deg");
712
713     int orig_warp = globals->get_warp();
714     SGTime *t = globals->get_time_params();
715     time_t cur_time = t->get_cur_time();
716     // cout << "cur_time = " << cur_time << endl;
717     // cout << "orig_warp = " << orig_warp << endl;
718
719     int warp = 0;
720     if ( offset_type == "real" ) {
721         warp = -orig_warp;
722     } else if ( offset_type == "dawn" ) {
723         warp = fgTimeSecondsUntilSunAngle( cur_time,
724                                            longitude->getDoubleValue()
725                                              * SGD_DEGREES_TO_RADIANS,
726                                            latitude->getDoubleValue()
727                                              * SGD_DEGREES_TO_RADIANS,
728                                            90.0, true ); 
729     } else if ( offset_type == "morning" ) {
730         warp = fgTimeSecondsUntilSunAngle( cur_time,
731                                            longitude->getDoubleValue()
732                                              * SGD_DEGREES_TO_RADIANS,
733                                            latitude->getDoubleValue()
734                                              * SGD_DEGREES_TO_RADIANS,
735                                            75.0, true ); 
736     } else if ( offset_type == "noon" ) {
737         warp = fgTimeSecondsUntilSunAngle( cur_time,
738                                            longitude->getDoubleValue()
739                                              * SGD_DEGREES_TO_RADIANS,
740                                            latitude->getDoubleValue()
741                                              * SGD_DEGREES_TO_RADIANS,
742                                            0.0, true ); 
743     } else if ( offset_type == "afternoon" ) {
744         warp = fgTimeSecondsUntilSunAngle( cur_time,
745                                            longitude->getDoubleValue()
746                                              * SGD_DEGREES_TO_RADIANS,
747                                            latitude->getDoubleValue()
748                                              * SGD_DEGREES_TO_RADIANS,
749                                            60.0, false ); 
750      } else if ( offset_type == "dusk" ) {
751         warp = fgTimeSecondsUntilSunAngle( cur_time,
752                                            longitude->getDoubleValue()
753                                              * SGD_DEGREES_TO_RADIANS,
754                                            latitude->getDoubleValue()
755                                              * SGD_DEGREES_TO_RADIANS,
756                                            90.0, false ); 
757      } else if ( offset_type == "evening" ) {
758         warp = fgTimeSecondsUntilSunAngle( cur_time,
759                                            longitude->getDoubleValue()
760                                              * SGD_DEGREES_TO_RADIANS,
761                                            latitude->getDoubleValue()
762                                              * SGD_DEGREES_TO_RADIANS,
763                                            100.0, false ); 
764     } else if ( offset_type == "midnight" ) {
765         warp = fgTimeSecondsUntilSunAngle( cur_time,
766                                            longitude->getDoubleValue()
767                                              * SGD_DEGREES_TO_RADIANS,
768                                            latitude->getDoubleValue()
769                                              * SGD_DEGREES_TO_RADIANS,
770                                            180.0, false ); 
771     }
772     
773
774     fgSetInt("/sim/time/warp", orig_warp + warp);
775     
776     return true;
777 }
778
779
780 /**
781  * Built-in command: toggle a bool property value.
782  *
783  * property: The name of the property to toggle.
784  */
785 static bool
786 do_property_toggle (const SGPropertyNode * arg)
787 {
788   SGPropertyNode * prop = get_prop(arg);
789   return prop->setBoolValue(!prop->getBoolValue());
790 }
791
792
793 /**
794  * Built-in command: assign a value to a property.
795  *
796  * property: the name of the property to assign.
797  * value: the value to assign; or
798  * property[1]: the property to copy from.
799  */
800 static bool
801 do_property_assign (const SGPropertyNode * arg)
802 {
803   SGPropertyNode * prop = get_prop(arg);
804   const SGPropertyNode * prop2 = get_prop2(arg);
805   const SGPropertyNode * value = arg->getNode("value");
806
807   if (value != 0)
808       return prop->setUnspecifiedValue(value->getStringValue());
809   else if (prop2)
810       return prop->setUnspecifiedValue(prop2->getStringValue());
811   else
812       return false;
813 }
814
815
816 /**
817  * Built-in command: increment or decrement a property value.
818  *
819  * If the 'step' argument is present, it will be used; otherwise,
820  * the command uses 'offset' and 'factor', usually from the mouse.
821  *
822  * property: the name of the property to increment or decrement.
823  * step: the amount of the increment or decrement (default: 0).
824  * offset: offset from the current setting (used for the mouse; multiplied 
825  *         by factor)
826  * factor: scaling amount for the offset (defaults to 1).
827  * min: the minimum allowed value (default: no minimum).
828  * max: the maximum allowed value (default: no maximum).
829  * mask: 'integer' to apply only to the left of the decimal point, 
830  *       'decimal' to apply only to the right of the decimal point,
831  *       or 'all' to apply to the whole number (the default).
832  * wrap: true if the value should be wrapped when it passes min or max;
833  *       both min and max must be present for this to work (default:
834  *       false).
835  */
836 static bool
837 do_property_adjust (const SGPropertyNode * arg)
838 {
839   SGPropertyNode * prop = get_prop(arg);
840
841   double amount = 0;
842   if (arg->hasValue("step"))
843       amount = arg->getDoubleValue("step");
844   else
845       amount = (arg->getDoubleValue("factor", 1)
846                 * arg->getDoubleValue("offset"));
847           
848   double unmodifiable, modifiable;
849   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
850               &unmodifiable, &modifiable);
851   modifiable += amount;
852   limit_value(&modifiable, arg);
853
854   prop->setDoubleValue(unmodifiable + modifiable);
855
856   return true;
857 }
858
859
860 /**
861  * Built-in command: multiply a property value.
862  *
863  * property: the name of the property to multiply.
864  * factor: the amount by which to multiply.
865  * min: the minimum allowed value (default: no minimum).
866  * max: the maximum allowed value (default: no maximum).
867  * mask: 'integer' to apply only to the left of the decimal point, 
868  *       'decimal' to apply only to the right of the decimal point,
869  *       or 'all' to apply to the whole number (the default).
870  * wrap: true if the value should be wrapped when it passes min or max;
871  *       both min and max must be present for this to work (default:
872  *       false).
873  */
874 static bool
875 do_property_multiply (const SGPropertyNode * arg)
876 {
877   SGPropertyNode * prop = get_prop(arg);
878   double factor = arg->getDoubleValue("factor", 1);
879
880   double unmodifiable, modifiable;
881   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
882               &unmodifiable, &modifiable);
883   modifiable *= factor;
884   limit_value(&modifiable, arg);
885
886   prop->setDoubleValue(unmodifiable + modifiable);
887
888   return true;
889 }
890
891
892 /**
893  * Built-in command: swap two property values.
894  *
895  * property[0]: the name of the first property.
896  * property[1]: the name of the second property.
897  */
898 static bool
899 do_property_swap (const SGPropertyNode * arg)
900 {
901   SGPropertyNode * prop1 = get_prop(arg);
902   SGPropertyNode * prop2 = get_prop2(arg);
903
904                                 // FIXME: inefficient
905   const string & tmp = prop1->getStringValue();
906   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
907           prop2->setUnspecifiedValue(tmp.c_str()));
908 }
909
910
911 /**
912  * Built-in command: Set a property to an axis or other moving input.
913  *
914  * property: the name of the property to set.
915  * setting: the current input setting, usually between -1.0 and 1.0.
916  * offset: the offset to shift by, before applying the factor.
917  * factor: the factor to multiply by (use negative to reverse).
918  */
919 static bool
920 do_property_scale (const SGPropertyNode * arg)
921 {
922   SGPropertyNode * prop = get_prop(arg);
923   double setting = arg->getDoubleValue("setting");
924   double offset = arg->getDoubleValue("offset", 0.0);
925   double factor = arg->getDoubleValue("factor", 1.0);
926   bool squared = arg->getBoolValue("squared", false);
927   int power = arg->getIntValue("power", (squared ? 2 : 1));
928
929   int sign = (setting < 0 ? -1 : 1);
930
931   switch (power) {
932   case 1:
933       break;
934   case 2:
935       setting = setting * setting * sign;
936       break;
937   case 3:
938       setting = setting * setting * setting;
939       break;
940   case 4:
941       setting = setting * setting * setting * setting * sign;
942       break;
943   default:
944       setting =  pow(setting, power);
945       if ((power % 2) == 0)
946           setting *= sign;
947       break;
948   }
949
950   return prop->setDoubleValue((setting + offset) * factor);
951 }
952
953
954 /**
955  * Built-in command: cycle a property through a set of values.
956  *
957  * If the current value isn't in the list, the cycle will
958  * (re)start from the beginning.
959  *
960  * property: the name of the property to cycle.
961  * value[*]: the list of values to cycle through.
962  */
963 static bool
964 do_property_cycle (const SGPropertyNode * arg)
965 {
966     SGPropertyNode * prop = get_prop(arg);
967     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
968     int selection = -1;
969     int nSelections = values.size();
970
971     if (nSelections < 1) {
972         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
973         return false;
974     }
975
976                                 // Try to find the current selection
977     for (int i = 0; i < nSelections; i++) {
978         if (compare_values(prop, values[i])) {
979             selection = i + 1;
980             break;
981         }
982     }
983
984                                 // Default or wrap to the first selection
985     if (selection < 0 || selection >= nSelections)
986         selection = 0;
987
988     prop->setUnspecifiedValue(values[selection]->getStringValue());
989     return true;
990 }
991
992
993 /**
994  * Built-in command: randomize a numeric property value.
995  *
996  * property: the name of the property value to randomize.
997  * min: the minimum allowed value.
998  * max: the maximum allowed value.
999  */
1000 static bool
1001 do_property_randomize (const SGPropertyNode * arg)
1002 {
1003     SGPropertyNode * prop = get_prop(arg);
1004     double min = arg->getDoubleValue("min", DBL_MIN);
1005     double max = arg->getDoubleValue("max", DBL_MAX);
1006     prop->setDoubleValue(sg_random() * (max - min) + min);
1007     return true;
1008 }
1009
1010
1011 /**
1012  * Built-in command: reinit the data logging system based on the
1013  * current contents of the /logger tree.
1014  */
1015 static bool
1016 do_data_logging_commit (const SGPropertyNode * arg)
1017 {
1018     FGLogger *log = (FGLogger *)globals->get_subsystem("logger");
1019     log->reinit();
1020     return true;
1021 }
1022
1023 /**
1024  * Built-in command: Add a dialog to the GUI system.  Does *not*
1025  * display the dialog.  The property node should have the same format
1026  * as a dialog XML configuration.  It must include:
1027  *
1028  * name: the name of the GUI dialog for future reference.
1029  */
1030 static bool
1031 do_dialog_new (const SGPropertyNode * arg)
1032 {
1033     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1034
1035     // Note the casting away of const: this is *real*.  Doing a
1036     // "dialog-apply" command later on will mutate this property node.
1037     // I'm not convinced that this isn't the Right Thing though; it
1038     // allows client to create a node, pass it to dialog-new, and get
1039     // the values back from the dialog by reading the same node.
1040     // Perhaps command arguments are not as "const" as they would
1041     // seem?
1042     gui->newDialog((SGPropertyNode*)arg);
1043     return true;
1044 }
1045
1046 /**
1047  * Built-in command: Show an XML-configured dialog.
1048  *
1049  * dialog-name: the name of the GUI dialog to display.
1050  */
1051 static bool
1052 do_dialog_show (const SGPropertyNode * arg)
1053 {
1054     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1055     gui->showDialog(arg->getStringValue("dialog-name"));
1056     return true;
1057 }
1058
1059
1060 /**
1061  * Built-in Command: Hide the active XML-configured dialog.
1062  */
1063 static bool
1064 do_dialog_close (const SGPropertyNode * arg)
1065 {
1066     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1067     if(arg->hasValue("dialog-name"))
1068         return gui->closeDialog(arg->getStringValue("dialog-name"));
1069     return gui->closeActiveDialog();
1070 }
1071
1072
1073 /**
1074  * Update a value in the active XML-configured dialog.
1075  *
1076  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1077  */
1078 static bool
1079 do_dialog_update (const SGPropertyNode * arg)
1080 {
1081     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1082     FGDialog * dialog;
1083     if (arg->hasValue("dialog-name"))
1084         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1085     else
1086         dialog = gui->getActiveDialog();
1087
1088     if (dialog != 0) {
1089         dialog->updateValues(arg->getStringValue("object-name"));
1090         return true;
1091     } else {
1092         return false;
1093     }
1094 }
1095
1096
1097 /**
1098  * Apply a value in the active XML-configured dialog.
1099  *
1100  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
1101  */
1102 static bool
1103 do_dialog_apply (const SGPropertyNode * arg)
1104 {
1105     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1106     FGDialog * dialog;
1107     if (arg->hasValue("dialog-name"))
1108         dialog = gui->getDialog(arg->getStringValue("dialog-name"));
1109     else
1110         dialog = gui->getActiveDialog();
1111
1112     if (dialog != 0) {
1113         dialog->applyValues(arg->getStringValue("object-name"));
1114         return true;
1115     } else {
1116         return false;
1117     }
1118 }
1119
1120
1121 /**
1122  * Redraw GUI (applying new widget colors). Doesn't reload the dialogs,
1123  * unlike reinit().
1124  */
1125 static bool
1126 do_gui_redraw (const SGPropertyNode * arg)
1127 {
1128     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
1129     gui->redraw();
1130     return true;
1131 }
1132
1133
1134 /**
1135  * Adds model to the scenery. The path to the added branch (/models/model[*])
1136  * is returned in property "property".
1137  */
1138 static bool
1139 do_add_model (const SGPropertyNode * arg)
1140 {
1141     SGPropertyNode * model = fgGetNode("models", true);
1142     for (int i = 0;; i++) {
1143         if (i < 0)
1144             return false;
1145         if (!model->getChild("model", i, false)) {
1146             model = model->getChild("model", i, true);
1147             break;
1148         }
1149     }
1150     copyProperties(arg, model);
1151     if (model->hasValue("elevation-m"))
1152         model->setDoubleValue("elevation-ft", model->getDoubleValue("elevation-m")
1153                 * SG_METER_TO_FEET);
1154     model->getNode("load", true);
1155     model->removeChildren("load");
1156     const_cast<SGPropertyNode *>(arg)->setStringValue("property", model->getPath());
1157     return true;
1158 }
1159
1160
1161 /**
1162  * Set mouse cursor coordinates and cursor shape.
1163  */
1164 static bool
1165 do_set_cursor (const SGPropertyNode * arg)
1166 {
1167     if (arg->hasValue("x") || arg->hasValue("y")) {
1168         SGPropertyNode *mx = fgGetNode("/devices/status/mice/mouse/x", true);
1169         SGPropertyNode *my = fgGetNode("/devices/status/mice/mouse/y", true);
1170         int x = arg->getIntValue("x", mx->getIntValue());
1171         int y = arg->getIntValue("y", my->getIntValue());
1172         fgWarpMouse(x, y);
1173         mx->setIntValue(x);
1174         my->setIntValue(y);
1175     }
1176
1177     SGPropertyNode *cursor = const_cast<SGPropertyNode *>(arg)->getNode("cursor", true);
1178     if (cursor->getType() != simgear::props::NONE)
1179         fgSetMouseCursor(cursor->getIntValue());
1180
1181     cursor->setIntValue(fgGetMouseCursor());
1182     return true;
1183 }
1184
1185
1186 /**
1187  * Built-in command: play an audio message (i.e. a wav file) This is
1188  * fire and forget.  Call this once per message and it will get dumped
1189  * into a queue.  Messages are played sequentially so they do not
1190  * overlap.
1191  */
1192 static bool
1193 do_play_audio_sample (const SGPropertyNode * arg)
1194 {
1195     string path = arg->getStringValue("path");
1196     string file = arg->getStringValue("file");
1197     float volume = arg->getFloatValue("volume");
1198     // cout << "playing " << path << " / " << file << endl;
1199     try {
1200         static FGSampleQueue *queue = 0;
1201         if ( !queue ) {
1202            SGSoundMgr *smgr = globals->get_soundmgr();
1203            queue = new FGSampleQueue(smgr, "chatter");
1204            queue->tie_to_listener();
1205         }
1206
1207         SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
1208         msg->set_volume( volume );
1209         queue->add( msg );
1210
1211         return true;
1212
1213     } catch (const sg_io_exception&) {
1214         SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
1215                 "failed to load" << path << '/' << file);
1216         return false;
1217     }
1218 }
1219
1220 /**
1221  * Built-in command: commit presets (read from in /sim/presets/)
1222  */
1223 static bool
1224 do_presets_commit (const SGPropertyNode * arg)
1225 {
1226     if (fgGetBool("/sim/initialized", false)) {
1227       fgReInitSubsystems();
1228     } else {
1229       // Nasal can trigger this during initial init, which confuses
1230       // the logic in ReInitSubsystems, since initial state has not been
1231       // saved at that time. Short-circuit everything here.
1232       fgInitPosition();
1233     }
1234     
1235     return true;
1236 }
1237
1238 /**
1239  * Built-in command: set log level (0 ... 7)
1240  */
1241 static bool
1242 do_log_level (const SGPropertyNode * arg)
1243 {
1244    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
1245
1246    return true;
1247 }
1248
1249 /**
1250  * Built-in command: replay the FDR buffer
1251  */
1252 static bool
1253 do_replay (const SGPropertyNode * arg)
1254 {
1255     // freeze the fdm, resume from sim pause 
1256     fgSetInt( "/sim/freeze/replay-state", 1 );
1257     fgSetBool("/sim/freeze/master", 0 );
1258     fgSetBool("/sim/freeze/clock", 0 );
1259     fgSetDouble( "/sim/replay/time", -1 );
1260
1261     // cout << "start = " << r->get_start_time()
1262     //      << "  end = " << r->get_end_time() << endl;
1263
1264     return true;
1265 }
1266
1267 /*
1268 static bool
1269 do_decrease_visibility (const SGPropertyNode * arg)
1270 {
1271     Environment::Presets::VisibilitySingleton::instance()->adjust( 0.9 );
1272     return true;
1273 }
1274  
1275 static bool
1276 do_increase_visibility (const SGPropertyNode * arg)
1277 {
1278     Environment::Presets::VisibilitySingleton::instance()->adjust( 1.1 );
1279     return true;
1280 }
1281 */
1282 /**
1283  * An fgcommand to allow loading of xml files via nasal,
1284  * the xml file's structure will be made available within
1285  * a property tree node defined under argument "targetnode",
1286  * or in the given argument tree under "data" otherwise.
1287  *
1288  * @param filename a string to hold the complete path & filename of an XML file
1289  * @param targetnode a string pointing to a location within the property tree
1290  * where to store the parsed XML file. If <targetnode> is undefined, then the
1291  * file contents are stored under a node <data> in the argument tree.
1292  */
1293
1294 static bool
1295 do_load_xml_to_proptree(const SGPropertyNode * arg)
1296 {
1297     SGPath file(arg->getStringValue("filename"));
1298     if (file.str().empty())
1299         return false;
1300
1301     if (file.extension() != "xml")
1302         file.concat(".xml");
1303
1304     if (file.isRelative()) {
1305       file = globals->resolve_maybe_aircraft_path(file.str());
1306     }
1307
1308     if (!fgValidatePath(file.c_str(), false)) {
1309         SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file.str() << "' denied "
1310                 "(unauthorized access)");
1311         return false;
1312     }
1313
1314     SGPropertyNode *targetnode;
1315     if (arg->hasValue("targetnode"))
1316         targetnode = fgGetNode(arg->getStringValue("targetnode"), true);
1317     else
1318         targetnode = const_cast<SGPropertyNode *>(arg)->getNode("data", true);
1319
1320     try {
1321         readProperties(file.c_str(), targetnode, true);
1322     } catch (const sg_exception &e) {
1323         SG_LOG(SG_IO, SG_WARN, "loadxml: " << e.getFormattedMessage());
1324         return false;
1325     }
1326
1327     return true;
1328 }
1329
1330
1331 /**
1332  * An fgcommand to allow saving of xml files via nasal,
1333  * the file's structure will be determined based on what's
1334  * encountered in the passed (source) property tree node
1335  *
1336  * @param filename a string to hold the complete path & filename of the (new)
1337  * XML file
1338  * @param sourcenode a string pointing to a location within the property tree
1339  * where to find the nodes that should be written recursively into an XML file
1340  * @param data if no sourcenode is given, then the file contents are taken from
1341  * the argument tree's "data" node.
1342  */
1343
1344 static bool
1345 do_save_xml_from_proptree(const SGPropertyNode * arg)
1346 {
1347     SGPath file(arg->getStringValue("filename"));
1348     if (file.str().empty())
1349         return false;
1350
1351     if (file.extension() != "xml")
1352         file.concat(".xml");
1353
1354     if (!fgValidatePath(file.c_str(), true)) {
1355         SG_LOG(SG_IO, SG_ALERT, "savexml: writing to '" << file.str() << "' denied "
1356                 "(unauthorized access)");
1357         return false;
1358     }
1359
1360     SGPropertyNode *sourcenode;
1361     if (arg->hasValue("sourcenode"))
1362         sourcenode = fgGetNode(arg->getStringValue("sourcenode"), true);
1363     else if (arg->getNode("data", false))
1364         sourcenode = const_cast<SGPropertyNode *>(arg)->getNode("data");
1365     else
1366         return false;
1367
1368     try {
1369         writeProperties (file.c_str(), sourcenode, true);
1370     } catch (const sg_exception &e) {
1371         SG_LOG(SG_IO, SG_WARN, "savexml: " << e.getFormattedMessage());
1372         return false;
1373     }
1374
1375     return true;
1376 }
1377
1378 static bool
1379 do_press_cockpit_button (const SGPropertyNode *arg)
1380 {
1381   const char *prefix = arg->getStringValue("prefix");
1382
1383   if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1)
1384     return true;
1385
1386   string prop = string(prefix) + "-button";
1387   double value;
1388
1389   if (arg->getBoolValue("latching"))
1390     value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1;
1391   else
1392     value = 1;
1393
1394   fgSetDouble(prop.c_str(), value);
1395   fgSetBool(arg->getStringValue("discrete"), value > 0);
1396
1397   return true;
1398 }
1399
1400 static bool
1401 do_release_cockpit_button (const SGPropertyNode *arg)
1402 {
1403   const char *prefix = arg->getStringValue("prefix");
1404
1405   if (arg->getBoolValue("guarded")) {
1406     string prop = string(prefix) + "-guard";
1407     if (fgGetDouble(prop.c_str()) < 1) {
1408       fgSetDouble(prop.c_str(), 1);
1409       return true;
1410     }
1411   }
1412
1413   if (! arg->getBoolValue("latching")) {
1414     fgSetDouble((string(prefix) + "-button").c_str(), 0);
1415     fgSetBool(arg->getStringValue("discrete"), false);
1416   }
1417
1418   return true;
1419 }
1420
1421
1422 ////////////////////////////////////////////////////////////////////////
1423 // Command setup.
1424 ////////////////////////////////////////////////////////////////////////
1425
1426
1427 /**
1428  * Table of built-in commands.
1429  *
1430  * New commands do not have to be added here; any module in the application
1431  * can add a new command using globals->get_commands()->addCommand(...).
1432  */
1433 static struct {
1434   const char * name;
1435   SGCommandMgr::command_t command;
1436 } built_ins [] = {
1437     { "null", do_null },
1438     { "nasal", do_nasal },
1439     { "exit", do_exit },
1440     { "reset", do_reset },
1441     { "reinit", do_reinit },
1442     { "suspend", do_reinit },
1443     { "resume", do_reinit },
1444     { "pause", do_pause },
1445     { "load", do_load },
1446     { "save", do_save },
1447     { "panel-load", do_panel_load },
1448     { "panel-mouse-click", do_panel_mouse_click },
1449     { "preferences-load", do_preferences_load },
1450     { "view-cycle", do_view_cycle },
1451     { "screen-capture", do_screen_capture },
1452     { "hires-screen-capture", do_hires_screen_capture },
1453     { "tile-cache-reload", do_tile_cache_reload },
1454     /*
1455     { "set-sea-level-air-temp-degc", do_set_sea_level_degc },
1456     { "set-outside-air-temp-degc", do_set_oat_degc },
1457     { "set-dewpoint-sea-level-air-temp-degc", do_set_dewpoint_sea_level_degc },
1458     { "set-dewpoint-temp-degc", do_set_dewpoint_degc },
1459     */
1460     { "timeofday", do_timeofday },
1461     { "property-toggle", do_property_toggle },
1462     { "property-assign", do_property_assign },
1463     { "property-adjust", do_property_adjust },
1464     { "property-multiply", do_property_multiply },
1465     { "property-swap", do_property_swap },
1466     { "property-scale", do_property_scale },
1467     { "property-cycle", do_property_cycle },
1468     { "property-randomize", do_property_randomize },
1469     { "data-logging-commit", do_data_logging_commit },
1470     { "dialog-new", do_dialog_new },
1471     { "dialog-show", do_dialog_show },
1472     { "dialog-close", do_dialog_close },
1473     { "dialog-update", do_dialog_update },
1474     { "dialog-apply", do_dialog_apply },
1475     { "gui-redraw", do_gui_redraw },
1476     { "add-model", do_add_model },
1477     { "set-cursor", do_set_cursor },
1478     { "play-audio-sample", do_play_audio_sample },
1479     { "presets-commit", do_presets_commit },
1480     { "log-level", do_log_level },
1481     { "replay", do_replay },
1482     /*
1483     { "decrease-visibility", do_decrease_visibility },
1484     { "increase-visibility", do_increase_visibility },
1485     */
1486     { "loadxml", do_load_xml_to_proptree},
1487     { "savexml", do_save_xml_from_proptree },
1488     { "press-cockpit-button", do_press_cockpit_button },
1489     { "release-cockpit-button", do_release_cockpit_button },
1490     { "dump-scenegraph", do_dump_scene_graph },
1491     { "dump-terrainbranch", do_dump_terrain_branch },
1492     { "print-visible-scene", do_print_visible_scene_info },
1493     { "reload-shaders", do_reload_shaders },
1494     { 0, 0 }                    // zero-terminated
1495 };
1496
1497
1498 /**
1499  * Initialize the default built-in commands.
1500  *
1501  * Other commands may be added by other parts of the application.
1502  */
1503 void
1504 fgInitCommands ()
1505 {
1506   SG_LOG(SG_GENERAL, SG_BULK, "Initializing basic built-in commands:");
1507   for (int i = 0; built_ins[i].name != 0; i++) {
1508     SG_LOG(SG_GENERAL, SG_BULK, "  " << built_ins[i].name);
1509     globals->get_commands()->addCommand(built_ins[i].name,
1510                                         built_ins[i].command);
1511   }
1512
1513   typedef bool (*dummy)();
1514   fgTie( "/command/view/next", dummy(0), do_view_next );
1515   fgTie( "/command/view/prev", dummy(0), do_view_prev );
1516 }
1517
1518 // end of fg_commands.cxx