Skip to content

Commit e693d42

Browse files
committed
Fixed bug #611
From Tim Angus 2008-08-12 11:18:06 I'm one of the maintainers of ioquake3.org, an updated version of the Quake 3 engine. Relatively recently, we moved ioq3 to use SDL as a replacement for 95% of the platform specific code that was there. On the whole it's doing a great job but unfortunately since the move we've been getting complaints about the quality of the mouse input on the Windows platform to the point where for many the game is unplayable. Put in other terms, the current stable SDL 1.2 is basically not fit for purpose if you need high quality mouse input as you do in a first person shooter. Over the weekend I decided to pull my finger out and actually figure out what's going on. There are basically two major problems. Firstly, when using the "windib" driver, mouse input is gathered via the WM_MOUSEMOVE message. Googling for this indicates that often this is known to result in "spurious" and/or "missing" mouse movement events; this is the primary cause of the poor mouse input. The second problem is that the "directx" driver does not work at all in combination with OpenGL meaning that you can't use DirectInput if your application also uses OpenGL. In other words you're locked into using the "windib" driver and its poor mouse input. In order to address these problems I've done the following: * Remove WM_MOUSEMOVE based motion event generation and replace with calls to GetCursorPos which seems much more reliable. In order to achieve this I've moved mouse motion out into a separate function that is called once per DIB_PumpEvents. * Remove the restriction on the "directx" driver being inoperable in combination with OpenGL. There is a bug for this issues that I've hijacked to a certain extent (http://bugzilla.libsdl.org/show_bug.cgi?id=265). I'm the first to admit I don't really understand why this restriction is there in the first place. The commit message for the bug fix that introduced this restriction (r581) isn't very elaborate and I couldn't see any other bug tracking the issue. If anyone has more information on the bug that was avoided by r581 it would be helpful as I/someone could then look into addressing the problem without disabling the "directx" driver. * I've also removed the restriction on not being allowed to use DirectInput in windowed mode. I couldn't see any reason for this, at least not from our perspective. I have my suspicions that it'll be something like matching up the cursor with the mouse coordinates... * I bumped up the DirectInput API used to version 7 in order to get access to mouse buttons 4-7. I've had to inject a little bit of the DX7 headers into SDL there as the MinGW ones aren't up to date in this respect.
1 parent 1b92065 commit e693d42

File tree

7 files changed

+190
-61
lines changed

7 files changed

+190
-61
lines changed

configure.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,7 @@ case "$host" in
24702470
# Set up the system libraries we need
24712471
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -luser32 -lgdi32 -lwinmm"
24722472
if test x$have_directx = xyes; then
2473-
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldxguid"
2473+
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -ldxguid -ldinput8"
24742474
fi
24752475
# The Win32 platform requires special setup
24762476
SOURCES="$SOURCES $srcdir/src/main/win32/*.rc"

src/video/wincommon/SDL_lowvideo.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,32 @@
5151
/* Hidden "this" pointer for the video functions */
5252
#define _THIS SDL_VideoDevice *this
5353

54+
#define FULLSCREEN() \
55+
((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN)
56+
5457
#define WINDIB_FULLSCREEN() \
5558
( \
5659
SDL_VideoSurface && \
57-
((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
60+
FULLSCREEN() && \
5861
(((SDL_VideoSurface->flags & SDL_OPENGL ) == SDL_OPENGL ) || \
5962
((SDL_strcmp(this->name, "windib") == 0) || \
6063
(SDL_strcmp(this->name, "gapi") == 0))) \
6164
)
6265
#define DDRAW_FULLSCREEN() \
6366
( \
6467
SDL_VideoSurface && \
65-
((SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && \
68+
FULLSCREEN() && \
6669
((SDL_VideoSurface->flags & SDL_OPENGL ) != SDL_OPENGL ) && \
6770
(SDL_strcmp(this->name, "directx") == 0) \
6871
)
6972

70-
#define DINPUT_FULLSCREEN() DDRAW_FULLSCREEN()
73+
#define DINPUT_FULLSCREEN() \
74+
( \
75+
FULLSCREEN() && \
76+
(strcmp(this->name, "directx") == 0) \
77+
)
78+
79+
#define DINPUT() (strcmp(this->name, "directx") == 0)
7180

7281
/* The main window -- and a function to set it for the audio */
7382
#ifdef _WIN32_WCE

src/video/wincommon/SDL_sysevents.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
363363
{
364364
SDL_VideoDevice *this = current_video;
365365
static int mouse_pressed = 0;
366-
static int in_window = 0;
367366
#ifdef WMMSG_DEBUG
368367
fprintf(stderr, "Received windows message: ");
369368
if ( msg > MAX_WMMSG ) {
@@ -508,7 +507,7 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
508507
case WM_XBUTTONDOWN:
509508
case WM_XBUTTONUP: {
510509
/* Mouse is handled by DirectInput when fullscreen */
511-
if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
510+
if ( SDL_VideoSurface && ! DINPUT() ) {
512511
WORD xbuttonval = 0;
513512
Sint16 x, y;
514513
Uint8 button, state;
@@ -606,7 +605,7 @@ LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
606605

607606
#if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
608607
case WM_MOUSEWHEEL:
609-
if ( SDL_VideoSurface && ! DINPUT_FULLSCREEN() ) {
608+
if ( SDL_VideoSurface && ! DINPUT() ) {
610609
int move = (short)HIWORD(wParam);
611610
if ( move ) {
612611
Uint8 button;

src/video/wincommon/SDL_sysmouse.c

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ int WIN_ShowWMCursor(_THIS, WMcursor *cursor)
188188
{
189189
POINT mouse_pos;
190190

191-
/* The fullscreen cursor must be done in software with DirectInput */
192-
if ( !this->screen || DDRAW_FULLSCREEN() ) {
191+
if ( !this->screen ) {
193192
return(0);
194193
}
195194

@@ -208,15 +207,20 @@ int WIN_ShowWMCursor(_THIS, WMcursor *cursor)
208207

209208
void WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
210209
{
211-
if ( DDRAW_FULLSCREEN() ) {
212-
SDL_PrivateMouseMotion(0, 0, x, y);
213-
} else if ( mouse_relative) {
210+
if ( mouse_relative) {
214211
/* RJR: March 28, 2000
215212
leave physical cursor at center of screen if
216213
mouse hidden and grabbed */
217214
SDL_PrivateMouseMotion(0, 0, x, y);
218215
} else {
219216
POINT pt;
217+
218+
/* With DirectInput the position doesn't follow
219+
* the cursor, so it is set manually */
220+
if ( DINPUT() ) {
221+
SDL_PrivateMouseMotion(0, 0, x, y);
222+
}
223+
220224
pt.x = x;
221225
pt.y = y;
222226
ClientToScreen(SDL_Window, &pt);
@@ -227,20 +231,15 @@ void WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
227231
/* Update the current mouse state and position */
228232
void WIN_UpdateMouse(_THIS)
229233
{
230-
RECT rect;
231234
POINT pt;
232235

233-
if ( ! DDRAW_FULLSCREEN() ) {
234-
GetClientRect(SDL_Window, &rect);
235-
GetCursorPos(&pt);
236-
MapWindowPoints(NULL, SDL_Window, &pt, 1);
237-
if (PtInRect(&rect, pt) && (WindowFromPoint(pt) == SDL_Window)){
238-
SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
239-
SDL_PrivateMouseMotion(0,0, (Sint16)pt.x, (Sint16)pt.y);
240-
} else {
241-
SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
242-
}
243-
}
236+
/* Always unset SDL_APPMOUSEFOCUS to give the WM_MOUSEMOVE event
237+
* handler a chance to install a TRACKMOUSEEVENT */
238+
SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
239+
240+
GetCursorPos(&pt);
241+
ScreenToClient(SDL_Window, &pt);
242+
SDL_PrivateMouseMotion(0,0, (Sint16)pt.x, (Sint16)pt.y);
244243
}
245244

246245
/* Check to see if we need to enter or leave mouse relative mode */

src/video/windib/SDL_dibevents.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,36 @@ LRESULT DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar
271271
return(DefWindowProc(hwnd, msg, wParam, lParam));
272272
}
273273

274+
static void DIB_GenerateMouseMotionEvent(void)
275+
{
276+
extern int mouse_relative;
277+
extern int posted;
278+
279+
POINT mouse;
280+
GetCursorPos( &mouse );
281+
282+
if ( mouse_relative ) {
283+
POINT center;
284+
center.x = (SDL_VideoSurface->w/2);
285+
center.y = (SDL_VideoSurface->h/2);
286+
ClientToScreen(SDL_Window, &center);
287+
288+
mouse.x -= (Sint16)center.x;
289+
mouse.y -= (Sint16)center.y;
290+
if ( mouse.x || mouse.y ) {
291+
SetCursorPos(center.x, center.y);
292+
posted = SDL_PrivateMouseMotion(0, 1, mouse.x, mouse.y);
293+
}
294+
} else if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
295+
ScreenToClient(SDL_Window, &mouse);
296+
#ifdef _WIN32_WCE
297+
if (SDL_VideoSurface)
298+
GapiTransform(this->hidden->userOrientation, this->hidden->hiresFix, &mouse.x, &mouse.y);
299+
#endif
300+
posted = SDL_PrivateMouseMotion(0, 0, mouse.x, mouse.y);
301+
}
302+
}
303+
274304
void DIB_PumpEvents(_THIS)
275305
{
276306
MSG msg;
@@ -280,6 +310,10 @@ void DIB_PumpEvents(_THIS)
280310
DispatchMessage(&msg);
281311
}
282312
}
313+
314+
if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) {
315+
DIB_GenerateMouseMotionEvent( );
316+
}
283317
}
284318

285319
static HKL hLayoutUS = NULL;

0 commit comments

Comments
 (0)