Make MultiPlayer a well-behaved subsystem.
This commit is contained in:
parent
d39841d2df
commit
0c342308eb
8 changed files with 34 additions and 52 deletions
|
@ -1397,6 +1397,14 @@ bool fgInitSubsystems() {
|
|||
////////////////////////////////////////////////////////////////////
|
||||
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
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
@ -1465,13 +1473,6 @@ bool fgInitSubsystems() {
|
|||
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
|
||||
|
|
|
@ -292,6 +292,10 @@ int fgOSMainLoop()
|
|||
|
||||
int fgGetKeyModifiers()
|
||||
{
|
||||
if (!globals->get_renderer()) { // happens during shutdown
|
||||
return 0;
|
||||
}
|
||||
|
||||
return globals->get_renderer()->getEventHandler()->getCurrentModifiers();
|
||||
}
|
||||
|
||||
|
|
|
@ -150,8 +150,8 @@ FGGlobals::FGGlobals() :
|
|||
tacanlist( NULL ),
|
||||
carrierlist( NULL ),
|
||||
channellist( NULL ),
|
||||
airwaynet( NULL ),
|
||||
multiplayer_mgr( NULL )
|
||||
airwaynet( NULL )
|
||||
|
||||
{
|
||||
simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider());
|
||||
}
|
||||
|
@ -161,6 +161,8 @@ FGGlobals::FGGlobals() :
|
|||
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
|
||||
|
@ -168,16 +170,11 @@ FGGlobals::~FGGlobals()
|
|||
// 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;
|
||||
|
@ -203,7 +200,6 @@ FGGlobals::~FGGlobals()
|
|||
delete carrierlist;
|
||||
delete channellist;
|
||||
delete airwaynet;
|
||||
delete multiplayer_mgr;
|
||||
|
||||
soundmgr->unbind();
|
||||
delete soundmgr;
|
||||
|
|
|
@ -66,7 +66,6 @@ class FGLight;
|
|||
class FGModelMgr;
|
||||
class FGRouteMgr;
|
||||
class FGScenery;
|
||||
class FGMultiplayMgr;
|
||||
class FGPanel;
|
||||
class FGTileMgr;
|
||||
class FGViewMgr;
|
||||
|
@ -175,9 +174,6 @@ private:
|
|||
FGTACANList *channellist;
|
||||
FGAirwayNetwork *airwaynet;
|
||||
|
||||
//Mulitplayer managers
|
||||
FGMultiplayMgr *multiplayer_mgr;
|
||||
|
||||
/// roots of Aircraft trees
|
||||
string_list fg_aircraft_dirs;
|
||||
public:
|
||||
|
@ -289,13 +285,6 @@ 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;
|
||||
}
|
||||
|
|
|
@ -146,11 +146,6 @@ static void fgMainLoop( void ) {
|
|||
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"))
|
||||
|
|
|
@ -366,7 +366,7 @@ FGMultiplayMgr::~FGMultiplayMgr()
|
|||
// Initialise object
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
bool
|
||||
void
|
||||
FGMultiplayMgr::init (void)
|
||||
{
|
||||
//////////////////////////////////////////////////
|
||||
|
@ -374,7 +374,7 @@ FGMultiplayMgr::init (void)
|
|||
//////////////////////////////////////////////////
|
||||
if (mInitialised) {
|
||||
SG_LOG(SG_NETWORK, SG_WARN, "FGMultiplayMgr::init - already initialised");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
//////////////////////////////////////////////////
|
||||
// Set members from property values
|
||||
|
@ -400,7 +400,7 @@ FGMultiplayMgr::init (void)
|
|||
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
|
||||
|
@ -415,17 +415,17 @@ FGMultiplayMgr::init (void)
|
|||
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()
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -710,7 +710,7 @@ FGMultiplayMgr::SendTextMessage(const string &MsgText)
|
|||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
FGMultiplayMgr::Update(void)
|
||||
FGMultiplayMgr::update(double)
|
||||
{
|
||||
if (!mInitialised)
|
||||
return;
|
||||
|
|
|
@ -33,25 +33,20 @@
|
|||
|
||||
#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:
|
||||
|
||||
|
@ -67,13 +62,15 @@ 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;
|
||||
|
@ -93,7 +90,7 @@ private:
|
|||
netAddress mServer;
|
||||
bool mHaveServer;
|
||||
bool mInitialised;
|
||||
string mCallsign;
|
||||
std::string mCallsign;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -243,7 +243,7 @@ bool FGMultiplay::process() {
|
|||
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
|
||||
|
@ -272,7 +272,7 @@ bool FGMultiplay::process() {
|
|||
******************************************************************/
|
||||
bool FGMultiplay::close() {
|
||||
|
||||
FGMultiplayMgr *mgr = globals->get_multiplayer_mgr();
|
||||
FGMultiplayMgr* mgr = (FGMultiplayMgr*) globals->get_subsystem("mp");
|
||||
|
||||
if (mgr == 0) {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Reference in a new issue