diff options
-rw-r--r-- | proto-wine/CMakeLists.txt | 20 | ||||
-rw-r--r-- | proto-wine/ftnoir_protocol_wine.cpp | 37 | ||||
-rw-r--r-- | proto-wine/ftnoir_protocol_wine.h | 37 | ||||
-rw-r--r-- | proto-wine/lang/nl_NL.ts | 6 | ||||
-rw-r--r-- | proto-wine/lang/ru_RU.ts | 6 | ||||
-rw-r--r-- | proto-wine/lang/stub.ts | 6 | ||||
-rw-r--r-- | proto-wine/lang/zh_CN.ts | 6 | ||||
-rw-r--r-- | proto-wine/opentrack-wrapper-wine-main.cxx | 10 |
8 files changed, 86 insertions, 42 deletions
diff --git a/proto-wine/CMakeLists.txt b/proto-wine/CMakeLists.txt index 86559435..ec24ed5a 100644 --- a/proto-wine/CMakeLists.txt +++ b/proto-wine/CMakeLists.txt @@ -1,10 +1,16 @@ if(NOT WIN32) - set(SDK_WINE_PREFIX "" CACHE PATH "Wine install prefix") - set(SDK_WINE_NO_WRAPPER FALSE CACHE BOOL "disable Wine wrapper -- use Wine only for X-Plane") - if(SDK_WINE_PREFIX) + set(SDK_WINE "" CACHE BOOL "Build for Wine") + set(no-wrapper FALSE) + if(NOT SDK_WINE AND SDK_XPLANE) + set(no-wrapper TRUE) + endif() + if(SDK_WINE OR no-wrapper) + if(no-wrapper) + add_definitions(-DOTR_WINE_NO_WRAPPER) + endif() otr_module(proto-wine) - target_link_libraries(opentrack-proto-wine opentrack-csv) - if(NOT SDK_WINE_NO_WRAPPER) + if(NOT no-wrapper) + target_link_libraries(opentrack-proto-wine opentrack-csv) set(my-rt -lrt) if(APPLE) set(my-rt) @@ -14,11 +20,11 @@ if(NOT WIN32) add_custom_command( OUTPUT opentrack-wrapper-wine.exe.so DEPENDS ${wine-deps} - COMMAND ${SDK_WINE_PREFIX}/bin/wineg++ -g -DNOMINMAX -O2 -m32 -std=c++17 -fPIC -o + COMMAND wineg++ -g -DNOMINMAX -O2 -m32 -std=c++17 -fPIC -o opentrack-wrapper-wine.exe -I "${CMAKE_SOURCE_DIR}" -I "${CMAKE_BINARY_DIR}" ${wine-deps} ${my-rt}) - add_custom_target(wine-wrapper ALL DEPENDS opentrack-wrapper-wine.exe.so) + add_custom_target(wine-wrapper DEPENDS opentrack-wrapper-wine.exe.so) add_dependencies(opentrack-proto-wine wine-wrapper) add_dependencies(wine-wrapper opentrack-compat) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/opentrack-wrapper-wine.exe.so" DESTINATION ${opentrack-hier-pfx}) diff --git a/proto-wine/ftnoir_protocol_wine.cpp b/proto-wine/ftnoir_protocol_wine.cpp index 7d415555..edeb8ce4 100644 --- a/proto-wine/ftnoir_protocol_wine.cpp +++ b/proto-wine/ftnoir_protocol_wine.cpp @@ -7,28 +7,23 @@ #include <sys/mman.h> #include <sys/stat.h> /* For mode constants */ #include <fcntl.h> /* For O_* constants */ -#include "csv/csv.h" +#ifndef OTR_WINE_NO_WRAPPER +# include "csv/csv.h" +#endif #include "compat/macros.hpp" #include "compat/library-path.hpp" -wine::wine() : lck_shm(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM)), shm(NULL), gameid(0) -{ - if (lck_shm.success()) { - shm = (WineSHM*) lck_shm.ptr(); - memset(shm, 0, sizeof(*shm)); - } - static const QString library_path(QCoreApplication::applicationDirPath() + OPENTRACK_LIBRARY_PATH); - wrapper.setWorkingDirectory(QCoreApplication::applicationDirPath()); - wrapper.start("wine", QStringList() << (library_path + "opentrack-wrapper-wine.exe.so")); -} +wine::wine() = default; wine::~wine() { +#ifndef OTR_WINE_NO_WRAPPER if (shm) { shm->stop = true; wrapper.waitForFinished(100); } - wrapper.close(); + wrapper.kill(); +#endif //shm_unlink("/" WINE_SHM_NAME); } @@ -38,9 +33,10 @@ void wine::pose( const double *headpose ) { lck_shm.lock(); for (int i = 3; i < 6; i++) - shm->data[i] = headpose[i] / (180 / M_PI ); + shm->data[i] = (headpose[i] * M_PI) / 180; for (int i = 0; i < 3; i++) shm->data[i] = headpose[i] * 10; +#ifndef OTR_WINE_NO_WRAPPER if (shm->gameid != gameid) { QString gamename; @@ -51,16 +47,29 @@ void wine::pose( const double *headpose ) gameid = shm->gameid2 = shm->gameid; connected_game = gamename; } +#endif lck_shm.unlock(); } } module_status wine::initialize() { +#ifndef OTR_WINE_NO_WRAPPER + static const QString library_path(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH); + wrapper.setWorkingDirectory(OPENTRACK_BASE_PATH); + wrapper.start("wine", { library_path + "opentrack-wrapper-wine.exe.so" }); +#endif + + if (lck_shm.success()) + { + shm = (WineSHM*) lck_shm.ptr(); + memset(shm, 0, sizeof(*shm)); + } + if (lck_shm.success()) return status_ok(); else return error(tr("Can't open shared memory mapping")); } -OPENTRACK_DECLARE_PROTOCOL(wine, FTControls, wineDll) +OPENTRACK_DECLARE_PROTOCOL(wine, FTControls, wine_metadata) diff --git a/proto-wine/ftnoir_protocol_wine.h b/proto-wine/ftnoir_protocol_wine.h index 19b905e7..b4cbd305 100644 --- a/proto-wine/ftnoir_protocol_wine.h +++ b/proto-wine/ftnoir_protocol_wine.h @@ -1,16 +1,16 @@ #pragma once -#include "ui_ftnoir_winecontrols.h" -#include <QMessageBox> -#include <QProcess> -#include <QDebug> -#include <QMutex> -#include <QMutexLocker> -#include <QFile> #include "api/plugin-api.hpp" #include "compat/shm.h" #include "wine-shm.h" -#include "compat/tr.hpp" + +#include "ui_ftnoir_winecontrols.h" + +#include <QString> +#include <QProcess> +#include <QMutex> + +#include <QDebug> class wine : TR, public IProtocol { @@ -25,21 +25,29 @@ public: QString game_name() override { +#ifndef OTR_WINE_NO_WRAPPER QMutexLocker foo(&game_name_mutex); return connected_game; +#else + return QStringLiteral("X-Plane"); +#endif } private: - shm_wrapper lck_shm; - WineSHM* shm; + shm_wrapper lck_shm { WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM) }; + WineSHM* shm = nullptr; + +#ifndef OTR_WINE_NO_WRAPPER QProcess wrapper; - int gameid; + int gameid = 0; QString connected_game; QMutex game_name_mutex; +#endif }; class FTControls: public IProtocolDialog { Q_OBJECT + public: FTControls(); void register_protocol(IProtocol *) override {} @@ -53,11 +61,16 @@ private slots: void doCancel(); }; -class wineDll : public Metadata +class wine_metadata : public Metadata { Q_OBJECT public: +#ifndef OTR_WINE_NO_WRAPPER QString name() override { return tr("Wine -- Windows layer for Unix"); } QIcon icon() override { return QIcon(":/images/wine.png"); } +#else + QString name() override { return tr("X-Plane"); } + QIcon icon() override { return {}; } +#endif }; diff --git a/proto-wine/lang/nl_NL.ts b/proto-wine/lang/nl_NL.ts index 49051961..239e73d1 100644 --- a/proto-wine/lang/nl_NL.ts +++ b/proto-wine/lang/nl_NL.ts @@ -28,10 +28,14 @@ </message> </context> <context> - <name>wineDll</name> + <name>wine_metadata</name> <message> <source>Wine -- Windows layer for Unix</source> <translation type="unfinished"></translation> </message> + <message> + <source>X-Plane</source> + <translation type="unfinished"></translation> + </message> </context> </TS> diff --git a/proto-wine/lang/ru_RU.ts b/proto-wine/lang/ru_RU.ts index 2ea9274b..1e80e43f 100644 --- a/proto-wine/lang/ru_RU.ts +++ b/proto-wine/lang/ru_RU.ts @@ -28,10 +28,14 @@ </message> </context> <context> - <name>wineDll</name> + <name>wine_metadata</name> <message> <source>Wine -- Windows layer for Unix</source> <translation type="unfinished"></translation> </message> + <message> + <source>X-Plane</source> + <translation type="unfinished"></translation> + </message> </context> </TS> diff --git a/proto-wine/lang/stub.ts b/proto-wine/lang/stub.ts index 21185491..2da10a0b 100644 --- a/proto-wine/lang/stub.ts +++ b/proto-wine/lang/stub.ts @@ -28,10 +28,14 @@ </message> </context> <context> - <name>wineDll</name> + <name>wine_metadata</name> <message> <source>Wine -- Windows layer for Unix</source> <translation type="unfinished"></translation> </message> + <message> + <source>X-Plane</source> + <translation type="unfinished"></translation> + </message> </context> </TS> diff --git a/proto-wine/lang/zh_CN.ts b/proto-wine/lang/zh_CN.ts index 21185491..2da10a0b 100644 --- a/proto-wine/lang/zh_CN.ts +++ b/proto-wine/lang/zh_CN.ts @@ -28,10 +28,14 @@ </message> </context> <context> - <name>wineDll</name> + <name>wine_metadata</name> <message> <source>Wine -- Windows layer for Unix</source> <translation type="unfinished"></translation> </message> + <message> + <source>X-Plane</source> + <translation type="unfinished"></translation> + </message> </context> </TS> diff --git a/proto-wine/opentrack-wrapper-wine-main.cxx b/proto-wine/opentrack-wrapper-wine-main.cxx index 1c88755a..6370e7f4 100644 --- a/proto-wine/opentrack-wrapper-wine-main.cxx +++ b/proto-wine/opentrack-wrapper-wine-main.cxx @@ -1,9 +1,9 @@ #include <cerrno> + // OSX sdk 10.8 build error otherwise -#ifdef _LIBCPP_MSVCRT -# undef _LIBCPP_MSVCRT -#endif +#undef _LIBCPP_MSVCRT #include <cstdio> + #include "freetrackclient/fttypes.h" #include "wine-shm.h" #include "compat/export.hpp" @@ -48,11 +48,11 @@ 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()) { - printf("Can't open posix map: %d\n", errno); + fprintf(stderr, "Can't open posix map: %d\n", errno); return 1; } if(!lck_wine.success()) { - printf("Can't open Wine map\n"); + fprintf(stderr, "Can't open Wine map\n"); return 1; } WineSHM* shm_posix = (WineSHM*) lck_posix.ptr(); |