]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/multiplay.cxx
Sync. w. JSBSim CVS
[flightgear.git] / src / Network / multiplay.cxx
index 00d6dcefad706023049f77a02bb9ba5383ee76fe..cea4e8ab4d8ffb957c0db460fb738fc7da9f40e1 100644 (file)
@@ -19,7 +19,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 
 #ifdef HAVE_CONFIG_H
@@ -28,7 +28,7 @@
 
 #include <simgear/compiler.h>
 
-#include STL_STRING
+#include <string>
 
 #include <iostream>
 #include <map>
@@ -42,7 +42,7 @@
 
 #include "multiplay.hxx"
 
-SG_USING_STD(string);
+using std::string;
 
 
 // These constants are provided so that the ident command can list file versions.
@@ -101,13 +101,12 @@ bool FGMultiplay::open() {
     SGPropertyNode* root = globals->get_props();
 
     /// Build up the id to property map
-    unsigned i = 0;
-    while (FGMultiplayMgr::sIdPropertyList[i].name) {
+    
+    for (unsigned i = 0; i < FGMultiplayMgr::numProperties; ++i) {
       const char* name = FGMultiplayMgr::sIdPropertyList[i].name;
       SGPropertyNode* pNode = root->getNode(name);
       if (pNode)
         mPropertyMap[FGMultiplayMgr::sIdPropertyList[i].id] = pNode;
-      ++i;
     }
 
     return is_enabled();
@@ -156,11 +155,11 @@ bool FGMultiplay::process() {
     // first the aprioriate structure for the geodetic one
     SGGeod geod = SGGeod::fromRadFt(lon, lat, ifce->get_Altitude());
     // Convert to cartesion coordinate
-    motionInfo.position = geod;
+    motionInfo.position = SGVec3d::fromGeod(geod);
     
     // The quaternion rotating from the earth centered frame to the
     // horizontal local frame
-    SGQuatf qEc2Hl = SGQuatf::fromLonLat((float)lon, (float)lat);
+    SGQuatf qEc2Hl = SGQuatf::fromLonLatRad((float)lon, (float)lat);
     // The orientation wrt the horizontal local frame
     float heading = ifce->get_Psi();
     float pitch = ifce->get_Theta();
@@ -198,14 +197,68 @@ bool FGMultiplay::process() {
     // now send the properties
     PropertyMap::iterator it;
     for (it = mPropertyMap.begin(); it != mPropertyMap.end(); ++it) {
-      FGFloatPropertyData pData;
-      pData.id = it->first;
-      pData.value = it->second->getFloatValue();
+      FGPropertyData* pData = new FGPropertyData;
+      pData->id = it->first;
+      pData->type = it->second->getType();
+      
+      switch (pData->type) {
+        case SGPropertyNode::INT:        
+        case SGPropertyNode::LONG:       
+        case SGPropertyNode::BOOL:
+          pData->int_value = it->second->getIntValue();
+          break;
+        case SGPropertyNode::FLOAT:
+        case SGPropertyNode::DOUBLE:
+          pData->float_value = it->second->getFloatValue();
+          break;
+        case SGPropertyNode::STRING:
+        case SGPropertyNode::UNSPECIFIED:
+          {
+            // FIXME: We assume unspecified are strings for the moment.
+
+            const char* cstr = it->second->getStringValue();
+            int len = strlen(cstr);
+            
+            if (len > 0)
+            {            
+              pData->string_value = new char[len + 1];
+              strcpy(pData->string_value, cstr);
+            }
+            else
+            {
+              // Size 0 - ignore
+              pData->string_value = 0;            
+            }
+
+            //cout << " Sending property " << pData->id << " " << pData->type << " " <<  pData->string_value << "\n";
+            break;        
+          }
+        default:
+          // FIXME Currently default to a float. 
+          //cout << "Unknown type when iterating through props: " << pData->type << "\n";
+          pData->float_value = it->second->getFloatValue();
+          break;
+      }
+      
       motionInfo.properties.push_back(pData);
     }
 
     FGMultiplayMgr* mpmgr = globals->get_multiplayer_mgr();
     mpmgr->SendMyPosition(motionInfo);
+    
+    // Now remove the data
+    std::vector<FGPropertyData*>::const_iterator propIt;
+    std::vector<FGPropertyData*>::const_iterator propItEnd;
+    propIt = motionInfo.properties.begin();
+    propItEnd = motionInfo.properties.end();
+
+    //cout << "Deleting data\n";
+
+    while (propIt != propItEnd)
+    {
+      delete *propIt;
+      propIt++;
+    }    
   }
 
   return true;
@@ -219,13 +272,19 @@ bool FGMultiplay::process() {
 ******************************************************************/
 bool FGMultiplay::close() {
 
+  FGMultiplayMgr *mgr = globals->get_multiplayer_mgr();
+
+  if (mgr == 0) {
+    return false;
+  }
+
   if (get_direction() == SG_IO_IN) {
 
-    globals->get_multiplayer_mgr()->Close();
+    mgr->Close();
 
   } else if (get_direction() == SG_IO_OUT) {
 
-    globals->get_multiplayer_mgr()->Close();
+    mgr->Close();
 
   }