// Templates cause ambiguity here
inline void
-fgTie (const string &name, bool *pointer)
+fgTie (const string &name, bool *pointer, bool useDefault = true)
{
- if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer)))
+ if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to a pointer");
}
inline void
-fgTie (const string &name, int *pointer)
+fgTie (const string &name, int *pointer, bool useDefault = true)
{
- if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer)))
+ if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to a pointer");
}
inline void
-fgTie (const string &name, float *pointer)
+fgTie (const string &name, float *pointer, bool useDefault = true)
{
- if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer)))
+ if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to a pointer");
}
inline void
-fgTie (const string &name, double *pointer)
+fgTie (const string &name, double *pointer, bool useDefault = true)
{
- if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer)))
+ if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to a pointer");
}
inline void
-fgTie (const string &name, string *pointer)
+fgTie (const string &name, string *pointer, bool useDefault = true)
{
- if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer)))
+ if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to a pointer");
}
template <class V>
inline void
-fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
+fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
+ bool useDefault = true)
{
- if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter)))
+ if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to functions");
}
template <class V>
inline void
fgTie (const string &name, int index, V (*getter)(int),
- void (*setter)(int, V) = 0)
+ void (*setter)(int, V) = 0, bool useDefault = true)
{
if (!globals->get_props()->tie(name,
SGRawValueFunctionsIndexed<V>(index,
getter,
- setter)))
+ setter),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to indexed functions");
}
template <class T, class V>
inline void
fgTie (const string &name, T * obj, V (T::*getter)() const,
- void (T::*setter)(V) = 0)
+ void (T::*setter)(V) = 0, bool useDefault = true)
{
if (!globals->get_props()->tie(name,
- SGRawValueMethods<T,V>(*obj, getter, setter)))
+ SGRawValueMethods<T,V>(*obj, getter, setter),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to object methods");
}
template <class T, class V>
inline void
fgTie (const string &name, T * obj, int index,
- V (T::*getter)(int) const, void (T::*setter)(int, V) = 0)
+ V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
+ bool useDefault = true)
{
if (!globals->get_props()->tie(name,
SGRawValueMethodsIndexed<T,V>(*obj,
index,
getter,
- setter)))
+ setter),
+ useDefault))
FG_LOG(FG_GENERAL, FG_WARN,
"Failed to tie property " << name << " to indexed object methods");
}
#include "fg_props.hxx"
+\f
+////////////////////////////////////////////////////////////////////////
+// Implementation of FGGlobals.
+////////////////////////////////////////////////////////////////////////
+
// global global :-)
FGGlobals *globals;
FGGlobals::FGGlobals() :
freeze( false ),
warp( 0 ),
- warp_delta( 0 )
+ warp_delta( 0 ),
+ props(0),
+ initial_state(0)
{
- // TODO: move to a proper bind method
-// fgTie("/sim/freeze", &freeze);
-// fgTie("/sim/warp", &warp);
-// fgTie("/sim/warp-delta", &warp_delta);
}
// Destructor
FGGlobals::~FGGlobals()
{
- // TODO: move to a proper unbind method
-// fgUntie("/sim/freeze");
-// fgUntie("/sim/warp");
-// fgUntie("/sim/warp-delta");
+ delete initial_state;
+}
+
+
+// Save the current state as the initial state.
+void
+FGGlobals::saveInitialState ()
+{
+ delete initial_state;
+ initial_state = new SGPropertyNode();
+ if (!copyProperties(props, initial_state))
+ FG_LOG(FG_GENERAL, FG_ALERT, "Error saving initial state");
}
+
+// Restore the saved initial state, if any
+void
+FGGlobals::restoreInitialState ()
+{
+ if (initial_state == 0) {
+ FG_LOG(FG_GENERAL, FG_ALERT, "No initial state available to restore!!!");
+ } else if (!copyProperties(initial_state, props)) {
+ FG_LOG(FG_GENERAL, FG_INFO,
+ "Some errors restoring initial state (probably just read-only props)");
+ } else {
+ FG_LOG(FG_GENERAL, FG_INFO, "Initial state restored successfully");
+ }
+}
+
+
+// end of globals.cxx