summaryrefslogtreecommitdiffhomepage
path: root/proto-simconnect
diff options
context:
space:
mode:
Diffstat (limited to 'proto-simconnect')
-rw-r--r--proto-simconnect/ftnoir_protocol_sc.cpp13
-rw-r--r--proto-simconnect/ftnoir_protocol_sc.h18
2 files changed, 17 insertions, 14 deletions
diff --git a/proto-simconnect/ftnoir_protocol_sc.cpp b/proto-simconnect/ftnoir_protocol_sc.cpp
index 9c0f1a5b..be0c23c4 100644
--- a/proto-simconnect/ftnoir_protocol_sc.cpp
+++ b/proto-simconnect/ftnoir_protocol_sc.cpp
@@ -14,13 +14,13 @@
#include "opentrack-library-path.h"
#include "compat/timer.hpp"
-simconnect::simconnect() : hSimConnect(nullptr), should_stop(false), should_reconnect(false)
+simconnect::simconnect() : hSimConnect(nullptr), should_reconnect(false)
{
}
simconnect::~simconnect()
{
- should_stop = true;
+ requestInterruption();
wait();
}
@@ -34,7 +34,7 @@ void simconnect::run()
return;
}
- while (!should_stop)
+ while (!isInterruptionRequested())
{
HRESULT hr;
@@ -52,7 +52,7 @@ void simconnect::run()
Timer tm;
int idle_seconds = 0;
- while (!should_stop)
+ while (!isInterruptionRequested())
{
if (should_reconnect)
{
@@ -88,14 +88,15 @@ void simconnect::run()
qDebug() << "simconnect: can't open handle:" << hr;
}
- if (!should_stop)
+ if (!isInterruptionRequested())
Sleep(100);
}
CloseHandle(event);
}
-void simconnect::pose( const double *headpose ) {
+void simconnect::pose( const double *headpose )
+{
// euler degrees
virtSCRotX = float(-headpose[Pitch]);
virtSCRotY = float(headpose[Yaw]);
diff --git a/proto-simconnect/ftnoir_protocol_sc.h b/proto-simconnect/ftnoir_protocol_sc.h
index 270d922d..93376885 100644
--- a/proto-simconnect/ftnoir_protocol_sc.h
+++ b/proto-simconnect/ftnoir_protocol_sc.h
@@ -11,8 +11,10 @@
*/
#pragma once
#include "api/plugin-api.hpp"
-
#include "ui_ftnoir_sccontrols.h"
+
+#include <atomic>
+
#include <QThread>
#include <QMessageBox>
#include <QSettings>
@@ -70,12 +72,12 @@ private:
void run() override;
- volatile float virtSCPosX;
- volatile float virtSCPosY;
- volatile float virtSCPosZ;
- volatile float virtSCRotX;
- volatile float virtSCRotY;
- volatile float virtSCRotZ;
+ std::atomic<float> virtSCPosX;
+ std::atomic<float> virtSCPosY;
+ std::atomic<float> virtSCPosZ;
+ std::atomic<float> virtSCRotX;
+ std::atomic<float> virtSCRotY;
+ std::atomic<float> virtSCRotZ;
importSimConnect_Open simconnect_open;
importSimConnect_Close simconnect_close;
@@ -84,7 +86,7 @@ private:
importSimConnect_SubscribeToSystemEvent simconnect_subscribetosystemevent;
HANDLE hSimConnect;
- volatile bool should_stop, should_reconnect;
+ std::atomic<bool> should_reconnect;
static void CALLBACK processNextSimconnectEvent(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext);
settings s;
QLibrary SCClientLib;