diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-31 16:10:17 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2013-12-31 16:10:17 +0100 |
commit | 40f4c6944799bd696ccf358c5378b230ecc7f52b (patch) | |
tree | 5b4d8f8e61ba57800f8570ee195551ce1abecd18 /ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | |
parent | 4abd0ca3b5090018a7db05e8c2e0f478d861d978 (diff) |
sc: settings framework
Diffstat (limited to 'ftnoir_protocol_sc/ftnoir_protocol_sc.cpp')
-rw-r--r-- | ftnoir_protocol_sc/ftnoir_protocol_sc.cpp | 173 |
1 files changed, 31 insertions, 142 deletions
diff --git a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp index 8449f6ce..9fb48527 100644 --- a/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp +++ b/ftnoir_protocol_sc/ftnoir_protocol_sc.cpp @@ -50,15 +50,12 @@ float FTNoIR_Protocol::prevSCRotZ = 0.0f; static QLibrary SCClientLib; -/** constructor **/ FTNoIR_Protocol::FTNoIR_Protocol() { - ProgramName = "Microsoft FSX"; blnSimConnectActive = false; hSimConnect = 0; } -/** destructor **/ FTNoIR_Protocol::~FTNoIR_Protocol() { qDebug() << "~FTNoIR_Protocol says: inside" << FTNoIR_Protocol::hSimConnect; @@ -69,18 +66,8 @@ FTNoIR_Protocol::~FTNoIR_Protocol() qDebug() << "~FTNoIR_Protocol says: close SUCCEEDED"; } } -// SCClientLib.unload(); Generates crash when tracker is ended... } -// -// Load the current Settings from the currently 'active' INI-file. -// -void FTNoIR_Protocol::loadSettings() { -} - -// -// Update Headpose in Game. -// void FTNoIR_Protocol::sendHeadposeToGame( const double *headpose ) { virtSCRotX = -headpose[Pitch]; // degrees virtSCRotY = -headpose[Yaw]; @@ -90,14 +77,8 @@ void FTNoIR_Protocol::sendHeadposeToGame( const double *headpose ) { virtSCPosY = headpose[TY]/100.f; virtSCPosZ = -headpose[TZ]/100.f; - // - // It's only useful to send data, if the connection was made. - // if (!blnSimConnectActive) { if (SUCCEEDED(simconnect_open(&hSimConnect, "FaceTrackNoIR", NULL, 0, 0, 0))) { - qDebug() << "FTNoIR_Protocol::sendHeadposeToGame() says: SimConnect active!"; - - //set up the events we want to listen for HRESULT hr; simconnect_subscribetosystemevent(hSimConnect, EVENT_PING, "Frame"); @@ -105,39 +86,11 @@ void FTNoIR_Protocol::sendHeadposeToGame( const double *headpose ) { hr = simconnect_mapclienteventtosimevent(hSimConnect, EVENT_INIT, ""); hr = simconnect_addclienteventtonotificationgroup(hSimConnect, GROUP0, EVENT_INIT, false); hr = simconnect_setnotificationgrouppriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_HIGHEST); - ////hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "VK_COMMA", EVENT_INIT); - ////hr = SimConnect_SetInputGroupState(hSimConnect, INPUT0, SIMCONNECT_STATE_ON); - blnSimConnectActive = true; } } - else { - // - // Write the 6DOF-data to FSX -// // -// // Only do this when the data has changed. This way, the HAT-switch can be used when tracking is OFF. -// // -// if ((prevPosX != virtPosX) || (prevPosY != virtPosY) || (prevPosZ != virtPosZ) || -// (prevRotX != virtRotX) || (prevRotY != virtRotY) || (prevRotZ != virtRotZ)) { -//// if (S_OK == simconnect_set6DOF(hSimConnect, virtPosX, virtPosY, virtPosZ, virtRotX, virtRotZ, virtRotY)) { -//// qDebug() << "FTNoIR_Protocol::run() says: SimConnect data written!"; -//// } -// } -// -// prevPosX = virtPosX; -// prevPosY = virtPosY; -// prevPosZ = virtPosZ; -// prevRotX = virtRotX; -// prevRotY = virtRotY; -// prevRotZ = virtRotZ; - - if (SUCCEEDED(simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL))) { - qDebug() << "FTNoIR_Protocol::sendHeadposeToGame() says: Dispatching"; - } - else { - qDebug() << "FTNoIR_Protocol::sendHeadposeToGame() says: Error Dispatching!"; - } - } + else + (void) (simconnect_calldispatch(hSimConnect, processNextSimconnectEvent, NULL)); } class ActivationContext { @@ -176,30 +129,16 @@ private: HANDLE hactctx; }; -// -// Returns 'true' if all seems OK. -// bool FTNoIR_Protocol::checkServerInstallationOK() { if (!SCClientLib.isLoaded()) { - qDebug() << "SCCheckClientDLL says: Starting Function"; - - QSettings settings("opentrack"); - QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString(); - QSettings iniFile( currentFile, QSettings::IniFormat ); // Application settings (in INI-file) - iniFile.beginGroup ( "FSX" ); - int act = iniFile.value("version", 0).toInt(); - iniFile.endGroup(); - - ActivationContext ctx(142 + act); + ActivationContext ctx(142 + static_cast<int>(s.sxs_manifest)); if (!SCClientLib.load()) { qDebug() << "SC load" << SCClientLib.errorString(); return false; } - } else { - qDebug() << "SimConnect already loaded"; } // @@ -260,97 +199,47 @@ bool FTNoIR_Protocol::checkServerInstallationOK() void CALLBACK FTNoIR_Protocol::processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext) { -// HRESULT hr; - switch(pData->dwID) { - case SIMCONNECT_RECV_ID_EVENT: - { - SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData; - - qDebug() << "FTNoIR_Protocol::processNextSimconnectEvent() says: SimConnect active!"; - //switch(evt->uEventID) - //{ - // //case EVENT_CAMERA_RIGHT: - - // // cameraBank = normalize180( cameraBank + 5.0f); - - // // hr = SimConnect_CameraSetRelative6DOF(hSimConnect, 0.0f, 0.0f, 0.0f, - // // SIMCONNECT_CAMERA_IGNORE_FIELD,SIMCONNECT_CAMERA_IGNORE_FIELD, cameraBank); - - // // printf("\nCamera Bank = %f", cameraBank); - // // break; - - // //case EVENT_CAMERA_LEFT: - // // - // // cameraBank = normalize180( cameraBank - 5.0f); - - // // hr = SimConnect_CameraSetRelative6DOF(hSimConnect, 0.0f, 0.0f, 0.0f, - // // SIMCONNECT_CAMERA_IGNORE_FIELD,SIMCONNECT_CAMERA_IGNORE_FIELD, cameraBank); - // // - // // printf("\nCamera Bank = %f", cameraBank); - // // break; - - // //default: - // // break; - //} - //break; + 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); } - case SIMCONNECT_RECV_ID_EVENT_FRAME: - { -// qDebug() << "FTNoIR_Protocol::processNextSimconnectEvent() says: Frame event!"; - if ((prevSCPosX != virtSCPosX) || (prevSCPosY != virtSCPosY) || (prevSCPosZ != virtSCPosZ) || - (prevSCRotX != virtSCRotX) || (prevSCRotY != virtSCRotY) || (prevSCRotZ != virtSCRotZ)) { - if (S_OK == simconnect_set6DOF(hSimConnect, virtSCPosX, virtSCPosY, virtSCPosZ, virtSCRotX, virtSCRotZ, virtSCRotY)) { - // qDebug() << "FTNoIR_Protocol::run() says: SimConnect data written!"; - } - } - prevSCPosX = virtSCPosX; - prevSCPosY = virtSCPosY; - prevSCPosZ = virtSCPosZ; - prevSCRotX = virtSCRotX; - prevSCRotY = virtSCRotY; - prevSCRotZ = virtSCRotZ; - } + prevSCPosX = virtSCPosX; + prevSCPosY = virtSCPosY; + prevSCPosZ = virtSCPosZ; + prevSCRotX = virtSCRotX; + prevSCRotY = virtSCRotY; + prevSCRotZ = virtSCRotZ; + } + case SIMCONNECT_RECV_ID_EXCEPTION: + { + SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData; - case SIMCONNECT_RECV_ID_EXCEPTION: + switch (except->dwException) { - SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION*)pData; - - switch (except->dwException) - { - case SIMCONNECT_EXCEPTION_ERROR: - printf("\nCamera error"); - break; - - default: - printf("\nException"); - break; - } + case SIMCONNECT_EXCEPTION_ERROR: + qDebug() << "Camera error"; break; - } - case SIMCONNECT_RECV_ID_QUIT: - { - qDebug() << "FTNoIR_Protocol::processNextSimconnectEvent() says: Quit event!"; -// quit = 1; + default: + qDebug() << "Exception"; break; } + break; + } - default: - break; + case SIMCONNECT_RECV_ID_QUIT: + { + break; + } } } -//////////////////////////////////////////////////////////////////////////////// -// Factory function that creates instances if the Protocol object. - -// Export both decorated and undecorated names. -// GetProtocol - Undecorated name, which can be easily used with GetProcAddress -// Win32 API function. -// _GetProtocol@0 - Common name decoration for __stdcall functions in C language. -//#pragma comment(linker, "/export:GetProtocol=_GetProtocol@0") - extern "C" FTNOIR_PROTOCOL_BASE_EXPORT IProtocol* CALLING_CONVENTION GetConstructor() { return new FTNoIR_Protocol; |