From bab093ebbe392927a92ef201fe60344d5c1191dd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 25 Dec 2018 09:53:52 +0100 Subject: compat/shm, proto/wine: remove duplication The X-Plane plugin is next and should build on win32 then. --- proto-wine/ftnoir_protocol_wine.h | 4 +- proto-wine/opentrack-wrapper-wine-main.cxx | 114 ++++++++++++-------------- proto-wine/opentrack-wrapper-wine-posix.cxx | 9 +- proto-wine/opentrack-wrapper-wine-windows.cxx | 6 +- 4 files changed, 64 insertions(+), 69 deletions(-) (limited to 'proto-wine') diff --git a/proto-wine/ftnoir_protocol_wine.h b/proto-wine/ftnoir_protocol_wine.h index b4cbd305..8feaf0de 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.h" +#include "compat/shm.hpp" #include "wine-shm.h" #include "ui_ftnoir_winecontrols.h" @@ -33,7 +33,7 @@ public: #endif } private: - shm_wrapper lck_shm { WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM) }; + mem 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 6370e7f4..491cc917 100644 --- a/proto-wine/opentrack-wrapper-wine-main.cxx +++ b/proto-wine/opentrack-wrapper-wine-main.cxx @@ -1,80 +1,74 @@ #include +#include // usleep -// OSX sdk 10.8 build error otherwise -#undef _LIBCPP_MSVCRT -#include - +#include "compat/macros1.h" #include "freetrackclient/fttypes.h" #include "wine-shm.h" -#include "compat/export.hpp" enum Axis { TX = 0, TY, TZ, Yaw, Pitch, Roll }; -#include "compat/shm.h" - -void create_registry_key(void); +#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" -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; -}; +#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 +#include "compat/shm.hpp" -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 +void create_registry_key(void); int main(void) { - 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); + 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()) return 1; - } - if(!lck_wine.success()) { - fprintf(stderr, "Can't open Wine map\n"); + if(!lck_wine.success()) return 1; - } - WineSHM* shm_posix = (WineSHM*) lck_posix.ptr(); - FTHeap* shm_wine = (FTHeap*) lck_wine.ptr(); - FTData* data = &shm_wine->data; + create_registry_key(); - 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; + + 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) + { + MEMBAR(); + 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; for (int i = 0; i < 8; i++) - shm_wine->table[i] = shm_posix->table[i]; - (void) Sleep(4); + mem_wine.table[i] = mem_wine.table[i]; + MEMBAR(); + (void)usleep(4 * 1000); } } diff --git a/proto-wine/opentrack-wrapper-wine-posix.cxx b/proto-wine/opentrack-wrapper-wine-posix.cxx index e36407a9..17a74b66 100644 --- a/proto-wine/opentrack-wrapper-wine-posix.cxx +++ b/proto-wine/opentrack-wrapper-wine-posix.cxx @@ -1,7 +1,6 @@ -#ifdef _WIN32 -# undef _WIN32 -#endif +#undef _WIN32 -#define shm_wrapper ShmPosix -#include "compat/shm.h" +#define SHM_TYPE_NAME shm_impl_unix +#define SHM_FUN_PREFIX shm_impl_unix_ +#define SHMXX_TYPE_NAME mem_unix #include "compat/shm.cpp" diff --git a/proto-wine/opentrack-wrapper-wine-windows.cxx b/proto-wine/opentrack-wrapper-wine-windows.cxx index d464cf6c..a18900c3 100644 --- a/proto-wine/opentrack-wrapper-wine-windows.cxx +++ b/proto-wine/opentrack-wrapper-wine-windows.cxx @@ -2,9 +2,11 @@ # error "bad cross" #endif -#define shm_wrapper ShmWine -#include "compat/shm.h" +#define SHM_TYPE_NAME shm_impl_winelib +#define SHM_FUN_PREFIX shm_impl_winelib_ +#define SHMXX_TYPE_NAME mem_winelib #include "compat/shm.cpp" + #include "wine-shm.h" #include "compat/library-path.hpp" #include -- cgit v1.2.3