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 <plib/pu.h> // plib include
|
||||||
|
|
||||||
|
|
||||||
|
#include <Main/globals.hxx>
|
||||||
#include <Main/fg_init.hxx>
|
#include <Main/fg_init.hxx>
|
||||||
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
@ -38,6 +39,7 @@ void reInit(puObject *cb)
|
||||||
BusyCursor(0);
|
BusyCursor(0);
|
||||||
Quat0();
|
Quat0();
|
||||||
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
||||||
|
/* check */ globals->restoreInitialState();
|
||||||
fgReInitSubsystems();
|
fgReInitSubsystems();
|
||||||
BusyCursor(1);
|
BusyCursor(1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -778,6 +778,10 @@ bool fgInitSubsystems( void ) {
|
||||||
|
|
||||||
FG_LOG( FG_GENERAL, FG_INFO, endl);
|
FG_LOG( FG_GENERAL, FG_INFO, endl);
|
||||||
|
|
||||||
|
// Save the initial state for future
|
||||||
|
// reference.
|
||||||
|
globals->saveInitialState();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,7 +871,7 @@ void fgReInitSubsystems( void )
|
||||||
<< globals->get_current_view()->get_abs_view_pos());
|
<< globals->get_current_view()->get_abs_view_pos());
|
||||||
|
|
||||||
cur_fdm_state->init();
|
cur_fdm_state->init();
|
||||||
cur_fdm_state->bind();
|
// cur_fdm_state->bind();
|
||||||
// cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
|
// cur_fdm_state->init( 1.0 / fgGetInt("/sim/model-hz") );
|
||||||
|
|
||||||
scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
|
scenery.cur_elev = cur_fdm_state->get_Runway_altitude() * FEET_TO_METER;
|
||||||
|
|
|
@ -45,7 +45,16 @@ fgSaveFlight (ostream &output)
|
||||||
bool
|
bool
|
||||||
fgLoadFlight (istream &input)
|
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
|
// end of fg_props.cxx
|
||||||
|
|
|
@ -101,50 +101,57 @@ fgUntie (const string &name)
|
||||||
|
|
||||||
// Templates cause ambiguity here
|
// Templates cause ambiguity here
|
||||||
inline void
|
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,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to a pointer");
|
"Failed to tie property " << name << " to a pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
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,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to a pointer");
|
"Failed to tie property " << name << " to a pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
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,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to a pointer");
|
"Failed to tie property " << name << " to a pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
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,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to a pointer");
|
"Failed to tie property " << name << " to a pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
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,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to a pointer");
|
"Failed to tie property " << name << " to a pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class V>
|
template <class V>
|
||||||
inline void
|
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,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to functions");
|
"Failed to tie property " << name << " to functions");
|
||||||
}
|
}
|
||||||
|
@ -152,12 +159,13 @@ fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0)
|
||||||
template <class V>
|
template <class V>
|
||||||
inline void
|
inline void
|
||||||
fgTie (const string &name, int index, V (*getter)(int),
|
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,
|
if (!globals->get_props()->tie(name,
|
||||||
SGRawValueFunctionsIndexed<V>(index,
|
SGRawValueFunctionsIndexed<V>(index,
|
||||||
getter,
|
getter,
|
||||||
setter)))
|
setter),
|
||||||
|
useDefault))
|
||||||
FG_LOG(FG_GENERAL, FG_WARN,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to indexed functions");
|
"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>
|
template <class T, class V>
|
||||||
inline void
|
inline void
|
||||||
fgTie (const string &name, T * obj, V (T::*getter)() const,
|
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,
|
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,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to object methods");
|
"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>
|
template <class T, class V>
|
||||||
inline void
|
inline void
|
||||||
fgTie (const string &name, T * obj, int index,
|
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,
|
if (!globals->get_props()->tie(name,
|
||||||
SGRawValueMethodsIndexed<T,V>(*obj,
|
SGRawValueMethodsIndexed<T,V>(*obj,
|
||||||
index,
|
index,
|
||||||
getter,
|
getter,
|
||||||
setter)))
|
setter),
|
||||||
|
useDefault))
|
||||||
FG_LOG(FG_GENERAL, FG_WARN,
|
FG_LOG(FG_GENERAL, FG_WARN,
|
||||||
"Failed to tie property " << name << " to indexed object methods");
|
"Failed to tie property " << name << " to indexed object methods");
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,11 @@
|
||||||
#include "fg_props.hxx"
|
#include "fg_props.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Implementation of FGGlobals.
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// global global :-)
|
// global global :-)
|
||||||
FGGlobals *globals;
|
FGGlobals *globals;
|
||||||
|
|
||||||
|
@ -33,21 +38,44 @@ FGGlobals *globals;
|
||||||
FGGlobals::FGGlobals() :
|
FGGlobals::FGGlobals() :
|
||||||
freeze( false ),
|
freeze( false ),
|
||||||
warp( 0 ),
|
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
|
// Destructor
|
||||||
FGGlobals::~FGGlobals()
|
FGGlobals::~FGGlobals()
|
||||||
{
|
{
|
||||||
// TODO: move to a proper unbind method
|
delete initial_state;
|
||||||
// fgUntie("/sim/freeze");
|
|
||||||
// fgUntie("/sim/warp");
|
|
||||||
// fgUntie("/sim/warp-delta");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 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
|
// properties
|
||||||
SGPropertyNode *props;
|
SGPropertyNode *props;
|
||||||
|
SGPropertyNode *initial_state;
|
||||||
|
|
||||||
// list of serial port-like configurations
|
// list of serial port-like configurations
|
||||||
string_list channel_options_list;
|
string_list channel_options_list;
|
||||||
|
@ -134,7 +135,19 @@ public:
|
||||||
inline string_list get_channel_options_list () {
|
inline string_list get_channel_options_list () {
|
||||||
return 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