The FlightGear patches add new saveInitialState and
restoreInitialState methods to FGGlobals, as well as the two-stage commit described above for loading saved files. fgInit now takes a snapshot of the initial state before handing off to the main loop, and the GUI reInit function restores that state explicitly before calling fgReInit. The FlightGear patches also modify fg_props.hxx to add optional useDefault arguments to all of the fgTie functions -- that lets you choose whether you want to pick up any default value in the property tree when you tie the property (the default is true).
This commit is contained in:
parent
bfcef94570
commit
e1dd52d38a
6 changed files with 97 additions and 30 deletions
|
@ -2,6 +2,7 @@
|
|||
#include <plib/pu.h> // plib include
|
||||
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_init.hxx>
|
||||
|
||||
#include "gui.h"
|
||||
|
@ -38,6 +39,7 @@ void reInit(puObject *cb)
|
|||
BusyCursor(0);
|
||||
Quat0();
|
||||
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
||||
/* check */ globals->restoreInitialState();
|
||||
fgReInitSubsystems();
|
||||
BusyCursor(1);
|
||||
}
|
||||
|
|
|
@ -778,6 +778,10 @@ bool fgInitSubsystems( void ) {
|
|||
|
||||
FG_LOG( FG_GENERAL, FG_INFO, endl);
|
||||
|
||||
// Save the initial state for future
|
||||
// reference.
|
||||
globals->saveInitialState();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -867,7 +871,7 @@ void fgReInitSubsystems( void )
|
|||
<< globals->get_current_view()->get_abs_view_pos());
|
||||
|
||||
cur_fdm_state->init();
|
||||
cur_fdm_state->bind();
|
||||
// cur_fdm_state->bind();
|
||||
// cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
|
||||
|
||||
scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
|
||||
|
|
|
@ -45,7 +45,16 @@ fgSaveFlight (ostream &output)
|
|||
bool
|
||||
fgLoadFlight (istream &input)
|
||||
{
|
||||
return readProperties(input, globals->get_props());
|
||||
SGPropertyNode props;
|
||||
if (readProperties(input, &props)) {
|
||||
copyProperties(&props, globals->get_props());
|
||||
// When loading a flight, make it the
|
||||
// new initial state.
|
||||
globals->saveInitialState();
|
||||
} else {
|
||||
FG_LOG(FG_INPUT, FG_ALERT, "Error restoring flight; aborted");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// end of fg_props.cxx
|
||||
|
|
|
@ -101,50 +101,57 @@ fgUntie (const string &name)
|
|||
|
||||
// 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");
|
||||
}
|
||||
|
@ -152,12 +159,13 @@ fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
|
|||
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");
|
||||
}
|
||||
|
@ -165,10 +173,11 @@ fgTie (const string &name, int index, V (*getter)(int),
|
|||
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");
|
||||
}
|
||||
|
@ -176,13 +185,15 @@ fgTie (const string &name, T * obj, V (T::*getter)() const,
|
|||
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");
|
||||
}
|
||||
|
|
|
@ -25,6 +25,11 @@
|
|||
#include "fg_props.hxx"
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of FGGlobals.
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// global global :-)
|
||||
FGGlobals *globals;
|
||||
|
||||
|
@ -33,21 +38,44 @@ 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
|
||||
|
|
|
@ -83,6 +83,7 @@ private:
|
|||
|
||||
// properties
|
||||
SGPropertyNode *props;
|
||||
SGPropertyNode *initial_state;
|
||||
|
||||
// list of serial port-like configurations
|
||||
string_list channel_options_list;
|
||||
|
@ -134,7 +135,19 @@ public:
|
|||
inline string_list get_channel_options_list () {
|
||||
return channel_options_list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Save the current state as the initial state.
|
||||
*/
|
||||
void saveInitialState ();
|
||||
|
||||
|
||||
/**
|
||||
* Restore the saved initial state, if any.
|
||||
*/
|
||||
void restoreInitialState ();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue