]> git.mxchange.org Git - flightgear.git/blob - src/MultiPlayer/multiplaymgr.hxx
toggle fullscreen: also adapt GUI plane when resizing
[flightgear.git] / src / MultiPlayer / multiplaymgr.hxx
1 //////////////////////////////////////////////////////////////////////
2 //
3 // multiplaymgr.hxx
4 //
5 // Written by Duncan McCreanor, started February 2003.
6 // duncan.mccreanor@airservicesaustralia.com
7 //
8 // Copyright (C) 2003  Airservices Australia
9 // Copyright (C) 2005  Oliver Schroeder
10 //
11 // This program is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU General Public License as
13 // published by the Free Software Foundation; either version 2 of the
14 // License, or (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 // General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24 //
25 // $Id$
26 //  
27 //////////////////////////////////////////////////////////////////////
28
29 #ifndef MULTIPLAYMGR_H
30 #define MULTIPLAYMGR_H
31
32 #define MULTIPLAYTXMGR_HID "$Id$"
33
34
35 #include <string>
36 #include <vector>
37 #include <memory>
38
39 #include <simgear/compiler.h>
40 #include <simgear/props/props.hxx>
41 #include <simgear/io/raw_socket.hxx>
42 #include <simgear/structure/subsystem_mgr.hxx>
43
44 struct FGExternalMotionData;
45 class MPPropertyListener;
46 struct T_MsgHdr;
47 class FGAIMultiplayer;
48
49 class FGMultiplayMgr : public SGSubsystem
50 {
51 public:  
52   FGMultiplayMgr();
53   ~FGMultiplayMgr();
54   
55   virtual void init(void);
56   virtual void update(double dt);
57   
58   virtual void shutdown(void);
59   virtual void reinit();
60   
61   // transmitter
62   
63   void SendTextMessage(const string &sMsgText);
64   // receiver
65   
66 private:
67   friend class MPPropertyListener;
68   
69   void setPropertiesChanged()
70   {
71     mPropertiesChanged = true;
72   }
73   
74   void findProperties();
75   
76   void Send();
77   void SendMyPosition(const FGExternalMotionData& motionInfo);
78
79   union MsgBuf;
80   FGAIMultiplayer* addMultiplayer(const std::string& callsign,
81                                   const std::string& modelName);
82   FGAIMultiplayer* getMultiplayer(const std::string& callsign);
83   void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
84   void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
85                      long stamp);
86   void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
87   bool isSane(const FGExternalMotionData& motionInfo);
88
89   /// maps from the callsign string to the FGAIMultiplayer
90   typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
91   MultiPlayerMap mMultiPlayerMap;
92
93   std::auto_ptr<simgear::Socket> mSocket;
94   simgear::IPAddress mServer;
95   bool mHaveServer;
96   bool mInitialised;
97   std::string mCallsign;
98   
99   // Map between the property id's from the multiplayers network packets
100   // and the property nodes
101   typedef std::map<unsigned int, SGSharedPtr<SGPropertyNode> > PropertyMap;
102   PropertyMap mPropertyMap;
103   
104   bool mPropertiesChanged;
105   MPPropertyListener* mListener;
106   
107   double mDt; // reciprocal of /sim/multiplay/tx-rate-hz
108   double mTimeUntilSend;
109 };
110
111 #endif
112