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