summaryrefslogtreecommitdiffhomepage
path: root/proto-ft
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-05-22 17:09:19 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-05-22 17:09:19 +0200
commit9a6ca1e6dce0b7e29b7a47c0ea7b47dd4266f18f (patch)
treed0bde87dd5d1a96fcc86b5b7102526bbb8e6ec0c /proto-ft
parentdec40bea45d222a1a2447ca126631bc744ba7faa (diff)
proto/ft: revert npclient-related changes
Diffstat (limited to 'proto-ft')
-rw-r--r--proto-ft/ftnoir_ftcontrols.ui96
-rw-r--r--proto-ft/ftnoir_protocol_ft.cpp108
-rw-r--r--proto-ft/ftnoir_protocol_ft.h29
-rw-r--r--proto-ft/ftnoir_protocol_ft_dialog.cpp10
4 files changed, 125 insertions, 118 deletions
diff --git a/proto-ft/ftnoir_ftcontrols.ui b/proto-ft/ftnoir_ftcontrols.ui
index 4ad00514..0d142d09 100644
--- a/proto-ft/ftnoir_ftcontrols.ui
+++ b/proto-ft/ftnoir_ftcontrols.ui
@@ -8,15 +8,23 @@
<property name="enabled">
<bool>true</bool>
</property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>508</width>
+ <height>232</height>
+ </rect>
+ </property>
<property name="sizePolicy">
- <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
- <width>571</width>
+ <width>0</width>
<height>0</height>
</size>
</property>
@@ -34,15 +42,8 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
- <item row="2" column="0">
- <widget class="QDialogButtonBox" name="buttonBox">
- <property name="standardButtons">
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QGroupBox" name="groupBox_4">
+ <item row="0" column="0">
+ <widget class="QGroupBox" name="groupBox_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -50,7 +51,7 @@
</sizepolicy>
</property>
<property name="title">
- <string>Repair NPClient location</string>
+ <string>Select interface</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignTop</set>
@@ -58,29 +59,33 @@
<property name="flat">
<bool>false</bool>
</property>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
<property name="spacing">
<number>9</number>
</property>
<item>
- <widget class="QPushButton" name="bntLocateNPClient">
- <property name="text">
- <string>Locate DLL</string>
- </property>
+ <widget class="QComboBox" name="cbxSelectInterface">
+ <item>
+ <property name="text">
+ <string>Enable both</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Use freetrack, disable TrackIR</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Use TrackIR, disable freetrack</string>
+ </property>
+ </item>
</widget>
</item>
<item>
- <widget class="QLabel" name="label_10">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
+ <widget class="QLabel" name="label_8">
<property name="text">
- <string>Replace the registry entry if you want to use other software with the NPClient protocol and it doesn't work automatically.
-
-Starting tracking will again overwrite the DLL locations.</string>
+ <string>Disable one of the protocols if game is confused by presence of both at the same time.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@@ -90,8 +95,8 @@ Starting tracking will again overwrite the DLL locations.</string>
</layout>
</widget>
</item>
- <item row="0" column="0">
- <widget class="QGroupBox" name="groupBox_3">
+ <item row="1" column="0">
+ <widget class="QGroupBox" name="groupBox_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -99,7 +104,7 @@ Starting tracking will again overwrite the DLL locations.</string>
</sizepolicy>
</property>
<property name="title">
- <string>Select interface</string>
+ <string>Repair NPClient location</string>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignTop</set>
@@ -107,17 +112,29 @@ Starting tracking will again overwrite the DLL locations.</string>
<property name="flat">
<bool>false</bool>
</property>
- <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>9</number>
</property>
<item>
- <widget class="QComboBox" name="cbxSelectInterface"/>
+ <widget class="QPushButton" name="bntLocateNPClient">
+ <property name="text">
+ <string>Locate DLL</string>
+ </property>
+ </widget>
</item>
<item>
- <widget class="QLabel" name="label_8">
+ <widget class="QLabel" name="label_10">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="text">
- <string>Disable one of the protocols if game is confused by presence of both at the same time.</string>
+ <string>Replace the registry entry if you want to use other software with the NPClient protocol and it doesn't work automatically.
+
+Starting tracking will again overwrite the DLL locations.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@@ -127,10 +144,21 @@ Starting tracking will again overwrite the DLL locations.</string>
</layout>
</widget>
</item>
+ <item row="2" column="0">
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources>
<include location="ft-protocol.qrc"/>
+ <include location="ft-protocol.qrc"/>
+ <include location="ft-protocol.qrc"/>
+ <include location="ft-protocol.qrc"/>
+ <include location="ft-protocol.qrc"/>
</resources>
<connections/>
<slots>
diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp
index 6b245ed3..42b1bbf6 100644
--- a/proto-ft/ftnoir_protocol_ft.cpp
+++ b/proto-ft/ftnoir_protocol_ft.cpp
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2018 Stanislaw Halik <sthalik@misaki.pl>
+/* Copyright (c) 2013-2015, 2017 Stanislaw Halik <sthalik@misaki.pl>
* Copyright (c) 2015 Wim Vriend
*
* Permission to use, copy, modify, and/or distribute this software for any
@@ -6,34 +6,30 @@
* copyright notice and this permission notice appear in all copies.
*/
+#include "compat/library-path.hpp"
+
#include "ftnoir_protocol_ft.h"
#include "csv/csv.h"
-#include "compat/library-path.hpp"
-#include <cassert>
-#include <cstddef>
-#include <atomic>
#include <cmath>
-#include <cstdlib>
-
#include <windows.h>
-#include <intrin.h>
-static int page_size()
+freetrack::~freetrack()
{
- SYSTEM_INFO system_info;
- GetSystemInfo(&system_info);
- return system_info.dwPageSize;
+ dummyTrackIR.close();
}
+static_assert(sizeof(LONG) == sizeof(std::int32_t), "");
static_assert(sizeof(LONG) == 4u, "");
+static constexpr inline float d2r = float(M_PI/180);
+
never_inline void store(float volatile& place, const float value)
{
union
{
float f32;
- LONG i32;
+ LONG i32 alignas(alignof(float));
} value_;
value_.f32 = value;
@@ -44,11 +40,10 @@ never_inline void store(float volatile& place, const float value)
(void)InterlockedExchange((LONG volatile*)&place, value_.i32);
}
-template<typename t, typename u>
-force_inline
-std::enable_if_t<(std::is_integral_v<t>) && sizeof(t) == 4>
-store(t volatile& place, u value)
+template<typename t>
+force_inline void store(t volatile& place, t value)
{
+ static_assert(sizeof(t) == 4u, "");
(void)InterlockedExchange((LONG volatile*) &place, value);
}
@@ -57,35 +52,20 @@ force_inline std::int32_t load(std::int32_t volatile& place)
return InterlockedCompareExchange((volatile LONG*) &place, 0, 0);
}
-freetrack::freetrack()
-{
-}
-
-freetrack::~freetrack()
-{
- if (shm.success())
- {
- store(pMemData->data.DataID, 0);
- store(pMemData->GameID2, -1);
- }
-
- dummyTrackIR.close();
-}
-
void freetrack::pose(const double* headpose)
{
- const float yaw = -degrees_to_rads(headpose[Yaw]);
- const float roll = degrees_to_rads(headpose[Roll]);
+ const float yaw = -headpose[Yaw] * d2r;
+ const float roll = headpose[Roll] * d2r;
const float tx = float(headpose[TX] * 10);
const float ty = float(headpose[TY] * 10);
const float tz = float(headpose[TZ] * 10);
// HACK: Falcon BMS makes a "bump" if pitch is over the value -sh 20170615
const bool is_crossing_90 = std::fabs(headpose[Pitch] - 90) < 1e-4;
- const float pitch = -degrees_to_rads(is_crossing_90 ? 89.85 : headpose[Pitch]);
+ const float pitch = -d2r * (is_crossing_90 ? 89.86 : headpose[Pitch]);
- FTHeap* ft = pMemData;
- FTData* data = &ft->data;
+ FTHeap* const ft = pMemData;
+ FTData* const data = &ft->data;
store(data->X, tx);
store(data->Y, ty);
@@ -97,15 +77,10 @@ void freetrack::pose(const double* headpose)
const std::int32_t id = load(ft->GameID);
- data_id++;
- data_id %= 128;
-
- store(data->DataID, 60 * 5 + data_id);
-
if (intGameID != id)
{
QString gamename;
- union {
+ union {
unsigned char table[8];
std::int32_t ints[2];
} t;
@@ -114,36 +89,46 @@ void freetrack::pose(const double* headpose)
(void)CSV::getGameData(id, t.table, gamename);
- if (gamename.isEmpty() && id > 0)
- gamename = tr("Unknown game");
+ {
+#if 0
+ const std::uintptr_t addr = (std::uintptr_t)(void*)&pMemData->table[0];
+ const std::uintptr_t addr_ = addr & ~(sizeof(LONG)-1u);
- static_assert(sizeof(LONG) == 4, "");
- static_assert(sizeof(int) == 4, "");
+ // the data `happens' to be aligned by virtue of element ordering
+ // inside FTHeap. there's no deeper reason behind it.
- // memory mappings are page-aligned due to TLB
- if ((std::intptr_t(pMemData) & page_size() - 1) != 0)
- assert(!"proto/freetrack: memory mapping not page aligned");
+ if (addr != addr_)
+ assert(!"unaligned access");
+
+ static_assert(sizeof(LONG) == 4, "");
+#endif
- // no atomic access for `char'
- for (unsigned k = 0; k < 2; k++)
- store(pMemData->table_ints[k], t.ints[k]);
+ for (unsigned k = 0; k < 2; k++)
+ store(pMemData->table_ints[k], t.ints[k]);
+ }
store(ft->GameID2, id);
+ store((std::uint32_t volatile &)data->DataID, 0u);
intGameID = id;
+ if (gamename.isEmpty())
+ gamename = tr("Unknown game");
+
QMutexLocker foo(&game_name_mutex);
connected_game = gamename;
}
+ else
+ (void)InterlockedAdd((LONG volatile*)&data->DataID, 1);
}
-float freetrack::degrees_to_rads(double degrees)
+QString freetrack::game_name()
{
- return float(degrees*M_PI/180);
+ QMutexLocker foo(&game_name_mutex);
+ return connected_game;
}
-void freetrack::start_dummy()
-{
+void freetrack::start_dummy() {
static const QString program = OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH "TrackIR.exe";
dummyTrackIR.setProgram("\"" + program + "\"");
dummyTrackIR.start();
@@ -176,7 +161,6 @@ module_status freetrack::initialize()
bool use_ft = false, use_npclient = false;
switch (s.intUsedInterface) {
- default:
case 0:
use_ft = true;
use_npclient = true;
@@ -187,14 +171,17 @@ module_status freetrack::initialize()
case 2:
use_npclient = true;
break;
+ default:
+ break;
}
set_protocols(use_ft, use_npclient);
+ pMemData->data.DataID = 1;
pMemData->data.CamWidth = 100;
pMemData->data.CamHeight = 250;
-#if 1
+#if 0
store(pMemData->data.X1, float(100));
store(pMemData->data.Y1, float(200));
store(pMemData->data.X2, float(300));
@@ -203,8 +190,7 @@ module_status freetrack::initialize()
store(pMemData->data.Y3, float(100));
#endif
- store(pMemData->GameID2, -1);
- store(pMemData->data.DataID, 0);
+ store(pMemData->GameID2, 0);
for (unsigned k = 0; k < 2; k++)
store(pMemData->table_ints[k], 0);
diff --git a/proto-ft/ftnoir_protocol_ft.h b/proto-ft/ftnoir_protocol_ft.h
index 18a5596f..4ddda8de 100644
--- a/proto-ft/ftnoir_protocol_ft.h
+++ b/proto-ft/ftnoir_protocol_ft.h
@@ -7,21 +7,21 @@
*/
#pragma once
-
#include "ui_ftnoir_ftcontrols.h"
-
-#include "freetrackclient/fttypes.h"
-
-#include "compat/shm.h"
-#include "compat/tr.hpp"
-#include "options/options.hpp"
#include "api/plugin-api.hpp"
#include <QProcess>
#include <QString>
#include <QMutex>
+#include <QDebug>
+
#include <cinttypes>
+#include "freetrackclient/fttypes.h"
+
+#include "compat/shm.h"
+#include "options/options.hpp"
+
#include <memory>
using namespace options;
@@ -34,30 +34,26 @@ struct settings : opts {
{}
};
-class freetrack : public TR, public IProtocol
+class freetrack : TR, public IProtocol
{
Q_OBJECT
public:
- freetrack();
+ freetrack() = default;
~freetrack() override;
module_status initialize() override;
- void pose( const double *headpose );
- QString game_name() override {
- QMutexLocker foo(&game_name_mutex);
- return connected_game;
- }
+ void pose(const double* pose) override;
+ QString game_name() override;
private:
settings s;
shm_wrapper shm { FREETRACK_HEAP, FREETRACK_MUTEX, sizeof(FTHeap) };
- FTHeap *pMemData { (FTHeap*) shm.ptr() };
+ FTHeap* pMemData { (FTHeap*) shm.ptr() };
QProcess dummyTrackIR;
int intGameID = -1;
QString connected_game;
QMutex game_name_mutex;
- unsigned data_id = 0;
void start_dummy();
static float degrees_to_rads(double degrees);
@@ -86,6 +82,7 @@ class freetrackDll : public Metadata
{
Q_OBJECT
+public:
QString name() { return tr("freetrack 2.0 Enhanced"); }
QIcon icon() { return QIcon(":/images/freetrack.png"); }
};
diff --git a/proto-ft/ftnoir_protocol_ft_dialog.cpp b/proto-ft/ftnoir_protocol_ft_dialog.cpp
index df2878ec..58077b87 100644
--- a/proto-ft/ftnoir_protocol_ft_dialog.cpp
+++ b/proto-ft/ftnoir_protocol_ft_dialog.cpp
@@ -8,11 +8,11 @@
* purpose with or without fee is hereby granted, provided that the above *
* copyright notice and this permission notice appear in all copies. *
*/
-#include "ftnoir_protocol_ft.h"
-#include "compat/library-path.hpp"
+#include "compat/library-path.hpp"
+#include "ftnoir_protocol_ft.h"
+#include <QDebug>
#include <QFileDialog>
-#include <QFileInfo>
FTControls::FTControls()
{
@@ -22,10 +22,6 @@ FTControls::FTControls()
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel()));
connect(ui.bntLocateNPClient, SIGNAL(clicked()), this, SLOT(selectDLL()));
- ui.cbxSelectInterface->addItem("Enable both");
- ui.cbxSelectInterface->addItem("Use FreeTrack, hide TrackIR");
- ui.cbxSelectInterface->addItem("Use TrackIR, hide FreeTrack");
-
tie_setting(s.intUsedInterface, ui.cbxSelectInterface);
}