2001-01-05 17:37:59 +00:00
|
|
|
|
#ifndef __FG_PROPS_HXX
|
|
|
|
|
#define __FG_PROPS_HXX 1
|
|
|
|
|
|
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
|
#include <simgear/misc/props.hxx>
|
|
|
|
|
#include "globals.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Loading and saving properties.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
extern bool fgSaveFlight (ostream &output);
|
|
|
|
|
extern bool fgLoadFlight (istream &input);
|
|
|
|
|
|
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Convenience functions for getting property values.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
I'm attaching diffs to add a new FGInput module to FlightGear
(src/Input). So far, FGInput replaces most of src/Main/keyboard.cxx
(I've left a tiny stub); in the very near future, it will also take
over control of the joystick, mouse (Norm permitting), and panel
instrument interactions, so that there is a single mechanism for
configuring all input devices.
The new format should be (close to) self-explanatory by looking at the
new base-package file keyboard.xml, which is now included by
preferences.xml (I'll do the same thing for the joystick when I have a
chance). I have not managed to move all keybindings into this file
yet, but I've made a good start. I'm including Tony in the recipient
list so that he can see how bindings can use an external XML file.
This patch also adds support for multiple bindings for a single key,
special keys (i.e. keypad and function keys), and key modifiers
(shift/alt/ctrl); special keys use the PUI convention of adding 256 to
the Glut key code.
Unfortunately, everything comes with a price; in this case, I have not
yet found a general mechanism for the old (hard-coded) modal bindings,
which behaved differently depending on the autopilot state (i.e. left
rudder or move AP heading left); with my patches, this functionality
disappears, but you can still adjust the autopilot using the panel or
the GUI input dialogs.
2001-05-23 23:01:15 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a property node.
|
|
|
|
|
*
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param create true to create the node if it doesn't exist.
|
|
|
|
|
*/
|
|
|
|
|
inline SGPropertyNode *
|
|
|
|
|
fgGetNode (const string &path, bool create = false)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getNode(path, create);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get an SGValue pointer that can be queried repeatedly.
|
|
|
|
|
*
|
|
|
|
|
* If the property value is going to be accessed within the loop,
|
|
|
|
|
* it is best to use this method for maximum efficiency.
|
|
|
|
|
*/
|
I'm attaching diffs to add a new FGInput module to FlightGear
(src/Input). So far, FGInput replaces most of src/Main/keyboard.cxx
(I've left a tiny stub); in the very near future, it will also take
over control of the joystick, mouse (Norm permitting), and panel
instrument interactions, so that there is a single mechanism for
configuring all input devices.
The new format should be (close to) self-explanatory by looking at the
new base-package file keyboard.xml, which is now included by
preferences.xml (I'll do the same thing for the joystick when I have a
chance). I have not managed to move all keybindings into this file
yet, but I've made a good start. I'm including Tony in the recipient
list so that he can see how bindings can use an external XML file.
This patch also adds support for multiple bindings for a single key,
special keys (i.e. keypad and function keys), and key modifiers
(shift/alt/ctrl); special keys use the PUI convention of adding 256 to
the Glut key code.
Unfortunately, everything comes with a price; in this case, I have not
yet found a general mechanism for the old (hard-coded) modal bindings,
which behaved differently depending on the autopilot state (i.e. left
rudder or move AP heading left); with my patches, this functionality
disappears, but you can still adjust the autopilot using the panel or
the GUI input dialogs.
2001-05-23 23:01:15 +00:00
|
|
|
|
inline SGValue *
|
|
|
|
|
fgGetValue (const string &name, bool create = false)
|
2001-01-13 22:06:39 +00:00
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getValue(name, create);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool fgHasValue (const string &name)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->hasValue(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool fgGetBool (const string &name, bool defaultValue = false)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getBoolValue(name, defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline int fgGetInt (const string &name, int defaultValue = 0)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getIntValue(name, defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-29 03:49:02 +00:00
|
|
|
|
inline int fgGetLong (const string &name, long defaultValue = 0L)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getLongValue(name, defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
inline float fgGetFloat (const string &name, float defaultValue = 0.0)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getFloatValue(name, defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline double fgGetDouble (const string &name, double defaultValue = 0.0)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getDoubleValue(name, defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline string fgGetString (const string &name, string defaultValue = "")
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->getStringValue(name, defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool fgSetBool (const string &name, bool val)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->setBoolValue(name, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool fgSetInt (const string &name, int val)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->setIntValue(name, val);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-29 03:49:02 +00:00
|
|
|
|
inline bool fgSetLong (const string &name, long val)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->setLongValue(name, val);
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
inline bool fgSetFloat (const string &name, float val)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->setFloatValue(name, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool fgSetDouble (const string &name, double val)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->setDoubleValue(name, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool fgSetString (const string &name, const string &val)
|
|
|
|
|
{
|
|
|
|
|
return globals->get_props()->setStringValue(name, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Convenience functions for tying properties, with logging.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
inline void
|
|
|
|
|
fgUntie (const string &name)
|
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->untie(name))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
|
2001-01-05 17:37:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Templates cause ambiguity here
|
|
|
|
|
inline void
|
2001-01-19 22:57:24 +00:00
|
|
|
|
fgTie (const string &name, bool *pointer, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to a pointer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void
|
2001-01-19 22:57:24 +00:00
|
|
|
|
fgTie (const string &name, int *pointer, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to a pointer");
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-29 03:49:02 +00:00
|
|
|
|
inline void
|
|
|
|
|
fgTie (const string &name, long *pointer, bool useDefault = true)
|
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValuePointer<long>(pointer),
|
|
|
|
|
useDefault))
|
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
|
|
|
|
"Failed to tie property " << name << " to a pointer");
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
inline void
|
2001-01-19 22:57:24 +00:00
|
|
|
|
fgTie (const string &name, float *pointer, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to a pointer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void
|
2001-01-19 22:57:24 +00:00
|
|
|
|
fgTie (const string &name, double *pointer, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to a pointer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline void
|
2001-01-19 22:57:24 +00:00
|
|
|
|
fgTie (const string &name, string *pointer, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to a pointer");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class V>
|
|
|
|
|
inline void
|
2001-01-19 22:57:24 +00:00
|
|
|
|
fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
|
|
|
|
|
bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to functions");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class V>
|
|
|
|
|
inline void
|
|
|
|
|
fgTie (const string &name, int index, V (*getter)(int),
|
2001-01-19 22:57:24 +00:00
|
|
|
|
void (*setter)(int, V) = 0, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->tie(name,
|
|
|
|
|
SGRawValueFunctionsIndexed<V>(index,
|
|
|
|
|
getter,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
setter),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"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,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
void (T::*setter)(V) = 0, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->tie(name,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
SGRawValueMethods<T,V>(*obj, getter, setter),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to object methods");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T, class V>
|
|
|
|
|
inline void
|
|
|
|
|
fgTie (const string &name, T * obj, int index,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
|
|
|
|
|
bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->tie(name,
|
|
|
|
|
SGRawValueMethodsIndexed<T,V>(*obj,
|
|
|
|
|
index,
|
|
|
|
|
getter,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
setter),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2001-01-05 17:37:59 +00:00
|
|
|
|
"Failed to tie property " << name << " to indexed object methods");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif // __FG_PROPS_HXX
|
|
|
|
|
|