From c26423c613619a40df81a3cd30870e4ef2784007 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 9 Feb 2019 10:39:39 +0100 Subject: proto/simconnect: cleanup Issue: #804 - don't call simconnect_close without a valid handle - remove magic numbers - fix event handle logic. only use it for checking whether we're timing out. - add more informative stderr output - don't hardcode QFunctionPointer type alias - remove awful VirtPos/Rot... --- proto-simconnect/ftnoir_protocol_sc.h | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'proto-simconnect/ftnoir_protocol_sc.h') diff --git a/proto-simconnect/ftnoir_protocol_sc.h b/proto-simconnect/ftnoir_protocol_sc.h index dfe80ef7..a51d1518 100644 --- a/proto-simconnect/ftnoir_protocol_sc.h +++ b/proto-simconnect/ftnoir_protocol_sc.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -61,30 +62,26 @@ private: DWORD dwID; }; - typedef void (CALLBACK *DispatchProc)(SIMCONNECT_RECV*, DWORD, void*); + typedef void (CALLBACK *SC_DispatchProc)(SIMCONNECT_RECV*, DWORD, void*); - typedef HRESULT (WINAPI *importSimConnect_Open)(HANDLE * phSimConnect, LPCSTR szName, HWND hWnd, DWORD UserEventWin32, HANDLE hEventHandle, DWORD ConfigIndex); - 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, DWORD EventID, const char * SystemEventName); + typedef HRESULT (WINAPI *SC_Open)(HANDLE* phSimConnect, LPCSTR szName, HWND hWnd, DWORD UserEventWin32, HANDLE hEventHandle, DWORD ConfigIndex); + typedef HRESULT (WINAPI *SC_Close)(HANDLE hSimConnect); + typedef HRESULT (WINAPI *SC_CameraSetRelative6DOF)(HANDLE hSimConnect, float fDeltaX, float fDeltaY, float fDeltaZ, float fPitchDeg, float fBankDeg, float fHeadingDeg); + typedef HRESULT (WINAPI *SC_CallDispatch)(HANDLE hSimConnect, SC_DispatchProc pfcnDispatch, void * pContext); + typedef HRESULT (WINAPI *SC_SubscribeToSystemEvent)(HANDLE hSimConnect, DWORD EventID, const char * SystemEventName); - std::atomic virtSCPosX {0}; - std::atomic virtSCPosY {0}; - std::atomic virtSCPosZ {0}; - std::atomic virtSCRotX {0}; - std::atomic virtSCRotY {0}; - std::atomic virtSCRotZ {0}; + float data[6] {}; + QMutex mtx; - importSimConnect_Open simconnect_open = nullptr; - importSimConnect_Close simconnect_close = nullptr; - importSimConnect_CameraSetRelative6DOF simconnect_set6DOF = nullptr; - importSimConnect_CallDispatch simconnect_calldispatch = nullptr; - importSimConnect_SubscribeToSystemEvent simconnect_subscribetosystemevent = nullptr; + SC_Open simconnect_open = nullptr; + SC_Close simconnect_close = nullptr; + SC_CameraSetRelative6DOF simconnect_set6DOF = nullptr; + SC_CallDispatch simconnect_calldispatch = nullptr; + SC_SubscribeToSystemEvent simconnect_subscribe = nullptr; HANDLE handle = nullptr; std::atomic reconnect = false; - static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext); + static void CALLBACK event_handler(SIMCONNECT_RECV* pData, DWORD cbData, void* pContext); settings s; QLibrary library; }; -- cgit v1.2.3