1 // mpplayer.hxx -- routines for a player within a multiplayer Flightgear
3 // Written by Duncan McCreanor, started February 2003.
4 // duncan.mccreanor@airservicesaustralia.com
6 // Copyright (C) 2003 Airservices Australia
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define MPPLAYER_HID "$Id$"
29 /****************************************************************
32 * Description: This class holds information about a player in a
33 * multiplayer game. The model for a remote player is loaded and
34 * added onto the aircraft branch of the scene on calling Open.
35 * The model is unloaded from the scene when Close is called
36 * or the object is deleted. The model's positioning transform is
37 * updated by calling SetPosition. The updated position transform
38 * is applied to the model on the scene by calling Draw.
40 ******************************************************************/
42 #include "mpmessages.hxx"
45 #include <plib/netSocket.h>
46 #include <simgear/io/sg_socket_udp.hxx>
52 // Number of seconds before a player is consider to be lost
53 #define TIME_TO_LIVE 10
56 class ssgPlacementTransform;
63 /** Enumeration of the states for the player's data */
66 PLAYER_DATA_NOT_AVAILABLE = 0,
67 PLAYER_DATA_AVAILABLE,
70 /** Player data state */
71 typedef enum PlayerDataState TPlayerDataState;
72 /** Initialises the class.
73 * @param sIP IP address or host name for sending data to the player
74 * @param sPort Port number for sending data to the player
75 * @param sCallsign Callsign of the player (must be unique across all instances of MPPlayer).
76 * @param sModelName Path and name of the aircraft model file for the player
77 * @param bLocalPlayer True if this player is the local player, else false
78 * @return True if class opens successfully, else false
80 bool Open(const string &IP, const int &Port, const string &Callsign,
81 const string &ModelName, const bool LocalPlayer);
82 /** Closes the player connection */
84 /** Sets the positioning matrix held for this player
85 * @param PlayerPosMat4 Matrix for positioning player's aircraft
87 void SetPosition(const sgQuat PlayerOrientation,
88 const sgdVec3 PlayerPosition);
89 /** Transform and place model for player
91 TPlayerDataState Draw(void);
92 /** Returns the callsign for the player
93 * @return Aircraft's callsign
95 string Callsign(void) const;
96 /** Compares the player's callsign with the given callsign
97 * @param sCallsign Callsign to compare
98 * @return True if callsign matches
100 bool CompareCallsign(const char *Callsign) const;
101 /** Populates a position message for the player
102 * @param MsgHdr Header to be populated
103 * @param PosMsg Position message to be populated
105 void FillPosMsg(T_MsgHdr *MsgHdr, T_PositionMsg *PosMsg);
106 /** Populates a mesage header with information for the player
107 * @param MsgHdr Header to be populated
108 * @param iMsgId Message type identifier to insert into header
110 void FillMsgHdr(T_MsgHdr *MsgHdr, const int iMsgId);
112 void LoadModel(void); // Loads the model of the aircraft
113 bool m_Initialised; // True if object is initialised
114 sgdVec3 m_ModelPosition; // players global position on earth
115 sgQuat m_ModelOrientation; // players global orientation
116 time_t m_LastUpdate; // last time update data received
117 bool m_Updated; // Set when the player data is updated
118 string m_Callsign; // players callsign
119 bool m_LocalPlayer; // true if player is the local player
120 string m_ModelName; // Aircraft model name for player
121 ssgEntity *m_Model; // The player's loaded model
122 netAddress m_PlayerAddress; // Address information for the player
123 ssgPlacementTransform *m_ModelTrans; // Model transform