1 // multiplay.cxx -- protocol object for multiplay in Flightgear
3 // Written by Diarmuid Tyson, started February 2003.
4 // diarmuid.tyson@airservicesaustralia.com
6 // Copyright (C) 2003 Airservices Australia
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <simgear/compiler.h>
30 #include <simgear/debug/logstream.hxx>
32 #include <Model/placement.hxx>
34 #include "multiplay.hxx"
39 // These constants are provided so that the ident command can list file versions.
40 const char sFG_MULTIPLAY_BID[] = "$Id$";
41 const char sFG_MULTIPLAY_HID[] = FG_MULTIPLAY_HID;
44 /******************************************************************
46 * Description: Constructor. Initialises the protocol and stores
47 * host and port information.
48 ******************************************************************/
49 FGMultiplay::FGMultiplay (const string &dir, const int rate, const string &host, const int port) {
55 if (get_direction() == SG_IO_IN) {
57 fgSetInt("/sim/multiplay/rxport", port);
58 fgSetString("/sim/multiplay/rxhost", host.c_str());
60 } else if (get_direction() == SG_IO_OUT) {
62 fgSetInt("/sim/multiplay/txport", port);
63 fgSetString("/sim/multiplay/txhost", host.c_str());
70 /******************************************************************
72 * Description: Destructor.
73 ******************************************************************/
74 FGMultiplay::~FGMultiplay () {
78 /******************************************************************
80 * Description: Enables the protocol.
81 ******************************************************************/
82 bool FGMultiplay::open() {
85 SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
86 << "is already in use, ignoring" );
96 /******************************************************************
98 * Description: Prompts the multiplayer mgr to either send
99 * or receive data over the network
100 ******************************************************************/
101 bool FGMultiplay::process() {
103 if (get_direction() == SG_IO_IN) {
105 globals->get_multiplayer_rx_mgr()->ProcessData();
107 } else if (get_direction() == SG_IO_OUT) {
109 globals->get_multiplayer_tx_mgr()->
110 SendMyPosition(globals->get_aircraft_model()->get3DModel()->get_POS());
118 /******************************************************************
120 * Description: Closes the multiplayer mgrs to stop any further
122 ******************************************************************/
123 bool FGMultiplay::close() {
125 if (get_direction() == SG_IO_IN) {
127 globals->get_multiplayer_rx_mgr()->Close();
129 } else if (get_direction() == SG_IO_OUT) {
131 globals->get_multiplayer_tx_mgr()->Close();