]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
Wire frame mode got broke somehow. This seems to fix it.
[flightgear.git] / src / Main / fg_commands.cxx
1 // fg_commands.cxx - internal FGFS commands.
2
3 #include <string.h>             // strcmp()
4
5 #include <simgear/compiler.h>
6 #include <simgear/misc/exception.hxx>
7
8 #include STL_STRING
9 #include STL_FSTREAM
10
11 #include <simgear/debug/logstream.hxx>
12 #include <simgear/misc/commands.hxx>
13 #include <simgear/misc/props.hxx>
14 #include <simgear/sg_inlines.h>
15
16 #include <Cockpit/panel.hxx>
17 #include <Cockpit/panel_io.hxx>
18 #include <FDM/flight.hxx>
19 #include <GUI/gui.h>
20 #include <GUI/new_gui.hxx>
21 #include <GUI/dialog.hxx>
22 #include <Scenery/tilemgr.hxx>
23 #if defined(HAVE_PLIB_PSL)
24 #include <Scripting/scriptmgr.hxx>
25 #endif
26 #include <Time/tmp.hxx>
27
28 #include "fg_init.hxx"
29 #include "fg_commands.hxx"
30
31 SG_USING_STD(string);
32 SG_USING_STD(ifstream);
33 SG_USING_STD(ofstream);
34
35 #include "fg_props.hxx"
36 #include "fg_io.hxx"
37 #include "globals.hxx"
38 #include "util.hxx"
39 #include "viewmgr.hxx"
40
41
42 \f
43 ////////////////////////////////////////////////////////////////////////
44 // Static helper functions.
45 ////////////////////////////////////////////////////////////////////////
46
47
48 static inline SGPropertyNode *
49 get_prop (const SGPropertyNode * arg)
50 {
51     return fgGetNode(arg->getStringValue("property[0]", "/null"), true);
52 }
53
54 static inline SGPropertyNode *
55 get_prop2 (const SGPropertyNode * arg)
56 {
57     return fgGetNode(arg->getStringValue("property[1]", "/null"), true);
58 }
59
60
61 /**
62  * Get a double value and split it as required.
63  */
64 static void
65 split_value (double full_value, const char * mask,
66              double * unmodifiable, double * modifiable)
67 {
68     if (!strcmp("integer", mask)) {
69         *modifiable = (full_value < 0 ? ceil(full_value) : floor (full_value));
70         *unmodifiable = full_value - *modifiable;
71     } else if (!strcmp("decimal", mask)) {
72         *unmodifiable = (full_value < 0 ? ceil(full_value) : floor(full_value));
73         *modifiable = full_value - *unmodifiable;
74     } else {
75         if (strcmp("all", mask))
76             SG_LOG(SG_GENERAL, SG_ALERT, "Bad value " << mask << " for mask;"
77                    << " assuming 'all'");
78         *unmodifiable = 0;
79         *modifiable = full_value;
80     }
81 }
82
83
84 /**
85  * Clamp or wrap a value as specified.
86  */
87 static void
88 limit_value (double * value, const SGPropertyNode * arg)
89 {
90     const SGPropertyNode * min_node = arg->getChild("min");
91     const SGPropertyNode * max_node = arg->getChild("max");
92
93     bool wrap = arg->getBoolValue("wrap");
94
95     if (min_node == 0 || max_node == 0)
96         wrap = false;
97   
98     if (wrap) {                 // wrap such that min <= x < max
99         double min_val = min_node->getDoubleValue();
100         double max_val = max_node->getDoubleValue();
101         double resolution = arg->getDoubleValue("resolution");
102         if (resolution > 0.0) {
103             // snap to (min + N*resolution), taking special care to handle imprecision
104             int n = (int)floor((*value - min_val) / resolution + 0.5);
105             int steps = (int)floor((max_val - min_val) / resolution + 0.5);
106             SG_NORMALIZE_RANGE(n, 0, steps);
107             *value = min_val + resolution * n;
108         } else {
109             // plain circular wrapping
110             SG_NORMALIZE_RANGE(*value, min_val, max_val);
111         }
112     } else {                    // clamp such that min <= x <= max
113         if ((min_node != 0) && (*value < min_node->getDoubleValue()))
114             *value = min_node->getDoubleValue();
115         else if ((max_node != 0) && (*value > max_node->getDoubleValue()))
116             *value = max_node->getDoubleValue();
117     }
118 }
119
120 static bool
121 compare_values (SGPropertyNode * value1, SGPropertyNode * value2)
122 {
123     switch (value1->getType()) {
124     case SGPropertyNode::BOOL:
125         return (value1->getBoolValue() == value2->getBoolValue());
126     case SGPropertyNode::INT:
127         return (value1->getIntValue() == value2->getIntValue());
128     case SGPropertyNode::LONG:
129         return (value1->getLongValue() == value2->getLongValue());
130     case SGPropertyNode::FLOAT:
131         return (value1->getFloatValue() == value2->getFloatValue());
132     case SGPropertyNode::DOUBLE:
133         return (value1->getDoubleValue() == value2->getDoubleValue());
134     default:
135         return !strcmp(value1->getStringValue(), value2->getStringValue());
136     }
137 }
138
139
140 \f
141 ////////////////////////////////////////////////////////////////////////
142 // Command implementations.
143 ////////////////////////////////////////////////////////////////////////
144
145
146 /**
147  * Built-in command: do nothing.
148  */
149 static bool
150 do_null (const SGPropertyNode * arg)
151 {
152   return true;
153 }
154
155 #if defined(HAVE_PLIB_PSL)
156 /**
157  * Built-in command: run a PSL script.
158  *
159  * script: the PSL script to execute
160  */
161 static bool
162 do_script (const SGPropertyNode * arg)
163 {
164     FGScriptMgr * mgr = (FGScriptMgr *)globals->get_subsystem("scripting");
165     return mgr->run(arg->getStringValue("script"));
166 }
167 #endif // HAVE_PLIB_PSL
168
169
170 /**
171  * Built-in command: exit FlightGear.
172  *
173  * status: the exit status to return to the operating system (defaults to 0)
174  */
175 static bool
176 do_exit (const SGPropertyNode * arg)
177 {
178   SG_LOG(SG_INPUT, SG_INFO, "Program exit requested.");
179   fgExit(arg->getIntValue("status", 0));
180   return true;
181 }
182
183
184 /**
185  * Built-in command: reinitialize one or more subsystems.
186  *
187  * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
188  * none is specified, reinitialize all of them.
189  */
190 static bool
191 do_reinit (const SGPropertyNode * arg)
192 {
193     bool result = true;
194
195     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
196     if (subsystems.size() == 0)
197         globals->get_subsystem_mgr()->reinit();
198     else for (int i = 0; i < subsystems.size(); i++) {
199         const char * name = subsystems[i]->getStringValue();
200         FGSubsystem * subsystem = globals->get_subsystem(name);
201         if (subsystem == 0) {
202             result = false;
203             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
204         } else {
205             subsystem->reinit();
206         }
207     }
208     return result;
209 }
210
211
212 /**
213  * Built-in command: suspend one or more subsystems.
214  *
215  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
216  */
217 static bool
218 do_suspend (const SGPropertyNode * arg)
219 {
220     bool result = true;
221
222     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
223     for (int i = 0; i < subsystems.size(); i++) {
224         const char * name = subsystems[i]->getStringValue();
225         FGSubsystem * subsystem = globals->get_subsystem(name);
226         if (subsystem == 0) {
227             result = false;
228             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
229         } else {
230             subsystem->suspend();
231         }
232     }
233     return result;
234 }
235
236 /**
237  * Built-in command: suspend one or more subsystems.
238  *
239  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
240  */
241 static bool
242 do_resume (const SGPropertyNode * arg)
243 {
244     bool result = true;
245
246     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
247     for (int i = 0; i < subsystems.size(); i++) {
248         const char * name = subsystems[i]->getStringValue();
249         FGSubsystem * subsystem = globals->get_subsystem(name);
250         if (subsystem == 0) {
251             result = false;
252             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
253         } else {
254             subsystem->resume();
255         }
256     }
257     return result;
258 }
259
260
261 /**
262  * Built-in command: load flight.
263  *
264  * file (optional): the name of the file to load (relative to current
265  *   directory).  Defaults to "fgfs.sav"
266  */
267 static bool
268 do_load (const SGPropertyNode * arg)
269 {
270   const string &file = arg->getStringValue("file", "fgfs.sav");
271   ifstream input(file.c_str());
272   if (input.good() && fgLoadFlight(input)) {
273     input.close();
274     SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
275     return true;
276   } else {
277     SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight from " << file);
278     return false;
279   }
280 }
281
282
283 /**
284  * Built-in command: save flight.
285  *
286  * file (optional): the name of the file to save (relative to the
287  * current directory).  Defaults to "fgfs.sav".
288  */
289 static bool
290 do_save (const SGPropertyNode * arg)
291 {
292   const string &file = arg->getStringValue("file", "fgfs.sav");
293   bool write_all = arg->getBoolValue("write-all", false);
294   SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
295   ofstream output(file.c_str());
296   if (output.good() && fgSaveFlight(output, write_all)) {
297     output.close();
298     SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
299     return true;
300   } else {
301     SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
302     return false;
303   }
304 }
305
306
307 /**
308  * Built-in command: (re)load the panel.
309  *
310  * path (optional): the file name to load the panel from 
311  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
312  * and if that's unspecified, to "Panels/Default/default.xml".
313  */
314 static bool
315 do_panel_load (const SGPropertyNode * arg)
316 {
317   string panel_path =
318     arg->getStringValue("path",
319                         fgGetString("/sim/panel/path",
320                                     "Panels/Default/default.xml"));
321   FGPanel * new_panel = fgReadPanel(panel_path);
322   if (new_panel == 0) {
323     SG_LOG(SG_INPUT, SG_ALERT,
324            "Error reading new panel from " << panel_path);
325     return false;
326   }
327   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
328   current_panel->unbind();
329   delete current_panel;
330   current_panel = new_panel;
331   current_panel->bind();
332   return true;
333 }
334
335
336 /**
337  * Built-in command: pass a mouse click to the panel.
338  *
339  * button: the mouse button number, zero-based.
340  * is-down: true if the button is down, false if it is up.
341  * x-pos: the x position of the mouse click.
342  * y-pos: the y position of the mouse click.
343  */
344 static bool
345 do_panel_mouse_click (const SGPropertyNode * arg)
346 {
347   if (current_panel != 0)
348     return current_panel
349       ->doMouseAction(arg->getIntValue("button"),
350                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
351                       arg->getIntValue("x-pos"),
352                       arg->getIntValue("y-pos"));
353   else
354     return false;
355 }
356
357
358 /**
359  * Built-in command: (re)load preferences.
360  *
361  * path (optional): the file name to load the panel from (relative
362  * to FG_ROOT). Defaults to "preferences.xml".
363  */
364 static bool
365 do_preferences_load (const SGPropertyNode * arg)
366 {
367   try {
368     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
369                 globals->get_props());
370   } catch (const sg_exception &e) {
371     guiErrorMessage("Error reading global preferences: ", e);
372     return false;
373   }
374   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
375   return true;
376 }
377
378
379 static void
380 fix_hud_visibility()
381 {
382   if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
383       globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
384       if ( globals->get_viewmgr()->get_current() == 1 ) {
385           globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
386       }
387   }
388 }
389
390 static void
391 do_view_next( bool )
392 {
393     globals->get_current_view()->setHeadingOffset_deg(0.0);
394     globals->get_viewmgr()->next_view();
395     fix_hud_visibility();
396     globals->get_tile_mgr()->refresh_view_timestamps();
397 }
398
399 static void
400 do_view_prev( bool )
401 {
402     globals->get_current_view()->setHeadingOffset_deg(0.0);
403     globals->get_viewmgr()->prev_view();
404     fix_hud_visibility();
405     globals->get_tile_mgr()->refresh_view_timestamps();
406 }
407
408 /**
409  * Built-in command: cycle view.
410  */
411 static bool
412 do_view_cycle (const SGPropertyNode * arg)
413 {
414   globals->get_current_view()->setHeadingOffset_deg(0.0);
415   globals->get_viewmgr()->next_view();
416   fix_hud_visibility();
417   globals->get_tile_mgr()->refresh_view_timestamps();
418 //   fgReshape(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"));
419   return true;
420 }
421
422 /**
423  * Built-in command: capture screen.
424  */
425 static bool
426 do_screen_capture (const SGPropertyNode * arg)
427 {
428   fgDumpSnapShot();
429   return true;
430 }
431
432
433 /**
434  * Reload the tile cache.
435  */
436 static bool
437 do_tile_cache_reload (const SGPropertyNode * arg)
438 {
439     static const SGPropertyNode *master_freeze
440         = fgGetNode("/sim/freeze/master");
441     bool freeze = master_freeze->getBoolValue();
442     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
443     if ( !freeze ) {
444         fgSetBool("/sim/freeze/master", true);
445     }
446     // BusyCursor(0);
447     if ( globals->get_tile_mgr()->init() ) {
448         // Load the local scenery data
449         double visibility_meters = fgGetDouble("/environment/visibility-m");
450         globals->get_tile_mgr()->update( visibility_meters );
451     } else {
452         SG_LOG( SG_GENERAL, SG_ALERT, 
453                 "Error in Tile Manager initialization!" );
454         exit(-1);
455     }
456     // BusyCursor(1);
457     if ( !freeze ) {
458         fgSetBool("/sim/freeze/master", false);
459     }
460     return true;
461 }
462
463
464 /**
465  * Update the lighting manually.
466  */
467 static bool
468 do_lighting_update (const SGPropertyNode * arg)
469 {
470   fgUpdateSkyAndLightingParams();
471   return true;
472 }
473
474
475 /**
476  * Built-in command: toggle a bool property value.
477  *
478  * property: The name of the property to toggle.
479  */
480 static bool
481 do_property_toggle (const SGPropertyNode * arg)
482 {
483   SGPropertyNode * prop = get_prop(arg);
484   return prop->setBoolValue(!prop->getBoolValue());
485 }
486
487
488 /**
489  * Built-in command: assign a value to a property.
490  *
491  * property: the name of the property to assign.
492  * value: the value to assign; or
493  * property[1]: the property to copy from.
494  */
495 static bool
496 do_property_assign (const SGPropertyNode * arg)
497 {
498   SGPropertyNode * prop = get_prop(arg);
499   const SGPropertyNode * prop2 = get_prop2(arg);
500   const SGPropertyNode * value = arg->getNode("value");
501
502   if (value != 0)
503       return prop->setUnspecifiedValue(value->getStringValue());
504   else if (prop2)
505       return prop->setUnspecifiedValue(prop2->getStringValue());
506   else
507       return false;
508 }
509
510
511 /**
512  * Built-in command: increment or decrement a property value.
513  *
514  * If the 'step' argument is present, it will be used; otherwise,
515  * the command uses 'offset' and 'factor', usually from the mouse.
516  *
517  * property: the name of the property to increment or decrement.
518  * step: the amount of the increment or decrement (default: 0).
519  * offset: offset from the current setting (used for the mouse; multiplied 
520  *         by factor)
521  * factor: scaling amount for the offset (defaults to 1).
522  * min: the minimum allowed value (default: no minimum).
523  * max: the maximum allowed value (default: no maximum).
524  * mask: 'integer' to apply only to the left of the decimal point, 
525  *       'decimal' to apply only to the right of the decimal point,
526  *       or 'all' to apply to the whole number (the default).
527  * wrap: true if the value should be wrapped when it passes min or max;
528  *       both min and max must be present for this to work (default:
529  *       false).
530  */
531 static bool
532 do_property_adjust (const SGPropertyNode * arg)
533 {
534   SGPropertyNode * prop = get_prop(arg);
535
536   double amount = 0;
537   if (arg->hasValue("step"))
538       amount = arg->getDoubleValue("step");
539   else
540       amount = (arg->getDoubleValue("factor", 1)
541                 * arg->getDoubleValue("offset"));
542           
543   double unmodifiable, modifiable;
544   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
545               &unmodifiable, &modifiable);
546   modifiable += amount;
547   limit_value(&modifiable, arg);
548
549   prop->setDoubleValue(unmodifiable + modifiable);
550
551   return true;
552 }
553
554
555 /**
556  * Built-in command: multiply a property value.
557  *
558  * property: the name of the property to multiply.
559  * factor: the amount by which to multiply.
560  * min: the minimum allowed value (default: no minimum).
561  * max: the maximum allowed value (default: no maximum).
562  * mask: 'integer' to apply only to the left of the decimal point, 
563  *       'decimal' to apply only to the right of the decimal point,
564  *       or 'all' to apply to the whole number (the default).
565  * wrap: true if the value should be wrapped when it passes min or max;
566  *       both min and max must be present for this to work (default:
567  *       false).
568  */
569 static bool
570 do_property_multiply (const SGPropertyNode * arg)
571 {
572   SGPropertyNode * prop = get_prop(arg);
573   double factor = arg->getDoubleValue("factor", 1);
574
575   double unmodifiable, modifiable;
576   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
577               &unmodifiable, &modifiable);
578   modifiable *= factor;
579   limit_value(&modifiable, arg);
580
581   prop->setDoubleValue(unmodifiable + modifiable);
582
583   return true;
584 }
585
586
587 /**
588  * Built-in command: swap two property values.
589  *
590  * property[0]: the name of the first property.
591  * property[1]: the name of the second property.
592  */
593 static bool
594 do_property_swap (const SGPropertyNode * arg)
595 {
596   SGPropertyNode * prop1 = get_prop(arg);
597   SGPropertyNode * prop2 = get_prop2(arg);
598
599                                 // FIXME: inefficient
600   const string & tmp = prop1->getStringValue();
601   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
602           prop2->setUnspecifiedValue(tmp.c_str()));
603 }
604
605
606 /**
607  * Built-in command: Set a property to an axis or other moving input.
608  *
609  * property: the name of the property to set.
610  * setting: the current input setting, usually between -1.0 and 1.0.
611  * offset: the offset to shift by, before applying the factor.
612  * factor: the factor to multiply by (use negative to reverse).
613  */
614 static bool
615 do_property_scale (const SGPropertyNode * arg)
616 {
617   SGPropertyNode * prop = get_prop(arg);
618   double setting = arg->getDoubleValue("setting");
619   double offset = arg->getDoubleValue("offset", 0.0);
620   double factor = arg->getDoubleValue("factor", 1.0);
621   bool squared = arg->getBoolValue("squared", false);
622   int power = arg->getIntValue("power", (squared ? 2 : 1));
623
624   int sign = (setting < 0 ? -1 : 1);
625
626   switch (power) {
627   case 1:
628       break;
629   case 2:
630       setting = setting * setting * sign;
631       break;
632   case 3:
633       setting = setting * setting * setting;
634       break;
635   case 4:
636       setting = setting * setting * setting * setting * sign;
637       break;
638   default:
639       setting =  pow(setting, power);
640       if ((power % 2) == 0)
641           setting *= sign;
642       break;
643   }
644
645   return prop->setDoubleValue((setting + offset) * factor);
646 }
647
648
649 /**
650  * Built-in command: cycle a property through a set of values.
651  *
652  * If the current value isn't in the list, the cycle will
653  * (re)start from the beginning.
654  *
655  * property: the name of the property to cycle.
656  * value[*]: the list of values to cycle through.
657  */
658 static bool
659 do_property_cycle (const SGPropertyNode * arg)
660 {
661     SGPropertyNode * prop = get_prop(arg);
662     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
663     int selection = -1;
664     int nSelections = values.size();
665
666     if (nSelections < 1) {
667         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
668         return false;
669     }
670
671                                 // Try to find the current selection
672     for (int i = 0; i < nSelections; i++) {
673         if (compare_values(prop, values[i])) {
674             selection = i + 1;
675             break;
676         }
677     }
678
679                                 // Default or wrap to the first selection
680     if (selection < 0 || selection >= nSelections)
681         selection = 0;
682
683     prop->setUnspecifiedValue(values[selection]->getStringValue());
684     return true;
685 }
686
687
688 /**
689  * Built-in command: Show an XML-configured dialog.
690  *
691  * dialog-name: the name of the GUI dialog to display.
692  */
693 static bool
694 do_dialog_show (const SGPropertyNode * arg)
695 {
696     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
697     gui->showDialog(arg->getStringValue("dialog-name"));
698     return true;
699 }
700
701
702 /**
703  * Built-in Command: Hide the active XML-configured dialog.
704  */
705 static bool
706 do_dialog_close (const SGPropertyNode * arg)
707 {
708     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
709     gui->closeActiveDialog();
710 }
711
712
713 /**
714  * Update a value in the active XML-configured dialog.
715  *
716  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
717  */
718 static bool
719 do_dialog_update (const SGPropertyNode * arg)
720 {
721     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
722     FGDialog * dialog = gui->getActiveDialog();
723     if (dialog != 0) {
724         if (arg->hasValue("object-name")) {
725             dialog->updateValue(arg->getStringValue("object-name"));
726         } else {
727             dialog->updateValues();
728         }
729         return true;
730     } else {
731         return false;
732     }
733 }
734
735
736 /**
737  * Apply a value in the active XML-configured dialog.
738  *
739  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
740  */
741 static bool
742 do_dialog_apply (const SGPropertyNode * arg)
743 {
744     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
745     FGDialog * dialog = gui->getActiveDialog();
746     if (dialog != 0) {
747         if (arg->hasValue("object-name")) {
748             const char * name = arg->getStringValue("object-name");
749             dialog->applyValue(name);
750             dialog->updateValue(name);
751         } else {
752             dialog->applyValues();
753             dialog->updateValues();
754         }
755         return true;
756     } else {
757         return false;
758     }
759 }
760
761
762 /**
763  * Built-in command: commit presets (read from in /sim/presets/)
764  */
765 static bool
766 do_presets_commit (const SGPropertyNode * arg)
767 {
768     // unbind the current fdm state so property changes
769     // don't get lost when we subsequently delete this fdm
770     // and create a new one.
771     cur_fdm_state->unbind();
772         
773     // set position from presets
774     fgInitPosition();
775
776     // BusyCursor(0);
777     fgReInitSubsystems();
778
779     globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") );
780
781     if ( ! fgGetBool("/sim/presets/onground") ) {
782         fgSetBool( "/sim/freeze/master", true );
783         fgSetBool( "/sim/freeze/clock", true );
784     }
785
786     return true;
787 }
788
789
790 \f
791 ////////////////////////////////////////////////////////////////////////
792 // Command setup.
793 ////////////////////////////////////////////////////////////////////////
794
795
796 /**
797  * Table of built-in commands.
798  *
799  * New commands do not have to be added here; any module in the application
800  * can add a new command using globals->get_commands()->addCommand(...).
801  */
802 static struct {
803   const char * name;
804   SGCommandMgr::command_t command;
805 } built_ins [] = {
806     { "null", do_null },
807 #if defined(HAVE_PLIB_PSL)
808     { "script", do_script },
809 #endif // HAVE_PLIB_PSL
810     { "exit", do_exit },
811     { "reinit", do_reinit },
812     { "suspend", do_reinit },
813     { "resume", do_reinit },
814     { "load", do_load },
815     { "save", do_save },
816     { "panel-load", do_panel_load },
817     { "panel-mouse-click", do_panel_mouse_click },
818     { "preferences-load", do_preferences_load },
819     { "view-cycle", do_view_cycle },
820     { "screen-capture", do_screen_capture },
821     { "tile-cache-reload", do_tile_cache_reload },
822     { "lighting-update", do_lighting_update },
823     { "property-toggle", do_property_toggle },
824     { "property-assign", do_property_assign },
825     { "property-adjust", do_property_adjust },
826     { "property-multiply", do_property_multiply },
827     { "property-swap", do_property_swap },
828     { "property-scale", do_property_scale },
829     { "property-cycle", do_property_cycle },
830     { "dialog-show", do_dialog_show },
831     { "dialog-close", do_dialog_close },
832     { "dialog-show", do_dialog_show },
833     { "dialog-update", do_dialog_update },
834     { "dialog-apply", do_dialog_apply },
835     { "presets-commit", do_presets_commit },
836     { 0, 0 }                    // zero-terminated
837 };
838
839
840 /**
841  * Initialize the default built-in commands.
842  *
843  * Other commands may be added by other parts of the application.
844  */
845 void
846 fgInitCommands ()
847 {
848   SG_LOG(SG_GENERAL, SG_INFO, "Initializing basic built-in commands:");
849   for (int i = 0; built_ins[i].name != 0; i++) {
850     SG_LOG(SG_GENERAL, SG_INFO, "  " << built_ins[i].name);
851     globals->get_commands()->addCommand(built_ins[i].name,
852                                         built_ins[i].command);
853   }
854
855   typedef bool (*dummy)();
856   fgTie( "/command/view/next", dummy(0), do_view_next );
857   fgTie( "/command/view/prev", dummy(0), do_view_prev );
858 }
859
860 // end of fg_commands.cxx