X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=vid_wgl.c;h=4f97d31a716e057d63007f1364dd535e36acd8b1;hb=3eb300b2b135dd6eaed51c703f2d1622cac55732;hp=38c4d868ce1acb0e2f42b75a017c4eecd77c7a4d;hpb=cd7454f9df6b152a24c5a28750041d27023fbc1f;p=xonotic%2Fdarkplaces.git diff --git a/vid_wgl.c b/vid_wgl.c index 38c4d868..4f97d31a 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -131,6 +131,8 @@ static HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, LP #ifndef MK_XBUTTON1 #define MK_XBUTTON1 0x0020 #define MK_XBUTTON2 0x0040 +#endif +#ifndef MK_XBUTTON3 // LordHavoc: lets hope this allows more buttons in the future... #define MK_XBUTTON3 0x0080 #define MK_XBUTTON4 0x0100 @@ -144,11 +146,7 @@ static HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, LP static int mouse_buttons; static int mouse_oldbuttonstate; -static qboolean restore_spi; -static int originalmouseparms[3], newmouseparms[3] = {0, 0, 0}; - static unsigned int uiWheelMessage; -static qboolean mouseparmsvalid; static qboolean dinput_acquired; static unsigned int mstate_di; @@ -218,39 +216,6 @@ static JOYINFOEX ji; static HINSTANCE hInstDI; -//static qboolean dinput; - -typedef struct MYDATA { - LONG lX; // X axis goes here - LONG lY; // Y axis goes here - LONG lZ; // Z axis goes here - BYTE bButtonA; // One button goes here - BYTE bButtonB; // Another button goes here - BYTE bButtonC; // Another button goes here - BYTE bButtonD; // Another button goes here -} MYDATA; - -static DIOBJECTDATAFORMAT rgodf[] = { - { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,}, - { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,}, - { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, -}; - -#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0])) - -static DIDATAFORMAT df = { - sizeof(DIDATAFORMAT), // this structure - sizeof(DIOBJECTDATAFORMAT), // size of object data format - DIDF_RELAXIS, // absolute axis coordinates - sizeof(MYDATA), // device data size - NUM_OBJECTS, // number of objects - rgodf, // and here they are -}; - // forward-referenced functions static void IN_StartupJoystick (void); static void Joy_AdvancedUpdate_f (void); @@ -417,16 +382,22 @@ void AppActivate(BOOL fActive, BOOL minimize) vid_activewindow = fActive; vid_hidden = minimize; -// enable/disable sound on focus gain/loss - if (!vid_activewindow && sound_active) + // enable/disable sound on focus gain/loss + if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer)) { - S_BlockSound (); - sound_active = false; + if (!sound_active) + { + S_UnblockSound (); + sound_active = true; + } } - else if (vid_activewindow && !sound_active) + else { - S_UnblockSound (); - sound_active = true; + if (sound_active) + { + S_BlockSound (); + sound_active = false; + } } if (fActive) @@ -465,7 +436,7 @@ void Sys_SendKeyEvents (void) while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage (&msg, NULL, 0, 0)) - Sys_Quit (); + Sys_Quit (1); TranslateMessage (&msg); DispatchMessage (&msg); @@ -618,7 +589,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_CLOSE: if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES) - Sys_Quit (); + Sys_Quit (0); break; @@ -728,7 +699,7 @@ void VID_Init(void) IN_Init(); } -int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrate) +int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer) { int i; HDC hdc; @@ -776,6 +747,9 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat pfd.cAlphaBits = 0; } + if (stereobuffer) + pfd.dwFlags |= PFD_STEREO; + gldrivername = "opengl32.dll"; // COMMANDLINEOPTION: Windows WGL: -gl_driver selects a GL driver library, default is opengl32.dll, useful only for 3dfxogl.dll or 3dfxvgl.dll, if you don't know what this is for, you don't need it i = COM_CheckParm("-gl_driver"); @@ -862,7 +836,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL); if (!mainwindow) { - Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %d, %p) failed\n", ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL); + Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %d, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), NULL, NULL, (int)global_hInstance, NULL); VID_Shutdown(); return false; } @@ -903,14 +877,14 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat if ((pixelformat = ChoosePixelFormat(baseDC, &pfd)) == 0) { VID_Shutdown(); - Con_Printf("ChoosePixelFormat(%d, %p) failed\n", baseDC, &pfd); + Con_Printf("ChoosePixelFormat(%d, %p) failed\n", (int)baseDC, &pfd); return false; } if (SetPixelFormat(baseDC, pixelformat, &pfd) == false) { VID_Shutdown(); - Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", baseDC, pixelformat, &pfd); + Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", (int)baseDC, pixelformat, &pfd); return false; } @@ -931,7 +905,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat if (!qwglMakeCurrent(baseDC, baseRC)) { VID_Shutdown(); - Con_Printf("wglMakeCurrent(%d, %d) failed\n", baseDC, baseRC); + Con_Printf("wglMakeCurrent(%d, %d) failed\n", (int)baseDC, (int)baseRC); return false; } @@ -1019,6 +993,9 @@ void VID_Shutdown (void) static void IN_Activate (qboolean grab) { + static qboolean restore_spi; + static int originalmouseparms[3]; + if (!mouseinitialized) return; @@ -1027,7 +1004,7 @@ static void IN_Activate (qboolean grab) if (!vid_usingmouse) { vid_usingmouse = true; - cl_ignoremousemove = true; + cl_ignoremousemoves = 2; if (dinput && g_pMouse) { IDirectInputDevice_Acquire(g_pMouse); @@ -1040,9 +1017,21 @@ static void IN_Activate (qboolean grab) window_rect.top = window_y; window_rect.right = window_x + vid.width; window_rect.bottom = window_y + vid.height; - if (mouseparmsvalid) + + // change mouse settings to turn off acceleration +// COMMANDLINEOPTION: Windows GDI Input: -noforcemparms disables setting of mouse parameters (not used with -dinput, windows only) + if (!COM_CheckParm ("-noforcemparms") && SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0)) + { + int newmouseparms[3]; + newmouseparms[0] = 0; // threshold to double movement (only if accel level is >= 1) + newmouseparms[1] = 0; // threshold to quadruple movement (only if accel level is >= 2) + newmouseparms[2] = 0; // maximum level of acceleration (0 = off) restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0); + } + else + restore_spi = false; SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2)); + SetCapture (mainwindow); ClipCursor (&window_rect); } @@ -1054,7 +1043,7 @@ static void IN_Activate (qboolean grab) if (vid_usingmouse) { vid_usingmouse = false; - cl_ignoremousemove = true; + cl_ignoremousemoves = 2; if (dinput_acquired) { IDirectInputDevice_Unacquire(g_pMouse); @@ -1062,8 +1051,10 @@ static void IN_Activate (qboolean grab) } else { + // restore system mouseparms if we changed them if (restore_spi) SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0); + restore_spi = false; ClipCursor (NULL); ReleaseCapture (); } @@ -1131,7 +1122,7 @@ static qboolean IN_InitDInput (void) } // set the data format to "mouse format". - hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df); + hr = IDirectInputDevice_SetDataFormat(g_pMouse, &c_dfDIMouse); if (FAILED(hr)) { @@ -1171,7 +1162,7 @@ IN_StartupMouse */ static void IN_StartupMouse (void) { - if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe")) + if (COM_CheckParm ("-nomouse")) return; mouseinitialized = true; @@ -1185,30 +1176,6 @@ static void IN_StartupMouse (void) else Con_Print("DirectInput not initialized\n"); - mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0); - - if (mouseparmsvalid) - { -// COMMANDLINEOPTION: Windows GDI Input: -noforcemspd disables setting of mouse speed (not used with -dinput, windows only) - if ( COM_CheckParm ("-noforcemspd") ) - newmouseparms[2] = originalmouseparms[2]; - -// COMMANDLINEOPTION: Windows GDI Input: -noforcemaccel disables setting of mouse acceleration (not used with -dinput, windows only) - if ( COM_CheckParm ("-noforcemaccel") ) - { - newmouseparms[0] = originalmouseparms[0]; - newmouseparms[1] = originalmouseparms[1]; - } - -// COMMANDLINEOPTION: Windows GDI Input: -noforcemparms disables setting of mouse parameters (not used with -dinput, windows only) - if ( COM_CheckParm ("-noforcemparms") ) - { - newmouseparms[0] = originalmouseparms[0]; - newmouseparms[1] = originalmouseparms[1]; - newmouseparms[2] = originalmouseparms[2]; - } - } - mouse_buttons = 10; } @@ -1260,11 +1227,24 @@ static void IN_MouseMove (void) switch (od.dwOfs) { case DIMOFS_X: - mx += od.dwData; + mx += (LONG) od.dwData; break; case DIMOFS_Y: - my += od.dwData; + my += (LONG) od.dwData; + break; + + case DIMOFS_Z: + if((LONG) od.dwData < 0) + { + Key_Event (K_MWHEELDOWN, 0, true); + Key_Event (K_MWHEELDOWN, 0, false); + } + else if((LONG) od.dwData > 0) + { + Key_Event (K_MWHEELUP, 0, true); + Key_Event (K_MWHEELUP, 0, false); + } break; case DIMOFS_BUTTON0: @@ -1287,6 +1267,13 @@ static void IN_MouseMove (void) else mstate_di &= ~(1<<2); break; + + case DIMOFS_BUTTON3: + if (od.dwData & 0x80) + mstate_di |= (1<<3); + else + mstate_di &= ~(1<<3); + break; } } @@ -1348,7 +1335,7 @@ static void IN_StartupJoystick (void) // abort startup if user requests no joystick // COMMANDLINEOPTION: Windows Input: -nojoy disables joystick support, may be a small speed increase - if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe")) + if (COM_CheckParm ("-nojoy")) return; // verify joystick driver is present