]> git.mxchange.org Git - flightgear.git/blobdiff - src/MultiPlayer/mpplayer.cxx
Frederic: MSVC doesn't have stdint.h. I just copied the code found in net_gui.hxx...
[flightgear.git] / src / MultiPlayer / mpplayer.cxx
index adfe19e52e5702ac6c40679b89a31a59dc7417b7..90a4f8e480fa67e7f3b32a50587922c8f8f74f0e 100644 (file)
 #include <plib/netSocket.h>
 #include <plib/sg.h>
 
+#include <simgear/scene/model/modellib.hxx>
+#include <simgear/scene/model/placementtrans.hxx>
+
 #include <Main/globals.hxx>
-#include <Model/loader.hxx>
 #include <Scenery/scenery.hxx>
 
 
@@ -106,9 +108,12 @@ bool MPPlayer::Open(const string &sAddress, const int &iPort, const string &sCal
 
         // If the player is remote then load the model
         if (!bLocalPlayer) {
-
-             LoadModel();
-
+             try {
+                 LoadModel();
+             } catch (...) {
+                 SG_LOG( SG_NETWORK, SG_ALERT, "Failed to load remote model '" << sModelName << "'." );
+                 return false;
+             }
         }
 
         m_bInitialised = bSuccess;
@@ -136,11 +141,12 @@ 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
         // models.
-        globals->get_model_loader()->flush();
+        globals->get_model_lib()->flush1();
 
         // Assume that plib/ssg deletes the model and transform as their
         // refcounts should be zero.
@@ -160,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;
     }
@@ -183,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;
 
@@ -243,10 +251,13 @@ 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_loader()->load_model(m_sModelName);
+    m_Model = globals->get_model_lib()->load_model( globals->get_fg_root(),
+                                                    m_sModelName,
+                                                    globals->get_props(),
+                                                    globals->get_sim_time_sec() );
     m_Model->clrTraversalMaskBits( SSGTRAV_HOT );
 
     // Add model to transform
@@ -258,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);
 
 
 }
@@ -273,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);
 
 
 }