1
0
Fork 0

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.
This commit is contained in:
ehofman 2005-07-28 08:40:03 +00:00
parent 4bd2314430
commit ee73d9fbff
7 changed files with 56 additions and 33 deletions

View file

@ -35,34 +35,36 @@
* *
******************************************************************/ ******************************************************************/
#include <stdint.h>
#include <plib/sg.h> #include <plib/sg.h>
// Message identifiers // Message identifiers
#define CHAT_MSG_ID 1 #define CHAT_MSG_ID 1
#define POS_DATA_ID 2 #define UNUSABLE_POS_DATA_ID 2
#define POS_DATA_ID 3
#define MAX_CALLSIGN_LEN 10 /* should be a multiple of 8! */
#define MAX_CALLSIGN_LEN 8
/** Header for use with all messages sent */ /** Header for use with all messages sent */
typedef struct { typedef struct {
/** Message identifier */ /** Message identifier, multiple of 8! */
char MsgId; uint32_t MsgId;
/** Length of the message inclusive of this header */ /** Length of the message inclusive of this header */
unsigned int iMsgLen; uint32_t iMsgLen;
/** IP address for reply to message (player's receiver address) */ /** IP address for reply to message (player's receiver address) */
unsigned long int lReplyAddress; uint32_t lReplyAddress;
/** Port for replies (player's receiver port) */ /** Port for replies (player's receiver port) */
unsigned int iReplyPort; uint32_t iReplyPort;
/** Callsign used by the player */ /** Callsign used by the player */
char sCallsign[MAX_CALLSIGN_LEN]; char sCallsign[MAX_CALLSIGN_LEN];
} T_MsgHdr; } T_MsgHdr;
#define MAX_CHAT_MSG_LEN 50 #define MAX_CHAT_MSG_LEN 48
/** Chat message */ /** Chat message */
typedef struct { typedef struct {
@ -71,8 +73,8 @@ typedef struct {
} T_ChatMsg; } T_ChatMsg;
/* should be a multiple of 8! */
#define MAX_MODEL_NAME_LEN 50 #define MAX_MODEL_NAME_LEN 48
/** Aircraft position message */ /** Aircraft position message */
typedef struct { typedef struct {
@ -80,12 +82,12 @@ typedef struct {
char sModel[MAX_MODEL_NAME_LEN]; char sModel[MAX_MODEL_NAME_LEN];
/** Position data for the aircraft */ /** Position data for the aircraft */
sgMat4 PlayerPos; sgdVec3 PlayerPosition;
sgQuat PlayerOrientation;
} T_PositionMsg; } T_PositionMsg;
#endif #endif

View file

@ -53,6 +53,7 @@
#include <plib/sg.h> #include <plib/sg.h>
#include <simgear/scene/model/modellib.hxx> #include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/model/placementtrans.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Scenery/scenery.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. // Disconnect the model from the transform, then the transform from the scene.
m_ModelTrans->removeKid(m_Model); m_ModelTrans->removeKid(m_Model);
globals->get_scenery()->unregister_placement_transform(m_ModelTrans);
globals->get_scenery()->get_aircraft_branch()->removeKid( 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 // 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 * Description: Updates position data held for this player and resets
* the last update time. * 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 // Save the position matrix and update time
if (m_bInitialised) { if (m_bInitialised) {
sgCopyMat4(m_ModelPos, PlayerPosMat4); sgdCopyVec3(m_ModelPosition, PlayerPosition);
sgCopyVec4(m_ModelOrientation, PlayerOrientation);
time(&m_LastUpdate); time(&m_LastUpdate);
m_bUpdated = true; m_bUpdated = true;
} }
@ -187,16 +191,16 @@ MPPlayer::TPlayerDataState MPPlayer::Draw(void) {
MPPlayer::TPlayerDataState eResult = PLAYER_DATA_NOT_AVAILABLE; MPPlayer::TPlayerDataState eResult = PLAYER_DATA_NOT_AVAILABLE;
sgCoord sgPlayerCoord;
if (m_bInitialised && !m_bLocalPlayer) { if (m_bInitialised && !m_bLocalPlayer) {
if ((time(NULL) - m_LastUpdate < TIME_TO_LIVE)) { if ((time(NULL) - m_LastUpdate < TIME_TO_LIVE)) {
// Peform an update if it has changed since the last update // Peform an update if it has changed since the last update
if (m_bUpdated) { if (m_bUpdated) {
// Transform and update player model // Transform and update player model
sgSetCoord( &sgPlayerCoord, m_ModelPos); sgMat4 orMat;
m_ModelTrans->setTransform( &sgPlayerCoord ); sgMakeIdentMat4(orMat);
sgQuatToMatrix(orMat, m_ModelOrientation);
m_ModelTrans->setTransform(m_ModelPosition, orMat);
eResult = PLAYER_DATA_AVAILABLE; eResult = PLAYER_DATA_AVAILABLE;
@ -247,7 +251,7 @@ bool MPPlayer::CompareCallsign(const char *sCallsign) const {
void MPPlayer::LoadModel(void) { void MPPlayer::LoadModel(void) {
m_ModelTrans = new ssgTransform; m_ModelTrans = new ssgPlacementTransform;
// Load the model // Load the model
m_Model = globals->get_model_lib()->load_model( globals->get_fg_root(), 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 // Place on scene under aircraft branch
globals->get_scenery()->get_aircraft_branch()->addKid( m_ModelTrans ); 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); strncpy(PosMsg->sModel, m_sModelName.c_str(), MAX_MODEL_NAME_LEN);
PosMsg->sModel[MAX_MODEL_NAME_LEN - 1] = '\0'; PosMsg->sModel[MAX_MODEL_NAME_LEN - 1] = '\0';
sgCopyMat4(PosMsg->PlayerPos, m_ModelPos); sgdCopyVec3(PosMsg->PlayerPosition, m_ModelPosition);
sgCopyQuat(PosMsg->PlayerOrientation, m_ModelOrientation);
} }

View file

@ -54,7 +54,7 @@ SG_USING_STD(string);
class ssgEntity; class ssgEntity;
class ssgTransform; class ssgPlacementTransform;
class MPPlayer { class MPPlayer {
@ -89,7 +89,8 @@ public:
/** Sets the positioning matrix held for this player /** Sets the positioning matrix held for this player
* @param PlayerPosMat4 Matrix for positioning player's aircraft * @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 /** Transform and place model for player
*/ */
@ -127,8 +128,11 @@ private:
/** True if object is initialised */ /** True if object is initialised */
bool m_bInitialised; bool m_bInitialised;
/** Position matrix for the player's aircraft */ /** Position of the player's aircraft wrt the earth fixed global system */
sgMat4 m_ModelPos; sgdVec3 m_ModelPosition;
/** Orientation the player's aircraft wrt the earth fixed global system */
sgQuat m_ModelOrientation;
/** Used to remove player if no activity */ /** Used to remove player if no activity */
time_t m_LastUpdate; time_t m_LastUpdate;
@ -146,7 +150,7 @@ private:
ssgEntity *m_Model; ssgEntity *m_Model;
/** Model transform */ /** Model transform */
ssgTransform *m_ModelTrans; ssgPlacementTransform *m_ModelTrans;
/** True if this player is the local player */ /** True if this player is the local player */
bool m_bLocalPlayer; bool m_bLocalPlayer;

View file

@ -269,7 +269,7 @@ void FGMultiplayRxMgr::ProcessData(void) {
if (m_Player[iPlayerCnt]->CompareCallsign(MsgHdr->sCallsign)) { if (m_Player[iPlayerCnt]->CompareCallsign(MsgHdr->sCallsign)) {
// Player found. Update the data for the player. // Player found. Update the data for the player.
m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerPos); m_Player[iPlayerCnt]->SetPosition(PosMsg->PlayerOrientation, PosMsg->PlayerPosition);
bActivePlayer = true; 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 ); 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] = new MPPlayer;
m_Player[iPlayerCnt]->Open(sIpAddress, iPort, sCallsign, sModelName, false); 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; bActivePlayer = true;
} }
iPlayerCnt++; iPlayerCnt++;

View file

@ -189,14 +189,15 @@ void FGMultiplayTxMgr::Close(void) {
* Name: SendMyPosition * Name: SendMyPosition
* Description: Sends the position data for the local position. * 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_MsgHdr MsgHdr;
T_PositionMsg PosMsg; T_PositionMsg PosMsg;
char sMsg[sizeof(T_MsgHdr) + sizeof(T_PositionMsg)]; char sMsg[sizeof(T_MsgHdr) + sizeof(T_PositionMsg)];
if (m_bInitialised) { if (m_bInitialised) {
mLocalPlayer->SetPosition(PlayerPosMat4); mLocalPlayer->SetPosition(PlayerOrientation, PlayerPosition);
mLocalPlayer->FillPosMsg(&MsgHdr, &PosMsg); mLocalPlayer->FillPosMsg(&MsgHdr, &PosMsg);
memcpy(sMsg, &MsgHdr, sizeof(T_MsgHdr)); memcpy(sMsg, &MsgHdr, sizeof(T_MsgHdr));
memcpy(sMsg + sizeof(T_MsgHdr), &PosMsg, sizeof(T_PositionMsg)); memcpy(sMsg + sizeof(T_MsgHdr), &PosMsg, sizeof(T_PositionMsg));

View file

@ -70,7 +70,7 @@ public:
/** Sends the position data for the local player /** Sends the position data for the local player
* @param PlayerPosMat4 Transformation matrix for the player's position * @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. /** Sends a tex chat message.
* @param sMsgText Message text to send * @param sMsgText Message text to send

View file

@ -30,6 +30,8 @@
#include <simgear/debug/logstream.hxx> #include <simgear/debug/logstream.hxx>
#include <simgear/scene/model/placement.hxx> #include <simgear/scene/model/placement.hxx>
#include <Scenery/scenery.hxx>
#include "multiplay.hxx" #include "multiplay.hxx"
SG_USING_STD(string); SG_USING_STD(string);
@ -105,8 +107,16 @@ bool FGMultiplay::process() {
} else if (get_direction() == SG_IO_OUT) { } else if (get_direction() == SG_IO_OUT) {
globals->get_multiplayer_tx_mgr()-> sgMat4 posTrans;
SendMyPosition(globals->get_aircraft_model()->get3DModel()->get_POS()); 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);
} }