From 340906d3571ba3c75e67d8457de4129381d5a6b3 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 2 Jul 2015 11:58:04 +0200 Subject: try fix MSVC --- ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ftnoir_protocol_sc/ftnoir_protocol_sc.cpp') diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 36764edc..b1d84f9b 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -103,7 +103,7 @@ public: actx.lpResourceName = MAKEINTRESOURCEA(resid); actx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID; #ifdef _MSC_VER -# error "MSVC support removed" +# define PREFIX "" #else # define PREFIX "lib" #endif -- cgit v1.2.3 From 2d0ecf757c91c12d9a73420c5f142b652b5e3d7c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Jul 2015 11:19:57 +0200 Subject: maybe fix simconnect lag --- ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 107 ++++++++++++++---------------- ftnoir_protocol_sc/ftnoir_protocol_sc.h | 38 ++++++----- 2 files changed, 70 insertions(+), 75 deletions(-) (limited to 'ftnoir_protocol_sc/ftnoir_protocol_sc.cpp') diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index b1d84f9b..41fcf1b0 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -29,43 +29,39 @@ #include "ftnoir_protocol_sc.h" #include "opentrack/plugin-api.hpp" -importSimConnect_CameraSetRelative6DOF FTNoIR_Protocol::simconnect_set6DOF; -HANDLE FTNoIR_Protocol::hSimConnect = 0; // Handle to SimConnect - -float FTNoIR_Protocol::virtSCPosX = 0.0f; // Headpose -float FTNoIR_Protocol::virtSCPosY = 0.0f; -float FTNoIR_Protocol::virtSCPosZ = 0.0f; - -float FTNoIR_Protocol::virtSCRotX = 0.0f; -float FTNoIR_Protocol::virtSCRotY = 0.0f; -float FTNoIR_Protocol::virtSCRotZ = 0.0f; - -float FTNoIR_Protocol::prevSCPosX = 0.0f; // previous Headpose -float FTNoIR_Protocol::prevSCPosY = 0.0f; -float FTNoIR_Protocol::prevSCPosZ = 0.0f; - -float FTNoIR_Protocol::prevSCRotX = 0.0f; -float FTNoIR_Protocol::prevSCRotY = 0.0f; -float FTNoIR_Protocol::prevSCRotZ = 0.0f; - static QLibrary SCClientLib; -FTNoIR_Protocol::FTNoIR_Protocol() +FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr) { - blnSimConnectActive = false; - hSimConnect = 0; + start(); } FTNoIR_Protocol::~FTNoIR_Protocol() { - qDebug() << "~FTNoIR_Protocol says: inside" << FTNoIR_Protocol::hSimConnect; + should_stop = true; + wait(); - if (hSimConnect != 0) { - qDebug() << "~FTNoIR_Protocol says: before simconnect_close"; - if (SUCCEEDED( simconnect_close( FTNoIR_Protocol::hSimConnect ) ) ) { - qDebug() << "~FTNoIR_Protocol says: close SUCCEEDED"; - } - } + if (hSimConnect) + (void) simconnect_close(hSimConnect); +} + +void FTNoIR_Protocol::run() +{ + if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 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); + } + else + return; + + while (!should_stop) + { + (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast(this))); + Sleep(3); + } } void FTNoIR_Protocol::pose( const double *headpose ) { @@ -76,19 +72,6 @@ void FTNoIR_Protocol::pose( const double *headpose ) { virtSCPosX = headpose[TX]/100.f; // cm to meters virtSCPosY = headpose[TY]/100.f; virtSCPosZ = -headpose[TZ]/100.f; - - if (!blnSimConnectActive) { - if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 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); - blnSimConnectActive = true; - } - } - else - (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL)); } #pragma GCC diagnostic ignored "-Wmissing-field-initializers" @@ -203,25 +186,37 @@ bool FTNoIR_Protocol::correct() return true; } -void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD, void *) +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 CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD, void *self_) { + FTNoIR_Protocol& self = *reinterpret_cast(self_); + switch(pData->dwID) { default: break; case SIMCONNECT_RECV_ID_EVENT_FRAME: - { - 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; - } + self.handle(); + break; case SIMCONNECT_RECV_ID_EXCEPTION: { SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData; @@ -240,10 +235,8 @@ void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData } case SIMCONNECT_RECV_ID_QUIT: - { break; } - } } extern "C" OPENTRACK_EXPORT IProtocol* GetConstructor() diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h index f8db519b..b65bac85 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h @@ -39,6 +39,7 @@ #include #include "ui_ftnoir_sccontrols.h" +#include #include #include #include @@ -83,45 +84,46 @@ struct settings : opts { {} }; -class FTNoIR_Protocol : public IProtocol +class FTNoIR_Protocol : public IProtocol, private QThread { public: FTNoIR_Protocol(); ~FTNoIR_Protocol() override; bool correct(); void pose(const double* headpose); + void handle(); QString game_name() { return "FS2004/FSX"; } private: - static float virtSCPosX; - static float virtSCPosY; - static float virtSCPosZ; - - static float virtSCRotX; - static float virtSCRotY; - static float virtSCRotZ; + void run() override; + volatile bool should_stop; + + volatile float virtSCPosX; + volatile float virtSCPosY; + volatile float virtSCPosZ; + volatile float virtSCRotX; + volatile float virtSCRotY; + volatile float virtSCRotZ; - static float prevSCPosX; - static float prevSCPosY; - static float prevSCPosZ; + float prevSCPosX; + float prevSCPosY; + float prevSCPosZ; - static float prevSCRotX; - static float prevSCRotY; - static float prevSCRotZ; - - bool blnSimConnectActive; + float prevSCRotX; + float prevSCRotY; + float prevSCRotZ; importSimConnect_Open simconnect_open; // SimConnect function(s) in DLL importSimConnect_Close simconnect_close; - static importSimConnect_CameraSetRelative6DOF simconnect_set6DOF; + importSimConnect_CameraSetRelative6DOF simconnect_set6DOF; importSimConnect_CallDispatch simconnect_calldispatch; importSimConnect_SubscribeToSystemEvent simconnect_subscribetosystemevent; importSimConnect_MapClientEventToSimEvent simconnect_mapclienteventtosimevent; importSimConnect_AddClientEventToNotificationGroup simconnect_addclienteventtonotificationgroup; importSimConnect_SetNotificationGroupPriority simconnect_setnotificationgrouppriority; - static HANDLE hSimConnect; // Handle to SimConnect + HANDLE hSimConnect; // Handle to SimConnect static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); settings s; }; -- cgit v1.2.3 From 6aa89934e8f22a580dc8a63cec61fb9ea9d14f23 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Jul 2015 11:50:41 +0200 Subject: simconnect: prevent crash with no .dll --- ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 12 ++++++++---- ftnoir_protocol_sc/ftnoir_protocol_sc.h | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'ftnoir_protocol_sc/ftnoir_protocol_sc.cpp') diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 41fcf1b0..8e35248e 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -31,7 +31,7 @@ static QLibrary SCClientLib; -FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr) +FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr), should_start(false) { start(); } @@ -40,13 +40,13 @@ FTNoIR_Protocol::~FTNoIR_Protocol() { should_stop = true; wait(); - - if (hSimConnect) - (void) simconnect_close(hSimConnect); } void FTNoIR_Protocol::run() { + if (!should_start) + return; + if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); @@ -62,6 +62,8 @@ void FTNoIR_Protocol::run() (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast(this))); Sleep(3); } + + (void) simconnect_close(hSimConnect); } void FTNoIR_Protocol::pose( const double *headpose ) { @@ -182,6 +184,8 @@ bool FTNoIR_Protocol::correct() } qDebug() << "FTNoIR_Protocol::correct() says: SimConnect functions resolved in DLL!"; + + should_start = true; return true; } diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h index b65bac85..3ced16e5 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h @@ -126,6 +126,8 @@ private: HANDLE hSimConnect; // Handle to SimConnect static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); settings s; + + bool should_start; }; class SCControls: public IProtocolDialog -- cgit v1.2.3 From 8bdd22bccfb8df345d0a03f6c575bfc792027874 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Jul 2015 15:21:49 +0200 Subject: simconnect: don't race against initialization Issue: #174 --- ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 8 ++------ ftnoir_protocol_sc/ftnoir_protocol_sc.h | 2 -- 2 files changed, 2 insertions(+), 8 deletions(-) (limited to 'ftnoir_protocol_sc/ftnoir_protocol_sc.cpp') diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 8e35248e..02ad497d 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -31,9 +31,8 @@ static QLibrary SCClientLib; -FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr), should_start(false) +FTNoIR_Protocol::FTNoIR_Protocol() : should_stop(false), hSimConnect(nullptr) { - start(); } FTNoIR_Protocol::~FTNoIR_Protocol() @@ -44,9 +43,6 @@ FTNoIR_Protocol::~FTNoIR_Protocol() void FTNoIR_Protocol::run() { - if (!should_start) - return; - if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); @@ -185,7 +181,7 @@ bool FTNoIR_Protocol::correct() qDebug() << "FTNoIR_Protocol::correct() says: SimConnect functions resolved in DLL!"; - should_start = true; + start(); return true; } diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.h b/ftnoir_protocol_sc/ftnoir_protocol_sc.h index 3ced16e5..b65bac85 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.h +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.h @@ -126,8 +126,6 @@ private: HANDLE hSimConnect; // Handle to SimConnect static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); settings s; - - bool should_start; }; class SCControls: public IProtocolDialog -- cgit v1.2.3 From 8e442abcd71b7de741f615eac4fa1bd9fa63390e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Jul 2015 15:40:51 +0200 Subject: simconnect: try set camera without event notification --- ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'ftnoir_protocol_sc/ftnoir_protocol_sc.cpp') diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 02ad497d..4d76df03 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -43,20 +43,20 @@ FTNoIR_Protocol::~FTNoIR_Protocol() void FTNoIR_Protocol::run() { - if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { + if (!SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) + 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); - } - else - return; +#endif while (!should_stop) { (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, reinterpret_cast(this))); - Sleep(3); + Sleep(1); } (void) simconnect_close(hSimConnect); @@ -217,25 +217,6 @@ void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData case SIMCONNECT_RECV_ID_EVENT_FRAME: self.handle(); break; - case SIMCONNECT_RECV_ID_EXCEPTION: - { - SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData; - - switch (except->dwException) - { - case SIMCONNECT_EXCEPTION_ERROR: - qDebug() << "Camera error"; - break; - - default: - qDebug() << "Exception"; - break; - } - break; - } - - case SIMCONNECT_RECV_ID_QUIT: - break; } } -- cgit v1.2.3 From 8c43f5ad67f75c2160cd37209dbe93c7fe4e97f4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Jul 2015 17:01:47 +0200 Subject: sc: try fix load failure logic --- ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'ftnoir_protocol_sc/ftnoir_protocol_sc.cpp') diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 4d76df03..465d8d20 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -76,7 +76,7 @@ void FTNoIR_Protocol::pose( const double *headpose ) { class ActivationContext { public: - ActivationContext(const int resid) { + ActivationContext(const int resid) :ok (false) { hactctx = INVALID_HANDLE_VALUE; actctx_cookie = 0; ACTCTXA actx = {0}; @@ -100,7 +100,7 @@ public: hactctx = INVALID_HANDLE_VALUE; } } else { - qDebug() << "SC: can't create win32 activation context"; + qDebug() << "SC: can't create win32 activation context" << GetLastError(); } } ~ActivationContext() { @@ -110,9 +110,11 @@ public: ReleaseActCtx(hactctx); } } + bool is_ok() { return ok; } private: ULONG_PTR actctx_cookie; HANDLE hactctx; + bool ok; }; bool FTNoIR_Protocol::correct() @@ -121,11 +123,16 @@ bool FTNoIR_Protocol::correct() { ActivationContext ctx(142 + static_cast(s.sxs_manifest)); - SCClientLib.setFileName("SimConnect.dll"); - if (!SCClientLib.load()) { - qDebug() << "SC load" << SCClientLib.errorString(); - return false; + if (ctx.is_ok()) + { + SCClientLib.setFileName("SimConnect.dll"); + if (!SCClientLib.load()) { + qDebug() << "SC load" << SCClientLib.errorString(); + return false; + } } + else + return false; } // -- cgit v1.2.3