Changes from David Megginson in support of an xml based configuration file.
This commit is contained in:
parent
e7df2d5dc8
commit
a9ab25ddd1
6 changed files with 58 additions and 110 deletions
|
@ -128,101 +128,6 @@ struct joystick {
|
|||
static joystick joysticks[MAX_JOYSTICKS];
|
||||
|
||||
|
||||
/**
|
||||
* Set up default values if properties are not specified.
|
||||
*/
|
||||
static void
|
||||
setupDefaults ()
|
||||
{
|
||||
SGPropertyList &props = current_properties;
|
||||
|
||||
// Default axis 0 to aileron
|
||||
if (!props.getValue("/input/js0/axis0/control")) {
|
||||
props.setStringValue("/input/js0/axis0/control", "/controls/aileron");
|
||||
props.setDoubleValue("/input/js0/axis0/dead-band", 0.1);
|
||||
}
|
||||
|
||||
// Default axis 1 to elevator
|
||||
if (!props.getValue("/input/js0/axis1/control")) {
|
||||
props.setStringValue("/input/js0/axis1/control", "/controls/elevator");
|
||||
props.setDoubleValue("/input/js0/axis1/dead-band", 0.1);
|
||||
props.setDoubleValue("/input/js0/axis1/factor", -1.0);
|
||||
}
|
||||
|
||||
// Default axis 2 to rudder
|
||||
if (!props.getValue("/input/js0/axis2/control")) {
|
||||
props.setStringValue("/input/js0/axis2/control", "/controls/rudder");
|
||||
props.setDoubleValue("/input/js0/axis2/dead-band", 0.1);
|
||||
}
|
||||
|
||||
// Default axis 3 to throttle
|
||||
// We need to fiddle with the offset
|
||||
// and factor to make it work
|
||||
if (!props.getValue("/input/js0/axis3/control")) {
|
||||
props.setStringValue("/input/js0/axis3/control", "/controls/throttle");
|
||||
props.setDoubleValue("/input/js0/axis3/dead-band", 0.0);
|
||||
props.setDoubleValue("/input/js0/axis3/offset", -1.0);
|
||||
props.setDoubleValue("/input/js0/axis3/factor", -0.5);
|
||||
}
|
||||
|
||||
// Default button 0 to all brakes
|
||||
if (!props.getValue("/input/js0/button0/control")) {
|
||||
props.setStringValue("/input/js0/button0/action", "switch");
|
||||
props.setStringValue("/input/js0/button0/control", "/controls/brakes/all");
|
||||
props.setDoubleValue("/input/js0/button0/step", 1.0);
|
||||
props.setDoubleValue("/input/js0/button0/repeatable", false);
|
||||
}
|
||||
|
||||
// Default button 1 to left brake.
|
||||
if (!props.getValue("/input/js0/button1/control")) {
|
||||
props.setStringValue("/input/js0/button1/action", "switch");
|
||||
props.setStringValue("/input/js0/button1/control",
|
||||
"/controls/brakes/left");
|
||||
props.setDoubleValue("/input/js0/button1/step", 1.0);
|
||||
props.setDoubleValue("/input/js0/button1/repeatable", false);
|
||||
}
|
||||
|
||||
// Default button 2 to right brake.
|
||||
if (!props.getValue("/input/js0/button2/control")) {
|
||||
props.setStringValue("/input/js0/button2/action", "switch");
|
||||
props.setStringValue("/input/js0/button2/control",
|
||||
"/controls/brakes/right");
|
||||
props.setDoubleValue("/input/js0/button2/step", 1.0);
|
||||
props.setDoubleValue("/input/js0/button2/repeatable", false);
|
||||
}
|
||||
|
||||
// Default buttons 3 and 4 to elevator trim
|
||||
if (!props.getValue("/input/js0/button3/control")) {
|
||||
props.setStringValue("/input/js0/button3/action", "adjust");
|
||||
props.setStringValue("/input/js0/button3/control",
|
||||
"/controls/elevator-trim");
|
||||
props.setDoubleValue("/input/js0/button3/step", 0.001);
|
||||
props.setBoolValue("/input/js0/button3/repeatable", true);
|
||||
}
|
||||
if (!props.getValue("/input/js0/button4/control")) {
|
||||
props.setStringValue("/input/js0/button4/action", "adjust");
|
||||
props.setStringValue("/input/js0/button4/control",
|
||||
"/controls/elevator-trim");
|
||||
props.setDoubleValue("/input/js0/button4/step", -0.001);
|
||||
props.setBoolValue("/input/js0/button4/repeatable", true);
|
||||
}
|
||||
|
||||
// Default buttons 5 and 6 to flaps
|
||||
if (!props.getValue("/input/js0/button5/control")) {
|
||||
props.setStringValue("/input/js0/button5/action", "adjust");
|
||||
props.setStringValue("/input/js0/button5/control", "/controls/flaps");
|
||||
props.setDoubleValue("/input/js0/button5/step", -0.34);
|
||||
props.setBoolValue("/input/js0/button5/repeatable", false);
|
||||
}
|
||||
if (!props.getValue("/input/js0/button6/control")) {
|
||||
props.setStringValue("/input/js0/button6/action", "adjust");
|
||||
props.setStringValue("/input/js0/button6/control", "/controls/flaps");
|
||||
props.setDoubleValue("/input/js0/button6/step", 0.34);
|
||||
props.setBoolValue("/input/js0/button6/repeatable", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize any joysticks found.
|
||||
*/
|
||||
|
@ -233,8 +138,6 @@ fgJoystickInit()
|
|||
|
||||
FG_LOG(FG_INPUT, FG_INFO, "Initializing joysticks");
|
||||
|
||||
setupDefaults();
|
||||
|
||||
for (int i = 0; i < MAX_JOYSTICKS; i++) {
|
||||
jsJoystick * js = new jsJoystick(i);
|
||||
joysticks[i].js = js;
|
||||
|
@ -497,7 +400,7 @@ fgJoystickRead()
|
|||
// Buttons
|
||||
//
|
||||
for (j = 0; j < joysticks[i].nbuttons; j++) {
|
||||
bool flag;
|
||||
bool flag = false;
|
||||
button &b = joysticks[i].buttons[j];
|
||||
if (b.value == 0)
|
||||
continue;
|
||||
|
|
|
@ -156,7 +156,7 @@ FGBFI::init ()
|
|||
getLeftBrake, setLeftBrake);
|
||||
current_properties.tieDouble("/controls/brakes/right",
|
||||
getRightBrake, setRightBrake);
|
||||
current_properties.tieDouble("/controls/brakes/Center",
|
||||
current_properties.tieDouble("/controls/brakes/center",
|
||||
getRightBrake, setCenterBrake);
|
||||
|
||||
// Deprecated...
|
||||
|
|
|
@ -171,6 +171,10 @@ bool fgSetPosFromAirportID( const string& id ) {
|
|||
} else {
|
||||
current_options.set_lon( a.longitude );
|
||||
current_options.set_lat( a.latitude );
|
||||
current_properties.setDoubleValue("/position/longitude",
|
||||
a.longitude);
|
||||
current_properties.setDoubleValue("/position/latitude",
|
||||
a.latitude);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
@ -279,6 +283,9 @@ bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
|
|||
current_options.set_lon( lon2 );
|
||||
current_options.set_lat( lat2 );
|
||||
current_options.set_heading( heading );
|
||||
current_properties.setDoubleValue("/position/longitude", lon2);
|
||||
current_properties.setDoubleValue("/position/latitude", lat2);
|
||||
current_properties.setDoubleValue("/orientation/heading", heading);
|
||||
|
||||
FG_LOG( FG_GENERAL, FG_INFO,
|
||||
"Position for " << id << " is ("
|
||||
|
@ -612,15 +619,15 @@ bool fgInitSubsystems( void ) {
|
|||
// Initialize the underlying radio stack model
|
||||
current_radiostack = new FGRadioStack;
|
||||
|
||||
current_radiostack->set_nav1_freq( 117.30 );
|
||||
current_radiostack->set_nav1_alt_freq( 110.30 );
|
||||
current_radiostack->set_nav1_sel_radial( 119.0 );
|
||||
// current_radiostack->set_nav1_freq( 117.30 );
|
||||
// current_radiostack->set_nav1_alt_freq( 110.30 );
|
||||
// current_radiostack->set_nav1_sel_radial( 119.0 );
|
||||
|
||||
current_radiostack->set_nav2_freq( 111.80 );
|
||||
current_radiostack->set_nav2_alt_freq( 115.70 );
|
||||
current_radiostack->set_nav2_sel_radial( 029.0 );
|
||||
// current_radiostack->set_nav2_freq( 111.80 );
|
||||
// current_radiostack->set_nav2_alt_freq( 115.70 );
|
||||
// current_radiostack->set_nav2_sel_radial( 029.0 );
|
||||
|
||||
current_radiostack->set_adf_freq( 266.0 );
|
||||
// current_radiostack->set_adf_freq( 266.0 );
|
||||
|
||||
#if 0
|
||||
// This block of settings are Alex's defaults for San Diego
|
||||
|
@ -701,7 +708,7 @@ bool fgInitSubsystems( void ) {
|
|||
|
||||
// Initialize the 2D panel.
|
||||
string panel_path =
|
||||
current_properties.getStringValue("/sim/panel",
|
||||
current_properties.getStringValue("/sim/panel/path",
|
||||
"Panels/Default/default.xml");
|
||||
current_panel = fgReadPanel(panel_path);
|
||||
if (current_panel == 0) {
|
||||
|
@ -709,7 +716,6 @@ bool fgInitSubsystems( void ) {
|
|||
"Error reading new panel from " << panel_path);
|
||||
}
|
||||
FG_LOG(FG_INPUT, FG_INFO, "Loaded new panel from " << panel_path);
|
||||
// current_panel = fgCreateSmallSinglePropPanel(0, 0, 1024, 768);
|
||||
|
||||
// Initialize the BFI
|
||||
FGBFI::init();
|
||||
|
|
|
@ -445,7 +445,7 @@ void GLUTspecialkey(int k, int x, int y) {
|
|||
}
|
||||
case GLUT_KEY_F3: {
|
||||
string panel_path =
|
||||
current_properties.getStringValue("/sim/panel",
|
||||
current_properties.getStringValue("/sim/panel/path",
|
||||
"Panels/Default/default.xml");
|
||||
FGPanel * new_panel = fgReadPanel(panel_path);
|
||||
if (new_panel == 0) {
|
||||
|
@ -458,6 +458,19 @@ void GLUTspecialkey(int k, int x, int y) {
|
|||
current_panel = new_panel;
|
||||
return;
|
||||
}
|
||||
case GLUT_KEY_F4: {
|
||||
FGPath props_path(current_options.get_fg_root());
|
||||
props_path.append("preferences.xml");
|
||||
FG_LOG(FG_INPUT, FG_INFO, "Rereading global preferences");
|
||||
if (!readPropertyList(props_path.str(), ¤t_properties)) {
|
||||
FG_LOG(FG_INPUT, FG_ALERT,
|
||||
"Failed to reread global preferences from "
|
||||
<< props_path.str());
|
||||
} else {
|
||||
FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences");
|
||||
}
|
||||
return;
|
||||
}
|
||||
case GLUT_KEY_END: // numeric keypad 1
|
||||
v->set_goal_view_offset( FG_PI * 0.75 );
|
||||
return;
|
||||
|
|
|
@ -1295,7 +1295,22 @@ int main( int argc, char **argv ) {
|
|||
// seed the random number generater
|
||||
fg_srandom();
|
||||
|
||||
aircraft_dir = ""; // Initialize the Aircraft directory to "" (UIUC)
|
||||
// Read global preferences from $FG_ROOT/preferences.xml
|
||||
// FIXME: this will *not* work with an --fg_root option because
|
||||
// we have not read the command-line yet. Suggestions?
|
||||
|
||||
FGPath props_path(current_options.get_fg_root());
|
||||
props_path.append("preferences.xml");
|
||||
FG_LOG(FG_INPUT, FG_INFO, "Reading global preferences");
|
||||
if (!readPropertyList(props_path.str(), ¤t_properties)) {
|
||||
FG_LOG(FG_INPUT, FG_ALERT, "Failed to read global preferences from "
|
||||
<< props_path.str());
|
||||
} else {
|
||||
FG_LOG(FG_INPUT, FG_INFO, "Finished Reading global preferences");
|
||||
}
|
||||
|
||||
// Initialize the Aircraft directory to "" (UIUC)
|
||||
aircraft_dir = "";
|
||||
|
||||
// needs to happen before we parse command line options
|
||||
globals = new FGGlobals;
|
||||
|
|
|
@ -647,15 +647,18 @@ int fgOPTIONS::parse_option( const string& arg ) {
|
|||
} else if ( arg.find( "--lon=" ) != string::npos ) {
|
||||
lon = parse_degree( arg.substr(6) );
|
||||
airport_id = "";
|
||||
current_properties.setDoubleValue("/position/longitude", lon);
|
||||
} else if ( arg.find( "--lat=" ) != string::npos ) {
|
||||
lat = parse_degree( arg.substr(6) );
|
||||
airport_id = "";
|
||||
current_properties.setDoubleValue("/position/latitude", lat);
|
||||
} else if ( arg.find( "--altitude=" ) != string::npos ) {
|
||||
if ( units == FG_UNITS_FEET ) {
|
||||
altitude = atof( arg.substr(11) ) * FEET_TO_METER;
|
||||
} else {
|
||||
altitude = atof( arg.substr(11) );
|
||||
}
|
||||
current_properties.setDoubleValue("/position/altitude", altitude);
|
||||
} else if ( arg.find( "--uBody=" ) != string::npos ) {
|
||||
vkcas=mach=-1;
|
||||
if ( units == FG_UNITS_FEET ) {
|
||||
|
@ -663,6 +666,7 @@ int fgOPTIONS::parse_option( const string& arg ) {
|
|||
} else {
|
||||
uBody = atof( arg.substr(8) ) * FEET_TO_METER;
|
||||
}
|
||||
current_properties.setDoubleValue("/velocities/speed-north", uBody);
|
||||
} else if ( arg.find( "--vBody=" ) != string::npos ) {
|
||||
vkcas=mach=-1;
|
||||
if ( units == FG_UNITS_FEET ) {
|
||||
|
@ -670,6 +674,7 @@ int fgOPTIONS::parse_option( const string& arg ) {
|
|||
} else {
|
||||
vBody = atof( arg.substr(8) ) * FEET_TO_METER;
|
||||
}
|
||||
current_properties.setDoubleValue("/velocities/speed-east", vBody);
|
||||
} else if ( arg.find( "--wBody=" ) != string::npos ) {
|
||||
vkcas=mach=-1;
|
||||
if ( units == FG_UNITS_FEET ) {
|
||||
|
@ -677,6 +682,7 @@ int fgOPTIONS::parse_option( const string& arg ) {
|
|||
} else {
|
||||
wBody = atof( arg.substr(8) ) * FEET_TO_METER;
|
||||
}
|
||||
current_properties.setDoubleValue("/velocities/speed-down", wBody);
|
||||
} else if ( arg.find( "--vc=" ) != string::npos) {
|
||||
mach=-1;
|
||||
vkcas=atof( arg.substr(5) );
|
||||
|
@ -686,16 +692,20 @@ int fgOPTIONS::parse_option( const string& arg ) {
|
|||
mach=atof( arg.substr(7) );
|
||||
} else if ( arg.find( "--heading=" ) != string::npos ) {
|
||||
heading = atof( arg.substr(10) );
|
||||
current_properties.setDoubleValue("/orientation/heading", heading);
|
||||
} else if ( arg.find( "--roll=" ) != string::npos ) {
|
||||
roll = atof( arg.substr(7) );
|
||||
current_properties.setDoubleValue("/orientation/roll", roll);
|
||||
} else if ( arg.find( "--pitch=" ) != string::npos ) {
|
||||
pitch = atof( arg.substr(8) );
|
||||
current_properties.setDoubleValue("/orientation/pitch", pitch);
|
||||
} else if ( arg.find( "--fg-root=" ) != string::npos ) {
|
||||
fg_root = arg.substr( 10 );
|
||||
} else if ( arg.find( "--fg-scenery=" ) != string::npos ) {
|
||||
fg_scenery = arg.substr( 13 );
|
||||
} else if ( arg.find( "--fdm=" ) != string::npos ) {
|
||||
flight_model = parse_fdm( arg.substr(6) );
|
||||
current_properties.setIntValue("/sim/flight-model", flight_model);
|
||||
if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) {
|
||||
set_trim_mode(1);
|
||||
} else {
|
||||
|
@ -703,6 +713,7 @@ int fgOPTIONS::parse_option( const string& arg ) {
|
|||
}
|
||||
} else if ( arg.find( "--aircraft=" ) != string::npos ) {
|
||||
aircraft = arg.substr(11);
|
||||
current_properties.setStringValue("/sim/aircraft", aircraft);
|
||||
} else if ( arg.find( "--aircraft-dir=" ) != string::npos ) {
|
||||
aircraft_dir = arg.substr(15); // (UIUC)
|
||||
} else if ( arg.find( "--model-hz=" ) != string::npos ) {
|
||||
|
|
Loading…
Add table
Reference in a new issue