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