X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Ffg_commands.cxx;h=de4336833a344159e85801549e415fe0cf77dfca;hb=4fe615fff546df5e381f7fc9ddae92dd3dc36251;hp=2c2e90df30b8a7fa2cc15648069a26c63f74b2dc;hpb=3ed73e16b6aa2ca4e33692ed93718a860b94d4df;p=flightgear.git diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 2c2e90df3..de4336833 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1,5 +1,9 @@ // fg_commands.cxx - internal FGFS commands. +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include // strcmp() #include @@ -24,6 +28,7 @@ #include #include #include +#include #if defined(HAVE_PLIB_PSL) # include #endif @@ -192,6 +197,7 @@ static bool do_exit (const SGPropertyNode * arg) { SG_LOG(SG_INPUT, SG_INFO, "Program exit requested."); + fgSetBool("/sim/signals/exit", true); if (fgGetBool("/sim/startup/save-on-exit")) { #ifdef _MSC_VER @@ -204,16 +210,16 @@ do_exit (const SGPropertyNode * arg) SGPath config( homedir ); config.append( ".fgfs" ); #endif - config.append( "preferences.xml" ); + config.append( "autosave.xml" ); config.create_dir( 0700 ); - SG_LOG(SG_IO, SG_INFO, "Saving user preferences"); + SG_LOG(SG_IO, SG_INFO, "Saving user settings to " << config.str()); try { writeProperties(config.str(), globals->get_props(), false, SGPropertyNode::USERARCHIVE); } catch (const sg_exception &e) { - guiErrorMessage("Error saving preferences: ", e); + guiErrorMessage("Error writing autosave.xml: ", e); } - SG_LOG(SG_INPUT, SG_BULK, "Finished Saving user preferences"); + SG_LOG(SG_INPUT, SG_DEBUG, "Finished Saving user settings"); } } fgExit(arg->getIntValue("status", 0)); @@ -326,7 +332,7 @@ do_load (const SGPropertyNode * arg) SG_LOG(SG_INPUT, SG_INFO, "Restored flight from " << file); return true; } else { - SG_LOG(SG_INPUT, SG_ALERT, "Cannot load flight from " << file); + SG_LOG(SG_INPUT, SG_WARN, "Cannot load flight from " << file); return false; } } @@ -467,7 +473,6 @@ do_view_cycle (const SGPropertyNode * arg) globals->get_viewmgr()->next_view(); fix_hud_visibility(); globals->get_tile_mgr()->refresh_view_timestamps(); -// fgReshape(fgGetInt("/sim/startup/xsize"), fgGetInt("/sim/startup/ysize")); return true; } @@ -506,7 +511,6 @@ do_tile_cache_reload (const SGPropertyNode * arg) if ( !freeze ) { fgSetBool("/sim/freeze/master", true); } - // BusyCursor(0); if ( globals->get_tile_mgr()->init() ) { // Load the local scenery data double visibility_meters = fgGetDouble("/environment/visibility-m"); @@ -516,7 +520,6 @@ do_tile_cache_reload (const SGPropertyNode * arg) "Error in Tile Manager initialization!" ); exit(-1); } - // BusyCursor(1); if ( !freeze ) { fgSetBool("/sim/freeze/master", false); } @@ -583,9 +586,9 @@ do_set_oat_degc (const SGPropertyNode * arg) dummy.set_temperature_degc( atof( temp_str.c_str() ) ); double temp_sea_level_degc = dummy.get_temperature_sea_level_degc(); - cout << "Altitude = " << altitude_ft->getDoubleValue() << endl; - cout << "Temp at alt (C) = " << atof( temp_str.c_str() ) << endl; - cout << "Temp sea level (C) = " << temp_sea_level_degc << endl; + //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl; + //cout << "Temp at alt (C) = " << atof( temp_str.c_str() ) << endl; + //cout << "Temp sea level (C) = " << temp_sea_level_degc << endl; SGPropertyNode *node, *child; @@ -673,9 +676,9 @@ do_set_dewpoint_degc (const SGPropertyNode * arg) dummy.set_dewpoint_degc( atof( dewpoint_str.c_str() ) ); double dewpoint_sea_level_degc = dummy.get_dewpoint_sea_level_degc(); - cout << "Altitude = " << altitude_ft->getDoubleValue() << endl; - cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl; - cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl; + //cout << "Altitude = " << altitude_ft->getDoubleValue() << endl; + //cout << "Dewpoint at alt (C) = " << atof( dewpoint_str.c_str() ) << endl; + //cout << "Dewpoint at sea level (C) = " << dewpoint_sea_level_degc << endl; SGPropertyNode *node, *child; @@ -1092,13 +1095,14 @@ static bool do_dialog_update (const SGPropertyNode * arg) { NewGUI * gui = (NewGUI *)globals->get_subsystem("gui"); - FGDialog * dialog = gui->getActiveDialog(); + FGDialog * dialog; + if (arg->hasValue("dialog-name")) + dialog = gui->getDialog(arg->getStringValue("dialog-name")); + else + dialog = gui->getActiveDialog(); + if (dialog != 0) { - if (arg->hasValue("object-name")) { - dialog->updateValue(arg->getStringValue("object-name")); - } else { - dialog->updateValues(); - } + dialog->updateValues(arg->getStringValue("object-name")); return true; } else { return false; @@ -1115,16 +1119,14 @@ static bool do_dialog_apply (const SGPropertyNode * arg) { NewGUI * gui = (NewGUI *)globals->get_subsystem("gui"); - FGDialog * dialog = gui->getActiveDialog(); + FGDialog * dialog; + if (arg->hasValue("dialog-name")) + dialog = gui->getDialog(arg->getStringValue("dialog-name")); + else + dialog = gui->getActiveDialog(); + if (dialog != 0) { - if (arg->hasValue("object-name")) { - const char * name = arg->getStringValue("object-name"); - dialog->applyValue(name); - dialog->updateValue(name); - } else { - dialog->applyValues(); - dialog->updateValues(); - } + dialog->applyValues(arg->getStringValue("object-name")); return true; } else { return false; @@ -1156,8 +1158,9 @@ do_play_audio_message (const SGPropertyNode * arg) FGFX *fx = (FGFX *)globals->get_subsystem("fx"); string path = arg->getStringValue("path"); string file = arg->getStringValue("file"); - cout << "playing " << path << " / " << file << endl; - fx->play_message( path, file ); + double volume = arg->getDoubleValue("volume"); + // cout << "playing " << path << " / " << file << endl; + fx->play_message( path, file, volume ); return true; } @@ -1176,7 +1179,6 @@ do_presets_commit (const SGPropertyNode * arg) // set position from presets fgInitPosition(); - // BusyCursor(0); fgReInitSubsystems(); globals->get_tile_mgr()->update( fgGetDouble("/environment/visibility-m") ); @@ -1222,13 +1224,27 @@ do_replay (const SGPropertyNode * arg) fgSetDouble( "/sim/replay/time", r->get_start_time() ); } - cout << "start = " << r->get_start_time() - << " end = " << r->get_end_time() << endl; + // cout << "start = " << r->get_start_time() + // << " end = " << r->get_end_time() << endl; return true; } +/** + * Return terrain elevation for given longitude/latitude pair. + */ +static bool +do_terrain_elevation (const SGPropertyNode * arg) +{ + double lon = arg->getDoubleValue("longitude-deg", 0.0); + double lat = arg->getDoubleValue("latitude-deg", 0.0); + double elev; + bool ret = globals->get_scenery()->get_elevation_m(lat, lon, 10000.0, elev, 0, false); + const_cast(arg)->setDoubleValue("elevation-m", elev); + return ret; +} + static bool do_decrease_visibility (const SGPropertyNode * arg) @@ -1252,20 +1268,6 @@ do_increase_visibility (const SGPropertyNode * arg) return true; } -static bool -do_hud_brightkey(const SGPropertyNode *) -{ - HUD_brightkey( true ); - return true; -} - -static bool -do_hud_masterswitch(const SGPropertyNode *) -{ - HUD_masterswitch( true ); - return true; -} - static bool do_hud_init(const SGPropertyNode *) { @@ -1348,6 +1350,49 @@ do_save_xml_from_proptree(const SGPropertyNode * node) return true; } +static bool +do_press_cockpit_button (const SGPropertyNode *arg) +{ + const char *prefix = arg->getStringValue("prefix"); + + if (arg->getBoolValue("guarded") && fgGetDouble((string(prefix) + "-guard").c_str()) < 1) + return true; + + string prop = string(prefix) + "-button"; + double value; + + if (arg->getBoolValue("latching")) + value = fgGetDouble(prop.c_str()) > 0 ? 0 : 1; + else + value = 1; + + fgSetDouble(prop.c_str(), value); + fgSetBool(arg->getStringValue("discrete"), value > 0); + + return true; +} + +static bool +do_release_cockpit_button (const SGPropertyNode *arg) +{ + const char *prefix = arg->getStringValue("prefix"); + + if (arg->getBoolValue("guarded")) { + string prop = string(prefix) + "-guard"; + if (fgGetDouble(prop.c_str()) < 1) { + fgSetDouble(prop.c_str(), 1); + return true; + } + } + + if (! arg->getBoolValue("latching")) { + fgSetDouble((string(prefix) + "-button").c_str(), 0); + fgSetBool(arg->getStringValue("discrete"), false); + } + + return true; +} + //////////////////////////////////////////////////////////////////////// // Command setup. @@ -1406,14 +1451,15 @@ static struct { { "presets-commit", do_presets_commit }, { "log-level", do_log_level }, { "replay", do_replay }, + { "terrain-elevation", do_terrain_elevation }, { "decrease-visibility", do_decrease_visibility }, { "increase-visibility", do_increase_visibility }, - { "hud-brightkey", do_hud_brightkey }, - { "hud-masterswitch", do_hud_masterswitch }, { "hud-init", do_hud_init }, { "hud-init2", do_hud_init2 }, { "loadxml", do_load_xml_to_proptree}, { "savexml", do_save_xml_from_proptree }, + { "press-cockpit-button", do_press_cockpit_button }, + { "release-cockpit-button", do_release_cockpit_button }, { 0, 0 } // zero-terminated };