mirror of
https://github.com/DrBeef/Raze.git
synced 2025-01-18 15:11:51 +00:00
Better mouse fix?
git-svn-id: https://svn.eduke32.com/eduke32@1606 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
33780b42e9
commit
da1bdf711c
1 changed files with 66 additions and 85 deletions
|
@ -725,7 +725,7 @@ static HMODULE hDInputDLL = NULL;
|
|||
static LPDIRECTINPUT7A lpDI = NULL;
|
||||
static LPDIRECTINPUTDEVICE7A lpDID[NUM_INPUTS] = { NULL, NULL, NULL };
|
||||
static BOOL bDInputInited = FALSE;
|
||||
#define INPUT_BUFFER_SIZE 32
|
||||
#define INPUT_BUFFER_SIZE 256
|
||||
static GUID guidDevs[NUM_INPUTS];
|
||||
|
||||
static char devacquired[NUM_INPUTS] = { 0,0,0 };
|
||||
|
@ -886,68 +886,6 @@ void setkeypresscallback(void (*callback)(int32_t, int32_t)) { keypresscallback
|
|||
void setmousepresscallback(void (*callback)(int32_t, int32_t)) { mousepresscallback = callback; }
|
||||
void setjoypresscallback(void (*callback)(int32_t, int32_t)) { joypresscallback = callback; }
|
||||
|
||||
DWORD WINAPI ProcessMouse(LPVOID lpThreadParameter)
|
||||
{
|
||||
int32_t i;
|
||||
DIMOUSESTATE2 mousestate;
|
||||
|
||||
UNREFERENCED_PARAMETER(lpThreadParameter);
|
||||
|
||||
while (moustat && lpDID[MOUSE])
|
||||
{
|
||||
if (!appactive || !mousegrab)
|
||||
{
|
||||
Sleep(100);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((WaitForSingleObject(inputevt[MOUSE], INFINITE)) != WAIT_OBJECT_0)
|
||||
continue;
|
||||
|
||||
if (IDirectInputDevice7_GetDeviceState(lpDID[MOUSE], sizeof(DIMOUSESTATE2),
|
||||
(LPDIMOUSESTATE2)&mousestate) != DI_OK)
|
||||
continue;
|
||||
|
||||
mousex += (int16_t)mousestate.lX;
|
||||
mousey += (int16_t)mousestate.lY;
|
||||
|
||||
if (mousestate.lZ > 0) // wheel up
|
||||
{
|
||||
if (mousewheel[0] > 0 && mousepresscallback) mousepresscallback(5,0);
|
||||
mousewheel[0] = getticks();
|
||||
mouseb |= 16;
|
||||
if (mousepresscallback) mousepresscallback(5, 1);
|
||||
}
|
||||
else if (mousestate.lZ < 0) // wheel down
|
||||
{
|
||||
if (mousewheel[1] > 0 && mousepresscallback) mousepresscallback(6,0);
|
||||
mousewheel[1] = getticks();
|
||||
mouseb |= 32;
|
||||
if (mousepresscallback) mousepresscallback(6, 1);
|
||||
}
|
||||
|
||||
for (i=0; i<4; i++)
|
||||
{
|
||||
if (mousestate.rgbButtons[i] & 0x80) mouseb |= 1<<i;
|
||||
else mouseb &= ~(1<<i);
|
||||
|
||||
if (mousepresscallback)
|
||||
mousepresscallback(i, mouseb & (1<<i));
|
||||
}
|
||||
|
||||
// wheel up and down are sent to the game as buttons 5 and 6, so we offset these
|
||||
for (i=4; i<8; i++)
|
||||
{
|
||||
if (mousestate.rgbButtons[i] & 0x80) mouseb |= 1<<(i+2);
|
||||
else mouseb &= ~(1<<(i+2));
|
||||
|
||||
if (mousepresscallback)
|
||||
mousepresscallback(i, mouseb & (1<<(i+2)));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// initmouse() -- init mouse input
|
||||
//
|
||||
|
@ -960,25 +898,6 @@ int32_t initmouse(void)
|
|||
// initprintf("Initializing mouse... ");
|
||||
|
||||
moustat=1;
|
||||
mousethread = CreateThread
|
||||
(
|
||||
NULL,
|
||||
0,
|
||||
ProcessMouse,
|
||||
NULL,
|
||||
CREATE_SUSPENDED,
|
||||
&threadid
|
||||
);
|
||||
|
||||
if (!mousethread)
|
||||
{
|
||||
initprintf("Failed to create mouse thread!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SetThreadPriority(mousethread, THREAD_PRIORITY_TIME_CRITICAL);
|
||||
ResumeThread(mousethread);
|
||||
// initprintf("OK\n");
|
||||
|
||||
// grab input
|
||||
grabmouse(1);
|
||||
|
@ -1028,8 +947,7 @@ void readmousexy(int32_t *x, int32_t *y)
|
|||
if (!moustat || !devacquired[MOUSE] || !mousegrab) { *x = *y = 0; return; }
|
||||
*x = mousex;
|
||||
*y = mousey;
|
||||
mousex -= *x;
|
||||
mousey -= *y;
|
||||
mousex = mousey = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1630,7 +1548,7 @@ static inline void ProcessInputDevices(void)
|
|||
|
||||
for (t = 0; t < NUM_INPUTS; t++)
|
||||
{
|
||||
if (*devicedef[t].did&&t!=MOUSE)
|
||||
if (*devicedef[t].did)
|
||||
{
|
||||
result = IDirectInputDevice7_Poll(*devicedef[t].did);
|
||||
if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED)
|
||||
|
@ -1681,6 +1599,69 @@ static inline void ProcessInputDevices(void)
|
|||
{
|
||||
switch (idevnums[ev - WAIT_OBJECT_0])
|
||||
{
|
||||
case MOUSE:
|
||||
if (moustat)
|
||||
{
|
||||
dwElements = INPUT_BUFFER_SIZE;
|
||||
|
||||
result = IDirectInputDevice7_GetDeviceData(lpDID[MOUSE], sizeof(DIDEVICEOBJECTDATA),
|
||||
(LPDIDEVICEOBJECTDATA)&didod[0], &dwElements, 0);
|
||||
|
||||
if (!dwElements || (result != DI_OK && result != DI_BUFFEROVERFLOW))
|
||||
break;
|
||||
|
||||
do
|
||||
{
|
||||
int32_t bit = 1<<(didod[dwElements-1].dwOfs - DIMOFS_BUTTON0);
|
||||
|
||||
switch (didod[dwElements-1].dwOfs)
|
||||
{
|
||||
case DIMOFS_X:
|
||||
mousex += (int16_t)didod[dwElements-1].dwData;
|
||||
break;
|
||||
case DIMOFS_Y:
|
||||
mousey += (int16_t)didod[dwElements-1].dwData;
|
||||
break;
|
||||
case DIMOFS_Z:
|
||||
{
|
||||
if ((int32_t)didod[dwElements-1].dwData > 0) // wheel up
|
||||
{
|
||||
if (mousewheel[0] > 0 && mousepresscallback) mousepresscallback(5,0);
|
||||
mousewheel[0] = getticks();
|
||||
mouseb |= 16;
|
||||
if (mousepresscallback) mousepresscallback(5, 1);
|
||||
}
|
||||
else if ((int32_t)didod[dwElements-1].dwData < 0) // wheel down
|
||||
{
|
||||
if (mousewheel[1] > 0 && mousepresscallback) mousepresscallback(6,0);
|
||||
mousewheel[1] = getticks();
|
||||
mouseb |= 32;
|
||||
if (mousepresscallback) mousepresscallback(6, 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case DIMOFS_BUTTON4:
|
||||
case DIMOFS_BUTTON5:
|
||||
case DIMOFS_BUTTON6:
|
||||
case DIMOFS_BUTTON7:
|
||||
didod[dwElements-1].dwOfs += 2; // skip mousewheel buttons
|
||||
bit = 1<<(didod[dwElements-1].dwOfs - DIMOFS_BUTTON0);
|
||||
case DIMOFS_BUTTON0:
|
||||
case DIMOFS_BUTTON1:
|
||||
case DIMOFS_BUTTON2:
|
||||
case DIMOFS_BUTTON3:
|
||||
if (didod[dwElements-1].dwData & 0x80) mouseb |= bit;
|
||||
else mouseb &= ~bit;
|
||||
if (mousepresscallback)
|
||||
mousepresscallback(didod[dwElements-1].dwOfs - DIMOFS_BUTTON0 + 1, mouseb & bit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (--dwElements);
|
||||
}
|
||||
break;
|
||||
|
||||
case KEYBOARD: // keyboard
|
||||
if (!lpDID[KEYBOARD]) break;
|
||||
result = IDirectInputDevice7_GetDeviceData(lpDID[KEYBOARD], sizeof(DIDEVICEOBJECTDATA),
|
||||
|
|
Loading…
Reference in a new issue