]> git.mxchange.org Git - flightgear.git/commitdiff
Mathias Fröhlich:
authorehofman <ehofman>
Thu, 28 Jul 2005 08:40:03 +0000 (08:40 +0000)
committerehofman <ehofman>
Thu, 28 Jul 2005 08:40:03 +0000 (08:40 +0000)
I have now included a patch to the multiplyer protocoll which does:

1. place the 3d model into the scenery using a placement transform which can
dynamically change its scenry center.
2. Transmits unique position and orientation data for the 3d model.
3. Thus breaks protocol compatibility.

Oliver Schroeder:
With help from Norman I fixed the alignment in the used headers.

But this patch again fixes only symtoms, not the problems. I suggest to
put it into cvs anyway, as it will enable the majority to get experience
with the multiplayer mode.

src/MultiPlayer/mpmessages.hxx
src/MultiPlayer/mpplayer.cxx
src/MultiPlayer/mpplayer.hxx
src/MultiPlayer/multiplayrxmgr.cxx
src/MultiPlayer/multiplaytxmgr.cxx
src/MultiPlayer/multiplaytxmgr.hxx
src/Network/multiplay.cxx

index 61f04eca742e0d3e44f0cbb3d10c7b60a846f54a..b0f91b268331b0b800b0fa6d7de698185941e0ec 100644 (file)
 *
 ******************************************************************/
 
+#include <stdint.h>
 #include <plib/sg.h>
 
 // Message identifiers
 #define CHAT_MSG_ID 1
-#define POS_DATA_ID 2
-
-#define MAX_CALLSIGN_LEN 10
+#define UNUSABLE_POS_DATA_ID 2
+#define POS_DATA_ID 3
+/* should be a multiple of 8! */
+#define MAX_CALLSIGN_LEN 8
 /** Header for use with all messages sent */
 typedef struct {
 
-    /** Message identifier */
-    char MsgId;
+    /** Message identifier, multiple of 8! */
+    uint32_t MsgId;
 
     /** Length of the message inclusive of this header */
-    unsigned int iMsgLen;
+    uint32_t iMsgLen;
 
     /** IP address for reply to message (player's receiver address) */
-    unsigned long int lReplyAddress;
+    uint32_t lReplyAddress;
 
     /** Port for replies (player's receiver port) */
-    unsigned int iReplyPort;
+    uint32_t iReplyPort;
 
     /** Callsign used by the player */
     char sCallsign[MAX_CALLSIGN_LEN];
 
 } T_MsgHdr;
 
-#define MAX_CHAT_MSG_LEN 50
+#define MAX_CHAT_MSG_LEN 48
 /** Chat message */
 typedef struct {
 
@@ -71,8 +73,8 @@ typedef struct {
 
 } T_ChatMsg;
 
-
-#define MAX_MODEL_NAME_LEN 50
+/* should be a multiple of 8! */
+#define MAX_MODEL_NAME_LEN 48
 /** Aircraft position message */
 typedef struct {
 
@@ -80,12 +82,12 @@ typedef struct {
     char sModel[MAX_MODEL_NAME_LEN];
 
     /** Position data for the aircraft */
-    sgMat4 PlayerPos;
+    sgdVec3 PlayerPosition;
+    sgQuat PlayerOrientation;
 
 } T_PositionMsg;
 
 
-
 #endif
 
 
index 20b255ad56a5256ba6641f763b2f383154c2466f..90a4f8e480fa67e7f3b32a50587922c8f8f74f0e 100644 (file)
@@ -53,6 +53,7 @@
 #include <plib/sg.h>
 
 #include <simgear/scene/model/modellib.hxx>
+#include <simgear/scene/model/placementtrans.hxx>
 
 #include <Main/globals.hxx>
 #include <Scenery/scenery.hxx>
@@ -140,6 +141,7 @@ void MPPlayer::Close(void) {
 
         // Disconnect the model from the transform, then the transform from the scene.
         m_ModelTrans->removeKid(m_Model);
+        globals->get_scenery()->unregister_placement_transform(m_ModelTrans);
         globals->get_scenery()->get_aircraft_branch()->removeKid( m_ModelTrans);
 
         // Flush the model loader so that it erases the model from its list of
@@ -164,12 +166,14 @@ void MPPlayer::Close(void) {
 * Description: Updates position data held for this player and resets
 * the last update time.
 ******************************************************************/
-void MPPlayer::SetPosition(const sgMat4 PlayerPosMat4) {
+void MPPlayer::SetPosition(const sgQuat PlayerOrientation,
+                           const sgdVec3 PlayerPosition) {
 
 
     // Save the position matrix and update time
     if (m_bInitialised) {
-        sgCopyMat4(m_ModelPos, PlayerPosMat4);
+        sgdCopyVec3(m_ModelPosition, PlayerPosition);
+        sgCopyVec4(m_ModelOrientation, PlayerOrientation);
         time(&m_LastUpdate);
         m_bUpdated = true;
     }
@@ -187,16 +191,16 @@ MPPlayer::TPlayerDataState MPPlayer::Draw(void) {
 
     MPPlayer::TPlayerDataState eResult = PLAYER_DATA_NOT_AVAILABLE;
 
-    sgCoord sgPlayerCoord;
-
     if (m_bInitialised && !m_bLocalPlayer) {
         if ((time(NULL) - m_LastUpdate < TIME_TO_LIVE)) {
             // Peform an update if it has changed since the last update
             if (m_bUpdated) {
 
                 // Transform and update player model
-                sgSetCoord( &sgPlayerCoord, m_ModelPos);
-                m_ModelTrans->setTransform( &sgPlayerCoord );
+                sgMat4 orMat;
+                sgMakeIdentMat4(orMat);
+                sgQuatToMatrix(orMat, m_ModelOrientation);
+                m_ModelTrans->setTransform(m_ModelPosition, orMat);
 
                 eResult = PLAYER_DATA_AVAILABLE;
 
@@ -247,7 +251,7 @@ bool MPPlayer::CompareCallsign(const char *sCallsign) const {
 void MPPlayer::LoadModel(void) {
 
 
-    m_ModelTrans = new ssgTransform;
+    m_ModelTrans = new ssgPlacementTransform;
 
     // Load the model
     m_Model = globals->get_model_lib()->load_model( globals->get_fg_root(),
@@ -265,6 +269,7 @@ void MPPlayer::LoadModel(void) {
 
     // Place on scene under aircraft branch
     globals->get_scenery()->get_aircraft_branch()->addKid( m_ModelTrans );
+    globals->get_scenery()->register_placement_transform( m_ModelTrans);
 
 
 }
@@ -280,7 +285,8 @@ void MPPlayer::FillPosMsg(T_MsgHdr *MsgHdr, T_PositionMsg *PosMsg) {
 
     strncpy(PosMsg->sModel, m_sModelName.c_str(), MAX_MODEL_NAME_LEN);
     PosMsg->sModel[MAX_MODEL_NAME_LEN - 1] = '\0';
-    sgCopyMat4(PosMsg->PlayerPos, m_ModelPos);
+    sgdCopyVec3(PosMsg->PlayerPosition, m_ModelPosition);
+    sgCopyQuat(PosMsg->PlayerOrientation, m_ModelOrientation);
 
 
 }
index c16d9f1b0de3e2a707ea314ef102f97d0c4c66fb..04c5b648ff34920a3265fbdce86e2f733c6ed79f 100644 (file)
@@ -54,7 +54,7 @@ SG_USING_STD(string);
 
 
 class ssgEntity;
-class ssgTransform;
+class ssgPlacementTransform;
 
 
 class MPPlayer {
@@ -89,7 +89,8 @@ public:
     /** Sets the positioning matrix held for this player
     * @param PlayerPosMat4 Matrix for positioning player's aircraft
     */
-    void SetPosition(const sgMat4 PlayerPosMat4);
+    void SetPosition(const sgQuat PlayerOrientation,
+                     const sgdVec3 PlayerPosition);
 
     /** Transform and place model for player
     */
@@ -127,8 +128,11 @@ private:
     /** True if object is initialised */
     bool m_bInitialised;
 
-    /** Position matrix for the player's aircraft */
-    sgMat4 m_ModelPos;
+    /** Position of the player's aircraft wrt the earth fixed global system */
+    sgdVec3 m_ModelPosition;
+
+    /** Orientation the player's aircraft wrt the earth fixed global system */
+    sgQuat m_ModelOrientation;
 
     /** Used to remove player if no activity */
     time_t m_LastUpdate;
@@ -146,7 +150,7 @@ private:
     ssgEntity *m_Model;
 
     /** Model transform */
-    ssgTransform *m_ModelTrans;
+    ssgPlacementTransform *m_ModelTrans;
 
     /** True if this player is the local player */
     bool m_bLocalPlayer;
index 474a09faf14371c7effb6f9ecbf975d05751452f..95e65646f567f436d780a41349eea4c37fe8e2ee 100644 (file)
@@ -269,7 +269,7 @@ void FGMultiplayRxMgr::ProcessData(void) {
                                             if (m_Player[iPlayerCnt]->CompareCallsign(MsgHdr->sCallsign)) {
 
                                                 // Player found. Update the data for the player.
-                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerPos);
+                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerOrientation, PosMsg->PlayerPosition);
                                                 bActivePlayer = true;
 
                                             }
@@ -284,7 +284,7 @@ void FGMultiplayRxMgr::ProcessData(void) {
                                                 SG_LOG( SG_NETWORK, SG_INFO, "FGMultiplayRxMgr::ProcessRxData - Add new player. IP: " << sIpAddress << ", Call: " <<  sCallsign << ", model: " << sModelName );
                                                 m_Player[iPlayerCnt] = new MPPlayer;
                                                 m_Player[iPlayerCnt]->Open(sIpAddress, iPort, sCallsign, sModelName, false);
-                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerPos);
+                                                m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerOrientation, PosMsg->PlayerPosition);
                                                 bActivePlayer = true;
                                             }
                                             iPlayerCnt++;
index ff7079a803f1efd9d74d5a3bb88d83129f00c4ef..12570ffc77663a6739ca961f7338127ecccac8be 100644 (file)
@@ -189,14 +189,15 @@ void FGMultiplayTxMgr::Close(void) {
 * Name: SendMyPosition
 * Description: Sends the position data for the local position.
 ******************************************************************/
-void FGMultiplayTxMgr::SendMyPosition(const sgMat4 PlayerPosMat4) {
+void FGMultiplayTxMgr::SendMyPosition(const sgQuat PlayerOrientation,
+                                      const sgdVec3 PlayerPosition) {
 
     T_MsgHdr MsgHdr;
     T_PositionMsg PosMsg;
     char sMsg[sizeof(T_MsgHdr) + sizeof(T_PositionMsg)];
 
     if (m_bInitialised) {
-        mLocalPlayer->SetPosition(PlayerPosMat4);
+        mLocalPlayer->SetPosition(PlayerOrientation, PlayerPosition);
         mLocalPlayer->FillPosMsg(&MsgHdr, &PosMsg);
         memcpy(sMsg, &MsgHdr, sizeof(T_MsgHdr));
         memcpy(sMsg + sizeof(T_MsgHdr), &PosMsg, sizeof(T_PositionMsg));
index fd6d1d1f92b4f2af6f40e17f3da7eb866cd1b304..df9e80c4bfada6347ba3154d631ae367008d0c32 100644 (file)
@@ -70,7 +70,7 @@ public:
     /** Sends the position data for the local player
     * @param PlayerPosMat4 Transformation matrix for the player's position
     */
-    void SendMyPosition(const sgMat4 PlayerPosMat4);
+    void SendMyPosition(const sgQuat PlayerOrientation, const sgdVec3 PlayerPosition);
     
     /** Sends a tex chat message.
     * @param sMsgText Message text to send
index 4bc37c120acd023a07de770fe50b9bb8d9eb1404..54bd41da000288fb902d2dbdab6fca0be7221d6a 100644 (file)
@@ -30,6 +30,8 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/scene/model/placement.hxx>
 
+#include <Scenery/scenery.hxx>
+
 #include "multiplay.hxx"
 
 SG_USING_STD(string);
@@ -105,8 +107,16 @@ bool FGMultiplay::process() {
 
   } else if (get_direction() == SG_IO_OUT) {
 
-    globals->get_multiplayer_tx_mgr()->
-    SendMyPosition(globals->get_aircraft_model()->get3DModel()->get_POS());
+    sgMat4 posTrans;
+    sgCopyMat4(posTrans, globals->get_aircraft_model()->get3DModel()->get_POS());
+    Point3D center = globals->get_scenery()->get_center();
+    sgdVec3 PlayerPosition;
+    sgdSetVec3(PlayerPosition, posTrans[3][0] + center[0],
+               posTrans[3][1] + center[1], posTrans[3][2] + center[2]);
+    sgQuat PlayerOrientation;
+    sgMatrixToQuat(PlayerOrientation, posTrans);
+
+    globals->get_multiplayer_tx_mgr()->SendMyPosition(PlayerOrientation, PlayerPosition);
 
   }