]> git.mxchange.org Git - flightgear.git/blobdiff - src/MultiPlayer/mpmessages.hxx
Merge branch 'ehofman/atc-sound'
[flightgear.git] / src / MultiPlayer / mpmessages.hxx
index 0e6b9468ff1d9eab1fa4b3788b648a50a6c1328b..dded2b3e2175819b6fa1eef626e4f66b853c48ff 100644 (file)
@@ -4,8 +4,6 @@
 // Written by Duncan McCreanor, started February 2003.
 // duncan.mccreanor@airservicesaustralia.com
 //
-// With minor additions be Vivian Meazza, January 2006
-//
 // Copyright (C) 2003  Airservices Australia
 //
 // This program is free software; you can redistribute it and/or
@@ -20,7 +18,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.
 //
 
 #ifndef MPMESSAGES_H
 *
 ******************************************************************/
 
-#include <plib/sg.h>
+#include <vector>
+
 #include <simgear/compiler.h>
+#include <simgear/props/props.hxx>
+#include <simgear/math/SGMath.hxx>
 #include "tiny_xdr.hxx"
 
 // magic value for messages
@@ -49,9 +50,11 @@ const uint32_t PROTO_VER = 0x00010001;  // 1.1
 // Message identifiers
 #define CHAT_MSG_ID             1
 #define UNUSABLE_POS_DATA_ID    2
-#define OLD_POS_DATA_ID         3
-#define POS_DATA_ID             4
-#define PROP_MSG_ID             5
+#define OLD_OLD_POS_DATA_ID     3
+#define OLD_POS_DATA_ID         4
+#define OLD_PROP_MSG_ID         5
+#define RESET_DATA_ID           6
+#define POS_DATA_ID             7
 
 // XDR demands 4 byte alignment, but some compilers use8 byte alignment
 // so it's safe to let the overall size of a network message be a 
@@ -61,13 +64,8 @@ const uint32_t PROTO_VER = 0x00010001;  // 1.1
 #define MAX_MODEL_NAME_LEN      96
 #define MAX_PROPERTY_LEN        52
 
-/** Aircraft position message */
-typedef xdr_data2_t xdrPosition[3];
-typedef xdr_data_t  xdrOrientation[4];
-
 // Header for use with all messages sent 
-class T_MsgHdr {
-public:  
+struct T_MsgHdr {
     xdr_data_t  Magic;                  // Magic Value
     xdr_data_t  Version;                // Protocoll version
     xdr_data_t  MsgId;                  // Message identifier 
@@ -78,50 +76,96 @@ public:
 };
 
 // Chat message 
-class T_ChatMsg {
-public:    
+struct T_ChatMsg {
     char Text[MAX_CHAT_MSG_LEN];       // Text of chat message
 };
 
 // Position message
-class T_PositionMsg {
-public:
+struct T_PositionMsg {
     char Model[MAX_MODEL_NAME_LEN];    // Name of the aircraft model
-    xdr_data_t  time;                  // Time when this packet was generated
-    xdr_data_t  timeusec;              // Microsecs when this packet was generated
-    xdr_data2_t lat;                   // Position, orientation, speed
-    xdr_data2_t lon;                   // ...
-    xdr_data2_t alt;                   // ...
-    xdr_data2_t hdg;                   // ...
-    xdr_data2_t roll;                  // ...
-    xdr_data2_t pitch;                 // ...
-    xdr_data2_t speedN;                // ...
-    xdr_data2_t speedE;                // ...
-    xdr_data2_t speedD;                // ...
-       xdr_data_t  accN;                                  // acceleration N
-       xdr_data_t  accE;                  // acceleration E
-       xdr_data_t  accD;                  // acceleration D
-    xdr_data_t  left_aileron;          // control positions
-    xdr_data_t  right_aileron;         // control positions
-    xdr_data_t  elevator;              // ...
-    xdr_data_t  rudder;                // ...
-//    xdr_data_t  rpms[6];               // RPMs of all of the motors
-    xdr_data_t  rateH;                 // Rate of change of heading
-    xdr_data_t  rateR;                 // roll
-    xdr_data_t  rateP;                 // and pitch
-//     xdr_data_t  dummy;                 // pad message length
+
+    // Time when this packet was generated
+    xdr_data2_t time;
+    xdr_data2_t lag;
+
+    // position wrt the earth centered frame
+    xdr_data2_t position[3];
+    // orientation wrt the earth centered frame, stored in the angle axis
+    // representation where the angle is coded into the axis length
+    xdr_data_t orientation[3];
+
+    // linear velocity wrt the earth centered frame measured in
+    // the earth centered frame
+    xdr_data_t linearVel[3];
+    // angular velocity wrt the earth centered frame measured in
+    // the earth centered frame
+    xdr_data_t angularVel[3];
+
+    // linear acceleration wrt the earth centered frame measured in
+    // the earth centered frame
+    xdr_data_t linearAccel[3];
+    // angular acceleration wrt the earth centered frame measured in
+    // the earth centered frame
+    xdr_data_t angularAccel[3];
+    // Padding. The alignment is 8 bytes on x86_64 because there are
+    // 8-byte types in the message, so the size should be explicitly
+    // rounded out to a multiple of 8. Of course, it's a bad idea to
+    // put a C struct directly on the wire, but that's a fight for
+    // another day...
+    xdr_data_t pad;
 };
 
-// Property message
-class T_PropertyMsg {
-public:
-    char property[MAX_PROPERTY_LEN];   // the property name
-    xdr_data_t  type;                                  // the type
-    xdr_data2_t val;                                   // and value
-//     xdr_data2_t dummy;                                      // pad message length
-       
+struct FGPropertyData {
+  unsigned id;
+  
+  // While the type isn't transmitted, it is needed for the destructor
+  simgear::props::Type type;
+  union { 
+    int int_value;
+    float float_value;
+    char* string_value;
+  }; 
+  
+  ~FGPropertyData() {
+    if ((type == simgear::props::STRING) || (type == simgear::props::UNSPECIFIED))
+    {
+      delete [] string_value;
+    }
+  }
 };
 
-#endif
 
 
+// Position message
+struct FGExternalMotionData {
+  // simulation time when this packet was generated
+  double time;
+  // the artificial lag the client should stay behind the average
+  // simulation time to arrival time diference
+  // FIXME: should be some 'per model' instead of 'per packet' property
+  double lag;
+  
+  // position wrt the earth centered frame
+  SGVec3d position;
+  // orientation wrt the earth centered frame
+  SGQuatf orientation;
+  
+  // linear velocity wrt the earth centered frame measured in
+  // the earth centered frame
+  SGVec3f linearVel;
+  // angular velocity wrt the earth centered frame measured in
+  // the earth centered frame
+  SGVec3f angularVel;
+  
+  // linear acceleration wrt the earth centered frame measured in
+  // the earth centered frame
+  SGVec3f linearAccel;
+  // angular acceleration wrt the earth centered frame measured in
+  // the earth centered frame
+  SGVec3f angularAccel;
+  
+  // The set of properties recieved for this timeslot
+  std::vector<FGPropertyData*> properties;
+};
+
+#endif