////////////////////////////////////////////////////////////////////
globals->add_subsystem("atis", new FGAtisManager, SGSubsystemMgr::POST_FDM);
#endif
+
+
+ ////////////////////////////////////////////////////////////////////
+ // Initialize multiplayer subsystem
+ ////////////////////////////////////////////////////////////////////
+
+ globals->add_subsystem("mp", new FGMultiplayMgr, SGSubsystemMgr::POST_FDM);
+
////////////////////////////////////////////////////////////////////
// Initialise the AI Model Manager
////////////////////////////////////////////////////////////////////
globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init();
- ////////////////////////////////////////////////////////////////////
- // Initialize multiplayer subsystem
- ////////////////////////////////////////////////////////////////////
-
- globals->set_multiplayer_mgr(new FGMultiplayMgr);
- globals->get_multiplayer_mgr()->init();
-
////////////////////////////////////////////////////////////////////////
// Initialize the Nasal interpreter.
// Do this last, so that the loaded scripts see initialized state
int fgGetKeyModifiers()
{
+ if (!globals->get_renderer()) { // happens during shutdown
+ return 0;
+ }
+
return globals->get_renderer()->getEventHandler()->getCurrentModifiers();
}
tacanlist( NULL ),
carrierlist( NULL ),
channellist( NULL ),
- airwaynet( NULL ),
- multiplayer_mgr( NULL )
+ airwaynet( NULL )
+
{
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
}
FGGlobals::~FGGlobals()
{
delete renderer;
+ renderer = NULL;
+
// The AIModels manager performs a number of actions upon
// Shutdown that implicitly assume that other subsystems
// are still operational (Due to the dynamic allocation and
// shut down all subsystems, make sure we take down the
// AIModels system first.
subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("ai_model");
- // FGInput (FGInputEvent) and FGDialog calls get_subsystem() in their destructors,
- // which is not safe since some subsystem are already deleted but can be referred.
- // So these subsystems must be deleted prior to deleting subsystem_mgr unless
- // ~SGSubsystemGroup and SGSubsystemMgr::get_subsystem are changed not to refer to
- // deleted subsystems.
- subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("input");
- subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("gui");
+
subsystem_mgr->unbind();
delete subsystem_mgr;
delete event_mgr;
+
delete time_params;
delete mag;
delete matlib;
delete carrierlist;
delete channellist;
delete airwaynet;
- delete multiplayer_mgr;
soundmgr->unbind();
delete soundmgr;
class FGModelMgr;
class FGRouteMgr;
class FGScenery;
-class FGMultiplayMgr;
class FGPanel;
class FGTileMgr;
class FGViewMgr;
FGTACANList *channellist;
FGAirwayNetwork *airwaynet;
- //Mulitplayer managers
- FGMultiplayMgr *multiplayer_mgr;
-
/// roots of Aircraft trees
string_list fg_aircraft_dirs;
public:
model_mgr = mgr;
}
- inline FGMultiplayMgr *get_multiplayer_mgr () { return multiplayer_mgr; }
-
- inline void set_multiplayer_mgr (FGMultiplayMgr * mgr)
- {
- multiplayer_mgr = mgr;
- }
-
inline string_list *get_channel_options_list () {
return channel_options_list;
}
altitude->getDoubleValue() * SG_FEET_TO_METER,
globals->get_time_params()->getJD() );
-
- // Update any multiplayer's network queues, the AIMultiplayer
- // implementation is an AI model and depends on that
- globals->get_multiplayer_mgr()->Update();
-
#if ENABLE_ATCDCL
// Run ATC subsystem
if (fgGetBool("/sim/atc/enabled"))
// Initialise object
//
//////////////////////////////////////////////////////////////////////
-bool
+void
FGMultiplayMgr::init (void)
{
//////////////////////////////////////////////////
//////////////////////////////////////////////////
if (mInitialised) {
SG_LOG(SG_NETWORK, SG_WARN, "FGMultiplayMgr::init - already initialised");
- return false;
+ return;
}
//////////////////////////////////////////////////
// Set members from property values
if (rxPort <= 0) {
SG_LOG(SG_NETWORK, SG_DEBUG,
"FGMultiplayMgr - No receiver port, Multiplayermode disabled");
- return (false);
+ return;
}
if (mCallsign.empty())
mCallsign = "JohnDoe"; // FIXME: use getpwuid
if (!mSocket->open(false)) {
SG_LOG( SG_NETWORK, SG_DEBUG,
"FGMultiplayMgr::init - Failed to create data socket" );
- return false;
+ return;
}
mSocket->setBlocking(false);
if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) {
perror("bind");
SG_LOG( SG_NETWORK, SG_DEBUG,
"FGMultiplayMgr::Open - Failed to bind receive socket" );
- return false;
+ return;
}
+
mInitialised = true;
- return true;
} // FGMultiplayMgr::init()
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void
-FGMultiplayMgr::Update(void)
+FGMultiplayMgr::update(double)
{
if (!mInitialised)
return;
#include "mpmessages.hxx"
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
#include <string>
-using std::string;
#include <vector>
-using std::vector;
#include <simgear/compiler.h>
#include <simgear/props/props.hxx>
#include <plib/netSocket.h>
#include <Main/globals.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
#include <AIModel/AIMultiplayer.hxx>
struct FGExternalMotionInfo;
-class FGMultiplayMgr
+class FGMultiplayMgr : public SGSubsystem
{
public:
FGMultiplayMgr();
~FGMultiplayMgr();
- bool init(void);
+
+ virtual void init(void);
+ virtual void update(double dt);
+
void Close(void);
// transmitter
void SendMyPosition(const FGExternalMotionData& motionInfo);
void SendTextMessage(const string &sMsgText);
// receiver
- void Update(void);
private:
union MsgBuf;
netAddress mServer;
bool mHaveServer;
bool mInitialised;
- string mCallsign;
+ std::string mCallsign;
};
#endif
motionInfo.properties.push_back(pData);
}
- FGMultiplayMgr* mpmgr = globals->get_multiplayer_mgr();
+ FGMultiplayMgr* mpmgr = (FGMultiplayMgr*) globals->get_subsystem("mp");
mpmgr->SendMyPosition(motionInfo);
// Now remove the data
******************************************************************/
bool FGMultiplay::close() {
- FGMultiplayMgr *mgr = globals->get_multiplayer_mgr();
+ FGMultiplayMgr* mgr = (FGMultiplayMgr*) globals->get_subsystem("mp");
if (mgr == 0) {
return false;