From 3ac3b8edbb719cf145e97e38596a8c37ea0b1166 Mon Sep 17 00:00:00 2001 From: Elisha Riedlinger Date: Thu, 27 Jun 2024 12:37:57 -0700 Subject: [PATCH] Only merge sequential records #280 --- Dllmain/BuildNo.rc | 2 +- dinput8/IDirectInputDevice8.cpp | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Dllmain/BuildNo.rc b/Dllmain/BuildNo.rc index e82d8eed..0b1c088d 100644 --- a/Dllmain/BuildNo.rc +++ b/Dllmain/BuildNo.rc @@ -1 +1 @@ -#define BUILD_NUMBER 7066 +#define BUILD_NUMBER 7067 diff --git a/dinput8/IDirectInputDevice8.cpp b/dinput8/IDirectInputDevice8.cpp index ae17a470..9dd86bf3 100644 --- a/dinput8/IDirectInputDevice8.cpp +++ b/dinput8/IDirectInputDevice8.cpp @@ -173,21 +173,21 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE } // Loop through buffer and merge like data - bool isSet[3] = {}; - DWORD Loc[3] = {}; + bool isSet[2] = { false }; + DWORD Loc[2] = { 0 }; for (UINT x = 0; x < dwItems; x++) { // Storing movement data - if (lpdod->dwOfs == DIMOFS_X || lpdod->dwOfs == DIMOFS_Y || lpdod->dwOfs == DIMOFS_Z) + if (lpdod->dwOfs == DIMOFS_X || lpdod->dwOfs == DIMOFS_Y) { - int v = lpdod->dwOfs == DIMOFS_X ? 0 : - lpdod->dwOfs == DIMOFS_Y ? 1 : - lpdod->dwOfs == DIMOFS_Z ? 2 : 0; + int v = lpdod->dwOfs == DIMOFS_X ? 0 : 1; - // Check if record should be merged, if there is an existing record and the movement direction has not changed - if (isSet[v] && (dod[Loc[v]].lData & SignBit) == (lpdod->dwData & SignBit)) + // Merge sequential records + if (isSet[v] && // Check if there is an existing record + (dod[Loc[v]].lData & SignBit) == (lpdod->dwData & SignBit) && // Check if the mouse direction is the same + ((isSet[0] && dod[Loc[0]].dwSequence + 1 == lpdod->dwSequence) || + (isSet[1] && dod[Loc[1]].dwSequence + 1 == lpdod->dwSequence))) // Check if it is the next entry in the sequence { - // Updating movement data (merging records) dod[Loc[v]].lData += (LONG)lpdod->dwData; dod[Loc[v]].dwTimeStamp = lpdod->dwTimeStamp; dod[Loc[v]].dwSequence = lpdod->dwSequence; @@ -208,11 +208,6 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE else { dod.push_back({ (LONG)lpdod->dwData, lpdod->dwOfs, lpdod->dwTimeStamp, lpdod->dwSequence, (cbObjectData == sizeof(DIDEVICEOBJECTDATA)) ? lpdod->uAppData : NULL }); - - // Reset movement data - isSet[0] = false; - isSet[1] = false; - isSet[2] = false; } lpdod = (LPDIDEVICEOBJECTDATA)((DWORD)lpdod + cbObjectData); }