]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_commands.cxx
Fix to use renamed /controls properties.
[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  * Built-in command: suspend one or more subsystems.
213  *
214  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
215  */
216 static bool
217 do_suspend (const SGPropertyNode * arg)
218 {
219     bool result = true;
220
221     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
222     for (int i = 0; i < subsystems.size(); i++) {
223         const char * name = subsystems[i]->getStringValue();
224         FGSubsystem * subsystem = globals->get_subsystem(name);
225         if (subsystem == 0) {
226             result = false;
227             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
228         } else {
229             subsystem->suspend();
230         }
231     }
232     return result;
233 }
234
235 /**
236  * Built-in command: suspend one or more subsystems.
237  *
238  * subsystem[*] - the name(s) of the subsystem(s) to suspend.
239  */
240 static bool
241 do_resume (const SGPropertyNode * arg)
242 {
243     bool result = true;
244
245     vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
246     for (int i = 0; i < subsystems.size(); i++) {
247         const char * name = subsystems[i]->getStringValue();
248         FGSubsystem * subsystem = globals->get_subsystem(name);
249         if (subsystem == 0) {
250             result = false;
251             SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << "not found");
252         } else {
253             subsystem->resume();
254         }
255     }
256     return result;
257 }
258
259
260 /**
261  * Built-in command: load flight.
262  *
263  * file (optional): the name of the file to load (relative to current
264  *   directory).  Defaults to "fgfs.sav"
265  */
266 static bool
267 do_load (const SGPropertyNode * arg)
268 {
269   const string &file = arg->getStringValue("file", "fgfs.sav");
270   ifstream input(file.c_str());
271   if (input.good() && fgLoadFlight(input)) {
272     input.close();
273     SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file);
274     return true;
275   } else {
276     SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight from " << file);
277     return false;
278   }
279 }
280
281
282 /**
283  * Built-in command: save flight.
284  *
285  * file (optional): the name of the file to save (relative to the
286  * current directory).  Defaults to "fgfs.sav".
287  */
288 static bool
289 do_save (const SGPropertyNode * arg)
290 {
291   const string &file = arg->getStringValue("file", "fgfs.sav");
292   bool write_all = arg->getBoolValue("write-all", false);
293   SG_LOG(SG_INPUT, SG_INFO, "Saving flight");
294   ofstream output(file.c_str());
295   if (output.good() && fgSaveFlight(output, write_all)) {
296     output.close();
297     SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file);
298     return true;
299   } else {
300     SG_LOG(SG_INPUT, SG_ALERT, "Cannot save flight to " << file);
301     return false;
302   }
303 }
304
305
306 /**
307  * Built-in command: (re)load the panel.
308  *
309  * path (optional): the file name to load the panel from 
310  * (relative to FG_ROOT).  Defaults to the value of /sim/panel/path,
311  * and if that's unspecified, to "Panels/Default/default.xml".
312  */
313 static bool
314 do_panel_load (const SGPropertyNode * arg)
315 {
316   string panel_path =
317     arg->getStringValue("path",
318                         fgGetString("/sim/panel/path",
319                                     "Panels/Default/default.xml"));
320   FGPanel * new_panel = fgReadPanel(panel_path);
321   if (new_panel == 0) {
322     SG_LOG(SG_INPUT, SG_ALERT,
323            "Error reading new panel from " << panel_path);
324     return false;
325   }
326   SG_LOG(SG_INPUT, SG_INFO, "Loaded new panel from " << panel_path);
327   globals->get_current_panel()->unbind();
328   delete globals->get_current_panel();
329   globals->set_current_panel( new_panel );
330   globals->get_current_panel()->bind();
331   return true;
332 }
333
334
335 /**
336  * Built-in command: pass a mouse click to the panel.
337  *
338  * button: the mouse button number, zero-based.
339  * is-down: true if the button is down, false if it is up.
340  * x-pos: the x position of the mouse click.
341  * y-pos: the y position of the mouse click.
342  */
343 static bool
344 do_panel_mouse_click (const SGPropertyNode * arg)
345 {
346   if (globals->get_current_panel() != 0)
347     return globals->get_current_panel()
348       ->doMouseAction(arg->getIntValue("button"),
349                       arg->getBoolValue("is-down") ? PU_DOWN : PU_UP,
350                       arg->getIntValue("x-pos"),
351                       arg->getIntValue("y-pos"));
352   else
353     return false;
354 }
355
356
357 /**
358  * Built-in command: (re)load preferences.
359  *
360  * path (optional): the file name to load the panel from (relative
361  * to FG_ROOT). Defaults to "preferences.xml".
362  */
363 static bool
364 do_preferences_load (const SGPropertyNode * arg)
365 {
366   try {
367     fgLoadProps(arg->getStringValue("path", "preferences.xml"),
368                 globals->get_props());
369   } catch (const sg_exception &e) {
370     guiErrorMessage("Error reading global preferences: ", e);
371     return false;
372   }
373   SG_LOG(SG_INPUT, SG_INFO, "Successfully read global preferences.");
374   return true;
375 }
376
377
378 static void
379 fix_hud_visibility()
380 {
381   if ( !strcmp(fgGetString("/sim/flight-model"), "ada") ) {
382       globals->get_props()->setBoolValue( "/sim/hud/visibility", true );
383       if ( globals->get_viewmgr()->get_current() == 1 ) {
384           globals->get_props()->setBoolValue( "/sim/hud/visibility", false );
385       }
386   }
387 }
388
389 static void
390 do_view_next( bool )
391 {
392     globals->get_current_view()->setHeadingOffset_deg(0.0);
393     globals->get_viewmgr()->next_view();
394     fix_hud_visibility();
395     globals->get_tile_mgr()->refresh_view_timestamps();
396 }
397
398 static void
399 do_view_prev( bool )
400 {
401     globals->get_current_view()->setHeadingOffset_deg(0.0);
402     globals->get_viewmgr()->prev_view();
403     fix_hud_visibility();
404     globals->get_tile_mgr()->refresh_view_timestamps();
405 }
406
407 /**
408  * Built-in command: cycle view.
409  */
410 static bool
411 do_view_cycle (const SGPropertyNode * arg)
412 {
413   globals->get_current_view()->setHeadingOffset_deg(0.0);
414   globals->get_viewmgr()->next_view();
415   fix_hud_visibility();
416   globals->get_tile_mgr()->refresh_view_timestamps();
417 //   fgReshape(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize"));
418   return true;
419 }
420
421 /**
422  * Built-in command: capture screen.
423  */
424 static bool
425 do_screen_capture (const SGPropertyNode * arg)
426 {
427   fgDumpSnapShot();
428   return true;
429 }
430
431
432 /**
433  * Reload the tile cache.
434  */
435 static bool
436 do_tile_cache_reload (const SGPropertyNode * arg)
437 {
438     static const SGPropertyNode *master_freeze
439         = fgGetNode("/sim/freeze/master");
440     bool freeze = master_freeze->getBoolValue();
441     SG_LOG(SG_INPUT, SG_INFO, "ReIniting TileCache");
442     if ( !freeze ) {
443         fgSetBool("/sim/freeze/master", true);
444     }
445     // BusyCursor(0);
446     if ( globals->get_tile_mgr()->init() ) {
447         // Load the local scenery data
448         double visibility_meters = fgGetDouble("/environment/visibility-m");
449         globals->get_tile_mgr()->update( visibility_meters );
450     } else {
451         SG_LOG( SG_GENERAL, SG_ALERT, 
452                 "Error in Tile Manager initialization!" );
453         exit(-1);
454     }
455     // BusyCursor(1);
456     if ( !freeze ) {
457         fgSetBool("/sim/freeze/master", false);
458     }
459     return true;
460 }
461
462
463 /**
464  * Update the lighting manually.
465  */
466 static bool
467 do_lighting_update (const SGPropertyNode * arg)
468 {
469   fgUpdateSkyAndLightingParams();
470   return true;
471 }
472
473
474 /**
475  * Built-in command: toggle a bool property value.
476  *
477  * property: The name of the property to toggle.
478  */
479 static bool
480 do_property_toggle (const SGPropertyNode * arg)
481 {
482   SGPropertyNode * prop = get_prop(arg);
483   return prop->setBoolValue(!prop->getBoolValue());
484 }
485
486
487 /**
488  * Built-in command: assign a value to a property.
489  *
490  * property: the name of the property to assign.
491  * value: the value to assign; or
492  * property[1]: the property to copy from.
493  */
494 static bool
495 do_property_assign (const SGPropertyNode * arg)
496 {
497   SGPropertyNode * prop = get_prop(arg);
498   const SGPropertyNode * prop2 = get_prop2(arg);
499   const SGPropertyNode * value = arg->getNode("value");
500
501   if (value != 0)
502       return prop->setUnspecifiedValue(value->getStringValue());
503   else if (prop2)
504       return prop->setUnspecifiedValue(prop2->getStringValue());
505   else
506       return false;
507 }
508
509
510 /**
511  * Built-in command: increment or decrement a property value.
512  *
513  * If the 'step' argument is present, it will be used; otherwise,
514  * the command uses 'offset' and 'factor', usually from the mouse.
515  *
516  * property: the name of the property to increment or decrement.
517  * step: the amount of the increment or decrement (default: 0).
518  * offset: offset from the current setting (used for the mouse; multiplied 
519  *         by factor)
520  * factor: scaling amount for the offset (defaults to 1).
521  * min: the minimum allowed value (default: no minimum).
522  * max: the maximum allowed value (default: no maximum).
523  * mask: 'integer' to apply only to the left of the decimal point, 
524  *       'decimal' to apply only to the right of the decimal point,
525  *       or 'all' to apply to the whole number (the default).
526  * wrap: true if the value should be wrapped when it passes min or max;
527  *       both min and max must be present for this to work (default:
528  *       false).
529  */
530 static bool
531 do_property_adjust (const SGPropertyNode * arg)
532 {
533   SGPropertyNode * prop = get_prop(arg);
534
535   double amount = 0;
536   if (arg->hasValue("step"))
537       amount = arg->getDoubleValue("step");
538   else
539       amount = (arg->getDoubleValue("factor", 1)
540                 * arg->getDoubleValue("offset"));
541           
542   double unmodifiable, modifiable;
543   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
544               &unmodifiable, &modifiable);
545   modifiable += amount;
546   limit_value(&modifiable, arg);
547
548   prop->setDoubleValue(unmodifiable + modifiable);
549
550   return true;
551 }
552
553
554 /**
555  * Built-in command: multiply a property value.
556  *
557  * property: the name of the property to multiply.
558  * factor: the amount by which to multiply.
559  * min: the minimum allowed value (default: no minimum).
560  * max: the maximum allowed value (default: no maximum).
561  * mask: 'integer' to apply only to the left of the decimal point, 
562  *       'decimal' to apply only to the right of the decimal point,
563  *       or 'all' to apply to the whole number (the default).
564  * wrap: true if the value should be wrapped when it passes min or max;
565  *       both min and max must be present for this to work (default:
566  *       false).
567  */
568 static bool
569 do_property_multiply (const SGPropertyNode * arg)
570 {
571   SGPropertyNode * prop = get_prop(arg);
572   double factor = arg->getDoubleValue("factor", 1);
573
574   double unmodifiable, modifiable;
575   split_value(prop->getDoubleValue(), arg->getStringValue("mask", "all"),
576               &unmodifiable, &modifiable);
577   modifiable *= factor;
578   limit_value(&modifiable, arg);
579
580   prop->setDoubleValue(unmodifiable + modifiable);
581
582   return true;
583 }
584
585
586 /**
587  * Built-in command: swap two property values.
588  *
589  * property[0]: the name of the first property.
590  * property[1]: the name of the second property.
591  */
592 static bool
593 do_property_swap (const SGPropertyNode * arg)
594 {
595   SGPropertyNode * prop1 = get_prop(arg);
596   SGPropertyNode * prop2 = get_prop2(arg);
597
598                                 // FIXME: inefficient
599   const string & tmp = prop1->getStringValue();
600   return (prop1->setUnspecifiedValue(prop2->getStringValue()) &&
601           prop2->setUnspecifiedValue(tmp.c_str()));
602 }
603
604
605 /**
606  * Built-in command: Set a property to an axis or other moving input.
607  *
608  * property: the name of the property to set.
609  * setting: the current input setting, usually between -1.0 and 1.0.
610  * offset: the offset to shift by, before applying the factor.
611  * factor: the factor to multiply by (use negative to reverse).
612  */
613 static bool
614 do_property_scale (const SGPropertyNode * arg)
615 {
616   SGPropertyNode * prop = get_prop(arg);
617   double setting = arg->getDoubleValue("setting");
618   double offset = arg->getDoubleValue("offset", 0.0);
619   double factor = arg->getDoubleValue("factor", 1.0);
620   bool squared = arg->getBoolValue("squared", false);
621   int power = arg->getIntValue("power", (squared ? 2 : 1));
622
623   int sign = (setting < 0 ? -1 : 1);
624
625   switch (power) {
626   case 1:
627       break;
628   case 2:
629       setting = setting * setting * sign;
630       break;
631   case 3:
632       setting = setting * setting * setting;
633       break;
634   case 4:
635       setting = setting * setting * setting * setting * sign;
636       break;
637   default:
638       setting =  pow(setting, power);
639       if ((power % 2) == 0)
640           setting *= sign;
641       break;
642   }
643
644   return prop->setDoubleValue((setting + offset) * factor);
645 }
646
647
648 /**
649  * Built-in command: cycle a property through a set of values.
650  *
651  * If the current value isn't in the list, the cycle will
652  * (re)start from the beginning.
653  *
654  * property: the name of the property to cycle.
655  * value[*]: the list of values to cycle through.
656  */
657 static bool
658 do_property_cycle (const SGPropertyNode * arg)
659 {
660     SGPropertyNode * prop = get_prop(arg);
661     vector<SGPropertyNode_ptr> values = arg->getChildren("value");
662     int selection = -1;
663     int nSelections = values.size();
664
665     if (nSelections < 1) {
666         SG_LOG(SG_GENERAL, SG_ALERT, "No values for property-cycle");
667         return false;
668     }
669
670                                 // Try to find the current selection
671     for (int i = 0; i < nSelections; i++) {
672         if (compare_values(prop, values[i])) {
673             selection = i + 1;
674             break;
675         }
676     }
677
678                                 // Default or wrap to the first selection
679     if (selection < 0 || selection >= nSelections)
680         selection = 0;
681
682     prop->setUnspecifiedValue(values[selection]->getStringValue());
683     return true;
684 }
685
686
687 /**
688  * Built-in command: Show an XML-configured dialog.
689  *
690  * dialog-name: the name of the GUI dialog to display.
691  */
692 static bool
693 do_dialog_show (const SGPropertyNode * arg)
694 {
695     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
696     gui->showDialog(arg->getStringValue("dialog-name"));
697     return true;
698 }
699
700
701 /**
702  * Built-in Command: Hide the active XML-configured dialog.
703  */
704 static bool
705 do_dialog_close (const SGPropertyNode * arg)
706 {
707     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
708     return gui->closeActiveDialog();
709 }
710
711
712 /**
713  * Update a value in the active XML-configured dialog.
714  *
715  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
716  */
717 static bool
718 do_dialog_update (const SGPropertyNode * arg)
719 {
720     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
721     FGDialog * dialog = gui->getActiveDialog();
722     if (dialog != 0) {
723         if (arg->hasValue("object-name")) {
724             dialog->updateValue(arg->getStringValue("object-name"));
725         } else {
726             dialog->updateValues();
727         }
728         return true;
729     } else {
730         return false;
731     }
732 }
733
734
735 /**
736  * Apply a value in the active XML-configured dialog.
737  *
738  * object-name: The name of the GUI object(s) (all GUI objects if omitted).
739  */
740 static bool
741 do_dialog_apply (const SGPropertyNode * arg)
742 {
743     NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
744     FGDialog * dialog = gui->getActiveDialog();
745     if (dialog != 0) {
746         if (arg->hasValue("object-name")) {
747             const char * name = arg->getStringValue("object-name");
748             dialog->applyValue(name);
749             dialog->updateValue(name);
750         } else {
751             dialog->applyValues();
752             dialog->updateValues();
753         }
754         return true;
755     } else {
756         return false;
757     }
758 }
759
760
761 /**
762  * Built-in command: commit presets (read from in /sim/presets/)
763  */
764 static bool
765 do_presets_commit (const SGPropertyNode * arg)
766 {
767     // unbind the current fdm state so property changes
768     // don't get lost when we subsequently delete this fdm
769     // and create a new one.
770     cur_fdm_state->unbind();
771         
772     // set position from presets
773     fgInitPosition();
774
775     // BusyCursor(0);
776     fgReInitSubsystems();
777
778     globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") );
779
780 #if 0
781     if ( ! fgGetBool("/sim/presets/onground") ) {
782         fgSetBool( "/sim/freeze/master", true );
783         fgSetBool( "/sim/freeze/clock", true );
784     }
785 #endif
786
787     return true;
788 }
789
790 /**
791  * Built-in command: set log level (0 ... 7)
792  */
793 static bool
794 do_log_level (const SGPropertyNode * arg)
795 {
796    sglog().setLogLevels( SG_ALL, (sgDebugPriority)arg->getIntValue() );
797
798    return true;
799 }
800
801
802
803 \f
804 ////////////////////////////////////////////////////////////////////////
805 // Command setup.
806 ////////////////////////////////////////////////////////////////////////
807
808
809 /**
810  * Table of built-in commands.
811  *
812  * New commands do not have to be added here; any module in the application
813  * can add a new command using globals->get_commands()->addCommand(...).
814  */
815 static struct {
816   const char * name;
817   SGCommandMgr::command_t command;
818 } built_ins [] = {
819     { "null", do_null },
820 #if defined(HAVE_PLIB_PSL)
821     { "script", do_script },
822 #endif // HAVE_PLIB_PSL
823     { "exit", do_exit },
824     { "reinit", do_reinit },
825     { "suspend", do_reinit },
826     { "resume", do_reinit },
827     { "load", do_load },
828     { "save", do_save },
829     { "panel-load", do_panel_load },
830     { "panel-mouse-click", do_panel_mouse_click },
831     { "preferences-load", do_preferences_load },
832     { "view-cycle", do_view_cycle },
833     { "screen-capture", do_screen_capture },
834     { "tile-cache-reload", do_tile_cache_reload },
835     { "lighting-update", do_lighting_update },
836     { "property-toggle", do_property_toggle },
837     { "property-assign", do_property_assign },
838     { "property-adjust", do_property_adjust },
839     { "property-multiply", do_property_multiply },
840     { "property-swap", do_property_swap },
841     { "property-scale", do_property_scale },
842     { "property-cycle", do_property_cycle },
843     { "dialog-show", do_dialog_show },
844     { "dialog-close", do_dialog_close },
845     { "dialog-show", do_dialog_show },
846     { "dialog-update", do_dialog_update },
847     { "dialog-apply", do_dialog_apply },
848     { "presets-commit", do_presets_commit },
849     { "log-level", do_log_level },
850     { 0, 0 }                    // zero-terminated
851 };
852
853
854 /**
855  * Initialize the default built-in commands.
856  *
857  * Other commands may be added by other parts of the application.
858  */
859 void
860 fgInitCommands ()
861 {
862   SG_LOG(SG_GENERAL, SG_INFO, "Initializing basic built-in commands:");
863   for (int i = 0; built_ins[i].name != 0; i++) {
864     SG_LOG(SG_GENERAL, SG_INFO, "  " << built_ins[i].name);
865     globals->get_commands()->addCommand(built_ins[i].name,
866                                         built_ins[i].command);
867   }
868
869   typedef bool (*dummy)();
870   fgTie( "/command/view/next", dummy(0), do_view_next );
871   fgTie( "/command/view/prev", dummy(0), do_view_prev );
872 }
873
874 // end of fg_commands.cxx