summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_protocol_sc
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-06 09:09:18 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-06 09:09:18 +0200
commit1388d95ecf71d517d24ccb6713641220a5553e4a (patch)
treeb06b62465c30bc9d77598de2d9bad0e30362a585 /ftnoir_protocol_sc
parent68c8278b25b417c21dfbb0e3974044a36dfc151e (diff)
simconnect: use event handle without calldispatch in a loop
We aren't supposed to calldispatch in a loop, since it locks up FSX. Use calldispatch only if FSX signals us that an event has been received. This might fix slowness reported in #174.
Diffstat (limited to 'ftnoir_protocol_sc')
-rw-r--r--ftnoir_protocol_sc/ftnoir_protocol_sc.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
index c0e2fc02..5f70b093 100644
--- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
+++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp
@@ -41,19 +41,27 @@ FTNoIR_Protocol::~FTNoIR_Protocol()
void FTNoIR_Protocol::run()
{
- (void) timeBeginPeriod(1);
+ HANDLE event = CreateEvent(NULL, FALSE, FALSE, nullptr);
+
+ if (event == nullptr)
+ {
+ qDebug() << "simconnect: event create" << GetLastError();
+ return;
+ }
while (!should_stop)
{
- if (SUCCEEDED(simconnect_open(&hSimConnect, "opentrack", NULL, 0, 0, 0)))
+ if (SUCCEEDED(simconnect_open(&hSimConnect, "opentrack", NULL, 0, event, 0)))
{
simconnect_subscribetosystemevent(hSimConnect, 0, "Frame");
while (!should_stop)
{
- if (FAILED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast<void*>(this))))
- break;
- Sleep(16);
+ if (WaitForSingleObject(event, 10) == WAIT_OBJECT_0)
+ {
+ if (FAILED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast<void*>(this))))
+ break;
+ }
}
(void) simconnect_close(hSimConnect);
@@ -63,7 +71,7 @@ void FTNoIR_Protocol::run()
Sleep(100);
}
- (void) timeEndPeriod(1);
+ CloseHandle(event);
}
void FTNoIR_Protocol::pose( const double *headpose ) {
@@ -169,8 +177,6 @@ bool FTNoIR_Protocol::correct()
return false;
}
- qDebug() << "FTNoIR_Protocol::correct() says: SimConnect functions resolved in DLL!";
-
start();
return true;