]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/mpplayer.hxx
MSVC fix from Frederic Bouvier
[flightgear.git] / src / MultiPlayer / mpplayer.hxx
1 // mpplayer.hxx -- routines for a player within a multiplayer Flightgear
2 //
3 // Written by Duncan McCreanor, started February 2003.
4 // duncan.mccreanor@airservicesaustralia.com
5 //
6 // Copyright (C) 2003  Airservices Australia
7 //
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.
12 //
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.
17 //
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.
21 //
22
23
24 #ifndef MPPLAYER_H
25 #define MPPLAYER_H
26
27 #define MPPLAYER_HID "$Id$"
28
29 /****************************************************************
30 * @version $Id$
31 *
32 * Description:
33 *
34 ******************************************************************/
35
36 #include "mpmessages.hxx"
37
38 #include <plib/ssg.h>
39 #include <plib/sg.h>
40 #include <plib/netSocket.h>
41 #include <simgear/io/sg_socket_udp.hxx>
42 #include <time.h>
43
44 #include STL_STRING
45 SG_USING_STD(string);
46
47 // Number of seconds before a player is consider to be lost
48 #define TIME_TO_LIVE 10
49
50 #define PLAYER_DATA_NOT_AVAILABLE 0
51 #define PLAYER_DATA_AVAILABLE 1
52 #define PLAYER_DATA_EXPIRED 2
53
54 class MPPlayer {
55 public:
56
57     /** Constructor */
58     MPPlayer();
59
60     /** Destructor. */
61     ~MPPlayer();
62
63     /** Initialises the class.
64     * @param sIP IP address or host name for sending data to the player
65     * @param sPort Port number for sending data to the player
66     * @param sCallsign Callsign of the player (must be unique across all instances of MPPlayer).
67     * @param sModelName Path and name of the aircraft model file for the player
68     * @param bLocalPlayer True if this player is the local player, else false
69     * @return True if class opens successfully, else false
70     */
71     bool Open(const string &sIP, const int &iPort, const string &sCallsign,
72               const string &sModelName, const bool bLocalPlayer);
73
74     /** Initialises the player count for all instances of this object to zero. */
75     static void ResetPlayerCnt(void);
76
77     /** Closes the player connection */
78     void Close(void);
79
80     /** Sets the positioning matrix held for this player
81     * @param PlayerPosMat4 Matrix for positioning player's aircraft
82     */
83     void SetPosition(const sgMat4 PlayerPosMat4);
84
85     /** Transform and place model for player
86     */
87     int Draw(void);
88
89     /** Returns the callsign for the player
90     * @return Aircraft's callsign
91     */
92     string Callsign(void) const;
93
94     /** Compares the player's callsign with the given callsign
95     * @param sCallsign Callsign to compare
96     * @return True if callsign matches
97     */
98     bool CompareCallsign(const char *sCallsign) const;
99
100     /** Loads the model of the aircraft */
101     void LoadModel(void);
102
103     /** Populates a position message for the player
104     * @param MsgHdr Header to be populated
105     * @param PosMsg Position message to be populated
106     */
107     void FillPosMsg(T_MsgHdr *MsgHdr, T_PositionMsg *PosMsg);
108
109     /** Populates a mesage header with information for the player
110     * @param MsgHdr Header to be populated
111     * @param iMsgId Message type identifier to insert into header
112     */
113     void FillMsgHdr(T_MsgHdr *MsgHdr, const int iMsgId);
114
115
116 private:
117
118     /** True if object is initialised */
119     bool m_bInitialised;
120
121     /** Position matrix for the player's aircraft */
122     sgMat4 m_ModelPos;
123
124     /** Used to remove player if no activity */
125     time_t m_LastUpdate;
126
127     /** Set when the player data is updated and cleared when read */
128     bool m_bUpdated;
129
130     /** Player's callsign */
131     string m_sCallsign;
132
133     /** Aircraft model for player */
134     string m_sModelName;
135
136     /** Simgear model selection */
137     ssgSelector *m_ModelSel;
138
139     /** Simgear model transform */
140     ssgTransform *m_ModelTrans;
141
142     /** True if this player is the local player */
143     bool m_bLocalPlayer;
144
145     /** Address information for the player */
146     netAddress m_PlayerAddress;
147
148 };
149
150 #endif
151
152
153