From 37c427558ab35f992a15834552fb982afb12a52c Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 29 Mar 2003 15:04:52 +0000 Subject: [PATCH] A first stab at an aircraft selection dialog --- docs-mini/README.gui | 25 +++++++- src/Aircraft/aircraft.cxx | 125 ++++++++++++++++++++++++++++++++++++++ src/Aircraft/aircraft.hxx | 6 +- src/GUI/dialog.cxx | 21 ++++++- src/Main/fg_commands.cxx | 1 - src/Main/main.cxx | 6 ++ src/Sound/fg_sound.cxx | 3 +- src/Sound/soundmgr.cxx | 4 ++ 8 files changed, 185 insertions(+), 6 deletions(-) diff --git a/docs-mini/README.gui b/docs-mini/README.gui index 2f6dfe63f..4b7691728 100644 --- a/docs-mini/README.gui +++ b/docs-mini/README.gui @@ -105,10 +105,10 @@ All objects, including the top-level dialog, accept the following properties, though they will ignore any that are not relevant: x - the X position of the bottom left corner of the object, in - pseudo-pixels. The default is 0. + pseudo-pixels. The default is to center the dialog. y - the Y position of the bottom left corner of the object, in - pseudo-pixels. The default is 0. + pseudo-pixels. The default is to center the dialog. width - the width of the object, in pseudo-pixels. The default is the width of the parent container. @@ -290,6 +290,27 @@ Example: + +select +------ + +A scrollable list of selections. + + selection - a path in the property tree which holds the selectable items. + +Example: + + + + + slider ------ diff --git a/src/Aircraft/aircraft.cxx b/src/Aircraft/aircraft.cxx index 886cc149d..6679d6486 100644 --- a/src/Aircraft/aircraft.cxx +++ b/src/Aircraft/aircraft.cxx @@ -22,14 +22,26 @@ #include +#include // strdup + +#include +#include #include #include +#include +#include +#include #include
+#include
+#include
#include "aircraft.hxx" +extern void fgInitFDM(void); +class FGFX; + // This is a record containing all the info for the aircraft currently // being operated fgAIRCRAFT current_aircraft; @@ -69,3 +81,116 @@ void fgAircraftOutputCurrent(fgAIRCRAFT *a) { } +// Show available aircraft types +void fgReadAircraft(void) { + + SGPropertyNode *aircraft_types = fgGetNode("/sim/aircraft-types", true); + + SGPath path( globals->get_fg_root() ); + path.append("Aircraft"); + + ulDirEnt* dire; + ulDir *dirp; + + dirp = ulOpenDir(path.c_str()); + if (dirp == NULL) { + SG_LOG( SG_AIRCRAFT, SG_ALERT, "Unable to open aircraft directory." ); + ulCloseDir(dirp); + return; + } + + while ((dire = ulReadDir(dirp)) != NULL) { + char *ptr; + + if ((ptr = strstr(dire->d_name, "-set.xml")) && strlen(ptr) == 8) { + + *ptr = '\0'; +#if 0 + SGPath afile = path; + afile.append(dire->d_name); + + SGPropertyNode root; + try { + readProperties(afile.str(), &root); + } catch (...) { + continue; + } + + SGPropertyNode *node = root.getNode("sim"); + if (node) { + SGPropertyNode *desc = node->getNode("description"); + + if (desc) { +#endif + SGPropertyNode *aircraft = + aircraft_types->getChild(dire->d_name, 0, true); +#if 0 + + aircraft->setStringValue(strdup(desc->getStringValue())); + } + } +#endif + } + } + + ulCloseDir(dirp); + + globals->get_commands()->addCommand("load-aircraft", fgLoadAircraft); +} + +static inline bool +fgLoadAircraft (const SGPropertyNode * arg) +{ + static const SGPropertyNode *master_freeze + = fgGetNode("/sim/freeze/master"); + + bool freeze = master_freeze->getBoolValue(); + if ( !freeze ) { + fgSetBool("/sim/freeze/master", true); + } + + cur_fdm_state->unbind(); + + string aircraft = fgGetString("/sim/aircraft", ""); + globals->restoreInitialState(); + + if ( aircraft.size() > 0 ) { + SGPath aircraft_path(globals->get_fg_root()); + aircraft_path.append("Aircraft"); + aircraft_path.append(aircraft); + aircraft_path.concat("-set.xml"); + SG_LOG(SG_INPUT, SG_INFO, "Reading default aircraft: " << aircraft + << " from " << aircraft_path.str()); + try { + readProperties(aircraft_path.str(), globals->get_props()); + } catch (const sg_exception &e) { + string message = "Error reading default aircraft: "; + message += e.getFormattedMessage(); + SG_LOG(SG_INPUT, SG_ALERT, message); + exit(2); + } + } else { + SG_LOG(SG_INPUT, SG_ALERT, "No default aircraft specified"); + } + + // Update the FDM + // + fgSetString("/sim/aircraft", aircraft.c_str()); + fgInitFDM(); + + // update our position based on current presets + fgInitPosition(); + + SGTime *t = globals->get_time_params(); + delete t; + t = fgInitTime(); + globals->set_time_params( t ); + + fgReInitSubsystems(); + + if ( !freeze ) { + fgSetBool("/sim/freeze/master", false); + } + + return true; +} diff --git a/src/Aircraft/aircraft.hxx b/src/Aircraft/aircraft.hxx index a05a4cb3a..65450ffb1 100644 --- a/src/Aircraft/aircraft.hxx +++ b/src/Aircraft/aircraft.hxx @@ -34,6 +34,7 @@ #include #include +#include
// Define a structure containing all the parameters for an aircraft @@ -56,6 +57,9 @@ void fgAircraftInit( void ); void fgAircraftOutputCurrent(fgAIRCRAFT *a); +// Read the list of available aircraft into to property tree +void fgReadAircraft(void); +bool fgLoadAircraft (const SGPropertyNode * arg); + #endif // _AIRCRAFT_HXX - diff --git a/src/GUI/dialog.cxx b/src/GUI/dialog.cxx index 7dca5bf1a..c51910990 100644 --- a/src/GUI/dialog.cxx +++ b/src/GUI/dialog.cxx @@ -196,7 +196,9 @@ FGDialog::display (SGPropertyNode * props) return; } - _object = makeObject(props, 1024, 768); + _object = makeObject(props, + globals->get_props()->getIntValue("/sim/startup/xsize"), + globals->get_props()->getIntValue("/sim/startup/ysize")); if (_object != 0) { _object->reveal(); @@ -280,6 +282,23 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight) dial->setWrap(props->getBoolValue("wrap", true)); setupObject(dial, props); return dial; + } else if (type == "select") { + vector value_nodes; + SGPropertyNode * selection_node = + fgGetNode(props->getChild("selection")->getStringValue(), true); + + for (int q = 0; q < selection_node->nChildren(); q++) + value_nodes.push_back(selection_node->getChild(q)); + + char ** entries = make_char_array(value_nodes.size()); + for (int i = 0, j = value_nodes.size() - 1; + i < value_nodes.size(); + i++, j--) + entries[i] = strdup((char *)value_nodes[i]->getName()); + puSelectBox * select = + new puSelectBox(x, y, x + width, y + height, entries); + setupObject(select, props); + return select; } else { return 0; } diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index d8764c17b..a56a21ef9 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -208,7 +208,6 @@ do_reinit (const SGPropertyNode * arg) return result; } - /** * Built-in command: suspend one or more subsystems. * diff --git a/src/Main/main.cxx b/src/Main/main.cxx index b32e5c624..9f3ca07c2 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1368,6 +1368,9 @@ static void fgIdleFunction ( void ) { // setup OpenGL view parameters fgInitVisuals(); + // Read the list of available aircrafts + fgReadAircraft(); + idle_state++; } else if ( idle_state == 5 ) { @@ -1631,6 +1634,9 @@ static bool fgMainInit( int argc, char **argv ) { // fonts !!! guiInit(); + // Read the list of available aircrafts + fgReadAircraft(); + #ifdef GL_EXT_texture_lod_bias glTexEnvf( GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, -0.5 ) ; #endif diff --git a/src/Sound/fg_sound.cxx b/src/Sound/fg_sound.cxx index 9f76ce0ac..867a6e5c8 100644 --- a/src/Sound/fg_sound.cxx +++ b/src/Sound/fg_sound.cxx @@ -77,6 +77,8 @@ FGSound::FGSound() FGSound::~FGSound() { + _mgr->get_scheduler()->stopSample(_sample->get_sample()); + if (_property) delete _property; @@ -85,7 +87,6 @@ FGSound::~FGSound() _volume.clear(); _pitch.clear(); - delete _sample; } diff --git a/src/Sound/soundmgr.cxx b/src/Sound/soundmgr.cxx index 7faa4be4a..94e3099a1 100644 --- a/src/Sound/soundmgr.cxx +++ b/src/Sound/soundmgr.cxx @@ -125,6 +125,8 @@ FGSoundMgr::~FGSoundMgr() { sample_map_iterator sample_end = samples.end(); for ( ; sample_current != sample_end; ++sample_current ) { sample_ref *sr = sample_current->second; + + audio_sched->stopSample(sr->sample); delete sr->sample; delete sr; } @@ -136,6 +138,8 @@ FGSoundMgr::~FGSoundMgr() { sound_map_iterator sound_end = sounds.end(); for ( ; sound_current != sound_end; ++sound_current ) { FGSimpleSound *s = sound_current->second; + + audio_sched->stopSample(s->get_sample()); delete s; }