]> git.mxchange.org Git - flightgear.git/blobdiff - src/MultiPlayer/multiplaymgr.hxx
Clean-up: move autosave.xml loading code to proper method
[flightgear.git] / src / MultiPlayer / multiplaymgr.hxx
index 63add6b7702a395ab94170d0d93c30b87c42832a..42444f014021dc3bae4d0e092f55f71125f07990 100644 (file)
@@ -1,6 +1,6 @@
 //////////////////////////////////////////////////////////////////////
 //
-// multiplaymgr.hpp
+// multiplaymgr.hxx
 //
 // Written by Duncan McCreanor, started February 2003.
 // duncan.mccreanor@airservicesaustralia.com
@@ -20,7 +20,7 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 //  
 
 #define MULTIPLAYTXMGR_HID "$Id$"
 
-#include "mpplayer.hxx"
-#include "mpmessages.hxx"
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include STL_STRING
-SG_USING_STD(string);
+#include <string>
 #include <vector>
-SG_USING_STD(vector);
+#include <memory>
 
 #include <simgear/compiler.h>
-#include <plib/netSocket.h>
-#include <Main/globals.hxx>
+#include <simgear/props/props.hxx>
+#include <simgear/io/raw_socket.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
 
-// Maximum number of players that can exist at any time
-// FIXME: use a list<mplayer> instead
-#define MAX_PLAYERS 10
+struct FGExternalMotionData;
+class MPPropertyListener;
+struct T_MsgHdr;
+class FGAIMultiplayer;
 
-class FGMultiplayMgr 
+class FGMultiplayMgr : public SGSubsystem
 {
-public:
-    FGMultiplayMgr();
-    ~FGMultiplayMgr();
-    bool init(void);
-    void Close(void);
-    // transmitter
-    void SendMyPosition (const sgQuat PlayerOrientation, 
-                         const sgdVec3 PlayerPosition);
-    void SendTextMessage (const string &sMsgText) const;
-    // receiver
-    void ProcessData(void);
-    void ProcessPosMsg ( const char *Msg, netAddress & SenderAddress );
-    void ProcessChatMsg ( const char *Msg, netAddress & SenderAddress );
-    void Update(void);
+public:  
+  FGMultiplayMgr();
+  ~FGMultiplayMgr();
+  
+  virtual void init(void);
+  virtual void update(double dt);
+  
+  virtual void shutdown(void);
+  virtual void reinit();
+  
+  // transmitter
+  
+  void SendTextMessage(const string &sMsgText);
+  // receiver
+  
 private:
-    typedef vector<MPPlayer*>           t_MPClientList;
-    typedef t_MPClientList::iterator    t_MPClientListIterator;
-    MPPlayer*       m_LocalPlayer;
-    netSocket*      m_DataSocket;
-    netAddress      m_Server;
-    bool            m_HaveServer;
-    bool            m_Initialised;
-    t_MPClientList  m_MPClientList;
-    string          m_RxAddress;
-    int             m_RxPort;
-    string          m_Callsign;
+  friend class MPPropertyListener;
+  
+  void setPropertiesChanged()
+  {
+    mPropertiesChanged = true;
+  }
+  
+  void findProperties();
+  
+  void Send();
+  void SendMyPosition(const FGExternalMotionData& motionInfo);
+
+  union MsgBuf;
+  FGAIMultiplayer* addMultiplayer(const std::string& callsign,
+                                  const std::string& modelName);
+  FGAIMultiplayer* getMultiplayer(const std::string& callsign);
+  void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
+  void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
+                     long stamp);
+  void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
+  bool isSane(const FGExternalMotionData& motionInfo);
+
+  /// maps from the callsign string to the FGAIMultiplayer
+  typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
+  MultiPlayerMap mMultiPlayerMap;
+
+  std::auto_ptr<simgear::Socket> mSocket;
+  simgear::IPAddress mServer;
+  bool mHaveServer;
+  bool mInitialised;
+  std::string mCallsign;
+  
+  // Map between the property id's from the multiplayers network packets
+  // and the property nodes
+  typedef std::map<unsigned int, SGSharedPtr<SGPropertyNode> > PropertyMap;
+  PropertyMap mPropertyMap;
+  
+  bool mPropertiesChanged;
+  MPPropertyListener* mListener;
+  
+  double mDt; // reciprocal of /sim/multiplay/tx-rate-hz
+  double mTimeUntilSend;
 };
 
 #endif