]> git.mxchange.org Git - flightgear.git/blob - src/AIModel/AIMultiplayer.hxx
Fix huge multiplayer memory leak.
[flightgear.git] / src / AIModel / AIMultiplayer.hxx
1 // FGAIMultiplayer - AIBase derived class creates an AI multiplayer aircraft
2 //
3 // Written by David Culp, started October 2003.
4 //
5 // Copyright (C) 2003  David P. Culp - davidculp2@comcast.net
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #ifndef _FG_AIMultiplayer_HXX
22 #define _FG_AIMultiplayer_HXX
23
24 #include <map>
25 #include <string>
26
27 #include <MultiPlayer/mpmessages.hxx>
28 #include "AIBase.hxx"
29
30 class FGAIMultiplayer : public FGAIBase {
31 public:
32   FGAIMultiplayer();
33   virtual ~FGAIMultiplayer();
34
35   virtual bool init(bool search_in_AI_path=false);
36   virtual void bind();
37   virtual void unbind();
38   virtual void update(double dt);
39
40   void addMotionInfo(FGExternalMotionData& motionInfo, long stamp);
41   void setDoubleProperty(const std::string& prop, double val);
42
43   long getLastTimestamp(void) const
44   { return mLastTimestamp; }
45
46   void setAllowExtrapolation(bool allowExtrapolation)
47   { mAllowExtrapolation = allowExtrapolation; }
48   bool getAllowExtrapolation(void) const
49   { return mAllowExtrapolation; }
50   void setLagAdjustSystemSpeed(double lagAdjustSystemSpeed)
51   {
52     if (lagAdjustSystemSpeed < 0)
53       lagAdjustSystemSpeed = 0;
54     mLagAdjustSystemSpeed = lagAdjustSystemSpeed;
55   }
56   double getLagAdjustSystemSpeed(void) const
57   { return mLagAdjustSystemSpeed; }
58
59   void addPropertyId(unsigned id, const char* name)
60   { mPropertyMap[id] = props->getNode(name, true); }
61
62   SGPropertyNode* getPropertyRoot()
63   { return props; }
64
65   virtual const char* getTypeString(void) const { return "multiplayer"; }
66
67 private:
68
69   // Automatic sorting of motion data according to its timestamp
70   typedef std::map<double,FGExternalMotionData> MotionInfo;
71   MotionInfo mMotionInfo;
72
73   // Map between the property id's from the multiplayers network packets
74   // and the property nodes
75   typedef std::map<unsigned, SGSharedPtr<SGPropertyNode> > PropertyMap;
76   PropertyMap mPropertyMap;
77
78   double mTimeOffset;
79   bool mTimeOffsetSet;
80
81   /// Properties which are for now exposed for testing
82   bool mAllowExtrapolation;
83   double mLagAdjustSystemSpeed;
84
85   long mLastTimestamp;
86
87   // Propertiies for tankers
88   SGPropertyNode_ptr refuel_node;
89   bool isTanker;
90   bool contact;          // set if this tanker is within fuelling range
91 };
92
93 #endif  // _FG_AIMultiplayer_HXX