mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 13:55:36 +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");
|
m_planeViewSubMenu = m_menu.subMenu("Follow Plane View");
|
||||||
planeViewOwnAircraftMenuItem = m_planeViewSubMenu.item("Own Aircraft", [this] { switchToOwnAircraftView(); });
|
planeViewOwnAircraftMenuItem = m_planeViewSubMenu.item("Own Aircraft", [this] { switchToOwnAircraftView(); });
|
||||||
|
|
||||||
readConfig();
|
|
||||||
|
|
||||||
/*m_dbusThread = std::thread([this]()
|
/*m_dbusThread = std::thread([this]()
|
||||||
{
|
{
|
||||||
while(!m_shouldStop)
|
while(!m_shouldStop)
|
||||||
@@ -63,9 +61,9 @@ namespace XSwiftBus
|
|||||||
}
|
}
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
XPLMRegisterFlightLoopCallback(flightLoopCallback, -1, this);
|
// Delay the start of XSwiftBus.
|
||||||
|
// http://www.xsquawkbox.net/xpsdk/mediawiki/DeferredInitialization
|
||||||
startServer();
|
XPLMRegisterFlightLoopCallback(startServerDeferred, -1, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPlugin::~CPlugin()
|
CPlugin::~CPlugin()
|
||||||
@@ -87,6 +85,10 @@ namespace XSwiftBus
|
|||||||
|
|
||||||
void CPlugin::startServer()
|
void CPlugin::startServer()
|
||||||
{
|
{
|
||||||
|
XPLMRegisterFlightLoopCallback(flightLoopCallback, -1, this);
|
||||||
|
|
||||||
|
readConfig();
|
||||||
|
|
||||||
m_service = std::make_unique<CService>();
|
m_service = std::make_unique<CService>();
|
||||||
m_traffic = std::make_unique<CTraffic>();
|
m_traffic = std::make_unique<CTraffic>();
|
||||||
m_weather = std::make_unique<CWeather>();
|
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)
|
float CPlugin::flightLoopCallback(float, float, int, void *refcon)
|
||||||
{
|
{
|
||||||
auto *plugin = static_cast<CPlugin *>(refcon);
|
auto *plugin = static_cast<CPlugin *>(refcon);
|
||||||
|
|
||||||
plugin->m_dbusDispatcher.runOnce();
|
plugin->m_dbusDispatcher.runOnce();
|
||||||
if (plugin->m_service) { plugin->m_service->process(); }
|
if (plugin->m_service) { plugin->m_service->process(); }
|
||||||
if (plugin->m_weather) { plugin->m_weather->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;
|
DataRef<xplane::data::sim::flightmodel::position::local_z> m_ownAircraftPositionZ;
|
||||||
|
|
||||||
std::thread m_dbusThread;
|
std::thread m_dbusThread;
|
||||||
|
bool m_isRunning = false;
|
||||||
bool m_shouldStop = false;
|
bool m_shouldStop = false;
|
||||||
|
|
||||||
void readConfig();
|
void readConfig();
|
||||||
void startServer();
|
void startServer();
|
||||||
void switchToOwnAircraftView();
|
void switchToOwnAircraftView();
|
||||||
|
|
||||||
|
static float startServerDeferred(float, float, int, void *refcon);
|
||||||
static float flightLoopCallback(float, float, int, void *refcon);
|
static float flightLoopCallback(float, float, int, void *refcon);
|
||||||
static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
|
static int orbitOwnAircraftFunc(XPLMCameraPosition_t *cameraPosition, int isLosingControl, void *refcon);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user