diff options
Diffstat (limited to 'ftnoir_protocol_wine')
-rw-r--r-- | ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx | 75 | ||||
-rw-r--r-- | ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx | 12 | ||||
-rw-r--r-- | ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx | 5 |
3 files changed, 54 insertions, 38 deletions
diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx index fe5a95f9..40f36f8d 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx @@ -10,33 +10,57 @@ #include "compat/compat.h" void create_registry_key(void); -ptr<BasePortableLockedShm> make_shm_posix(); -ptr<BasePortableLockedShm> make_shm_win32(); + +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) { - ptr<BasePortableLockedShm> lck_posix = make_shm_posix(); - ptr<BasePortableLockedShm> lck_wine = make_shm_win32(); - 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->ptr(); - FTHeap* shm_wine = (FTHeap*) lck_wine->ptr(); + ShmPosix lck_posix(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM)); + ShmWine lck_wine("FT_SharedMem", "FT_Mutext", sizeof(FTHeap)); + 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.ptr(); + FTHeap* shm_wine = (FTHeap*) lck_wine.ptr(); FTData* data = &shm_wine->data; create_registry_key(); - while (1) { - (void) Sleep(4); - lck_posix->lock(); - if (shm_posix->stop) { - lck_posix->unlock(); - break; - } - lck_wine->lock(); + while (1) { + 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]; @@ -50,7 +74,8 @@ int main(void) 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(); - } + lck_wine.unlock(); + lck_posix.unlock(); + (void) Sleep(4); + } } diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx index ea01ff03..010c4440 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-posix.cxx @@ -1,12 +1,8 @@ #define OPENTRACK_COMPAT_BUNDLED +#ifdef _WIN32 +# undef _WIN32 +#endif + #define PortableLockedShm ShmPosix -#undef _WIN32 -#include "ftnoir_protocol_ft/fttypes.h" -#include "wine-shm.h" #include "compat/compat.h" #include "compat/compat.cpp" - -ptr<BasePortableLockedShm> make_shm_posix() -{ - return std::make_shared<ShmPosix>(FREETRACK_HEAP, FREETRACK_MUTEX, sizeof(FTHeap)); -} diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx index 715dcc69..b7dc531c 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-windows.cxx @@ -8,11 +8,6 @@ #include "compat/compat.cpp" #include "wine-shm.h" -ptr<BasePortableLockedShm> make_shm_win32() -{ - return std::make_shared<ShmWine>(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM)); -} - void create_registry_key(void) { char dir[8192]; |