2003-03-19 20:45:09 +00:00
|
|
|
// multiplay.hxx -- protocol object for multiplay in Flightgear
|
|
|
|
//
|
|
|
|
// Written by Diarmuid Tyson, started February 2003.
|
|
|
|
// diarmuid.tyson@airservicesaustralia.com
|
|
|
|
//
|
2006-02-09 12:29:05 +00:00
|
|
|
// With additions by Vivian Meazza, January 2006
|
|
|
|
//
|
2003-03-19 20:45:09 +00:00
|
|
|
// Copyright (C) 2003 Airservices Australia
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef _FG_MULTIPLAY_HXX
|
|
|
|
#define _FG_MULTIPLAY_HXX
|
|
|
|
|
|
|
|
#define FG_MULTIPLAY_HID "$Id$"
|
|
|
|
|
2003-05-09 20:40:59 +00:00
|
|
|
#include <simgear/compiler.h>
|
|
|
|
|
2003-03-19 20:45:09 +00:00
|
|
|
#include STL_STRING
|
|
|
|
|
2003-05-09 20:40:59 +00:00
|
|
|
#include <simgear/scene/model/model.hxx>
|
|
|
|
|
2003-03-19 20:45:09 +00:00
|
|
|
#include <Main/globals.hxx>
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
#include <Model/acmodel.hxx>
|
2005-11-01 13:41:49 +00:00
|
|
|
#include <MultiPlayer/multiplaymgr.hxx>
|
2003-03-19 20:45:09 +00:00
|
|
|
|
2003-05-09 20:40:59 +00:00
|
|
|
#include "protocol.hxx"
|
|
|
|
|
|
|
|
SG_USING_STD(string);
|
|
|
|
|
|
|
|
|
2003-03-19 20:45:09 +00:00
|
|
|
/****************************************************************
|
|
|
|
* @version $Id$
|
|
|
|
*
|
|
|
|
* Description: FGMultiplay is an FGProtocol object used as the basic
|
|
|
|
* interface for the multiplayer code into FlightGears generic IO
|
|
|
|
* subsystem. It only implements the basic FGProtocol methods: open(),
|
|
|
|
* process() and close(). It does not use Sim Gear's IO channels, as
|
|
|
|
* the MultiplayMgrs creates their own sockets through plib.
|
|
|
|
*
|
|
|
|
* It will set up it's direction and rate protocol properties when
|
|
|
|
* created. Subsequent calls to process will prompt the
|
|
|
|
* MultiplayMgr to either send or receive data over the network.
|
|
|
|
*
|
|
|
|
******************************************************************/
|
|
|
|
|
2006-02-09 12:29:05 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
|
|
|
|
2003-03-19 20:45:09 +00:00
|
|
|
class FGMultiplay : public FGProtocol {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Constructor */
|
|
|
|
FGMultiplay (const string &dir, const int rate, const string &host, const int port);
|
|
|
|
|
|
|
|
/** Destructor. */
|
|
|
|
~FGMultiplay ();
|
|
|
|
|
2006-02-09 12:29:05 +00:00
|
|
|
/** Enables the FGMultiplay object. */
|
2003-03-19 20:45:09 +00:00
|
|
|
bool open();
|
|
|
|
|
2006-02-09 12:29:05 +00:00
|
|
|
/** Tells the multiplayer_mgr to send/receive data. */
|
2003-03-19 20:45:09 +00:00
|
|
|
bool process();
|
|
|
|
|
2006-02-09 12:29:05 +00:00
|
|
|
/** Closes the multiplayer_mgr. */
|
2003-03-19 20:45:09 +00:00
|
|
|
bool close();
|
|
|
|
|
2006-02-09 12:29:05 +00:00
|
|
|
|
2003-03-19 20:45:09 +00:00
|
|
|
private:
|
2006-02-09 12:29:05 +00:00
|
|
|
struct _node_cache {
|
|
|
|
double val;
|
|
|
|
SGPropertyNode_ptr node;
|
|
|
|
_node_cache(double v, SGPropertyNode_ptr n) {
|
|
|
|
val = v; node = n;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/** calculate accelerations
|
|
|
|
*/
|
|
|
|
void calcAcc(double speedN, double speedE, double speedD);
|
|
|
|
|
|
|
|
double last_time ; //sec
|
|
|
|
double last_speedN, last_speedE, last_speedD; //fps
|
|
|
|
double calcaccN, calcaccE, calcaccD; //fps2
|
|
|
|
|
|
|
|
SGPropertyNode *lat_n, *lon_n, *alt_n;
|
|
|
|
SGPropertyNode *heading_n, *pitch_n, *roll_n;
|
|
|
|
SGPropertyNode *speedN_n, *speedE_n, *speedD_n;
|
|
|
|
SGPropertyNode *left_aileron_n, *right_aileron_n;
|
|
|
|
SGPropertyNode *elevator_n, *rudder_n;
|
|
|
|
// SGPropertyNode *rpms[5];
|
|
|
|
SGPropertyNode *rateH_n, *rateR_n, *rateP_n;
|
|
|
|
|
|
|
|
map<string,struct _node_cache*> props;
|
|
|
|
map<string,struct _node_cache*>::iterator propit;
|
2003-03-19 20:45:09 +00:00
|
|
|
};
|
|
|
|
#endif // _FG_MULTIPLAY_HXX
|