summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_protocol_wine
diff options
context:
space:
mode:
Diffstat (limited to 'ftnoir_protocol_wine')
-rw-r--r--ftnoir_protocol_wine/ftnoir_protocol_wine.cpp76
-rw-r--r--ftnoir_protocol_wine/ftnoir_protocol_wine.h102
-rw-r--r--ftnoir_protocol_wine/ftnoir_protocol_wine_dialog.cpp39
-rw-r--r--ftnoir_protocol_wine/ftnoir_protocol_wine_dll.cpp25
-rw-r--r--ftnoir_protocol_wine/ftnoir_winecontrols.ui170
-rw-r--r--ftnoir_protocol_wine/images/wine.pngbin0 -> 376 bytes
-rw-r--r--ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx74
-rw-r--r--ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx8
-rw-r--r--ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx38
-rw-r--r--ftnoir_protocol_wine/wine-protocol.qrc5
-rw-r--r--ftnoir_protocol_wine/wine-shm.h11
11 files changed, 548 insertions, 0 deletions
diff --git a/ftnoir_protocol_wine/ftnoir_protocol_wine.cpp b/ftnoir_protocol_wine/ftnoir_protocol_wine.cpp
new file mode 100644
index 00000000..58ffe974
--- /dev/null
+++ b/ftnoir_protocol_wine/ftnoir_protocol_wine.cpp
@@ -0,0 +1,76 @@
+#include "ftnoir_protocol_wine.h"
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h> /* For mode constants */
+#include <fcntl.h> /* For O_* constants */
+
+/** constructor **/
+FTNoIR_Protocol::FTNoIR_Protocol() : lck_shm(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM)), shm(NULL), gameid(0)
+{
+ if (lck_shm.success()) {
+ shm = (WineSHM*) lck_shm.mem;
+ memset(shm, 0, sizeof(*shm));
+ }
+ wrapper.start("wine", QStringList() << (QCoreApplication::applicationDirPath() + "/opentrack-wrapper-wine.exe.so"));
+}
+
+/** destructor **/
+FTNoIR_Protocol::~FTNoIR_Protocol()
+{
+ if (shm) {
+ shm->stop = true;
+ wrapper.waitForFinished(100);
+ }
+ wrapper.terminate();
+ if (!wrapper.waitForFinished(100))
+ {
+ wrapper.kill();
+ wrapper.waitForFinished(42);
+ }
+ //shm_unlink("/" WINE_SHM_NAME);
+}
+
+void FTNoIR_Protocol::sendHeadposeToGame( const double *headpose ) {
+ if (shm)
+ {
+ lck_shm.lock();
+ for (int i = 3; i < 6; i++)
+ shm->data[i] = headpose[i] / 57.295781;
+ for (int i = 0; i < 3; i++)
+ shm->data[i] = headpose[i] * 10;
+ if (shm->gameid != gameid)
+ {
+ QString gamename;
+ QMutexLocker foo(&game_name_mutex);
+ /* only EZCA for FSX requires dummy process, and FSX doesn't work on Linux */
+ /* memory-hacks DLL can't be loaded into a Linux process, either */
+ CSV::getGameData(shm->gameid, shm->table, gamename);
+ gameid = shm->gameid2 = shm->gameid;
+ connected_game = gamename;
+ }
+ lck_shm.unlock();
+ }
+}
+
+//
+// Check if the Client DLL exists and load it (to test it), if so.
+// Returns 'true' if all seems OK.
+//
+bool FTNoIR_Protocol::checkServerInstallationOK()
+{
+ return lck_shm.success();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// 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 void* CALLING_CONVENTION GetConstructor()
+{
+ return (IProtocol*) new FTNoIR_Protocol;
+}
diff --git a/ftnoir_protocol_wine/ftnoir_protocol_wine.h b/ftnoir_protocol_wine/ftnoir_protocol_wine.h
new file mode 100644
index 00000000..50d2bc0c
--- /dev/null
+++ b/ftnoir_protocol_wine/ftnoir_protocol_wine.h
@@ -0,0 +1,102 @@
+/********************************************************************************
+* FaceTrackNoIR This program is a private project of some enthusiastic *
+* gamers from Holland, who don't like to pay much for *
+* head-tracking. *
+* *
+* Copyright (C) 2010 Wim Vriend (Developing) *
+* Ron Hendriks (Researching and Testing) *
+* *
+* Homepage *
+* *
+* This program is free software; you can redistribute it and/or modify it *
+* under the terms of the GNU General Public License as published by the *
+* Free Software Foundation; either version 3 of the License, or (at your *
+* option) any later version. *
+* *
+* This program is distributed in the hope that it will be useful, but *
+* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
+* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
+* more details. *
+* *
+* You should have received a copy of the GNU General Public License along *
+* with this program; if not, see <http://www.gnu.org/licenses/>. *
+* *
+* FTServer FTServer is the Class, that communicates headpose-data *
+* to games, using the FreeTrackClient.dll. *
+********************************************************************************/
+#pragma once
+#ifndef INCLUDED_FTSERVER_H
+#define INCLUDED_FTSERVER_H
+
+#include "ftnoir_protocol_base/ftnoir_protocol_base.h"
+#include "ftnoir_protocol_ft/fttypes.h"
+#include "ftnoir_csv/csv.h"
+#include "ui_ftnoir_winecontrols.h"
+#include <QMessageBox>
+#include <QLibrary>
+#include <QProcess>
+#include <QDebug>
+#include <QMutex>
+#include <QMutexLocker>
+#include <QFile>
+#include "facetracknoir/global-settings.h"
+#include "compat/compat.h"
+#include "ftnoir_protocol_wine/wine-shm.h"
+
+class FTNoIR_Protocol : public IProtocol
+{
+public:
+ FTNoIR_Protocol();
+ virtual ~FTNoIR_Protocol();
+
+ bool checkServerInstallationOK();
+ void sendHeadposeToGame(const double* headpose);
+ QString getGameName() {
+ QMutexLocker foo(&game_name_mutex);
+ return connected_game;
+ }
+private:
+ PortableLockedShm lck_shm;
+ WineSHM* shm;
+ QProcess wrapper;
+ int gameid;
+ QString connected_game;
+ QMutex game_name_mutex;
+};
+
+// Widget that has controls for FTNoIR protocol client-settings.
+class FTControls: public QWidget, public IProtocolDialog
+{
+ Q_OBJECT
+public:
+ FTControls();
+ void registerProtocol(IProtocol *) {}
+ void unRegisterProtocol() {}
+
+private:
+ Ui::UICFTControls ui;
+
+private slots:
+ void doOK();
+ void doCancel();
+};
+
+//*******************************************************************************************************
+// FaceTrackNoIR Protocol DLL. Functions used to get general info on the Protocol
+//*******************************************************************************************************
+class FTNoIR_ProtocolDll : public Metadata
+{
+public:
+ FTNoIR_ProtocolDll();
+ ~FTNoIR_ProtocolDll();
+
+ void getFullName(QString *strToBeFilled) { *strToBeFilled = QString("Wine"); }
+ void getShortName(QString *strToBeFilled) { *strToBeFilled = QString("Wine"); }
+ void getDescription(QString *strToBeFilled) { *strToBeFilled = QString("Wine glue wrapper"); }
+
+ void getIcon(QIcon *icon) { *icon = QIcon(":/images/wine.png"); }
+};
+
+
+#endif//INCLUDED_FTSERVER_H
+//END
diff --git a/ftnoir_protocol_wine/ftnoir_protocol_wine_dialog.cpp b/ftnoir_protocol_wine/ftnoir_protocol_wine_dialog.cpp
new file mode 100644
index 00000000..ecbc2137
--- /dev/null
+++ b/ftnoir_protocol_wine/ftnoir_protocol_wine_dialog.cpp
@@ -0,0 +1,39 @@
+#include "ftnoir_protocol_wine.h"
+#include <QDebug>
+#include "facetracknoir/global-settings.h"
+
+//*******************************************************************************************************
+// FaceTrackNoIR Client Settings-dialog.
+//*******************************************************************************************************
+
+//
+// Constructor for server-settings-dialog
+//
+FTControls::FTControls() : QWidget()
+{
+ ui.setupUi( this );
+ connect(ui.btnOK, SIGNAL(clicked()), this, SLOT(doOK()));
+ connect(ui.btnCancel, SIGNAL(clicked()), this, SLOT(doCancel()));
+}
+
+//
+// Destructor for server-dialog
+
+//
+// OK clicked on server-dialog
+//
+void FTControls::doOK() {
+ this->close();
+}
+
+//
+// Cancel clicked on server-dialog
+//
+void FTControls::doCancel() {
+ this->close();
+}
+
+extern "C" FTNOIR_PROTOCOL_BASE_EXPORT void* CALLING_CONVENTION GetDialog( )
+{
+ return (IProtocolDialog*) new FTControls;
+}
diff --git a/ftnoir_protocol_wine/ftnoir_protocol_wine_dll.cpp b/ftnoir_protocol_wine/ftnoir_protocol_wine_dll.cpp
new file mode 100644
index 00000000..dd7f17a6
--- /dev/null
+++ b/ftnoir_protocol_wine/ftnoir_protocol_wine_dll.cpp
@@ -0,0 +1,25 @@
+#include "ftnoir_protocol_wine.h"
+#include <QDebug>
+#include "facetracknoir/global-settings.h"
+
+FTNoIR_ProtocolDll::FTNoIR_ProtocolDll() {
+}
+
+FTNoIR_ProtocolDll::~FTNoIR_ProtocolDll()
+{
+
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Factory function that creates instances if the Protocol object.
+
+// Export both decorated and undecorated names.
+// GetProtocolDll - Undecorated name, which can be easily used with GetProcAddress
+// Win32 API function.
+// _GetProtocolDll@0 - Common name decoration for __stdcall functions in C language.
+//#pragma comment(linker, "/export:GetProtocolDll=_GetProtocolDll@0")
+
+extern "C" FTNOIR_PROTOCOL_BASE_EXPORT Metadata* CALLING_CONVENTION GetMetadata()
+{
+ return new FTNoIR_ProtocolDll;
+}
diff --git a/ftnoir_protocol_wine/ftnoir_winecontrols.ui b/ftnoir_protocol_wine/ftnoir_winecontrols.ui
new file mode 100644
index 00000000..9356c448
--- /dev/null
+++ b/ftnoir_protocol_wine/ftnoir_winecontrols.ui
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>UICFTControls</class>
+ <widget class="QWidget" name="UICFTControls">
+ <property name="windowModality">
+ <enum>Qt::NonModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>409</width>
+ <height>110</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>FreeTrack settings FaceTrackNoIR</string>
+ </property>
+ <property name="windowIcon">
+ <iconset>
+ <normaloff>images/freetrack.png</normaloff>images/freetrack.png</iconset>
+ </property>
+ <property name="layoutDirection">
+ <enum>Qt::LeftToRight</enum>
+ </property>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <layout class="QVBoxLayout" name="_vertical_layout">
+ <item>
+ <layout class="QHBoxLayout">
+ <item>
+ <spacer name="horizontalSpacer_3">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>There are no settings necessary for the Wine protocol.</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetDefaultConstraint</enum>
+ </property>
+ <item>
+ <widget class="QPushButton" name="btnOK">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>100</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>OK</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="btnCancel">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>100</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>100</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Cancel</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Fixed</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>10</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <slots>
+ <slot>startEngineClicked()</slot>
+ <slot>stopEngineClicked()</slot>
+ <slot>cameraSettingsClicked()</slot>
+ </slots>
+</ui>
diff --git a/ftnoir_protocol_wine/images/wine.png b/ftnoir_protocol_wine/images/wine.png
new file mode 100644
index 00000000..bcf3a012
--- /dev/null
+++ b/ftnoir_protocol_wine/images/wine.png
Binary files differ
diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx
new file mode 100644
index 00000000..6e512b6e
--- /dev/null
+++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx
@@ -0,0 +1,74 @@
+#include <errno.h>
+#include <stdio.h>
+#include "ftnoir_protocol_ft/fttypes.h"
+#include "ftnoir_protocol_wine/wine-shm.h"
+#include "ftnoir_tracker_base/ftnoir_tracker_types.h"
+
+void create_registry_key(void);
+
+class ShmPosix {
+public:
+ ShmPosix(const char *shmName, const char *mutexName, int mapSize);
+ ~ShmPosix();
+ void lock();
+ void unlock();
+ bool success();
+ void* mem;
+private:
+ int fd, size;
+};
+
+class ShmWine {
+public:
+ ShmWine(const char *shmName, const char *mutexName, int mapSize);
+ ~ShmWine();
+ void lock();
+ void unlock();
+ bool success();
+ void* mem;
+private:
+ void *hMutex, *hMapFile;
+};
+#include <windows.h>
+
+int main(void)
+{
+ ShmPosix lck_posix(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM));
+ ShmWine lck_wine("FT_SharedMem", "FT_Mutext", sizeof(FTMemMap));
+ if(!lck_posix.success()) {
+ printf("Can't open posix map: %d\n", errno);
+ return 1;
+ }
+ if(!lck_wine.success()) {
+ printf("Can't open Wine map\n");
+ return 1;
+ }
+ WineSHM* shm_posix = (WineSHM*) lck_posix.mem;
+ FTMemMap* shm_wine = (FTMemMap*) lck_wine.mem;
+ TFreeTrackData* data = &shm_wine->data;
+ create_registry_key();
+ while (1) {
+ (void) Sleep(10);
+ lck_posix.lock();
+ if (shm_posix->stop) {
+ lck_posix.unlock();
+ break;
+ }
+ lck_wine.lock();
+ data->Yaw = shm_posix->data[Yaw];
+ data->Pitch = shm_posix->data[Pitch];
+ data->Roll = shm_posix->data[Roll];
+ data->X = shm_posix->data[TX];
+ data->Y = shm_posix->data[TY];
+ data->Z = shm_posix->data[TZ];
+ data->DataID++;
+ data->CamWidth = 250;
+ data->CamHeight = 100;
+ shm_wine->GameID2 = shm_posix->gameid2;
+ shm_posix->gameid = shm_wine->GameID;
+ for (int i = 0; i < 8; i++)
+ shm_wine->table[i] = shm_posix->table[i];
+ lck_wine.unlock();
+ lck_posix.unlock();
+ }
+}
diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx
new file mode 100644
index 00000000..010c4440
--- /dev/null
+++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx
@@ -0,0 +1,8 @@
+#define OPENTRACK_COMPAT_BUNDLED
+#ifdef _WIN32
+# undef _WIN32
+#endif
+
+#define PortableLockedShm ShmPosix
+#include "compat/compat.h"
+#include "compat/compat.cpp"
diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx
new file mode 100644
index 00000000..e7102600
--- /dev/null
+++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx
@@ -0,0 +1,38 @@
+#define OPENTRACK_COMPAT_BUNDLED
+
+#ifndef __WIN32
+#define __WIN32
+#endif
+
+#define PortableLockedShm ShmWine
+
+#include "ftnoir_protocol_ft/fttypes.h"
+#include "compat/compat.h"
+#include "compat/compat.cpp"
+#include <string.h>
+
+void create_registry_key(void) {
+ char dir[8192];
+
+ if (GetCurrentDirectoryA(8192, dir) < 8190)
+ {
+ HKEY hkpath;
+ if (RegCreateKeyExA(HKEY_CURRENT_USER,
+ "Software\\NaturalPoint\\NATURALPOINT\\NPClient Location",
+ 0,
+ NULL,
+ 0,
+ KEY_ALL_ACCESS,
+ NULL,
+ &hkpath,
+ NULL) == ERROR_SUCCESS)
+ {
+ for (int i = 0; dir[i]; i++)
+ if (dir[i] == '\\')
+ dir[i] = '/';
+ strcat(dir, "/");
+ (void) RegSetValueExA(hkpath, "Path", 0, REG_SZ, (BYTE*) dir, strlen(dir) + 1);
+ RegCloseKey(hkpath);
+ }
+ }
+}
diff --git a/ftnoir_protocol_wine/wine-protocol.qrc b/ftnoir_protocol_wine/wine-protocol.qrc
new file mode 100644
index 00000000..af81caea
--- /dev/null
+++ b/ftnoir_protocol_wine/wine-protocol.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>images/wine.png</file>
+ </qresource>
+</RCC>
diff --git a/ftnoir_protocol_wine/wine-shm.h b/ftnoir_protocol_wine/wine-shm.h
new file mode 100644
index 00000000..ddbda8b5
--- /dev/null
+++ b/ftnoir_protocol_wine/wine-shm.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#define WINE_SHM_NAME "facetracknoir-wine-shm"
+#define WINE_MTX_NAME "facetracknoir-wine-mtx"
+
+struct WineSHM {
+ double data[6];
+ int gameid, gameid2;
+ unsigned char table[8];
+ bool stop;
+};