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>
31 #include <simgear/scene/model/placement.hxx>
33 #include "multiplay.hxx"
38 // These constants are provided so that the ident command can list file versions.
39 const char sFG_MULTIPLAY_BID[] = "$Id$";
40 const char sFG_MULTIPLAY_HID[] = FG_MULTIPLAY_HID;
43 /******************************************************************
45 * Description: Constructor. Initialises the protocol and stores
46 * host and port information.
47 ******************************************************************/
48 FGMultiplay::FGMultiplay (const string &dir, const int rate, const string &host, const int port) {
54 if (get_direction() == SG_IO_IN) {
56 fgSetInt("/sim/multiplay/rxport", port);
57 fgSetString("/sim/multiplay/rxhost", host.c_str());
59 } else if (get_direction() == SG_IO_OUT) {
61 fgSetInt("/sim/multiplay/txport", port);
62 fgSetString("/sim/multiplay/txhost", host.c_str());
69 /******************************************************************
71 * Description: Destructor.
72 ******************************************************************/
73 FGMultiplay::~FGMultiplay () {
77 /******************************************************************
79 * Description: Enables the protocol.
80 ******************************************************************/
81 bool FGMultiplay::open() {
84 SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
85 << "is already in use, ignoring" );
95 /******************************************************************
97 * Description: Prompts the multiplayer mgr to either send
98 * or receive data over the network
99 ******************************************************************/
100 bool FGMultiplay::process() {
102 if (get_direction() == SG_IO_IN) {
104 globals->get_multiplayer_rx_mgr()->ProcessData();
106 } else if (get_direction() == SG_IO_OUT) {
108 globals->get_multiplayer_tx_mgr()->
109 SendMyPosition(globals->get_aircraft_model()->get3DModel()->get_POS());
117 /******************************************************************
119 * Description: Closes the multiplayer mgrs to stop any further
121 ******************************************************************/
122 bool FGMultiplay::close() {
124 if (get_direction() == SG_IO_IN) {
126 globals->get_multiplayer_rx_mgr()->Close();
128 } else if (get_direction() == SG_IO_OUT) {
130 globals->get_multiplayer_tx_mgr()->Close();