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