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