#include "logger.hxx"
#include "util.hxx"
#include "main.hxx"
+#include "positioninit.hxx"
#include <boost/scoped_array.hpp>
return true;
}
-
-/**
- * Built-in command: reinitialize one or more subsystems.
- *
- * subsystem[*]: the name(s) of the subsystem(s) to reinitialize; if
- * none is specified, reinitialize all of them.
- */
-static bool
-do_reinit (const SGPropertyNode * arg)
-{
- bool result = true;
-
- vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
- if (subsystems.size() == 0) {
- globals->get_subsystem_mgr()->reinit();
- } else {
- for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
- const char * name = subsystems[i]->getStringValue();
- SGSubsystem * subsystem = globals->get_subsystem(name);
- if (subsystem == 0) {
- result = false;
- SG_LOG( SG_GENERAL, SG_ALERT,
- "Subsystem " << name << " not found" );
- } else {
- subsystem->reinit();
- }
- }
- }
-
- globals->get_event_mgr()->reinit();
-
- return result;
-}
-
-#if 0
- //
- // these routines look useful ??? but are never used in the code ???
- //
-
-/**
- * Built-in command: suspend one or more subsystems.
- *
- * subsystem[*] - the name(s) of the subsystem(s) to suspend.
- */
-static bool
-do_suspend (const SGPropertyNode * arg)
-{
- bool result = true;
-
- vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
- for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
- const char * name = subsystems[i]->getStringValue();
- SGSubsystem * subsystem = globals->get_subsystem(name);
- if (subsystem == 0) {
- result = false;
- SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
- } else {
- subsystem->suspend();
- }
- }
- return result;
-}
-
-/**
- * Built-in command: suspend one or more subsystems.
- *
- * subsystem[*] - the name(s) of the subsystem(s) to suspend.
- */
-static bool
-do_resume (const SGPropertyNode * arg)
-{
- bool result = true;
-
- vector<SGPropertyNode_ptr> subsystems = arg->getChildren("subsystem");
- for ( unsigned int i = 0; i < subsystems.size(); i++ ) {
- const char * name = subsystems[i]->getStringValue();
- SGSubsystem * subsystem = globals->get_subsystem(name);
- if (subsystem == 0) {
- result = false;
- SG_LOG(SG_GENERAL, SG_ALERT, "Subsystem " << name << " not found");
- } else {
- subsystem->resume();
- }
- }
- return result;
-}
-
-#endif
-
/**
* Built-in command: replay the FDR buffer
*/
/**
* Built-in command: interpolate a property value over time
*
- * property: the name of the property value to interpolate.
- * value[0..n] any number of constant values to interpolate
- * time[0..n] time between each value, number of time elements must
- * match those of value elements
+ * property: the name of the property value to interpolate.
+ * value[0..n] any number of constant values to interpolate
+ * time/rate[0..n] time between each value, number of time elements must
+ * match those of value elements. Instead of time also rate can
+ * be used which automatically calculates the time to change
+ * the property value at the given speed.
* -or-
- * property[1..n] any number of target values taken from named properties
- * time[0..n] time between each value, number of time elements must
- * match those of property elements minus one
+ * property[1..n] any number of target values taken from named properties
+ * time/rate[0..n] time between each value, number of time elements must
+ * match those of value elements. Instead of time also rate can
+ * be used which automatically calculates the time to change
+ * the property value at the given speed.
*/
static bool
do_property_interpolate (const SGPropertyNode * arg)
simgear::PropertyList valueNodes = arg->getChildren( "value" );
simgear::PropertyList timeNodes = arg->getChildren( "time" );
+ simgear::PropertyList rateNodes = arg->getChildren( "rate" );
+
+ if( !timeNodes.empty() && !rateNodes.empty() )
+ // mustn't specify time and rate
+ return false;
+
+ simgear::PropertyList::size_type num_times = timeNodes.empty()
+ ? rateNodes.size()
+ : timeNodes.size();
boost::scoped_array<double> value;
boost::scoped_array<double> time;
if( valueNodes.size() > 0 ) {
// must match
- if( timeNodes.size() != valueNodes.size() )
+ if( num_times != valueNodes.size() )
return false;
value.reset( new double[valueNodes.size()] );
} else {
valueNodes = arg->getChildren("property");
// must have one more property node
- if( valueNodes.size() - 1 != timeNodes.size() )
+ if( valueNodes.size() - 1 != num_times )
return false;
value.reset( new double[valueNodes.size()-1] );
}
- time.reset( new double[timeNodes.size()] );
- for( simgear::PropertyList::size_type n = 0; n < timeNodes.size(); n++ ) {
- time[n] = timeNodes[n]->getDoubleValue();
+ time.reset( new double[num_times] );
+ if( !timeNodes.empty() ) {
+ for( simgear::PropertyList::size_type n = 0; n < num_times; n++ ) {
+ time[n] = timeNodes[n]->getDoubleValue();
+ }
+ } else {
+ for( simgear::PropertyList::size_type n = 0; n < num_times; n++ ) {
+ double delta = value[n]
+ - (n > 0 ? value[n - 1] : prop->getDoubleValue());
+ time[n] = fabs(delta / rateNodes[n]->getDoubleValue());
+ }
}
((SGInterpolator*)globals->get_subsystem_mgr()
->get_group(SGSubsystemMgr::INIT)->get_subsystem("interpolator"))
- ->interpolate(prop, timeNodes.size(), value.get(), time.get() );
+ ->interpolate(prop, num_times, value.get(), time.get() );
return true;
}
do_dialog_new (const SGPropertyNode * arg)
{
NewGUI * gui = (NewGUI *)globals->get_subsystem("gui");
-
+ if (!gui) {
+ return false;
+ }
+
// Note the casting away of const: this is *real*. Doing a
// "dialog-apply" command later on will mutate this property node.
// I'm not convinced that this isn't the Right Thing though; it
static bool
do_play_audio_sample (const SGPropertyNode * arg)
{
+ SGSoundMgr *smgr = globals->get_soundmgr();
+ if (!smgr) {
+ SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running");
+ return false;
+ }
+
string path = arg->getStringValue("path");
string file = arg->getStringValue("file");
float volume = arg->getFloatValue("volume");
try {
static FGSampleQueue *queue = 0;
if ( !queue ) {
- SGSoundMgr *smgr = globals->get_soundmgr();
queue = new FGSampleQueue(smgr, "chatter");
queue->tie_to_listener();
}
// Nasal can trigger this during initial init, which confuses
// the logic in ReInitSubsystems, since initial state has not been
// saved at that time. Short-circuit everything here.
- fgInitPosition();
+ flightgear::initPosition();
}
return true;
{ "nasal", do_nasal },
{ "exit", do_exit },
{ "reset", do_reset },
- { "reinit", do_reinit },
- { "suspend", do_reinit },
- { "resume", do_reinit },
{ "pause", do_pause },
{ "load", do_load },
{ "save", do_save },