summaryrefslogtreecommitdiffhomepage
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
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.
-rw-r--r--CMakeLists.txt2
-rw-r--r--ftnoir_protocol_sc/ftnoir_protocol_sc.cpp22
2 files changed, 15 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 448375f3..c45163dc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -304,7 +304,7 @@ endif()
if(SDK_SIMCONNECT)
opentrack_library(opentrack-proto-simconnect ftnoir_protocol_sc)
- target_link_libraries(opentrack-proto-simconnect ${SDK_SIMCONNECT}/lib/SimConnect.lib winmm)
+ target_link_libraries(opentrack-proto-simconnect ${SDK_SIMCONNECT}/lib/SimConnect.lib)
include_directories(opentrack-proto-simconnect SYSTEM PUBLIC ${SDK_SIMCONNECT}/inc)
endif()
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;