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