diff options
author | Tom Brazier <tom_github@firstsolo.net> | 2023-06-13 17:33:53 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-06-13 23:28:42 +0200 |
commit | 689332f5b6cdae4919dc3efcb2e9eb2c3d8c34f9 (patch) | |
tree | 88a8072b47763c4918bb9d7ec93d4f5c7359663b | |
parent | 19f79a9f1b9cc9e86afad9aafbf4408276f61f15 (diff) |
Move the call to simconnect_set6DOF() into the pipeline thread, potentially reducing jitter and reduce the simconnect thread to keepalive work
-rw-r--r-- | proto-simconnect/ftnoir_protocol_sc.cpp | 32 | ||||
-rw-r--r-- | proto-simconnect/ftnoir_protocol_sc.h | 2 |
2 files changed, 11 insertions, 23 deletions
diff --git a/proto-simconnect/ftnoir_protocol_sc.cpp b/proto-simconnect/ftnoir_protocol_sc.cpp index 6fb6b949..ca76e0ce 100644 --- a/proto-simconnect/ftnoir_protocol_sc.cpp +++ b/proto-simconnect/ftnoir_protocol_sc.cpp @@ -43,20 +43,15 @@ void simconnect::run() qDebug() << "fsx: connect failed, retry in" << sleep_time << "seconds..."; else { - Timer tm; - - if (!SUCCEEDED(hr = simconnect_subscribe(handle, 0, "Frame"))) + if (!SUCCEEDED(hr = simconnect_subscribe(handle, 0, "1sec"))) qDebug() << "fsx: can't subscribe to frame event:" << (void*)hr; else { while (!isInterruptionRequested()) { - constexpr int max_idle_seconds = 2; - - if (WaitForSingleObject(event, 1) == WAIT_OBJECT_0) - tm.start(); + constexpr int max_idle_ms = 2000; - if ((int)tm.elapsed_seconds() > max_idle_seconds) + if (WaitForSingleObject(event, max_idle_ms) != WAIT_OBJECT_0) { qDebug() << "fsx: timeout reached, reconnecting"; break; @@ -73,7 +68,9 @@ void simconnect::run() } } + QMutexLocker l(&mtx); (void)simconnect_close(handle); + handle = nullptr; } for (unsigned k = 0; k < sleep_time * 25; k++) @@ -91,8 +88,6 @@ void simconnect::run() void simconnect::pose(const double* pose, const double*) { - QMutexLocker l(&mtx); - data[Pitch] = (float)-pose[Pitch]; data[Yaw] = (float)pose[Yaw]; data[Roll] = (float)pose[Roll]; @@ -101,6 +96,12 @@ void simconnect::pose(const double* pose, const double*) data[TX] = (float)-pose[TX] * to_meters; data[TY] = (float)pose[TY] * to_meters; data[TZ] = (float)-pose[TZ] * to_meters; + + QMutexLocker l(&mtx); + if (handle) + (void)simconnect_set6DOF(handle, + data[TX], data[TY], data[TZ], + data[Pitch], data[Roll], data[Yaw]); } module_status simconnect::initialize() @@ -148,14 +149,6 @@ module_status simconnect::initialize() return {}; } -void simconnect::handler() -{ - QMutexLocker l(&mtx); - (void)simconnect_set6DOF(handle, - data[TX], data[TY], data[TZ], - data[Pitch], data[Roll], data[Yaw]); -} - void simconnect::event_handler(SIMCONNECT_RECV* pData, DWORD, void* self_) { simconnect& self = *reinterpret_cast<simconnect*>(self_); @@ -172,9 +165,6 @@ void simconnect::event_handler(SIMCONNECT_RECV* pData, DWORD, void* self_) qDebug() << "fsx: got quit event"; self.reconnect = true; break; - case SIMCONNECT_RECV_ID_EVENT_FRAME: - self.handler(); - break; } } diff --git a/proto-simconnect/ftnoir_protocol_sc.h b/proto-simconnect/ftnoir_protocol_sc.h index 28b9b1d8..df3a538d 100644 --- a/proto-simconnect/ftnoir_protocol_sc.h +++ b/proto-simconnect/ftnoir_protocol_sc.h @@ -47,8 +47,6 @@ public: void run() override; private: - void handler(); - enum { SIMCONNECT_RECV_ID_EXCEPTION = 2, SIMCONNECT_RECV_ID_QUIT = 3, |