diff options
Diffstat (limited to 'ftnoir_protocol_sc')
-rw-r--r-- | ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 92 | ||||
-rw-r--r-- | ftnoir_protocol_sc/ftnoir_protocol_sc.h | 33 |
2 files changed, 35 insertions, 90 deletions
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 465d8d20..7d4e09f9 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -29,8 +29,6 @@ #include "ftnoir_protocol_sc.h" #include "opentrack/plugin-api.hpp" -static QLibrary SCClientLib; - FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr) { } @@ -43,28 +41,42 @@ FTNoIR_Protocol::~FTNoIR_Protocol() void FTNoIR_Protocol::run() { - if (!SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) + HANDLE event = CreateEvent(NULL, FALSE, FALSE, nullptr); + + if (event == nullptr) + { + qDebug() << "simconnect: event create" << GetLastError(); return; -#if 0 - simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); + } - simconnect_mapclienteventtosimevent(hSimConnect, EVENT_INIT, ""); - simconnect_addclienteventtonotificationgroup(hSimConnect, GROUP0, EVENT_INIT, false); - simconnect_setnotificationgrouppriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST); -#endif - while (!should_stop) { - (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast<void*>(this))); - Sleep(1); + if (SUCCEEDED(simconnect_open(&hSimConnect, "opentrack", NULL, 0, event, 0))) + { + simconnect_subscribetosystemevent(hSimConnect, 0, "Frame"); + + while (!should_stop) + { + if (WaitForSingleObject(event, 10) == WAIT_OBJECT_0) + { + if (FAILED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast<void*>(this)))) + break; + } + } + + (void) simconnect_close(hSimConnect); + } + + if (!should_stop) + Sleep(100); } - - (void) simconnect_close(hSimConnect); + + CloseHandle(event); } void FTNoIR_Protocol::pose( const double *headpose ) { virtSCRotX = -headpose[Pitch]; // degrees - virtSCRotY = -headpose[Yaw]; + virtSCRotY = headpose[Yaw]; virtSCRotZ = headpose[Roll]; virtSCPosX = headpose[TX]/100.f; // cm to meters @@ -72,11 +84,13 @@ void FTNoIR_Protocol::pose( const double *headpose ) { virtSCPosZ = -headpose[TZ]/100.f; } -#pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-field-initializers" +#endif class ActivationContext { public: - ActivationContext(const int resid) :ok (false) { + ActivationContext(const int resid) : ok(false) { hactctx = INVALID_HANDLE_VALUE; actctx_cookie = 0; ACTCTXA actx = {0}; @@ -99,6 +113,8 @@ public: ReleaseActCtx(hactctx); hactctx = INVALID_HANDLE_VALUE; } + else + ok = true; } else { qDebug() << "SC: can't create win32 activation context" << GetLastError(); } @@ -135,9 +151,6 @@ bool FTNoIR_Protocol::correct() return false; } - // - // Get the functions from the DLL. - // simconnect_open = (importSimConnect_Open) SCClientLib.resolve("SimConnect_Open"); if (simconnect_open == NULL) { qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_Open function not found in DLL!"; @@ -154,8 +167,6 @@ bool FTNoIR_Protocol::correct() return false; } - //return true; - simconnect_calldispatch = (importSimConnect_CallDispatch) SCClientLib.resolve("SimConnect_CallDispatch"); if (simconnect_calldispatch == NULL) { qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_CallDispatch function not found in DLL!"; @@ -168,26 +179,6 @@ bool FTNoIR_Protocol::correct() return false; } - simconnect_mapclienteventtosimevent = (importSimConnect_MapClientEventToSimEvent) SCClientLib.resolve("SimConnect_MapClientEventToSimEvent"); - if (simconnect_subscribetosystemevent == NULL) { - qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_MapClientEventToSimEvent function not found in DLL!"; - return false; - } - - simconnect_addclienteventtonotificationgroup = (importSimConnect_AddClientEventToNotificationGroup) SCClientLib.resolve("SimConnect_AddClientEventToNotificationGroup"); - if (simconnect_subscribetosystemevent == NULL) { - qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_AddClientEventToNotificationGroup function not found in DLL!"; - return false; - } - - simconnect_setnotificationgrouppriority = (importSimConnect_SetNotificationGroupPriority) SCClientLib.resolve("SimConnect_SetNotificationGroupPriority"); - if (simconnect_subscribetosystemevent == NULL) { - qDebug() << "FTNoIR_Protocol::correct() says: SimConnect_SetNotificationGroupPriority function not found in DLL!"; - return false; - } - - qDebug() << "FTNoIR_Protocol::correct() says: SimConnect functions resolved in DLL!"; - start(); return true; @@ -195,22 +186,7 @@ bool FTNoIR_Protocol::correct() void FTNoIR_Protocol::handle() { - if (prevSCPosX != virtSCPosX || - prevSCPosY != virtSCPosY || - prevSCPosZ != virtSCPosZ || - prevSCRotX != virtSCRotX || - prevSCRotY != virtSCRotY || - prevSCRotZ != virtSCRotZ) - { - (void) simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY); - } - - prevSCPosX = virtSCPosX; - prevSCPosY = virtSCPosY; - prevSCPosZ = virtSCPosZ; - prevSCRotX = virtSCRotX; - prevSCRotY = virtSCRotY; - prevSCRotZ = virtSCRotZ; + (void) simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY); } void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD, void *self_) diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h index b65bac85..7c32d014 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h @@ -54,27 +54,6 @@ typedef HRESULT (WINAPI *importSimConnect_Close)(HANDLE hSimConnect); typedef HRESULT (WINAPI *importSimConnect_CameraSetRelative6DOF)(HANDLE hSimConnect, float fDeltaX, float fDeltaY, float fDeltaZ, float fPitchDeg, float fBankDeg, float fHeadingDeg); typedef HRESULT (WINAPI *importSimConnect_CallDispatch)(HANDLE hSimConnect, DispatchProc pfcnDispatch, void * pContext); typedef HRESULT (WINAPI *importSimConnect_SubscribeToSystemEvent)(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * SystemEventName); -typedef HRESULT (WINAPI *importSimConnect_MapClientEventToSimEvent)(HANDLE hSimConnect, SIMCONNECT_CLIENT_EVENT_ID EventID, const char * EventName); -typedef HRESULT (WINAPI *importSimConnect_AddClientEventToNotificationGroup)(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, SIMCONNECT_CLIENT_EVENT_ID EventID, BOOL bMaskable); -typedef HRESULT (WINAPI *importSimConnect_SetNotificationGroupPriority)(HANDLE hSimConnect, SIMCONNECT_NOTIFICATION_GROUP_ID GroupID, DWORD uPriority); - -#define SC_CLIENT_FILENAME "SimConnect.dll" - -enum GROUP_ID -{ - GROUP0=0, -}; - -enum EVENT_ID -{ - EVENT_PING=0, - EVENT_INIT, -}; - -enum INPUT_ID -{ - INPUT0=0, -}; struct settings : opts { value<int> sxs_manifest; @@ -106,26 +85,16 @@ private: volatile float virtSCRotY; volatile float virtSCRotZ; - float prevSCPosX; - float prevSCPosY; - float prevSCPosZ; - - float prevSCRotX; - float prevSCRotY; - float prevSCRotZ; - importSimConnect_Open simconnect_open; // SimConnect function(s) in DLL importSimConnect_Close simconnect_close; importSimConnect_CameraSetRelative6DOF simconnect_set6DOF; importSimConnect_CallDispatch simconnect_calldispatch; importSimConnect_SubscribeToSystemEvent simconnect_subscribetosystemevent; - importSimConnect_MapClientEventToSimEvent simconnect_mapclienteventtosimevent; - importSimConnect_AddClientEventToNotificationGroup simconnect_addclienteventtonotificationgroup; - importSimConnect_SetNotificationGroupPriority simconnect_setnotificationgrouppriority; HANDLE hSimConnect; // Handle to SimConnect static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); settings s; + QLibrary SCClientLib; }; class SCControls: public IProtocolDialog |