Skip to content

Commit 79095dd

Browse files
committed
Tweak high frequency mouse
Always get mouse data if no data is cached, merge like records even if the sign is different. #481
1 parent cc18a16 commit 79095dd

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed

Dllmain/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 8135
1+
#define BUILD_NUMBER 8136

dinput8/IDirectInputDevice8.cpp

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "ScopeGuard.h"
1919
#include "GDI\WndProc.h"
2020

21-
constexpr DWORD SignBit = 0x80000000;
22-
2321
HRESULT m_IDirectInputDevice8::QueryInterface(REFIID riid, LPVOID* ppvObj)
2422
{
2523
Logging::LogDebug() << __FUNCTION__ << " (" << this << ")";
@@ -157,7 +155,6 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
157155
ScopedCriticalSection ThreadLock(&dics);
158156

159157
// Get latest mouse data from the DirectInput8 buffer
160-
if (*pdwInOut > dod.size())
161158
{
162159
// Get buffer
163160
DWORD dwItems = 0;
@@ -175,7 +172,7 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
175172
bool isSet[3] = { false };
176173
DWORD Loc[3] = { 0 };
177174

178-
// Check for existing records to merge
175+
// Get location of existing records
179176
for (UINT x = 0; x < dod.size(); x++)
180177
{
181178
// Movement record exists
@@ -207,8 +204,7 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
207204
int v = lpdod->dwOfs == DIMOFS_X ? 0 : lpdod->dwOfs == DIMOFS_Y ? 1 : 2;
208205

209206
// Merge records
210-
if (isSet[v] && // Check if there is an existing record
211-
(dod[Loc[v]].lData & SignBit) == (lpdod->dwData & SignBit)) // Check if the mouse direction is the same
207+
if (isSet[v])
212208
{
213209
dod[Loc[v]].lData += (LONG)lpdod->dwData;
214210
dod[Loc[v]].dwTimeStamp = lpdod->dwTimeStamp;
@@ -236,47 +232,46 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
236232
isSet[1] = false;
237233
isSet[2] = false;
238234
}
239-
lpdod = (LPDIDEVICEOBJECTDATA)((DWORD)lpdod + cbObjectData);
235+
lpdod = (LPDIDEVICEOBJECTDATA)((BYTE*)lpdod + cbObjectData);
240236
}
241237
}
242238

243239
DWORD dwOut = 0;
244240

245-
// Checking for overflow
246-
if (rgdod == nullptr && *pdwInOut == 0)
247-
{
248-
// Never return overflow
249-
}
250-
// Flush buffer
251-
else if (rgdod == nullptr && *pdwInOut == INFINITE && !isPeek)
241+
// Checking for device object data
242+
if (rgdod == nullptr)
252243
{
253-
dod.clear();
254-
}
255-
// Number of records in the buffer
256-
else if (rgdod == nullptr && *pdwInOut == INFINITE && isPeek)
257-
{
258-
dwOut = dod.size();
244+
// Flush buffer
245+
if (*pdwInOut == INFINITE && !isPeek)
246+
{
247+
dod.clear();
248+
}
249+
// Get number of records in the buffer
250+
else
251+
{
252+
dwOut = dod.size();
253+
}
259254
}
260255
// Fill device object data
261-
else if (rgdod)
256+
else
262257
{
263258
LPDIDEVICEOBJECTDATA p_rgdod = rgdod;
264259

260+
// Loop through each object
265261
for (DWORD i = 0; i < *pdwInOut; i++)
266262
{
267263
if (dwOut < dod.size())
268264
{
269265
p_rgdod->dwOfs = dod[dwOut].dwOfs;
270266
if (p_rgdod->dwOfs == DIMOFS_X || p_rgdod->dwOfs == DIMOFS_Y)
271267
{
272-
double factor = (p_rgdod->dwOfs == DIMOFS_Y) ? Config.MouseMovementFactor : abs(Config.MouseMovementFactor);
273-
LONG baseMovement = (LONG)round(dod[dwOut].lData * factor);
274-
if (baseMovement != 0)
268+
if (dod[dwOut].lData != 0)
275269
{
270+
double factor = (p_rgdod->dwOfs == DIMOFS_Y) ? Config.MouseMovementFactor : abs(Config.MouseMovementFactor);
271+
LONG baseMovement = (LONG)round(dod[dwOut].lData * factor);
276272
if (abs(baseMovement) < (LONG)Config.MouseMovementPadding)
277273
{
278-
LONG Sign = (baseMovement < 0) ? -1 : 1;
279-
p_rgdod->dwData = Sign * (LONG)Config.MouseMovementPadding;
274+
p_rgdod->dwData = (baseMovement < 0) ? -(LONG)Config.MouseMovementPadding : (LONG)Config.MouseMovementPadding;
280275
}
281276
else
282277
{
@@ -306,27 +301,20 @@ HRESULT m_IDirectInputDevice8::GetMouseDeviceData(DWORD cbObjectData, LPDIDEVICE
306301
{
307302
break;
308303
}
309-
p_rgdod = (LPDIDEVICEOBJECTDATA)((DWORD)p_rgdod + cbObjectData);
304+
p_rgdod = (LPDIDEVICEOBJECTDATA)((BYTE*)p_rgdod + cbObjectData);
310305
}
311-
}
312306

313-
// Remove used entries from buffer
314-
if (!isPeek && dwOut)
315-
{
316-
// Save unsent mouse data
317-
if (dwOut < dod.size())
307+
// Remove used entries from buffer
308+
if (dwOut)
318309
{
319-
std::vector<MOUSECACHEDATA> tmp_dod;
320-
for (size_t x = dwOut; x < dod.size(); x++)
310+
if (dwOut < dod.size())
321311
{
322-
tmp_dod.push_back(dod[x]);
312+
dod.erase(dod.begin(), dod.begin() + dwOut);
313+
}
314+
else
315+
{
316+
dod.clear();
323317
}
324-
dod = std::move(tmp_dod);
325-
}
326-
// Clear buffer if all entries were used
327-
else
328-
{
329-
dod.clear();
330318
}
331319
}
332320

0 commit comments

Comments
 (0)