]> git.mxchange.org Git - flightgear.git/blobdiff - src/MultiPlayer/mpplayer.hxx
Portability fix - use SimGear when available
[flightgear.git] / src / MultiPlayer / mpplayer.hxx
index 37a9d6eb77f4645ea04e899b29d9c63a233238af..38165720798da403ef99f2a3680a0b71c0e3a075 100644 (file)
 /****************************************************************
 * @version $Id$
 *
-* Description:
+* Description: This class holds information about a player in a
+* multiplayer game. The model for a remote player is loaded and
+* added onto the aircraft branch of the scene on calling Open.
+* The model is unloaded from the scene when Close is called
+* or the object is deleted. The model's positioning transform is
+* updated by calling SetPosition. The updated position transform
+* is applied to the model on the scene by calling Draw.
 *
 ******************************************************************/
 
 #include "mpmessages.hxx"
 
-#include <plib/ssg.h>
 #include <plib/sg.h>
 #include <plib/netSocket.h>
 #include <simgear/io/sg_socket_udp.hxx>
+#include <simgear/props/props.hxx>
 #include <time.h>
 
 #include STL_STRING
@@ -47,19 +53,22 @@ SG_USING_STD(string);
 // Number of seconds before a player is consider to be lost
 #define TIME_TO_LIVE 10
 
-#define PLAYER_DATA_NOT_AVAILABLE 0
-#define PLAYER_DATA_AVAILABLE 1
-#define PLAYER_DATA_EXPIRED 2
+class FGAIMultiplayer;
 
-class MPPlayer {
+class MPPlayer 
+{
 public:
-
-    /** Constructor */
     MPPlayer();
-
-    /** Destructor. */
     ~MPPlayer();
-
+    /** Enumeration of the states for the player's data */
+    enum PlayerDataState
+    {
+        PLAYER_DATA_NOT_AVAILABLE = 0, 
+        PLAYER_DATA_AVAILABLE, 
+        PLAYER_DATA_EXPIRED
+    };
+    /** Player data state */
+    typedef enum PlayerDataState TPlayerDataState;
     /** Initialises the class.
     * @param sIP IP address or host name for sending data to the player
     * @param sPort Port number for sending data to the player
@@ -68,83 +77,84 @@ public:
     * @param bLocalPlayer True if this player is the local player, else false
     * @return True if class opens successfully, else false
     */
-    bool Open(const string &sIP, const int &iPort, const string &sCallsign,
-              const string &sModelName, const bool bLocalPlayer);
-
-    /** Initialises the player count for all instances of this object to zero. */
-    static void ResetPlayerCnt(void);
-
+    bool Open(const string &IP, const int &Port, const string &Callsign,
+              const string &ModelName, const bool LocalPlayer);
     /** Closes the player connection */
     void Close(void);
-
+    /** Checks if the time is valid for a position update and perhaps sets the time offset
+     */
+    bool CheckTime(int time, int timeusec);
     /** Sets the positioning matrix held for this player
-    * @param PlayerPosMat4 Matrix for positioning player's aircraft
     */
-    void SetPosition(const sgMat4 PlayerPosMat4);
-
+    void SetPosition(const double lat, const double lon, const double alt,
+                     const double heading, const double roll, const double pitch,
+                     const double speedN, const double speedE, const double speedD,
+                     const double left_aileron, const double right_aileron, const double elevator, const double rudder,
+                     //const double rpms[6],
+                     const double rateH, const double rateR, const double rateP,
+                     const double accN, const double accE, const double accD);
+    /** Sets a property for this player
+    */
+    void SetProperty(string property, SGPropertyNode::Type type, double val);
     /** Transform and place model for player
     */
-    int Draw(void);
-
+    TPlayerDataState Draw(void);
     /** Returns the callsign for the player
     * @return Aircraft's callsign
     */
     string Callsign(void) const;
-
     /** Compares the player's callsign with the given callsign
     * @param sCallsign Callsign to compare
     * @return True if callsign matches
     */
-    bool CompareCallsign(const char *sCallsign) const;
-
-    /** Loads the model of the aircraft */
-    void LoadModel(void);
-
+    bool CompareCallsign(const char *Callsign) const;
     /** Populates a position message for the player
     * @param MsgHdr Header to be populated
     * @param PosMsg Position message to be populated
     */
     void FillPosMsg(T_MsgHdr *MsgHdr, T_PositionMsg *PosMsg);
-
     /** Populates a mesage header with information for the player
     * @param MsgHdr Header to be populated
     * @param iMsgId Message type identifier to insert into header
     */
     void FillMsgHdr(T_MsgHdr *MsgHdr, const int iMsgId);
-
-
 private:
-
-    /** True if object is initialised */
-    bool m_bInitialised;
-
-    /** Position matrix for the player's aircraft */
-    sgMat4 m_ModelPos;
-
-    /** Used to remove player if no activity */
-    time_t m_LastUpdate;
-
-    /** Set when the player data is updated and cleared when read */
-    bool m_bUpdated;
-
-    /** Player's callsign */
-    string m_sCallsign;
-
-    /** Aircraft model for player */
-    string m_sModelName;
-
-    /** Simgear model selection */
-    ssgSelector *m_ModelSel;
-
-    /** Simgear model transform */
-    ssgTransform *m_ModelTrans;
-
-    /** True if this player is the local player */
-    bool m_bLocalPlayer;
-
-    /** Address information for the player */
-    netAddress m_PlayerAddress;
-
+    void    LoadAI(void);       // Loads the plane into the AI core
+    bool    m_Initialised;      // True if object is initialised 
+    
+    double  m_lat;              // location, orientation, etc...
+    double  m_lon;              // ...
+    double  m_alt;              // ...
+    double  m_hdg;              // ...
+    double  m_roll;             // ...
+    double  m_pitch;            // ...
+    double  m_speedN;           // ...
+    double  m_speedE;           // ...
+    double  m_speedD;           // ...
+    double  m_accN;             // ...
+    double  m_accE;             // ...
+    double  m_accD;             // ...
+    double  m_left_aileron;     // ...
+    double  m_right_aileron;     // ...
+    double  m_elevator;         // ...
+    double  m_rudder;           // ...
+    //double  m_rpms[6];          // ...
+    double  m_rateH;            // ...
+    double  m_rateR;            // ...
+    double  m_rateP;            // ...
+
+    time_t  m_LastUpdate;       // last time update data received
+    int     m_LastTime;         // last seconds according to the packet
+    int     m_LastUTime;        // last microseconds according to the packet
+    double  m_Elapsed;          // Elapsed other-side time between responses
+    double  m_TimeOffset;       // the offset to aim for
+    double  m_LastOffset;       // the last offset we got
+    bool    m_Updated;          // Set when the player data is updated
+    string  m_Callsign;         // players callsign
+    bool    m_LocalPlayer;      // true if player is the local player
+    string  m_ModelName;        // Aircraft model name for player
+    netAddress m_PlayerAddress; // Address information for the player
+    FGAIMultiplayer *m_AIModel; // The AI model of this aircraft
 };
 
 #endif