]> git.mxchange.org Git - flightgear.git/blob - src/Network/multiplay.hxx
Vivian Meazza:
[flightgear.git] / src / Network / multiplay.hxx
1 // multiplay.hxx -- protocol object for multiplay in Flightgear
2 //
3 // Written by Diarmuid Tyson, started February 2003.
4 // diarmuid.tyson@airservicesaustralia.com
5 //
6 // With additions by Vivian Meazza, January 2006
7 //
8 // Copyright (C) 2003  Airservices Australia
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 //
24
25 #ifndef _FG_MULTIPLAY_HXX
26 #define _FG_MULTIPLAY_HXX
27
28 #define FG_MULTIPLAY_HID "$Id$"
29
30 #include <simgear/compiler.h>
31
32 #include STL_STRING
33
34 #include <simgear/scene/model/model.hxx>
35
36 #include <Main/globals.hxx>
37 #include <Main/fg_props.hxx>
38 #include <Model/acmodel.hxx>
39 #include <MultiPlayer/multiplaymgr.hxx>
40
41 #include "protocol.hxx"
42
43 SG_USING_STD(string);
44
45
46 /****************************************************************
47 * @version $Id$
48 *
49 * Description: FGMultiplay is an FGProtocol object used as the basic
50 * interface for the multiplayer code into FlightGears generic IO
51 * subsystem.  It only implements the basic FGProtocol methods: open(),
52 * process() and close().  It does not use Sim Gear's IO channels, as
53 * the MultiplayMgrs creates their own sockets through plib.
54 *
55 * It will set up it's direction and rate protocol properties when
56 * created.  Subsequent calls to process will prompt the
57 * MultiplayMgr to either send or receive data over the network.
58 *
59 ******************************************************************/
60
61 #include <simgear/props/props.hxx>
62
63 class FGMultiplay : public FGProtocol {
64 public:
65
66     /** Constructor */
67     FGMultiplay (const string &dir, const int rate, const string &host, const int port);
68
69     /** Destructor. */
70     ~FGMultiplay ();
71
72     /** Enables the FGMultiplay object. */
73     bool open();
74
75     /** Tells the multiplayer_mgr to send/receive data. */
76     bool process();
77
78     /** Closes the multiplayer_mgr. */
79     bool close();
80
81     
82 private:
83     struct _node_cache {
84         double val;
85         SGPropertyNode_ptr node;
86         _node_cache(double v, SGPropertyNode_ptr n) {
87            val = v; node = n;
88         };
89     };
90
91     /** calculate accelerations
92     */
93     void calcAcc(double speedN, double speedE, double speedD);
94
95     double last_time ;                                //sec
96     double last_speedN, last_speedE, last_speedD;     //fps
97     double calcaccN, calcaccE, calcaccD;              //fps2
98
99     SGPropertyNode *lat_n, *lon_n, *alt_n;
100     SGPropertyNode *heading_n, *pitch_n, *roll_n;
101     SGPropertyNode *speedN_n, *speedE_n, *speedD_n;
102     SGPropertyNode *left_aileron_n, *right_aileron_n;
103     SGPropertyNode *elevator_n, *rudder_n;
104     // SGPropertyNode *rpms[5];
105     SGPropertyNode *rateH_n, *rateR_n, *rateP_n;
106
107     map<string,struct _node_cache*> props;
108     map<string,struct _node_cache*>::iterator propit;
109 };
110 #endif // _FG_MULTIPLAY_HXX