mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Delay the start of XSwiftBus
Starting XSwiftBus in CPlugin constructor called methods that are not supported during XPluginEnable. Therefore delay the start until X-Plane is fully loaded.
This commit is contained in:
@@ -53,8 +53,6 @@ namespace XSwiftBus
|
||||
m_planeViewSubMenu = m_menu.subMenu("Follow Plane View");
|
||||
planeViewOwnAircraftMenuItem = m_planeViewSubMenu.item("Own Aircraft", [this] { switchToOwnAircraftView(); });
|
||||
|
||||
readConfig();
|
||||
|
||||
/*m_dbusThread = std::thread([this]()
|
||||
{
|
||||
while(!m_shouldStop)
|
||||
@@ -63,9 +61,9 @@ namespace XSwiftBus
|
||||
}
|
||||
});*/
|
||||
|
||||
XPLMRegisterFlightLoopCallback(flightLoopCallback, -1, this);
|
||||
|
||||
startServer();
|
||||
// Delay the start of XSwiftBus.
|
||||
// http://www.xsquawkbox.net/xpsdk/mediawiki/DeferredInitialization
|
||||
XPLMRegisterFlightLoopCallback(startServerDeferred, -1, this);
|
||||
}
|
||||
|
||||
CPlugin::~CPlugin()
|
||||
@@ -87,6 +85,10 @@ namespace XSwiftBus
|
||||
|
||||
void CPlugin::startServer()
|
||||
{
|
||||
XPLMRegisterFlightLoopCallback(flightLoopCallback, -1, this);
|
||||
|
||||
readConfig();
|
||||
|
||||
m_service = std::make_unique<CService>();
|
||||
m_traffic = std::make_unique<CTraffic>();
|
||||
m_weather = std::make_unique<CWeather>();
|
||||
@@ -167,9 +169,21 @@ namespace XSwiftBus
|
||||
}
|
||||
}
|
||||
|
||||
float CPlugin::startServerDeferred(float, float, int, void *refcon)
|
||||
{
|
||||
auto *plugin = static_cast<CPlugin *>(refcon);
|
||||
if (! plugin->m_isRunning)
|
||||
{
|
||||
plugin->startServer();
|
||||
plugin->m_isRunning = true;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float CPlugin::flightLoopCallback(float, float, int, void *refcon)
|
||||
{
|
||||
auto *plugin = static_cast<CPlugin *>(refcon);
|
||||
|
||||
plugin->m_dbusDispatcher.runOnce();
|
||||
if (plugin->m_service) { plugin->m_service->process(); }
|
||||
if (plugin->m_weather) { plugin->m_weather->process(); }
|
||||
|
||||
@@ -78,12 +78,14 @@ namespace XSwiftBus
|
||||
DataRef<xplane::data::sim::flightmodel::position::local_z> m_ownAircraftPositionZ;
|
||||
|
||||
std::thread m_dbusThread;
|
||||
bool m_isRunning = false;
|
||||
bool m_shouldStop = false;
|
||||
|
||||
void readConfig();
|
||||
void startServer();
|
||||
void switchToOwnAircraftView();
|
||||
|
||||
static float startServerDeferred(float, float, int, void *refcon);
|
||||
static float flightLoopCallback(float, float, int, void *refcon);
|
||||
static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user