From: ehofman Date: Thu, 28 Jul 2005 08:40:03 +0000 (+0000) Subject: Mathias Fröhlich: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ee73d9fbff7fbaf6fca456f670e182eb63c7bd5c;p=flightgear.git Mathias Fröhlich: 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. --- diff --git a/src/MultiPlayer/mpmessages.hxx b/src/MultiPlayer/mpmessages.hxx index 61f04eca7..b0f91b268 100644 --- a/src/MultiPlayer/mpmessages.hxx +++ b/src/MultiPlayer/mpmessages.hxx @@ -35,34 +35,36 @@ * ******************************************************************/ +#include #include // 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 diff --git a/src/MultiPlayer/mpplayer.cxx b/src/MultiPlayer/mpplayer.cxx index 20b255ad5..90a4f8e48 100644 --- a/src/MultiPlayer/mpplayer.cxx +++ b/src/MultiPlayer/mpplayer.cxx @@ -53,6 +53,7 @@ #include #include +#include #include
#include @@ -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); } diff --git a/src/MultiPlayer/mpplayer.hxx b/src/MultiPlayer/mpplayer.hxx index c16d9f1b0..04c5b648f 100644 --- a/src/MultiPlayer/mpplayer.hxx +++ b/src/MultiPlayer/mpplayer.hxx @@ -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; diff --git a/src/MultiPlayer/multiplayrxmgr.cxx b/src/MultiPlayer/multiplayrxmgr.cxx index 474a09faf..95e65646f 100644 --- a/src/MultiPlayer/multiplayrxmgr.cxx +++ b/src/MultiPlayer/multiplayrxmgr.cxx @@ -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++; diff --git a/src/MultiPlayer/multiplaytxmgr.cxx b/src/MultiPlayer/multiplaytxmgr.cxx index ff7079a80..12570ffc7 100644 --- a/src/MultiPlayer/multiplaytxmgr.cxx +++ b/src/MultiPlayer/multiplaytxmgr.cxx @@ -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)); diff --git a/src/MultiPlayer/multiplaytxmgr.hxx b/src/MultiPlayer/multiplaytxmgr.hxx index fd6d1d1f9..df9e80c4b 100644 --- a/src/MultiPlayer/multiplaytxmgr.hxx +++ b/src/MultiPlayer/multiplaytxmgr.hxx @@ -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 diff --git a/src/Network/multiplay.cxx b/src/Network/multiplay.cxx index 4bc37c120..54bd41da0 100644 --- a/src/Network/multiplay.cxx +++ b/src/Network/multiplay.cxx @@ -30,6 +30,8 @@ #include #include +#include + #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); }