From 3b88c71122e33315c51bbf7676f12abf9c512989 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 19 Dec 2000 23:29:16 +0000 Subject: [PATCH] Applied changes relative to David Megginson's property manager rewrite. --- Makefile.am | 13 +- src/Cockpit/panel_io.cxx | 307 ++++++++++++++++++++------------------ src/Cockpit/steam.cxx | 58 +++---- src/Joystick/joystick.cxx | 32 ++-- src/Main/bfi.cxx | 255 +++++++++++++------------------ src/Main/bfi.hxx | 18 +-- src/Main/fg_init.cxx | 20 +-- src/Main/globals.hxx | 8 + src/Main/keyboard.cxx | 4 +- src/Main/main.cxx | 19 ++- src/Main/options.cxx | 44 +++--- src/Main/save.cxx | 4 +- src/Network/props.cxx | 100 ++++--------- 13 files changed, 418 insertions(+), 464 deletions(-) diff --git a/Makefile.am b/Makefile.am index d1124d23b..a9dbbeebb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,7 @@ EXTRA_DIST = Thanks acsite.m4 acconfig.h irix-hack.pl \ FlightGear.dsp FlightGear.dsw dist-hook: - (cd $(top_srcdir); ../admin/am2dsp.pl) + (cd $(top_srcdir); $(HOME)/projects/FlightGear-0.7/admin/am2dsp.pl) tar --exclude docs-mini/CVS --exclude hints/CVS -cf - docs-mini hints \ | (cd $(distdir); tar xvf -) # tar cf - Simulator/FDM/JSBsim/aircraft Simulator/FDM/JSBsim/engine | (cd $(distdir); tar xvf -) @@ -26,7 +26,8 @@ fgfs-base: fgfs-base-tar fgfs-base-zip fgfs-base-patch fgfs-textures-high fgfs-base-tar: (cd $(HOME); \ - tar --exclude=CVS -czvf fgfs-base-$(VERSION).tar.gz \ + tar --exclude=CVS --exclude='*/Textures/Unused' \ + -czvf fgfs-base-$(VERSION).tar.gz \ FlightGear/A[A-su-z]* \ FlightGear/[B-CE-R]* \ FlightGear/Scenery/w130n30/w123n37 \ @@ -43,7 +44,7 @@ fgfs-base-zip: FlightGear/Scenery/w130n30/w122n37 \ FlightGear/Sounds \ FlightGear/[T-Za]* FlightGear/[c-z]* \ - -x '*/CVS/*' ) + -x '*/CVS/*' -x '*/Textures/Unused/*' ) fgfs-base-patch: (cd $(HOME); \ @@ -72,15 +73,15 @@ jsbsim-data: fgfs-docs: fgfs-docs-tar fgfs-manual-zip fgfs-docs-tar: - ( cd ../.. ; \ + ( cd $(HOME)/projects ; \ tar czvf fgfs-docs-$(VERSION).tar.gz FlightGear-0.7/docs ) # fgfs-docs-zip: -# ( cd ../.. ; \ +# ( cd $(HOME)/projects ; \ # zip -r fgfs-docs-$(VERSION).zip FlightGear-0.7/docs ) fgfs-manual-zip: - ( cd ../.. ; \ + ( cd $(HOME)/projects ; \ zip -r fgfs-manual-$(VERSION).zip FlightGear-0.7/docs/InstallGuide ) # make the win32-bin distribution diff --git a/src/Cockpit/panel_io.cxx b/src/Cockpit/panel_io.cxx index f010f9b16..5e09ce0a7 100644 --- a/src/Cockpit/panel_io.cxx +++ b/src/Cockpit/panel_io.cxx @@ -212,14 +212,14 @@ FGMagRibbon::draw () * texture, x1=0.0, y1=0.0, x2=0.5, y2=0.5. */ static FGCroppedTexture -readTexture (SGPropertyNode node) +readTexture (const SGPropertyNode * node) { - FGCroppedTexture texture(node.getStringValue("path"), - node.getFloatValue("x1"), - node.getFloatValue("y1"), - node.getFloatValue("x2", 1.0), - node.getFloatValue("y2", 1.0)); - FG_LOG(FG_INPUT, FG_INFO, "Read texture " << node.getName()); + FGCroppedTexture texture(node->getStringValue("path"), + node->getFloatValue("x1"), + node->getFloatValue("y1"), + node->getFloatValue("x2", 1.0), + node->getFloatValue("y2", 1.0)); + FG_LOG(FG_INPUT, FG_INFO, "Read texture " << node->getName()); return texture; } @@ -250,18 +250,18 @@ readTexture (SGPropertyNode node) * being drawn at its regular size. */ static FGPanelAction * -readAction (SGPropertyNode node, float hscale, float vscale) +readAction (const SGPropertyNode * node, float hscale, float vscale) { FGPanelAction * action = 0; - string name = node.getStringValue("name"); - string type = node.getStringValue("type"); + string name = node->getStringValue("name"); + string type = node->getStringValue("type"); - int button = node.getIntValue("button"); - int x = int(node.getIntValue("x") * hscale); - int y = int(node.getIntValue("y") * vscale); - int w = int(node.getIntValue("w") * hscale); - int h = int(node.getIntValue("h") * vscale); + int button = node->getIntValue("button"); + int x = int(node->getIntValue("x") * hscale); + int y = int(node->getIntValue("y") * vscale); + int w = int(node->getIntValue("w") * hscale); + int h = int(node->getIntValue("h") * vscale); if (type == "") { FG_LOG(FG_INPUT, FG_ALERT, @@ -271,14 +271,14 @@ readAction (SGPropertyNode node, float hscale, float vscale) // Adjust a property value if (type == "adjust") { - string propName = node.getStringValue("property"); - SGValue * value = current_properties.getValue(propName, true); - float increment = node.getFloatValue("increment", 1.0); - float min = node.getFloatValue("min", 0.0); - float max = node.getFloatValue("max", 0.0); - bool wrap = node.getBoolValue("wrap", false); + string propName = node->getStringValue("property"); + SGValue * value = globals->get_props()->getValue(propName, true); + float increment = node->getFloatValue("increment", 1.0); + float min = node->getFloatValue("min", 0.0); + float max = node->getFloatValue("max", 0.0); + bool wrap = node->getBoolValue("wrap", false); if (min == max) - FG_LOG(FG_INPUT, FG_ALERT, "Action " << node.getName() + FG_LOG(FG_INPUT, FG_ALERT, "Action " << node->getName() << " has same min and max value"); action = new FGAdjustAction(button, x, y, w, h, value, increment, min, max, wrap); @@ -286,17 +286,17 @@ readAction (SGPropertyNode node, float hscale, float vscale) // Swap two property values else if (type == "swap") { - string propName1 = node.getStringValue("property1"); - string propName2 = node.getStringValue("property2"); - SGValue * value1 = current_properties.getValue(propName1, true); - SGValue * value2 = current_properties.getValue(propName2, true); + string propName1 = node->getStringValue("property1"); + string propName2 = node->getStringValue("property2"); + SGValue * value1 = globals->get_props()->getValue(propName1, true); + SGValue * value2 = globals->get_props()->getValue(propName2, true); action = new FGSwapAction(button, x, y, w, h, value1, value2); } // Toggle a boolean value else if (type == "toggle") { - string propName = node.getStringValue("property"); - SGValue * value = current_properties.getValue(propName, true); + string propName = node->getStringValue("property"); + SGValue * value = globals->get_props()->getValue(propName, true); action = new FGToggleAction(button, x, y, w, h, value); } @@ -336,13 +336,13 @@ readAction (SGPropertyNode node, float hscale, float vscale) * appear to be applied backwards. */ static FGPanelTransformation * -readTransformation (SGPropertyNode node, float hscale, float vscale) +readTransformation (const SGPropertyNode * node, float hscale, float vscale) { FGPanelTransformation * t = new FGPanelTransformation; - string name = node.getName(); - string type = node.getStringValue("type"); - string propName = node.getStringValue("property", ""); + string name = node->getName(); + string type = node->getStringValue("type"); + string propName = node->getStringValue("property", ""); SGValue * value = 0; if (type == "") { @@ -353,14 +353,14 @@ readTransformation (SGPropertyNode node, float hscale, float vscale) } if (propName != "") { - value = current_properties.getValue(propName, true); + value = globals->get_props()->getValue(propName, true); } t->value = value; - t->min = node.getFloatValue("min", -9999999); - t->max = node.getFloatValue("max", 99999999); - t->factor = node.getFloatValue("scale", 1.0); - t->offset = node.getFloatValue("offset", 0.0); + t->min = node->getFloatValue("min", -9999999); + t->max = node->getFloatValue("max", 99999999); + t->factor = node->getFloatValue("scale", 1.0); + t->offset = node->getFloatValue("offset", 0.0); // Move the layer horizontally. if (type == "x-shift") { @@ -413,12 +413,12 @@ readTransformation (SGPropertyNode node, float hscale, float vscale) * All three may also include a printf-style format string. */ FGTextLayer::Chunk * -readTextChunk (SGPropertyNode node) +readTextChunk (const SGPropertyNode * node) { FGTextLayer::Chunk * chunk; - string name = node.getStringValue("name"); - string type = node.getStringValue("type"); - string format = node.getStringValue("format"); + string name = node->getStringValue("name"); + string type = node->getStringValue("type"); + string format = node->getStringValue("format"); // Default to literal text. if (type == "") { @@ -429,22 +429,22 @@ readTextChunk (SGPropertyNode node) // A literal text string. if (type == "literal") { - string text = node.getStringValue("text"); + string text = node->getStringValue("text"); chunk = new FGTextLayer::Chunk(text, format); } // The value of a string property. else if (type == "text-value") { SGValue * value = - current_properties.getValue(node.getStringValue("property"), true); + globals->get_props()->getValue(node->getStringValue("property"), true); chunk = new FGTextLayer::Chunk(FGTextLayer::TEXT_VALUE, value, format); } // The value of a float property. else if (type == "number-value") { - string propName = node.getStringValue("property"); - float scale = node.getFloatValue("scale", 1.0); - SGValue * value = current_properties.getValue(propName, true); + string propName = node->getStringValue("property"); + float scale = node->getFloatValue("scale", 1.0); + SGValue * value = globals->get_props()->getValue(propName, true); chunk = new FGTextLayer::Chunk(FGTextLayer::DOUBLE_VALUE, value, format, scale); } @@ -482,13 +482,13 @@ readTextChunk (SGPropertyNode node) * Currently, the only built-in layer class is "compass-ribbon". */ static FGInstrumentLayer * -readLayer (SGPropertyNode node, float hscale, float vscale) +readLayer (const SGPropertyNode * node, float hscale, float vscale) { FGInstrumentLayer * layer = NULL; - string name = node.getStringValue("name"); - string type = node.getStringValue("type"); - int w = node.getIntValue("w", -1); - int h = node.getIntValue("h", -1); + string name = node->getStringValue("name"); + string type = node->getStringValue("type"); + int w = node->getIntValue("w", -1); + int h = node->getIntValue("h", -1); if (w != -1) w = int(w * hscale); if (h != -1) @@ -505,7 +505,7 @@ readLayer (SGPropertyNode node, float hscale, float vscale) // A textured instrument layer. if (type == "texture") { - FGCroppedTexture texture = readTexture(node.getSubNode("texture")); + FGCroppedTexture texture = readTexture(node->getNode("texture")); layer = new FGTexturedLayer(texture, w, h); } @@ -515,45 +515,47 @@ readLayer (SGPropertyNode node, float hscale, float vscale) FGTextLayer * tlayer = new FGTextLayer(w, h); // FIXME // Set the text color. - float red = node.getFloatValue("color/red", 0.0); - float green = node.getFloatValue("color/green", 0.0); - float blue = node.getFloatValue("color/blue", 0.0); + float red = node->getFloatValue("color/red", 0.0); + float green = node->getFloatValue("color/green", 0.0); + float blue = node->getFloatValue("color/blue", 0.0); tlayer->setColor(red, green, blue); // Set the point size. - float pointSize = node.getFloatValue("point-size", 10.0) * hscale; + float pointSize = node->getFloatValue("point-size", 10.0) * hscale; tlayer->setPointSize(pointSize); // Set the font. // TODO - SGPropertyNode chunk_group = node.getSubNode("chunks"); - int nChunks = chunk_group.size(); - for (int i = 0; i < nChunks; i++) { - FGTextLayer::Chunk * chunk = readTextChunk(chunk_group.getChild(i)); - if (chunk == 0) { - delete layer; - return 0; + const SGPropertyNode * chunk_group = node->getNode("chunks"); + if (chunk_group != 0) { + int nChunks = chunk_group->nChildren(); + for (int i = 0; i < nChunks; i++) { + FGTextLayer::Chunk * chunk = readTextChunk(chunk_group->getChild(i)); + if (chunk == 0) { + delete layer; + return 0; + } + tlayer->addChunk(chunk); } - tlayer->addChunk(chunk); + layer = tlayer; } - layer = tlayer; } // A switch instrument layer. else if (type == "switch") { SGValue * value = - current_properties.getValue(node.getStringValue("property"), true); + globals->get_props()->getValue(node->getStringValue("property"), true); FGInstrumentLayer * layer1 = - readLayer(node.getSubNode("layer1"), hscale, vscale); + readLayer(node->getNode("layer1"), hscale, vscale); FGInstrumentLayer * layer2 = - readLayer(node.getSubNode("layer2"), hscale, vscale); + readLayer(node->getNode("layer2"), hscale, vscale); layer = new FGSwitchLayer(w, h, value, layer1, layer2); } // A built-in instrument layer. else if (type == "built-in") { - string layerclass = node.getStringValue("class"); + string layerclass = node->getStringValue("class"); if (layerclass == "mag-ribbon") { layer = new FGMagRibbon(w, h); @@ -582,16 +584,18 @@ readLayer (SGPropertyNode node, float hscale, float vscale) // // Get the transformations for each layer. // - SGPropertyNode trans_group = node.getSubNode("transformations"); - int nTransformations = trans_group.size(); - for (int k = 0; k < nTransformations; k++) { - FGPanelTransformation * t = readTransformation(trans_group.getChild(k), - hscale, vscale); - if (t == 0) { - delete layer; - return 0; + const SGPropertyNode * trans_group = node->getNode("transformations"); + if (trans_group != 0) { + int nTransformations = trans_group->nChildren(); + for (int i = 0; i < nTransformations; i++) { + FGPanelTransformation * t = readTransformation(trans_group->getChild(i), + hscale, vscale); + if (t == 0) { + delete layer; + return 0; + } + layer->addTransformation(t); } - layer->addTransformation(t); } FG_LOG(FG_INPUT, FG_INFO, "Read layer " << name); @@ -611,11 +615,12 @@ readLayer (SGPropertyNode node, float hscale, float vscale) * scaled automatically if the instrument is not at its preferred size. */ static FGPanelInstrument * -readInstrument (SGPropertyNode node, int x, int y, int real_w, int real_h) +readInstrument (const SGPropertyNode * node, int x, int y, + int real_w, int real_h) { - int w = node.getIntValue("w"); - int h = node.getIntValue("h"); - const string &name = node.getStringValue("name"); + int w = node->getIntValue("w"); + int h = node->getIntValue("h"); + const string &name = node->getStringValue("name"); float hscale = 1.0; float vscale = 1.0; @@ -636,34 +641,37 @@ readInstrument (SGPropertyNode node, int x, int y, int real_w, int real_h) // // Get the actions for the instrument. // - SGPropertyNode action_group = node.getSubNode("actions"); - int nActions = action_group.size(); - int j; - for (j = 0; j < nActions; j++) { - FGPanelAction * action = readAction(action_group.getChild(j), - hscale, vscale); - if (action == 0) { - delete instrument; - return new DefaultInstrument(x, y, w, h); + const SGPropertyNode * action_group = node->getNode("actions"); + if (action_group != 0) { + int nActions = action_group->nChildren(); + for (int i = 0; i < nActions; i++) { + FGPanelAction * action = readAction(action_group->getChild(i), + hscale, vscale); + if (action == 0) { + delete instrument; + return new DefaultInstrument(x, y, w, h); + } + instrument->addAction(action); } - instrument->addAction(action); } // // Get the layers for the instrument. // - SGPropertyNode layer_group = node.getSubNode("layers"); - int nLayers = layer_group.size(); - for (j = 0; j < nLayers; j++) { - FGInstrumentLayer * layer = readLayer(layer_group.getChild(j), - hscale, vscale); - if (layer == 0) { - delete instrument; - return new DefaultInstrument(x, y, w, h); + const SGPropertyNode * layer_group = node->getNode("layers"); + if (layer_group != 0) { + int nLayers = layer_group->nChildren(); + for (int i = 0; i < nLayers; i++) { + FGInstrumentLayer * layer = readLayer(layer_group->getChild(i), + hscale, vscale); + if (layer == 0) { + delete instrument; + return new DefaultInstrument(x, y, w, h); + } + instrument->addLayer(layer); } - instrument->addLayer(layer); } - + FG_LOG(FG_INPUT, FG_INFO, "Done reading instrument " << name); return instrument; } @@ -682,18 +690,18 @@ readInstrument (SGPropertyNode node, int x, int y, int real_w, int real_h) FGPanel * fgReadPanel (istream &input) { - SGPropertyList props; + SGPropertyNode root; // // Read the property list from disk. // - if (!readPropertyList(input, &props)) { + if (!readProperties(input, &root)) { FG_LOG(FG_INPUT, FG_ALERT, "Malformed property list for panel."); return 0; } FG_LOG(FG_INPUT, FG_INFO, "Read properties for panel " << - props.getStringValue("/name")); + root.getStringValue("name")); // // Construct a new, empty panel. @@ -704,26 +712,26 @@ fgReadPanel (istream &input) // // Grab the panel's dimensions, default to 1024x443. // - int panel_w = (props.hasValue("/w") ? props.getIntValue("/w") : 1024); - int panel_h = (props.hasValue("/h") ? props.getIntValue("/h") : 443); + int panel_w = (root.hasValue("w") ? root.getIntValue("w") : 1024); + int panel_h = (root.hasValue("h") ? root.getIntValue("h") : 443); panel->setWidth(panel_w); panel->setHeight(panel_h); // // Grab the visible external viewing area, default to // - panel->setViewHeight(props.hasValue("/view-height") ? - props.getIntValue("/view-height") : + panel->setViewHeight(root.hasValue("view-height") ? + root.getIntValue("view-height") : 768 - panel_h + 2); // // Grab the panel's initial offsets, default to 0, 0. // - int xoffset = (props.hasValue("/x-offset") ? - props.getIntValue("x-offset") : + int xoffset = (root.hasValue("x-offset") ? + root.getIntValue("x-offset") : 0); - int yoffset = (props.hasValue("/y-offset") ? - props.getIntValue("y-offset") : + int yoffset = (root.hasValue("y-offset") ? + root.getIntValue("y-offset") : 0); panel->setXOffset(xoffset); panel->setYOffset(yoffset); @@ -731,7 +739,7 @@ fgReadPanel (istream &input) // // Assign the background texture, if any, or a bogus chequerboard. // - string bgTexture = props.getStringValue("/background"); + string bgTexture = root.getStringValue("background"); if (bgTexture == "") bgTexture = "FOO"; panel->setBackground(FGTextureManager::createTexture(bgTexture.c_str())); @@ -742,41 +750,46 @@ fgReadPanel (istream &input) // Create each instrument. // FG_LOG(FG_INPUT, FG_INFO, "Reading panel instruments"); - SGPropertyNode instrument_group("/instruments", &props); - int nInstruments = instrument_group.size(); - for (int i = 0; i < nInstruments; i++) { - SGPropertyList props2; - SGPropertyNode node = instrument_group.getChild(i); - - FGPath path( globals->get_options()->get_fg_root() ); - path.append(node.getStringValue("path")); - - FG_LOG(FG_INPUT, FG_INFO, "Reading instrument " - << node.getName() - << " from " - << path.str()); - - int x = node.getIntValue("x", -1); - int y = node.getIntValue("y", -1); - int w = node.getIntValue("w", -1); - int h = node.getIntValue("h", -1); - - if (x == -1 || y == -1) { - FG_LOG(FG_INPUT, FG_ALERT, "x and y positions must be specified and >0"); - delete panel; - return 0; - } - - - FGPanelInstrument * instrument = 0; + const SGPropertyNode * instrument_group = root.getChild("instruments"); + if (instrument_group != 0) { + int nInstruments = instrument_group->nChildren(); + for (int i = 0; i < nInstruments; i++) { + const SGPropertyNode * node = instrument_group->getChild(i); + + FGPath path( globals->get_options()->get_fg_root() ); + path.append(node->getStringValue("path")); + + FG_LOG(FG_INPUT, FG_INFO, "Reading instrument " + << node->getName() + << " from " + << path.str()); + + int x = node->getIntValue("x", -1); + int y = node->getIntValue("y", -1); + int w = node->getIntValue("w", -1); + int h = node->getIntValue("h", -1); + + if (x == -1 || y == -1) { + FG_LOG(FG_INPUT, FG_ALERT, "x and y positions must be specified and >0"); + delete panel; + return 0; + } - if (readPropertyList(path.str(), &props2)) { - instrument = readInstrument(SGPropertyNode("/", &props2), x, y, w, h); - } - if (instrument == 0) { - instrument = new DefaultInstrument(x, y, w, h); + // Read the instrument from + // a separate file. + FGPanelInstrument * instrument = 0; + + SGPropertyNode root2; + + if (readProperties(path.str(), &root2)) { + cerr << "Read " << root2.nChildren() << " top-level nodes from " + << path.c_str() << endl; + instrument = readInstrument(&root2, x, y, w, h); + } + if (instrument == 0) + instrument = new DefaultInstrument(x, y, w, h); + panel->addInstrument(instrument); } - panel->addInstrument(instrument); } FG_LOG(FG_INPUT, FG_INFO, "Done reading panel instruments"); diff --git a/src/Cockpit/steam.cxx b/src/Cockpit/steam.cxx index 618671e1d..df7a507a1 100644 --- a/src/Cockpit/steam.cxx +++ b/src/Cockpit/steam.cxx @@ -96,39 +96,47 @@ double FGSteam::get_TC_std () { _CatchUp(); return the_TC_std; } int FGSteam::_UpdatesPending = 1000000; /* Forces filter to reset */ + // FIXME: no need to use static + // functions any longer. +#define DF1(getter) SGRawValueFunctions(getter,0) +#define DF2(getter, setter) SGRawValueFunctions(getter,setter) + void FGSteam::update ( int timesteps ) { if (!isTied) { isTied = true; - current_properties.tieDouble("/steam/airspeed", - FGSteam::get_ASI_kias); - current_properties.tieDouble("/steam/altitude", - FGSteam::get_ALT_ft); - current_properties.tieDouble("/steam/turn-rate", - FGSteam::get_TC_std); - current_properties.tieDouble("/steam/slip-skid", - FGSteam::get_TC_rad); - current_properties.tieDouble("/steam/vertical-speed", - FGSteam::get_VSI_fps); - current_properties.tieDouble("/steam/gyro-compass", - FGSteam::get_DG_deg); - current_properties.tieDouble("/steam/vor1", - FGSteam::get_HackVOR1_deg); - current_properties.tieDouble("/steam/vor2", - FGSteam::get_HackVOR2_deg); - current_properties.tieDouble("/steam/glidescope1", - FGSteam::get_HackGS_deg); - current_properties.tieDouble("/steam/adf", - FGSteam::get_HackADF_deg); - current_properties.tieDouble("/steam/gyro-compass-error", - FGSteam::get_DG_err, - FGSteam::set_DG_err); - current_properties.tieDouble("/steam/mag-compass", - FGSteam::get_MH_deg); + globals->get_props()->tie("/steam/airspeed", + DF1(FGSteam::get_ASI_kias)); + globals->get_props()->tie("/steam/altitude", + DF1(FGSteam::get_ALT_ft)); + globals->get_props()->tie("/steam/turn-rate", + DF1(FGSteam::get_TC_std)); + globals->get_props()->tie("/steam/slip-skid", + DF1(FGSteam::get_TC_rad)); + globals->get_props()->tie("/steam/vertical-speed", + DF1(FGSteam::get_VSI_fps)); + globals->get_props()->tie("/steam/gyro-compass", + DF1(FGSteam::get_DG_deg)); + globals->get_props()->tie("/steam/vor1", + DF1(FGSteam::get_HackVOR1_deg)); + globals->get_props()->tie("/steam/vor2", + DF1(FGSteam::get_HackVOR2_deg)); + globals->get_props()->tie("/steam/glidescope1", + DF1(FGSteam::get_HackGS_deg)); + globals->get_props()->tie("/steam/adf", + DF1(FGSteam::get_HackADF_deg)); + globals->get_props()->tie("/steam/gyro-compass-error", + DF2(FGSteam::get_DG_err, + FGSteam::set_DG_err)); + globals->get_props()->tie("/steam/mag-compass", + DF1(FGSteam::get_MH_deg)); } _UpdatesPending += timesteps; } +#undef DF1 +#undef DF2 + void FGSteam::set_lowpass ( double *outthe, double inthe, double tc ) { diff --git a/src/Joystick/joystick.cxx b/src/Joystick/joystick.cxx index 17f0b203e..b415619e6 100644 --- a/src/Joystick/joystick.cxx +++ b/src/Joystick/joystick.cxx @@ -35,6 +35,8 @@ #include +#include
+ #include #include #include @@ -198,19 +200,19 @@ fgJoystickInit() // Control property string name = base; name += "/control"; - SGValue * value = current_properties.getValue(name); + SGValue * value = globals->get_props()->getValue(name); if (value == 0) { FG_LOG(FG_INPUT, FG_INFO, " no control defined"); continue; } const string &control = value->getStringValue(); - a.value = current_properties.getValue(control, true); + a.value = globals->get_props()->getValue(control, true); FG_LOG(FG_INPUT, FG_INFO, " using control " << control); // Dead band name = base; name += "/dead-band"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) js->setDeadBand(j, value->getDoubleValue()); FG_LOG(FG_INPUT, FG_INFO, " dead-band is " << js->getDeadBand(j)); @@ -218,7 +220,7 @@ fgJoystickInit() // Offset name = base; name += "/offset"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) a.offset = value->getDoubleValue(); FG_LOG(FG_INPUT, FG_INFO, " offset is " << a.offset); @@ -227,7 +229,7 @@ fgJoystickInit() // Factor name = base; name += "/factor"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) a.factor = value->getDoubleValue(); FG_LOG(FG_INPUT, FG_INFO, " factor is " << a.factor); @@ -236,7 +238,7 @@ fgJoystickInit() // Tolerance name = base; name += "/tolerance"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) a.tolerance = value->getDoubleValue(); FG_LOG(FG_INPUT, FG_INFO, " tolerance is " << a.tolerance); @@ -245,7 +247,7 @@ fgJoystickInit() // Saturation name = base; name += "/saturation"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) js->setSaturation(j, value->getDoubleValue()); FG_LOG(FG_INPUT, FG_INFO, " saturation is " << js->getSaturation(j)); @@ -253,7 +255,7 @@ fgJoystickInit() // Minimum range name = base; name += "/min-range"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) minRange[j] = value->getDoubleValue(); FG_LOG(FG_INPUT, FG_INFO, " min-range is " << minRange[j]); @@ -261,7 +263,7 @@ fgJoystickInit() // Maximum range name = base; name += "/max-range"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) maxRange[j] = value->getDoubleValue(); FG_LOG(FG_INPUT, FG_INFO, " max-range is " << maxRange[j]); @@ -269,7 +271,7 @@ fgJoystickInit() // Center name = base; name += "/center"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) center[j] = value->getDoubleValue(); FG_LOG(FG_INPUT, FG_INFO, " center is " << center[j]); @@ -292,19 +294,19 @@ fgJoystickInit() string name = base; name += "/control"; cout << "Trying name " << name << endl; - SGValue * value = current_properties.getValue(name); + SGValue * value = globals->get_props()->getValue(name); if (value == 0) { FG_LOG(FG_INPUT, FG_INFO, " no control defined"); continue; } const string &control = value->getStringValue(); - b.value = current_properties.getValue(control, true); + b.value = globals->get_props()->getValue(control, true); FG_LOG(FG_INPUT, FG_INFO, " using control " << control); // Step name = base; name += "/step"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) b.step = value->getDoubleValue(); FG_LOG(FG_INPUT, FG_INFO, " step is " << b.step); @@ -312,7 +314,7 @@ fgJoystickInit() // Type name = base; name += "/action"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); string action = "adjust"; if (value != 0) action = value->getStringValue(); @@ -336,7 +338,7 @@ fgJoystickInit() // Repeatability. name = base; name += "/repeatable"; - value = current_properties.getValue(name); + value = globals->get_props()->getValue(name); if (value != 0) b.isRepeatable = value->getBoolValue(); FG_LOG(FG_INPUT, FG_INFO, (b.isRepeatable ? diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index 3c54cae18..e9707e022 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -180,6 +180,25 @@ static inline void _check_lighting () // Local functions //////////////////////////////////////////////////////////////////////// +static inline void +TIE_BOOL(const char * name, bool (*getter)(), void (*setter)(bool)) { + globals->get_props()->tie(name, SGRawValueFunctions(getter, setter)); +} + +static inline void +TIE_INT(const char * name, int (*getter)(), void (*setter)(int)) { + globals->get_props()->tie(name, SGRawValueFunctions(getter, setter)); +} + +static inline void +TIE_DOUBLE(const char * name, double (*getter)(), void (*setter)(double)) { + globals->get_props()->tie(name, SGRawValueFunctions(getter, setter)); +} + +static inline void +TIE_STRING(const char * name, string (*getter)(), void (*setter)(string)) { + globals->get_props()->tie(name, SGRawValueFunctions(getter, setter)); +} /** * Initialize the BFI by binding its functions to properties. @@ -192,161 +211,95 @@ FGBFI::init () { FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init"); // Simulation - current_properties.tieInt("/sim/flight-model", - getFlightModel, setFlightModel); - current_properties.tieString("/sim/aircraft", - getAircraft, setAircraft); - current_properties.tieString("/sim/aircraft-dir", - getAircraftDir, setAircraftDir); - // TODO: timeGMT - current_properties.tieString("/sim/time/gmt", - getDateString, setDateString); - current_properties.tieString("/sim/time/gmt-string", - getGMTString, 0); - current_properties.tieBool("/sim/hud/visibility", - getHUDVisible, setHUDVisible); - current_properties.tieBool("/sim/panel/visibility", - getPanelVisible, setPanelVisible); - current_properties.tieInt("/sim/panel/x-offset", - getPanelXOffset, setPanelXOffset); - current_properties.tieInt("/sim/panel/y-offset", - getPanelYOffset, setPanelYOffset); + TIE_INT("/sim/flight-model", getFlightModel, setFlightModel); + TIE_STRING("/sim/aircraft", getAircraft, setAircraft); + TIE_STRING("/sim/aircraft-dir", getAircraftDir, setAircraftDir); + TIE_STRING("/sim/time/gmt", getDateString, setDateString); + TIE_STRING("/sim/time/gmt-string", getGMTString, 0); + TIE_BOOL("/sim/hud/visibility", getHUDVisible, setHUDVisible); + TIE_BOOL("/sim/panel/visibility", getPanelVisible, setPanelVisible); + TIE_INT("/sim/panel/x-offset", getPanelXOffset, setPanelXOffset); + TIE_INT("/sim/panel/y-offset", getPanelYOffset, setPanelYOffset); // Position - current_properties.tieString("/position/airport-id", - getTargetAirport, setTargetAirport); - current_properties.tieDouble("/position/latitude", - getLatitude, setLatitude); - current_properties.tieDouble("/position/longitude", - getLongitude, setLongitude); - current_properties.tieDouble("/position/altitude", - getAltitude, setAltitude); -// getAltitude, setAltitude, false); - current_properties.tieDouble("/position/altitude-agl", - getAGL, 0); + TIE_STRING("/position/airport-id", getTargetAirport, setTargetAirport); + TIE_DOUBLE("/position/latitude", getLatitude, setLatitude); + TIE_DOUBLE("/position/longitude", getLongitude, setLongitude); + TIE_DOUBLE("/position/altitude", getAltitude, setAltitude); + TIE_DOUBLE("/position/altitude-agl", getAGL, 0); // Orientation - current_properties.tieDouble("/orientation/heading", - getHeading, setHeading); - current_properties.tieDouble("/orientation/heading-magnetic", - getHeadingMag, 0); - current_properties.tieDouble("/orientation/pitch", - getPitch, setPitch); - current_properties.tieDouble("/orientation/roll", - getRoll, setRoll); + TIE_DOUBLE("/orientation/heading", getHeading, setHeading); + TIE_DOUBLE("/orientation/heading-magnetic", getHeadingMag, 0); + TIE_DOUBLE("/orientation/pitch", getPitch, setPitch); + TIE_DOUBLE("/orientation/roll", getRoll, setRoll); // Engine - current_properties.tieDouble("/engines/engine0/rpm", - getRPM, 0); - current_properties.tieDouble("/engines/engine0/egt", - getEGT, 0); - current_properties.tieDouble("/engines/engine0/cht", - getCHT, 0); - current_properties.tieDouble("/engines/engine0/mp", - getMP, 0); + TIE_DOUBLE("/engines/engine0/rpm", getRPM, 0); + TIE_DOUBLE("/engines/engine0/egt", getEGT, 0); + TIE_DOUBLE("/engines/engine0/cht", getCHT, 0); + TIE_DOUBLE("/engines/engine0/mp", getMP, 0); // Velocities - current_properties.tieDouble("/velocities/airspeed", - getAirspeed, setAirspeed); - current_properties.tieDouble("/velocities/side-slip", - getSideSlip, 0); - current_properties.tieDouble("/velocities/vertical-speed", - getVerticalSpeed, 0); - current_properties.tieDouble("/velocities/speed-north", - getSpeedNorth, 0); - current_properties.tieDouble("/velocities/speed-east", - getSpeedEast, 0); - current_properties.tieDouble("/velocities/speed-down", - getSpeedDown, 0); + TIE_DOUBLE("/velocities/airspeed", getAirspeed, setAirspeed); + TIE_DOUBLE("/velocities/side-slip", getSideSlip, 0); + TIE_DOUBLE("/velocities/vertical-speed", getVerticalSpeed, 0); + TIE_DOUBLE("/velocities/speed-north", getSpeedNorth, 0); + TIE_DOUBLE("/velocities/speed-east", getSpeedEast, 0); + TIE_DOUBLE("/velocities/speed-down", getSpeedDown, 0); // Controls - current_properties.tieDouble("/controls/throttle", - getThrottle, setThrottle); - current_properties.tieDouble("/controls/mixture", - getMixture, setMixture); - current_properties.tieDouble("/controls/propellor-pitch", - getPropAdvance, setPropAdvance); - current_properties.tieDouble("/controls/flaps", - getFlaps, setFlaps); - current_properties.tieDouble("/controls/aileron", - getAileron, setAileron); - current_properties.tieDouble("/controls/rudder", - getRudder, setRudder); - current_properties.tieDouble("/controls/elevator", - getElevator, setElevator); - current_properties.tieDouble("/controls/elevator-trim", - getElevatorTrim, setElevatorTrim); - current_properties.tieDouble("/controls/brakes/all", - getBrakes, setBrakes); - current_properties.tieDouble("/controls/brakes/left", - getLeftBrake, setLeftBrake); - current_properties.tieDouble("/controls/brakes/right", - getRightBrake, setRightBrake); - current_properties.tieDouble("/controls/brakes/center", - getRightBrake, setCenterBrake); + TIE_DOUBLE("/controls/throttle", getThrottle, setThrottle); + TIE_DOUBLE("/controls/mixture", getMixture, setMixture); + TIE_DOUBLE("/controls/propellor-pitch", getPropAdvance, setPropAdvance); + TIE_DOUBLE("/controls/flaps", getFlaps, setFlaps); + TIE_DOUBLE("/controls/aileron", getAileron, setAileron); + TIE_DOUBLE("/controls/rudder", getRudder, setRudder); + TIE_DOUBLE("/controls/elevator", getElevator, setElevator); + TIE_DOUBLE("/controls/elevator-trim", getElevatorTrim, setElevatorTrim); + TIE_DOUBLE("/controls/brakes/all", getBrakes, setBrakes); + TIE_DOUBLE("/controls/brakes/left", getLeftBrake, setLeftBrake); + TIE_DOUBLE("/controls/brakes/right", getRightBrake, setRightBrake); + TIE_DOUBLE("/controls/brakes/center", getRightBrake, setCenterBrake); // Autopilot - current_properties.tieBool("/autopilot/locks/altitude", - getAPAltitudeLock, setAPAltitudeLock); - current_properties.tieDouble("/autopilot/settings/altitude", - getAPAltitude, setAPAltitude); - current_properties.tieBool("/autopilot/locks/heading", - getAPHeadingLock, setAPHeadingLock); - current_properties.tieDouble("/autopilot/settings/heading", - getAPHeading, setAPHeading); - current_properties.tieDouble("/autopilot/settings/heading-magnetic", - getAPHeadingMag, setAPHeadingMag); - current_properties.tieBool("/autopilot/locks/nav1", - getAPNAV1Lock, setAPNAV1Lock); + TIE_BOOL("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock); + TIE_DOUBLE("/autopilot/settings/altitude", getAPAltitude, setAPAltitude); + TIE_BOOL("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock); + TIE_DOUBLE("/autopilot/settings/heading", getAPHeading, setAPHeading); + TIE_DOUBLE("/autopilot/settings/heading-magnetic", + getAPHeadingMag, setAPHeadingMag); + TIE_BOOL("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock); // Radio navigation - current_properties.tieDouble("/radios/nav1/frequencies/selected", - getNAV1Freq, setNAV1Freq); - current_properties.tieDouble("/radios/nav1/frequencies/standby", - getNAV1AltFreq, setNAV1AltFreq); - current_properties.tieDouble("/radios/nav1/radials/actual", - getNAV1Radial, 0); - current_properties.tieDouble("/radios/nav1/radials/selected", - getNAV1SelRadial, setNAV1SelRadial); - current_properties.tieDouble("/radios/nav1/dme/distance", - getNAV1DistDME, 0); - current_properties.tieBool("/radios/nav1/to-flag", - getNAV1TO, 0); - current_properties.tieBool("/radios/nav1/from-flag", - getNAV1FROM, 0); - current_properties.tieBool("/radios/nav1/in-range", - getNAV1InRange, 0); - current_properties.tieBool("/radios/nav1/dme/in-range", - getNAV1DMEInRange, 0); + TIE_DOUBLE("/radios/nav1/frequencies/selected", getNAV1Freq, setNAV1Freq); + TIE_DOUBLE("/radios/nav1/frequencies/standby", getNAV1AltFreq, setNAV1AltFreq); + TIE_DOUBLE("/radios/nav1/radials/actual", getNAV1Radial, 0); + TIE_DOUBLE("/radios/nav1/radials/selected", + getNAV1SelRadial, setNAV1SelRadial); + TIE_DOUBLE("/radios/nav1/dme/distance", getNAV1DistDME, 0); + TIE_BOOL("/radios/nav1/to-flag", getNAV1TO, 0); + TIE_BOOL("/radios/nav1/from-flag", getNAV1FROM, 0); + TIE_BOOL("/radios/nav1/in-range", getNAV1InRange, 0); + TIE_BOOL("/radios/nav1/dme/in-range", getNAV1DMEInRange, 0); - current_properties.tieDouble("/radios/nav2/frequencies/selected", - getNAV2Freq, setNAV2Freq); - current_properties.tieDouble("/radios/nav2/frequencies/standby", - getNAV2AltFreq, setNAV2AltFreq); - current_properties.tieDouble("/radios/nav2/radials/actual", - getNAV2Radial, 0); - current_properties.tieDouble("/radios/nav2/radials/selected", - getNAV2SelRadial, setNAV2SelRadial); - current_properties.tieDouble("/radios/nav2/dme/distance", - getNAV2DistDME, 0); - current_properties.tieBool("/radios/nav2/to-flag", - getNAV2TO, 0); - current_properties.tieBool("/radios/nav2/from-flag", - getNAV2FROM, 0); - current_properties.tieBool("/radios/nav2/in-range", - getNAV2InRange, 0); - current_properties.tieBool("/radios/nav2/dme/in-range", - getNAV2DMEInRange, 0); - - current_properties.tieDouble("/radios/adf/frequencies/selected", - getADFFreq, setADFFreq); - current_properties.tieDouble("/radios/adf/frequencies/standby", - getADFAltFreq, setADFAltFreq); - current_properties.tieDouble("/radios/adf/rotation", - getADFRotation, setADFRotation); - - current_properties.tieDouble("/environment/visibility", - getVisibility, setVisibility); + TIE_DOUBLE("/radios/nav2/frequencies/selected", getNAV2Freq, setNAV2Freq); + TIE_DOUBLE("/radios/nav2/frequencies/standby", + getNAV2AltFreq, setNAV2AltFreq); + TIE_DOUBLE("/radios/nav2/radials/actual", getNAV2Radial, 0); + TIE_DOUBLE("/radios/nav2/radials/selected", + getNAV2SelRadial, setNAV2SelRadial); + TIE_DOUBLE("/radios/nav2/dme/distance", getNAV2DistDME, 0); + TIE_BOOL("/radios/nav2/to-flag", getNAV2TO, 0); + TIE_BOOL("/radios/nav2/from-flag", getNAV2FROM, 0); + TIE_BOOL("/radios/nav2/in-range", getNAV2InRange, 0); + TIE_BOOL("/radios/nav2/dme/in-range", getNAV2DMEInRange, 0); + + TIE_DOUBLE("/radios/adf/frequencies/selected", getADFFreq, setADFFreq); + TIE_DOUBLE("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq); + TIE_DOUBLE("/radios/adf/rotation", getADFRotation, setADFRotation); + + TIE_DOUBLE("/environment/visibility", getVisibility, setVisibility); _needReinit = false; @@ -394,7 +347,7 @@ FGBFI::getFlightModel () /** * Return the current aircraft as a string. */ -const string & +string FGBFI::getAircraft () { _temp = globals->get_options()->get_aircraft(); @@ -405,7 +358,7 @@ FGBFI::getAircraft () /** * Return the current aircraft directory (UIUC) as a string. */ -const string & +string FGBFI::getAircraftDir () { _temp = aircraft_dir; @@ -432,7 +385,7 @@ FGBFI::setFlightModel (int model) * Set the current aircraft. */ void -FGBFI::setAircraft (const string &aircraft) +FGBFI::setAircraft (string aircraft) { if (getAircraft() != aircraft) { globals->get_options()->set_aircraft(aircraft); @@ -445,7 +398,7 @@ FGBFI::setAircraft (const string &aircraft) * Set the current aircraft directory (UIUC). */ void -FGBFI::setAircraftDir (const string &dir) +FGBFI::setAircraftDir (string dir) { if (getAircraftDir() != dir) { aircraft_dir = dir; @@ -457,10 +410,10 @@ FGBFI::setAircraftDir (const string &dir) /** * Return the current Zulu time. */ -const string & +string FGBFI::getDateString () { - static string out; // FIXME: not thread-safe + string out; char buf[64]; struct tm * t = globals->get_time_params()->getGmt(); sprintf(buf, "%.4d-%.2d-%.2dT%.2d:%.2d:%.2d", @@ -475,7 +428,7 @@ FGBFI::getDateString () * Set the current Zulu time. */ void -FGBFI::setDateString (const string &date_string) +FGBFI::setDateString (string date_string) // FGBFI::setTimeGMT (time_t time) { SGTime * st = globals->get_time_params(); @@ -521,10 +474,10 @@ FGBFI::setDateString (const string &date_string) /** * Return the GMT as a string. */ -const string & +string FGBFI::getGMTString () { - static string out; // FIXME: not thread-safe + string out; char buf[16]; struct tm * t = globals->get_time_params()->getGmt(); sprintf(buf, " %.2d:%.2d:%.2d", @@ -1682,7 +1635,7 @@ FGBFI::setGPSLock (bool lock) /** * Get the GPS target airport code. */ -const string & +string FGBFI::getTargetAirport () { // FIXME: not thread-safe @@ -1697,7 +1650,7 @@ FGBFI::getTargetAirport () * Set the GPS target airport code. */ void -FGBFI::setTargetAirport (const string &airportId) +FGBFI::setTargetAirport (string airportId) { // cout << "setting target airport id = " << airportId << endl; globals->get_options()->set_airport_id(airportId); diff --git a/src/Main/bfi.hxx b/src/Main/bfi.hxx index ac2753c88..cda9bc9ee 100644 --- a/src/Main/bfi.hxx +++ b/src/Main/bfi.hxx @@ -56,19 +56,19 @@ public: static int getFlightModel (); static void setFlightModel (int flightModel); - static const string &getAircraft (); - static void setAircraft (const string &aircraft); + static string getAircraft (); + static void setAircraft (string aircraft); - static const string &getAircraftDir (); - static void setAircraftDir (const string &aircraftDir); + static string getAircraftDir (); + static void setAircraftDir (string aircraftDir); // static time_t getTimeGMT (); // static void setTimeGMT (time_t time); - static const string &getDateString (); - static void setDateString (const string &time_string); + static string getDateString (); + static void setDateString (string time_string); // deprecated - static const string &getGMTString (); + static string getGMTString (); static bool getHUDVisible (); static void setHUDVisible (bool hudVisible); @@ -245,8 +245,8 @@ public: static void setADFRotation (double rot); // GPS - static const string &getTargetAirport (); - static void setTargetAirport (const string &targetAirport); + static string getTargetAirport (); + static void setTargetAirport (string targetAirport); static bool getGPSLock (); static void setGPSLock (bool lock); diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 70cb8137a..4ab671e02 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -199,9 +199,9 @@ bool fgSetPosFromAirportID( const string& id ) { if ( fgFindAirportID( id, &a ) ) { globals->get_options()->set_lon( a.longitude ); globals->get_options()->set_lat( a.latitude ); - current_properties.setDoubleValue("/position/longitude", + globals->get_props()->setDoubleValue("/position/longitude", a.longitude); - current_properties.setDoubleValue("/position/latitude", + globals->get_props()->setDoubleValue("/position/latitude", a.latitude); FG_LOG( FG_GENERAL, FG_INFO, @@ -311,9 +311,9 @@ bool fgSetPosFromAirportIDandHdg( const string& id, double tgt_hdg ) { globals->get_options()->set_lon( lon2 ); globals->get_options()->set_lat( lat2 ); globals->get_options()->set_heading( heading ); - current_properties.setDoubleValue("/position/longitude", lon2); - current_properties.setDoubleValue("/position/latitude", lat2); - current_properties.setDoubleValue("/orientation/heading", heading); + globals->get_props()->setDoubleValue("/position/longitude", lon2); + globals->get_props()->setDoubleValue("/position/latitude", lat2); + globals->get_props()->setDoubleValue("/orientation/heading", heading); FG_LOG( FG_GENERAL, FG_INFO, "Position for " << id << " is (" @@ -346,11 +346,11 @@ bool fgInitPosition( void ) { // f->get_Altitude() * FEET_TO_METER ); #if 0 - current_properties.setDoubleValue("/position/longitude", + globals->get_props()->setDoubleValue("/position/longitude", f->get_Longitude() * RAD_TO_DEG); - current_properties.setDoubleValue("/position/latitude", + globals->get_props()->setDoubleValue("/position/latitude", f->get_Latitude() * RAD_TO_DEG); - current_properties.setDoubleValue("/position/altitude", + globals->get_props()->setDoubleValue("/position/altitude", f->get_Altitude() * RAD_TO_DEG); #endif @@ -738,8 +738,8 @@ bool fgInitSubsystems( void ) { // Initialize the 2D panel. string panel_path = - current_properties.getStringValue("/sim/panel/path", - "Panels/Default/default.xml"); + globals->get_props()->getStringValue("/sim/panel/path", + "Panels/Default/default.xml"); current_panel = fgReadPanel(panel_path); if (current_panel == 0) { FG_LOG( FG_INPUT, FG_ALERT, diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index fdf7275a0..f73019835 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -29,6 +29,7 @@ #include #include #include +#include #include "options.hxx" #include "viewmgr.hxx" @@ -68,6 +69,9 @@ private: FGViewMgr *viewmgr; FGViewer *current_view; + // properties + SGPropertyNode *props; + public: FGGlobals(); @@ -103,6 +107,10 @@ public: inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; } inline FGViewer *get_current_view() const { return current_view; } inline void set_current_view( FGViewer *v ) { current_view = v; } + + inline SGPropertyNode *get_props () { return props; } + inline void set_props( SGPropertyNode *n ) { props = n; } + // inline const SGPropertyNode &get_props () const { return props; } }; diff --git a/src/Main/keyboard.cxx b/src/Main/keyboard.cxx index 531f910de..6d0f763e4 100644 --- a/src/Main/keyboard.cxx +++ b/src/Main/keyboard.cxx @@ -445,7 +445,7 @@ void GLUTspecialkey(int k, int x, int y) { } case GLUT_KEY_F3: { string panel_path = - current_properties.getStringValue("/sim/panel/path", + globals->get_props()->getStringValue("/sim/panel/path", "Panels/Default/default.xml"); FGPanel * new_panel = fgReadPanel(panel_path); if (new_panel == 0) { @@ -462,7 +462,7 @@ void GLUTspecialkey(int k, int x, int y) { FGPath props_path(globals->get_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)) { + if (!readProperties(props_path.str(), globals->get_props())) { FG_LOG(FG_INPUT, FG_ALERT, "Failed to reread global preferences from " << props_path.str()); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index f3bd98a1e..96d8fe16e 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -1426,6 +1426,9 @@ int main( int argc, char **argv ) { // set current view to 0 (first) which is our main pilot view globals->set_current_view( globals->get_viewmgr()->get_view( 0 ) ); + SGPropertyNode *props = new SGPropertyNode; + globals->set_props( props ); + // Scan the config file(s) and command line options to see if // fg_root was specified (ignore all other options for now) fgInitFGRoot(argc, argv); @@ -1436,7 +1439,7 @@ int main( int argc, char **argv ) { FGPath props_path(globals->get_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)) { + if (!readProperties(props_path.str(), globals->get_props())) { FG_LOG(FG_INPUT, FG_ALERT, "Failed to read global preferences from " << props_path.str()); } else { @@ -1619,7 +1622,7 @@ int main( int argc, char **argv ) { acmodel_pos = new ssgTransform; string acmodel_path = - current_properties.getStringValue("/sim/model/path", + globals->get_props()->getStringValue("/sim/model/path", "Models/Geometry/glider.ac"); ssgEntity *acmodel_obj = ssgLoad((char *)(acmodel_path.c_str())); @@ -1653,17 +1656,17 @@ int main( int argc, char **argv ) { sgMat4 off_matrix; sgMat4 res_matrix; float h_rot = - current_properties.getFloatValue("/sim/model/h-rotation", 0.0); + globals->get_props()->getFloatValue("/sim/model/h-rotation", 0.0); float p_rot = - current_properties.getFloatValue("/sim/model/p-rotation", 0.0); + globals->get_props()->getFloatValue("/sim/model/p-rotation", 0.0); float r_rot = - current_properties.getFloatValue("/sim/model/r-rotation", 0.0); + globals->get_props()->getFloatValue("/sim/model/r-rotation", 0.0); float x_off = - current_properties.getFloatValue("/sim/model/x-offset", 0.0); + globals->get_props()->getFloatValue("/sim/model/x-offset", 0.0); float y_off = - current_properties.getFloatValue("/sim/model/y-offset", 0.0); + globals->get_props()->getFloatValue("/sim/model/y-offset", 0.0); float z_off = - current_properties.getFloatValue("/sim/model/z-offset", 0.0); + globals->get_props()->getFloatValue("/sim/model/z-offset", 0.0); sgMakeRotMat4(rot_matrix, h_rot, p_rot, r_rot); sgMakeTransMat4(off_matrix, x_off, y_off, z_off); sgMultMat4(res_matrix, off_matrix, rot_matrix); diff --git a/src/Main/options.cxx b/src/Main/options.cxx index 2b5c0f38d..ae081c19b 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -666,25 +666,25 @@ int FGOptions::parse_option( const string& arg ) { auto_coordination = FG_AUTO_COORD_ENABLED; } else if ( arg == "--disable-hud" ) { hud_status = false; - current_properties.setBoolValue("/sim/hud/visibility", false); + globals->get_props()->setBoolValue("/sim/hud/visibility", false); //$$$ begin - added Neetha } else if ( arg == "--enable-default_hud" ) { hud_status = true; hud_flag = 1; - current_properties.setBoolValue("/sim/hud/visibility", true); + globals->get_props()->setBoolValue("/sim/hud/visibility", true); } else if ( arg == "--enable-ada_hud" ) { hud_status = true; hud_flag = 2; - current_properties.setBoolValue("/sim/hud/visibility", true); + globals->get_props()->setBoolValue("/sim/hud/visibility", true); //$$$ end - added Neetha } else if ( arg == "--disable-panel" ) { panel_status = false; - current_properties.setBoolValue("/sim/panel/visibility", false); + globals->get_props()->setBoolValue("/sim/panel/visibility", false); if ( current_panel != NULL ) current_panel->setVisibility(false); } else if ( arg == "--enable-panel" ) { panel_status = true; - current_properties.setBoolValue("/sim/panel/visibility", true); + globals->get_props()->setBoolValue("/sim/panel/visibility", true); if ( current_panel != NULL ) current_panel->setVisibility(true); } else if ( arg == "--disable-sound" ) { @@ -693,24 +693,24 @@ int FGOptions::parse_option( const string& arg ) { sound = true; } else if ( arg.find( "--airport-id=") != string::npos ) { airport_id = arg.substr( 13 ); - current_properties.setStringValue("/position/airport-id", airport_id); + globals->get_props()->setStringValue("/position/airport-id", airport_id); } else if ( arg.find( "--lon=" ) != string::npos ) { lon = parse_degree( arg.substr(6) ); airport_id = ""; - current_properties.setDoubleValue("/position/longitude", lon); - current_properties.setStringValue("/position/airport-id", airport_id); + globals->get_props()->setDoubleValue("/position/longitude", lon); + globals->get_props()->setStringValue("/position/airport-id", airport_id); } else if ( arg.find( "--lat=" ) != string::npos ) { lat = parse_degree( arg.substr(6) ); airport_id = ""; - current_properties.setDoubleValue("/position/latitude", lat); - current_properties.setStringValue("/position/airport-id", airport_id); + globals->get_props()->setDoubleValue("/position/latitude", lat); + globals->get_props()->setStringValue("/position/airport-id", airport_id); } 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); + globals->get_props()->setDoubleValue("/position/altitude", altitude); } else if ( arg.find( "--uBody=" ) != string::npos ) { speedset = FG_VTUVW; if ( units == FG_UNITS_FEET ) { @@ -718,7 +718,7 @@ int FGOptions::parse_option( const string& arg ) { } else { uBody = atof( arg.substr(8) ) * FEET_TO_METER; } - //current_properties.setDoubleValue("/velocities/speed-north", uBody); + //globals->get_props()->setDoubleValue("/velocities/speed-north", uBody); } else if ( arg.find( "--vBody=" ) != string::npos ) { speedset = FG_VTUVW; if ( units == FG_UNITS_FEET ) { @@ -726,7 +726,7 @@ int FGOptions::parse_option( const string& arg ) { } else { vBody = atof( arg.substr(8) ) * FEET_TO_METER; } - //current_properties.setDoubleValue("/velocities/speed-east", vBody); + //globals->get_props()->setDoubleValue("/velocities/speed-east", vBody); } else if ( arg.find( "--wBody=" ) != string::npos ) { speedset = FG_VTUVW; if ( units == FG_UNITS_FEET ) { @@ -741,7 +741,7 @@ int FGOptions::parse_option( const string& arg ) { } else { vNorth = atof( arg.substr(9) ) * FEET_TO_METER; } - current_properties.setDoubleValue("/velocities/speed-north", vNorth); + globals->get_props()->setDoubleValue("/velocities/speed-north", vNorth); } else if ( arg.find( "--vEast=" ) != string::npos ) { speedset = FG_VTNED; if ( units == FG_UNITS_FEET ) { @@ -749,7 +749,7 @@ int FGOptions::parse_option( const string& arg ) { } else { vEast = atof( arg.substr(8) ) * FEET_TO_METER; } - current_properties.setDoubleValue("/velocities/speed-east", vEast); + globals->get_props()->setDoubleValue("/velocities/speed-east", vEast); } else if ( arg.find( "--vDown=" ) != string::npos ) { speedset = FG_VTNED; if ( units == FG_UNITS_FEET ) { @@ -757,7 +757,7 @@ int FGOptions::parse_option( const string& arg ) { } else { vDown = atof( arg.substr(8) ) * FEET_TO_METER; } - current_properties.setDoubleValue("/velocities/speed-down", vDown); + globals->get_props()->setDoubleValue("/velocities/speed-down", vDown); } else if ( arg.find( "--vc=" ) != string::npos) { speedset = FG_VC; vkcas=atof( arg.substr(5) ); @@ -767,20 +767,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); + globals->get_props()->setDoubleValue("/orientation/heading", heading); } else if ( arg.find( "--roll=" ) != string::npos ) { roll = atof( arg.substr(7) ); - current_properties.setDoubleValue("/orientation/roll", roll); + globals->get_props()->setDoubleValue("/orientation/roll", roll); } else if ( arg.find( "--pitch=" ) != string::npos ) { pitch = atof( arg.substr(8) ); - current_properties.setDoubleValue("/orientation/pitch", pitch); + globals->get_props()->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); + globals->get_props()->setIntValue("/sim/flight-model", flight_model); if((flight_model == FGInterface::FG_JSBSIM) && (get_trim_mode() == 0)) { set_trim_mode(1); } else { @@ -788,7 +788,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); + globals->get_props()->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 ) { @@ -930,7 +930,7 @@ int FGOptions::parse_option( const string& arg ) { } string name = assign.substr(0, pos); string value = assign.substr(pos + 1); - current_properties.setStringValue(name.c_str(), value); + globals->get_props()->setStringValue(name.c_str(), value); FG_LOG(FG_GENERAL, FG_INFO, "Setting default value of property " << name << " to \"" << value << '"'); // $$$ begin - added VS Renganathan, 14 Oct 2K diff --git a/src/Main/save.cxx b/src/Main/save.cxx index 275d4dba9..0ae2cbdaf 100644 --- a/src/Main/save.cxx +++ b/src/Main/save.cxx @@ -50,7 +50,7 @@ using std::ostream; bool fgSaveFlight (ostream &output) { - return writePropertyList(output, ¤t_properties); + return writeProperties(output, globals->get_props()); } @@ -60,7 +60,7 @@ fgSaveFlight (ostream &output) bool fgLoadFlight (istream &input) { - return readPropertyList(input, ¤t_properties); + return readProperties(input, globals->get_props()); } // end of save.cxx diff --git a/src/Network/props.cxx b/src/Network/props.cxx index 29730db42..77fac588b 100644 --- a/src/Network/props.cxx +++ b/src/Network/props.cxx @@ -21,6 +21,8 @@ // $Id$ +#include
+ #include #include #include @@ -110,22 +112,19 @@ bool FGProps::process_command( const char *cmd ) { string command = tokens[0]; - SGPropertyNode node( path, ¤t_properties ); - if ( node.getPath() == "" ) { - node.setPath( "/" ); - } + SGPropertyNode * node = globals->get_props()->getNode(path); if ( command == "ls" ) { - for (int i = 0; i < (int)node.size(); i++) { - SGPropertyNode child = node.getChild(i); - string name = child.getName(); + for (int i = 0; i < (int)node->nChildren(); i++) { + SGPropertyNode * child = node->getChild(i); + string name = child->getName(); string line = name; - if ( child.size() > 0 ) { + if ( child->nChildren() > 0 ) { line += "/\n"; } else { - string value = node.getStringValue ( name, "" ); + string value = node->getStringValue ( name, "" ); line += " =\t'" + value + "'\t("; - line += getValueTypeString( node.getValue( name ) ); + line += getValueTypeString( node->getValue( name ) ); line += ")\n"; } io->writestring( line.c_str() ); @@ -134,26 +133,19 @@ bool FGProps::process_command( const char *cmd ) { // string tmp = "current path = " + node.getPath() + "\n"; // io->writestring( tmp.c_str() ); - if ( tokens.size() <= 1 ) { - // do nothing - } else if ( tokens[1] == "." ) { + if ( tokens.size() <= 1 ) { // do nothing - } else if ( tokens[1] == ".." ) { - // go back one level - string current = node.getPath(); - int pos = current.rfind("/"); - // cout << "path = " << current << endl; - // cout << "new path = " << current.substr(0, pos) << endl;d - string tmp = current.substr(0, pos); - node.setPath( tmp ); - path = tmp; } else { - // decend to specified child - string tmp = node.getPath(); - tmp += "/" + tokens[1]; - node.setPath( tmp ); - path = tmp; + node = node->getNode(tokens[1]); + path = node->getPath(); } + } else if ( command == "pwd" ) { + string ttt = node->getPath(); + if ( ttt == "" ) { + ttt = "/"; + } + ttt += "\n"; + io->writestring( ttt.c_str() ); } else if ( command == "show" ) { if ( tokens.size() <= 1 ) { // do nothing @@ -161,54 +153,27 @@ bool FGProps::process_command( const char *cmd ) { string ttt = "debug = '" + tokens[1] + "'\n"; io->writestring( ttt.c_str() ); - string value = node.getStringValue ( tokens[1], "" ); + string value = node->getStringValue ( tokens[1], "" ); string tmp = tokens[1] + " = '" + value + "' ("; - tmp += getValueTypeString( node.getValue( tokens[1] ) ); + tmp += getValueTypeString( node->getValue( tokens[1] ) ); tmp += ")\n"; io->writestring( tmp.c_str() ); } } else if ( command == "set" ) { - if ( tokens.size() <= 2 ) { + if ( tokens.size() <= 2 ) { // do nothing } else { - SGValue *v = node.getValue( tokens[1] ); - if ( v != NULL ) { - SGValue::Type type = v->getType(); - if ( type == SGValue::UNKNOWN ) { - v->setUnknownValue( tokens[2] ); - } else if ( type == SGValue::BOOL ) { - if ( tokens[2] == "true" ) { - v->setBoolValue( true ); - } else if ( tokens[2] == "false" ) { - v->setBoolValue( false ); - } else { - v->setBoolValue( atoi( tokens[2].c_str() ) ); - } - } else if ( type == SGValue::INT ) { - v->setIntValue( atoi( tokens[2].c_str() ) ); - } else if ( type == SGValue::FLOAT ) { - v->setFloatValue( atof( tokens[2].c_str() ) ); - } else if ( type == SGValue::DOUBLE ) { - v->setDoubleValue( atof( tokens[2].c_str() ) ); - } else if ( type == SGValue::STRING ) { - v->setStringValue( tokens[2] ); - } - - // now fetch and write out the new value as confirmation - // of the change - string value = node.getStringValue ( tokens[1], "" ); - string tmp = tokens[1] + " = '" + value + "' ("; - tmp += getValueTypeString( node.getValue( tokens[1] ) ); - tmp += ")\n"; - - io->writestring( tmp.c_str() ); - } else { - string tmp = tokens[1] + " is unknown.\n"; - - io->writestring( tmp.c_str() ); - } + node->getValue( tokens[1], true )->setStringValue(tokens[2]); + // now fetch and write out the new value as confirmation + // of the change + string value = node->getStringValue ( tokens[1], "" ); + string tmp = tokens[1] + " = '" + value + "' ("; + tmp += getValueTypeString( node->getValue( tokens[1] ) ); + tmp += ")\n"; + + io->writestring( tmp.c_str() ); } } else if ( command == "quit" ) { close(); @@ -219,13 +184,14 @@ bool FGProps::process_command( const char *cmd ) { io->writestring( "help show help message\n" ); io->writestring( "ls list current directory\n" ); io->writestring( "cd cd to a directory, '..' to move back\n" ); + io->writestring( "pwd display your current path\n" ); io->writestring( "show show the value of a parameter\n" ); io->writestring( "set set to a new \n" ); io->writestring( "quit terminate connection\n" ); io->writestring( "\n" ); } - string prompt = node.getPath(); + string prompt = node->getPath(); if ( prompt == "" ) { prompt = "/"; } -- 2.39.5