diff options
-rw-r--r-- | bin/NPClient.dll | bin | 16384 -> 16384 bytes | |||
-rw-r--r-- | bin/NPClient64.dll | bin | 17408 -> 17408 bytes | |||
-rw-r--r-- | contrib/npclient/COMPILE.TXT | 6 | ||||
-rw-r--r-- | contrib/npclient/npclient.c | 28 | ||||
-rw-r--r-- | proto-ft/ftnoir_protocol_ft.cpp | 78 |
5 files changed, 65 insertions, 47 deletions
diff --git a/bin/NPClient.dll b/bin/NPClient.dll Binary files differindex b54fcbe6..a71a8594 100644 --- a/bin/NPClient.dll +++ b/bin/NPClient.dll diff --git a/bin/NPClient64.dll b/bin/NPClient64.dll Binary files differindex abca4d4a..b1e4ac68 100644 --- a/bin/NPClient64.dll +++ b/bin/NPClient64.dll diff --git a/contrib/npclient/COMPILE.TXT b/contrib/npclient/COMPILE.TXT index cc562dd4..e61b6c14 100644 --- a/contrib/npclient/COMPILE.TXT +++ b/contrib/npclient/COMPILE.TXT @@ -1,7 +1,11 @@ +#!/bin/sh + # This makes small binaries: CC=clang CFLAGS='-Wall -Wextra -Wpedantic -Os -s -ffunction-sections -fdata-sections -Wl,--kill-at,--nxcompat,--dynamicbase,--as-needed,--gc-sections,--strip-all' +cd -- "$(dirname -- "$0")" && PATH=/mingw32/bin:"$PATH" sh -c "$CC $CFLAGS -mdll -o NPClient.dll npclient.c" && -PATH=/mingw64/bin:"$PATH" sh -c "$CC $CFLAGS -mdll -o NPClient64.dll npclient.c" +PATH=/mingw64/bin:"$PATH" sh -c "$CC $CFLAGS -mdll -o NPClient64.dll npclient.c" && +ls -l NPClient{64,}.dll && mv NPClient{64,}.dll ../../bin/ diff --git a/contrib/npclient/npclient.c b/contrib/npclient/npclient.c index 03fa589a..add5b4c1 100644 --- a/contrib/npclient/npclient.c +++ b/contrib/npclient/npclient.c @@ -332,8 +332,26 @@ NP_EXPORT(int) NP_GetData(tir_data_t * data) frameno++; data->frame = frameno; - bool running = y != 0 || p != 0 || r != 0 || - tx != 0 || ty != 0 || tz != 0; + int data_id = InterlockedDecrement((LONG volatile*) &pMemData->data.DataID); + + bool running; + + if (data_id == 0) + { + running = true; + y = 0, r = 0, p = 0, tx = 0, ty = 0, tz = 0; + InterlockedCompareExchange((LONG volatile*) &pMemData->data.DataID, -1, 0); + } + else if (data_id > 0) + { + running = true; + } + else + { + running = false; + // clamp to zero + InterlockedExchange((LONG volatile*) &pMemData->data.DataID, -1); + } data->status = running ? NPCLIENT_STATUS_OK : NPCLIENT_STATUS_DISABLED; data->cksum = 0; @@ -377,7 +395,7 @@ NP_EXPORT(int) NP_GetParameter(int arg0, int arg1) * */ -static volatile unsigned char part2_2[200] = { +static unsigned char volatile const part2_2[200] = { 0xe3, 0xe5, 0x8e, 0xe8, 0x06, 0xd4, 0xab, 0xcf, 0xfa, 0x51, 0xa6, 0x84, 0x69, 0x52, 0x21, 0xde, 0x6b, 0x71, 0xe6, 0xac, 0xaa, @@ -396,7 +414,7 @@ static volatile unsigned char part2_2[200] = { }; -static volatile unsigned char part1_2[200] = { +static unsigned char volatile const part1_2[200] = { 0x6d, 0x0b, 0xab, 0x56, 0x74, 0xe6, 0x1c, 0xff, 0x24, 0xe8, 0x34, 0x8f, 0x00, 0x63, 0xed, 0x47, 0x5d, 0x9b, 0xe1, 0xe0, 0x1d, @@ -579,6 +597,8 @@ static bool FTCreateMapping(void) hFTMemMap = CreateFileMappingA(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, sizeof(FTMemMap), (LPCSTR) FT_MM_DATA); pMemData = (FTMemMap *) MapViewOfFile(hFTMemMap, FILE_MAP_WRITE, 0, 0, sizeof(FTMemMap)); + if (pMemData != NULL) + pMemData->data.DataID = 0; return pMemData != NULL; } diff --git a/proto-ft/ftnoir_protocol_ft.cpp b/proto-ft/ftnoir_protocol_ft.cpp index f119f502..0e07a103 100644 --- a/proto-ft/ftnoir_protocol_ft.cpp +++ b/proto-ft/ftnoir_protocol_ft.cpp @@ -13,8 +13,10 @@ #include "csv/csv.h" #include "opentrack-library-path.h" +#include <cstddef> #include <atomic> #include <cmath> +#include <cstdlib> #include <windows.h> #include <intrin.h> @@ -25,22 +27,6 @@ static int page_size() return system_info.dwPageSize; } -freetrack::freetrack() -{ -} - -freetrack::~freetrack() -{ - if (shm.success()) - { - const double tmp[6] {}; - pose(tmp); - } - - dummyTrackIR.close(); -} - -static_assert(sizeof(LONG) == sizeof(std::int32_t), ""); static_assert(sizeof(LONG) == 4u, ""); never_inline void store(float volatile& place, const float value) @@ -61,7 +47,7 @@ never_inline void store(float volatile& place, const float value) template<typename t, typename u> force_inline -std::enable_if_t<std::is_integral_v<t> && sizeof(t) == 4> +std::enable_if_t<(std::is_integral_v<t>) && sizeof(t) == 4> store(t volatile& place, u value) { (void)InterlockedExchange((LONG volatile*) &place, value); @@ -72,6 +58,23 @@ force_inline std::int32_t load(std::int32_t volatile& place) return InterlockedCompareExchange((volatile LONG*) &place, 0, 0); } +freetrack::freetrack() +{ +} + +freetrack::~freetrack() +{ + if (shm.success()) + { + const double tmp[6] {}; + pose(tmp); + store(pMemData->data.DataID, 0); + store(pMemData->GameID2, -1); + } + + dummyTrackIR.close(); +} + void freetrack::pose(const double* headpose) { const float yaw = -degrees_to_rads(headpose[Yaw]); @@ -95,6 +98,8 @@ void freetrack::pose(const double* headpose) store(data->Pitch, pitch); store(data->Roll, roll); + store(data->DataID, 60 * 30 + (rand() % 120)); + const std::int32_t id = load(ft->GameID); if (intGameID != id) @@ -109,37 +114,28 @@ void freetrack::pose(const double* headpose) (void)CSV::getGameData(id, t.table, gamename); - { - const std::uintptr_t addr = (std::uintptr_t)(void*)&pMemData->table[0]; - const std::uintptr_t addr_ = addr & ~(sizeof(LONG)-1u); - - static_assert(sizeof(LONG) == 4, ""); - static_assert(sizeof(int) == 4, ""); + static_assert(sizeof(LONG) == 4, ""); + static_assert(sizeof(int) == 4, ""); - // memory mappings are page-aligned due to TLB - if (std::intptr_t(pMemData) & page_size() - 1) - assert(!"proto/freetrack: memory mapping not page aligned"); + // memory mappings are page-aligned due to TLB + if ((std::intptr_t(pMemData) & page_size() - 1) != 0) + assert(!"proto/freetrack: memory mapping not page aligned"); - // the data happens to be aligned by virtue of element ordering - // inside FTHeap. there's no deeper reason behind it. - if (addr != addr_) - assert(!"proto/freetrack: unaligned access"); + // the data happens to be aligned by virtue of element ordering + // inside `FTHeap'. there's no deeper reason behind it. + static_assert((offsetof(FTHeap, table) & sizeof(int) - 1) == 0, ""); - // no unaligned atomic access for `char' - for (unsigned k = 0; k < 2; k++) - store(pMemData->table_ints[k], t.ints[k]); - } + // no atomic access for `char' + for (unsigned k = 0; k < 2; k++) + store(pMemData->table_ints[k], t.ints[k]); store(ft->GameID2, id); - store(data->DataID, 0); intGameID = id; QMutexLocker foo(&game_name_mutex); connected_game = gamename; } - else - (void)InterlockedAdd((LONG volatile*)&data->DataID, 1); } float freetrack::degrees_to_rads(double degrees) @@ -181,6 +177,7 @@ module_status freetrack::initialize() bool use_ft = false, use_npclient = false; switch (s.intUsedInterface) { + default: case 0: use_ft = true; use_npclient = true; @@ -191,17 +188,14 @@ module_status freetrack::initialize() case 2: use_npclient = true; break; - default: - break; } set_protocols(use_ft, use_npclient); - pMemData->data.DataID = 1; pMemData->data.CamWidth = 100; pMemData->data.CamHeight = 250; -#if 0 +#if 1 store(pMemData->data.X1, float(100)); store(pMemData->data.Y1, float(200)); store(pMemData->data.X2, float(300)); @@ -210,7 +204,7 @@ module_status freetrack::initialize() store(pMemData->data.Y3, float(100)); #endif - store(pMemData->GameID2, 0); + store(pMemData->GameID2, -1); for (unsigned k = 0; k < 2; k++) store(*(std::int32_t volatile*)&pMemData->table_ints[k], 0); |