summaryrefslogtreecommitdiffhomepage
path: root/proto-wine
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2019-01-07 13:15:30 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-01-16 07:48:47 +0100
commitb3da5c6698d4ec39d62062d23f1da79f9c359cdf (patch)
tree8b74effb405c964653e47a773fb33f7c08c070d0 /proto-wine
parentfd3eb4515639e000b899544827b5fd4ff9473937 (diff)
Revert "compat/shm, proto/wine: remove duplication"
This reverts commit bab093ebbe392927a92ef201fe60344d5c1191dd.
Diffstat (limited to 'proto-wine')
-rw-r--r--proto-wine/ftnoir_protocol_wine.h4
-rw-r--r--proto-wine/opentrack-wrapper-wine-main.cxx114
-rw-r--r--proto-wine/opentrack-wrapper-wine-posix.cxx9
-rw-r--r--proto-wine/opentrack-wrapper-wine-windows.cxx10
4 files changed, 70 insertions, 67 deletions
diff --git a/proto-wine/ftnoir_protocol_wine.h b/proto-wine/ftnoir_protocol_wine.h
index 8feaf0de..b4cbd305 100644
--- a/proto-wine/ftnoir_protocol_wine.h
+++ b/proto-wine/ftnoir_protocol_wine.h
@@ -1,7 +1,7 @@
#pragma once
#include "api/plugin-api.hpp"
-#include "compat/shm.hpp"
+#include "compat/shm.h"
#include "wine-shm.h"
#include "ui_ftnoir_winecontrols.h"
@@ -33,7 +33,7 @@ public:
#endif
}
private:
- mem lck_shm { WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM) };
+ shm_wrapper lck_shm { WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM) };
WineSHM* shm = nullptr;
#ifndef OTR_WINE_NO_WRAPPER
diff --git a/proto-wine/opentrack-wrapper-wine-main.cxx b/proto-wine/opentrack-wrapper-wine-main.cxx
index 84ef57ab..6370e7f4 100644
--- a/proto-wine/opentrack-wrapper-wine-main.cxx
+++ b/proto-wine/opentrack-wrapper-wine-main.cxx
@@ -1,74 +1,80 @@
#include <cerrno>
-#include <unistd.h> // usleep
-#include "compat/macros1.h"
+// OSX sdk 10.8 build error otherwise
+#undef _LIBCPP_MSVCRT
+#include <cstdio>
+
#include "freetrackclient/fttypes.h"
#include "wine-shm.h"
+#include "compat/export.hpp"
enum Axis {
TX = 0, TY, TZ, Yaw, Pitch, Roll
};
-#undef SHM_HEADER_GUARD
-#undef SHMXX_HEADER_GUARD
-#undef SHM_TYPE_NAME
-#undef SHM_FUN_PREFIX
-#undef SHMXX_TYPE_NAME
-#undef SHM_WIN32_INIT
-#define SHM_TYPE_NAME shm_impl_winelib
-#define SHM_FUN_PREFIX shm_impl_winelib_
-#define SHMXX_TYPE_NAME mem_winelib
-#define SHM_WIN32_INIT 1
-#include "compat/shm.hpp"
-
-#undef SHM_HEADER_GUARD
-#undef SHMXX_HEADER_GUARD
-#undef SHM_TYPE_NAME
-#undef SHM_FUN_PREFIX
-#undef SHMXX_TYPE_NAME
-#undef SHM_WIN32_INIT
-#define SHM_TYPE_NAME shm_impl_unix
-#define SHM_FUN_PREFIX shm_impl_unix_
-#define SHMXX_TYPE_NAME mem_unix
-#define SHM_WIN32_INIT 0
-#include "compat/shm.hpp"
+#include "compat/shm.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();
+ inline void* ptr() { return mem; }
+private:
+ void* mem;
+ int fd, size;
+};
+
+class ShmWine {
+public:
+ ShmWine(const char *shmName, const char *mutexName, int mapSize);
+ ~ShmWine();
+ void lock();
+ void unlock();
+ bool success();
+ inline void* ptr() { return mem; }
+private:
+ void* mem;
+ void *hMutex, *hMapFile;
+};
+#include <windows.h>
+
int main(void)
{
- mem_unix lck_unix(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM));
- mem_winelib lck_wine("FT_SharedMem", "FT_Mutext", sizeof(FTHeap));
-
- if(!lck_unix.success())
+ ShmPosix lck_posix(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM));
+ ShmWine lck_wine("FT_SharedMem", "FT_Mutext", sizeof(FTHeap));
+ if(!lck_posix.success()) {
+ fprintf(stderr, "Can't open posix map: %d\n", errno);
return 1;
- if(!lck_wine.success())
+ }
+ if(!lck_wine.success()) {
+ fprintf(stderr, "Can't open Wine map\n");
return 1;
-
+ }
+ WineSHM* shm_posix = (WineSHM*) lck_posix.ptr();
+ FTHeap* shm_wine = (FTHeap*) lck_wine.ptr();
+ FTData* data = &shm_wine->data;
create_registry_key();
-
- WineSHM& mem_unix = *(WineSHM*) lck_unix.ptr();
- FTHeap& mem_wine = *(FTHeap*) lck_wine.ptr();
- FTData& data = mem_wine.data;
-
- data.CamWidth = 250;
- data.CamHeight = 100;
-
- while (!mem_unix.stop)
- {
- COMPILER_BARRIER();
- data.Yaw = -mem_unix.data[Yaw];
- data.Pitch = -mem_unix.data[Pitch];
- data.Roll = mem_unix.data[Roll];
- data.X = mem_unix.data[TX];
- data.Y = mem_unix.data[TY];
- data.Z = mem_unix.data[TZ];
- data.DataID = 1;
- mem_wine.GameID2 = mem_unix.gameid2;
- mem_unix.gameid = mem_wine.GameID;
+ while (1) {
+ if (shm_posix->stop)
+ break;
+ 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++)
- mem_wine.table[i] = mem_wine.table[i];
- COMPILER_BARRIER();
- (void)usleep(4 * 1000);
+ shm_wine->table[i] = shm_posix->table[i];
+ (void) Sleep(4);
}
}
diff --git a/proto-wine/opentrack-wrapper-wine-posix.cxx b/proto-wine/opentrack-wrapper-wine-posix.cxx
index 17a74b66..e36407a9 100644
--- a/proto-wine/opentrack-wrapper-wine-posix.cxx
+++ b/proto-wine/opentrack-wrapper-wine-posix.cxx
@@ -1,6 +1,7 @@
-#undef _WIN32
+#ifdef _WIN32
+# undef _WIN32
+#endif
-#define SHM_TYPE_NAME shm_impl_unix
-#define SHM_FUN_PREFIX shm_impl_unix_
-#define SHMXX_TYPE_NAME mem_unix
+#define shm_wrapper ShmPosix
+#include "compat/shm.h"
#include "compat/shm.cpp"
diff --git a/proto-wine/opentrack-wrapper-wine-windows.cxx b/proto-wine/opentrack-wrapper-wine-windows.cxx
index 063e35df..d464cf6c 100644
--- a/proto-wine/opentrack-wrapper-wine-windows.cxx
+++ b/proto-wine/opentrack-wrapper-wine-windows.cxx
@@ -2,18 +2,14 @@
# error "bad cross"
#endif
-#define SHM_TYPE_NAME shm_impl_winelib
-#define SHM_FUN_PREFIX shm_impl_winelib_
-#define SHMXX_TYPE_NAME mem_winelib
+#define shm_wrapper ShmWine
+#include "compat/shm.h"
#include "compat/shm.cpp"
-
#include "wine-shm.h"
#include "compat/library-path.hpp"
-
#include <cstring>
-#include <windows.h>
-#include <winreg.h>
+using std::strcat;
static void write_path(const char* key, const char* subkey)
{