X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=vid_wgl.c;h=e079fd84c0ffe506c153812a522653271d939d87;hb=380c83758fd51d7dd2d53802141e63747fe2dbd1;hp=b5ecef718dce6a0b031d55695b938439aa6fee6f;hpb=ee66bae6438ee948c6facb49534a4776f4034515;p=xonotic%2Fdarkplaces.git diff --git a/vid_wgl.c b/vid_wgl.c index b5ecef71..e079fd84 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -17,10 +17,16 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// gl_vidnt.c -- NT GL vid component +// vid_wgl.c -- NT GL vid component -// we don't need a very new dinput -#define DIRECTINPUT_VERSION 0x0300 +#ifdef SUPPORTDIRECTX +// Include DX libs +#pragma comment(lib, "dinput8.lib") +#pragma comment(lib, "dxguid.lib") +#ifndef DIRECTINPUT_VERSION +# define DIRECTINPUT_VERSION 0x0500 /* Version 5.0 */ +#endif +#endif #include "quakedef.h" #include @@ -95,6 +101,7 @@ static DEVMODE gdevmode, initialdevmode; static qboolean vid_initialized = false; static qboolean vid_wassuspended = false; static qboolean vid_usingmouse = false; +static qboolean vid_usinghidecursor = false; static qboolean vid_usingvsync = false; static qboolean vid_usevsync = false; static HICON hIcon; @@ -121,8 +128,6 @@ static qboolean vid_isfullscreen; static int window_x, window_y; -static void IN_Activate (qboolean grab); - static qboolean mouseinitialized; #ifdef SUPPORTDIRECTX @@ -178,6 +183,16 @@ static unsigned int mstate_di; #define JOY_AXIS_U 4 #define JOY_AXIS_V 5 +// joystick axes state +typedef struct +{ + float oldmove; + float move; + float mdelta; + double keytime; +}joy_axiscache_t; +static joy_axiscache_t joy_axescache[JOY_MAX_AXES]; + enum _ControlList { AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn @@ -216,6 +231,7 @@ static cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0", "how fast static cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0", "how fast the joystick turns left/right"}; static cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0", "special hack for wingman warrior"}; static cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0", "special hack for wingman warrior"}; +static cvar_t joy_axiskeyevents = {CVAR_SAVE, "joy_axiskeyevents", "0", "generate uparrow/leftarrow etc. keyevents for joystick axes, use if your joystick driver is not generating them"}; static cvar_t vid_forcerefreshrate = {0, "vid_forcerefreshrate", "0", "try to set the given vid_refreshrate even if Windows doesn't list it as valid video mode"}; @@ -243,31 +259,19 @@ static void IN_StartupMouse (void); //==================================== -void VID_Finish (qboolean allowmousegrab) +void VID_Finish (void) { - qboolean vid_usemouse; - - vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable; - if (vid_usingvsync != vid_usevsync && gl_videosyncavailable) + vid_usevsync = vid_vsync.integer && !cls.timedemo && qwglSwapIntervalEXT; + if (vid_usingvsync != vid_usevsync) { vid_usingvsync = vid_usevsync; qwglSwapIntervalEXT (vid_usevsync); } -// handle the mouse state when windowed if that's changed - vid_usemouse = false; - if (allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback)) - vid_usemouse = true; - if (vid_isfullscreen) - vid_usemouse = true; - if (!vid_activewindow) - vid_usemouse = false; - IN_Activate(vid_usemouse); - - if (r_render.integer && !vid_hidden) + if (!vid_hidden) { CHECKGLERROR - if (r_speeds.integer || gl_finish.integer) + if (r_speeds.integer == 2 || gl_finish.integer) { qglFinish();CHECKGLERROR } @@ -402,11 +406,11 @@ void AppActivate(BOOL fActive, BOOL minimize) { static qboolean sound_active = false; // initially blocked by Sys_InitConsole() - vid_activewindow = fActive; - vid_hidden = minimize; + vid_activewindow = fActive != FALSE; + vid_hidden = minimize != FALSE; // enable/disable sound on focus gain/loss - if (!vid_hidden && (vid_activewindow || !snd_mutewhenidle.integer)) + if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer) { if (!sound_active) { @@ -441,7 +445,7 @@ void AppActivate(BOOL fActive, BOOL minimize) if (!fActive) { - IN_Activate (false); + VID_SetMouse(false, false, false); if (vid_isfullscreen) { ChangeDisplaySettings (NULL, 0); @@ -489,12 +493,13 @@ static keynum_t buttonremap[16] = }; /* main window procedure */ +static qboolean IN_JoystickBlockDoubledKeyEvents(int keycode); LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LONG lRet = 1; int fActive, fMinimized, temp; - char state[256]; - char asciichar[4]; + unsigned char state[256]; + unsigned char asciichar[4]; int vkey; int charlength; qboolean down = false; @@ -515,7 +520,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOVE: window_x = (int) LOWORD(lParam); window_y = (int) HIWORD(lParam); - IN_Activate(false); + VID_SetMouse(false, false, false); break; case WM_KEYDOWN: @@ -527,13 +532,14 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) GetKeyboardState (state); // alt/ctrl/shift tend to produce funky ToAscii values, // and if it's not a single character we don't know care about it - charlength = ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0); + charlength = ToAscii (wParam, lParam >> 16, state, (LPWORD)asciichar, 0); if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0) asciichar[0] = 0; else if( charlength == 2 ) { asciichar[0] = asciichar[1]; } - Key_Event (vkey, asciichar[0], down); + if (!IN_JoystickBlockDoubledKeyEvents(vkey)) + Key_Event (vkey, asciichar[0], down); break; case WM_SYSCHAR: @@ -592,9 +598,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) temp |= 512; #ifdef SUPPORTDIRECTX - if (vid_usingmouse && !dinput_acquired) -#else - if (vid_usingmouse) + if (!dinput_acquired) #endif { // perform button actions @@ -796,7 +800,7 @@ void VID_Init(void) IN_Init(); } -int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples) +qboolean VID_InitMode(viddef_mode_t *mode) { int i; HDC hdc; @@ -825,7 +829,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat }; int windowpass; int pixelformat, newpixelformat; - int numpixelformats; + UINT numpixelformats; DWORD WindowStyle, ExWindowStyle; int CenterX, CenterY; const char *gldrivername; @@ -836,6 +840,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat float *af; int attribs[128]; float attribsf[16]; + int bpp = mode->bitsperpixel; + int width = mode->width; + int height = mode->height; + int refreshrate = (int)floor(mode->refreshrate+0.5); + int stereobuffer = mode->stereobuffer; + int samples = mode->samples; + int fullscreen = mode->fullscreen; if (vid_initialized) Sys_Error("VID_InitMode called when video is already initialised"); @@ -963,24 +974,24 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n"); continue; } - if(developer.integer >= 100) - Con_Printf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency); + if(developer_extra.integer) + Con_DPrintf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency); if(thismode.dmBitsPerPel != (DWORD)bpp) { - if(developer.integer >= 100) - Con_Printf("wrong bpp\n"); + if(developer_extra.integer) + Con_DPrintf("wrong bpp\n"); continue; } if(thismode.dmPelsWidth != (DWORD)width) { - if(developer.integer >= 100) - Con_Printf("wrong width\n"); + if(developer_extra.integer) + Con_DPrintf("wrong width\n"); continue; } if(thismode.dmPelsHeight != (DWORD)height) { - if(developer.integer >= 100) - Con_Printf("wrong height\n"); + if(developer_extra.integer) + Con_DPrintf("wrong height\n"); continue; } @@ -989,14 +1000,14 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat // if we have a good mode, make sure this mode is better than the previous one, and allowed by the refreshrate if(thismode.dmDisplayFrequency > (DWORD)refreshrate) { - if(developer.integer >= 100) - Con_Printf("too high refresh rate\n"); + if(developer_extra.integer) + Con_DPrintf("too high refresh rate\n"); continue; } else if(thismode.dmDisplayFrequency <= gdevmode.dmDisplayFrequency) { - if(developer.integer >= 100) - Con_Printf("doesn't beat previous best match (too low)\n"); + if(developer_extra.integer) + Con_DPrintf("doesn't beat previous best match (too low)\n"); continue; } } @@ -1005,8 +1016,8 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat // we do have one, but it isn't good... make sure it has a lower frequency than the previous one if(thismode.dmDisplayFrequency >= gdevmode.dmDisplayFrequency) { - if(developer.integer >= 100) - Con_Printf("doesn't beat previous best match (too high)\n"); + if(developer_extra.integer) + Con_DPrintf("doesn't beat previous best match (too high)\n"); continue; } } @@ -1017,12 +1028,12 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat foundgoodmode = true; else { - if(developer.integer >= 100) - Con_Printf("(out of range)\n"); + if(developer_extra.integer) + Con_DPrintf("(out of range)\n"); } foundmode = true; - if(developer.integer >= 100) - Con_Printf("accepted\n"); + if(developer_extra.integer) + Con_DPrintf("accepted\n"); } } @@ -1095,12 +1106,16 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat pixelformat = 0; newpixelformat = 0; - for (windowpass = 0;windowpass < 2;windowpass++) + // start out at the final windowpass if samples is 1 as it's the only feature we need extended pixel formats for + for (windowpass = samples == 1;windowpass < 2;windowpass++) { + gl_extensions = ""; + gl_platformextensions = ""; + 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", (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); + Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %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, global_hInstance, NULL); VID_Shutdown(); return false; } @@ -1113,14 +1128,14 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat if (!pixelformat) { VID_Shutdown(); - Con_Printf("ChoosePixelFormat(%d, %p) failed\n", (int)baseDC, &pfd); + Con_Printf("ChoosePixelFormat(%p, %p) failed\n", baseDC, &pfd); return false; } if (SetPixelFormat(baseDC, pixelformat, &pfd) == false) { VID_Shutdown(); - Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", (int)baseDC, pixelformat, &pfd); + Con_Printf("SetPixelFormat(%p, %d, %p) failed\n", baseDC, pixelformat, &pfd); return false; } @@ -1141,7 +1156,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", (int)baseDC, (int)baseRC); + Con_Printf("wglMakeCurrent(%p, %p) failed\n", baseDC, baseRC); return false; } @@ -1154,15 +1169,17 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL) Con_Print("wglGetExtensionsStringARB not found\n"); - gl_renderer = qglGetString(GL_RENDERER); - gl_vendor = qglGetString(GL_VENDOR); - gl_version = qglGetString(GL_VERSION); - gl_extensions = qglGetString(GL_EXTENSIONS); + gl_extensions = (const char *)qglGetString(GL_EXTENSIONS); gl_platform = "WGL"; gl_platformextensions = ""; if (qwglGetExtensionsStringARB) - gl_platformextensions = qwglGetExtensionsStringARB(baseDC); + gl_platformextensions = (const char *)qwglGetExtensionsStringARB(baseDC); + + if (!gl_extensions) + gl_extensions = ""; + if (!gl_platformextensions) + gl_platformextensions = ""; // now some nice Windows pain: // we have created a window, we needed one to find out if there are @@ -1187,12 +1204,6 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat } } - Con_DPrintf("GL_VENDOR: %s\n", gl_vendor); - Con_DPrintf("GL_RENDERER: %s\n", gl_renderer); - Con_DPrintf("GL_VERSION: %s\n", gl_version); - Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions); - Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions); - /* if (!fullscreen) SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME); @@ -1224,16 +1235,15 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat // fix the leftover Alt from any Alt-Tab or the like that switched us away ClearAllStates (); - gl_videosyncavailable = false; - // COMMANDLINEOPTION: Windows WGL: -novideosync disables WGL_EXT_swap_control - gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false); + GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false); GL_Init (); //vid_menudrawfn = VID_MenuDraw; //vid_menukeyfn = VID_MenuKey; vid_usingmouse = false; + vid_usinghidecursor = false; vid_usingvsync = false; vid_hidden = false; vid_initialized = true; @@ -1241,10 +1251,10 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat IN_StartupMouse (); IN_StartupJoystick (); - if (gl_videosyncavailable) + if (qwglSwapIntervalEXT) { - vid_usevsync = vid_vsync.integer; - vid_usingvsync = vid_vsync.integer; + vid_usevsync = vid_vsync.integer != 0; + vid_usingvsync = vid_vsync.integer != 0; qwglSwapIntervalEXT (vid_usevsync); } @@ -1257,6 +1267,7 @@ void VID_Shutdown (void) if(vid_initialized == false) return; + VID_SetMouse(false, false, false); VID_RestoreSystemGamma(); vid_initialized = false; @@ -1278,7 +1289,7 @@ void VID_Shutdown (void) vid_isfullscreen = false; } -static void IN_Activate (qboolean grab) +void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor) { static qboolean restore_spi; static int originalmouseparms[3]; @@ -1286,7 +1297,7 @@ static void IN_Activate (qboolean grab) if (!mouseinitialized) return; - if (grab) + if (relative) { if (!vid_usingmouse) { @@ -1315,7 +1326,7 @@ static void IN_Activate (qboolean grab) 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); + restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0) != FALSE; } else restore_spi = false; @@ -1324,7 +1335,6 @@ static void IN_Activate (qboolean grab) SetCapture (mainwindow); ClipCursor (&window_rect); } - ShowCursor (false); } } else @@ -1349,9 +1359,14 @@ static void IN_Activate (qboolean grab) ClipCursor (NULL); ReleaseCapture (); } - ShowCursor (true); } } + + if (vid_usinghidecursor != hidecursor) + { + vid_usinghidecursor = hidecursor; + ShowCursor (!hidecursor); + } } @@ -1387,7 +1402,7 @@ static qboolean IN_InitDInput (void) if (!pDirectInputCreate) { - pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA"); + pDirectInputCreate = (HRESULT (__stdcall *)(HINSTANCE,DWORD,LPDIRECTINPUT *,LPUNKNOWN))GetProcAddress(hInstDI,"DirectInputCreateA"); if (!pDirectInputCreate) { @@ -1405,7 +1420,11 @@ static qboolean IN_InitDInput (void) } // obtain an interface to the system mouse device. +#ifdef __cplusplus + hr = IDirectInput_CreateDevice(g_pdi, GUID_SysMouse, &g_pMouse, NULL); +#else hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL); +#endif if (FAILED(hr)) { @@ -1482,15 +1501,14 @@ IN_MouseMove */ static void IN_MouseMove (void) { - int mx, my; POINT current_pos; + GetCursorPos (¤t_pos); + in_windowmouse_x = current_pos.x - window_x; + in_windowmouse_y = current_pos.y - window_y; + if (!vid_usingmouse) - { - //GetCursorPos (¤t_pos); - //ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y); return; - } #ifdef SUPPORTDIRECTX if (dinput_acquired) @@ -1499,8 +1517,6 @@ static void IN_MouseMove (void) DIDEVICEOBJECTDATA od; DWORD dwElements; HRESULT hr; - mx = 0; - my = 0; for (;;) { @@ -1524,11 +1540,11 @@ static void IN_MouseMove (void) switch (od.dwOfs) { case DIMOFS_X: - mx += (LONG) od.dwData; + in_mouse_x += (LONG) od.dwData; break; case DIMOFS_Y: - my += (LONG) od.dwData; + in_mouse_y += (LONG) od.dwData; break; case DIMOFS_Z: @@ -1579,23 +1595,15 @@ static void IN_MouseMove (void) if ((mstate_di ^ mouse_oldbuttonstate) & (1<= JOY_MAX_AXES) + return 0; // no such axis on this joystick + + // get the floating point zero-centered, potentially-inverted data for the current axis + fAxisValue = (float) *pdwRawValue[axis]; + + // move centerpoint to zero + fAxisValue -= 32768.0; + + if (joy_wwhack2.integer != 0.0) + { + if (dwAxisMap[axis] == AxisTurn) + { + // this is a special formula for the Logitech WingMan Warrior + // y=ax^b; where a = 300 and b = 1.3 + // also x values are in increments of 800 (so this is factored out) + // then bounds check result to level out excessively high spin rates + fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3); + if (fTemp > 14000.0) + fTemp = 14000.0; + // restore direction information + fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp; + } + } + + // convert range from -32768..32767 to -1..1 + fAxisValue /= 32768.0; + + // deadzone around center + if (fabs(fAxisValue) < deadzone) + return 0; + + // apply sensitivity + return fAxisValue * sensitivity; +} + +/* +=========== + IN_JoystickKeyeventForAxis +=========== +*/ + +static void IN_JoystickKeyeventForAxis(int axis, int key_pos, int key_neg) +{ + double joytime; + + if (axis < 0 || axis >= JOY_MAX_AXES) + return; // no such axis on this joystick + + joytime = Sys_DoubleTime(); + // no key event, continuous keydown event + if (joy_axescache[axis].move == joy_axescache[axis].oldmove) + { + if (joy_axescache[axis].move != 0 && joytime > joy_axescache[axis].keytime) + { + //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].move > 0) ? key_pos : key_neg), 1, cl.time); + Key_Event((joy_axescache[axis].move > 0) ? key_pos : key_neg, 0, 1); + joy_axescache[axis].keytime = joytime + 0.5 / 20; + } + return; + } + // generate key up event + if (joy_axescache[axis].oldmove) + { + //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].oldmove > 0) ? key_pos : key_neg), 1, cl.time); + Key_Event((joy_axescache[axis].oldmove > 0) ? key_pos : key_neg, 0, 0); + } + // generate key down event + if (joy_axescache[axis].move) + { + //Con_Printf("joy %s %i %f\n", Key_KeynumToString((joy_axescache[axis].move > 0) ? key_pos : key_neg), 1, cl.time); + Key_Event((joy_axescache[axis].move > 0) ? key_pos : key_neg, 0, 1); + joy_axescache[axis].keytime = joytime + 0.5; + } +} + +/* +=========== + IN_JoystickBlockDoubledKeyEvents +=========== +*/ + +static qboolean IN_ReadJoystick (void); +static qboolean IN_JoystickBlockDoubledKeyEvents(int keycode) +{ + int axis; + + if (!joy_axiskeyevents.integer) + return false; + + // block keyevent if it's going to be provided by joystick keyevent system + if (joy_avail) + { + // collect the joystick data, if possible + if (IN_ReadJoystick() != true) + return false; + axis = IN_JoystickGetAxisNum(AxisForward); + if (keycode == K_UPARROW || keycode == K_DOWNARROW) + if (IN_JoystickGetAxis(axis, 1, 0.01) || joy_axescache[axis].move || joy_axescache[axis].oldmove) + return true; + axis = IN_JoystickGetAxisNum(AxisSide); + if (keycode == K_RIGHTARROW || keycode == K_LEFTARROW) + if (IN_JoystickGetAxis(axis, 1, 0.01) || joy_axescache[axis].move || joy_axescache[axis].oldmove) + return true; + } + + return false; +} + +/* +=========== + IN_JoyMove =========== */ static void IN_JoyMove (void) { float speed, aspeed; - float fAxisValue, fTemp; - int i, mouselook = (in_mlook.state & 1) || freelook.integer; + float fAxisValue; + int i, mouselook = (in_mlook.state & 1) || freelook.integer, AxisForwardIndex = -1, AxisSideIndex = -1; // complete initialization if first time in // this is needed as cvars are not available at initialization time @@ -1851,7 +1992,6 @@ static void IN_JoyMove (void) key_index = (i < 16) ? K_JOY1 : K_AUX1; Key_Event (key_index + i, 0, true); } - if ( !(buttonstate & (1< 14000.0) - fTemp = 14000.0; - // restore direction information - fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp; - } - } - - // convert range from -32768..32767 to -1..1 - fAxisValue /= 32768.0; - + // convert axis to real move switch (dwAxisMap[i]) { - case AxisForward: - if ((joy_advanced.integer == 0) && mouselook) - { - // user wants forward control to become look control - if (fabs(fAxisValue) > joy_pitchthreshold.value) + case AxisForward: + if (AxisForwardIndex < 0) + AxisForwardIndex = i; + if ((joy_advanced.integer == 0) && mouselook) { - // if mouse invert is on, invert the joystick pitch value - // only absolute control support here (joy_advanced is false) - if (m_pitch.value < 0.0) + // user wants forward control to become look control + fAxisValue = IN_JoystickGetAxis(i, joy_pitchsensitivity.value, joy_pitchthreshold.value); + if (fAxisValue != 0) { - cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value; + // if mouse invert is on, invert the joystick pitch value + // only absolute control support here (joy_advanced is false) + if (m_pitch.value < 0.0) + cl.viewangles[PITCH] -= fAxisValue * aspeed * cl_pitchspeed.value; + else + cl.viewangles[PITCH] += fAxisValue * aspeed * cl_pitchspeed.value; + V_StopPitchDrift(); } else { - cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value; + // no pitch movement + // disable pitch return-to-center unless requested by user + // *** this code can be removed when the lookspring bug is fixed + // *** the bug always has the lookspring feature on + if (lookspring.value == 0.0) + V_StopPitchDrift(); } - V_StopPitchDrift(); } else { - // no pitch movement - // disable pitch return-to-center unless requested by user - // *** this code can be removed when the lookspring bug is fixed - // *** the bug always has the lookspring feature on - if(lookspring.value == 0.0) - V_StopPitchDrift(); - } - } - else - { - // user wants forward control to be forward control - if (fabs(fAxisValue) > joy_forwardthreshold.value) - { - cl.cmd.forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value; + // user wants forward control to be forward control + fAxisValue = IN_JoystickGetAxis(i, joy_forwardsensitivity.value, joy_forwardthreshold.value); + cl.cmd.forwardmove += fAxisValue * speed * cl_forwardspeed.value; } - } - break; + break; - case AxisSide: - if (fabs(fAxisValue) > joy_sidethreshold.value) - { - cl.cmd.sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value; - } - break; + case AxisSide: + if (AxisSideIndex < 0) + AxisSideIndex = i; + fAxisValue = IN_JoystickGetAxis(i, joy_sidesensitivity.value, joy_sidethreshold.value); + cl.cmd.sidemove += fAxisValue * speed * cl_sidespeed.value; + break; - case AxisTurn: - if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook)) - { - // user wants turn control to become side control - if (fabs(fAxisValue) > joy_sidethreshold.value) + case AxisTurn: + if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook)) { - cl.cmd.sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value; + // user wants turn control to become side control + fAxisValue = IN_JoystickGetAxis(i, joy_sidesensitivity.value, joy_sidethreshold.value); + cl.cmd.sidemove -= fAxisValue * speed * cl_sidespeed.value; } - } - else - { - // user wants turn control to be turn control - if (fabs(fAxisValue) > joy_yawthreshold.value) + else { - if(dwControlMap[i] == JOY_ABSOLUTE_AXIS) - { - cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value; - } + // user wants turn control to be turn control + fAxisValue = IN_JoystickGetAxis(i, joy_yawsensitivity.value, joy_yawthreshold.value); + if (dwControlMap[i] == JOY_ABSOLUTE_AXIS) + cl.viewangles[YAW] += fAxisValue * aspeed * cl_yawspeed.value; else - { - cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0; - } - + cl.viewangles[YAW] += fAxisValue * speed * 180.0; } - } - break; + break; - case AxisLook: - if (mouselook) - { - if (fabs(fAxisValue) > joy_pitchthreshold.value) + case AxisLook: + fAxisValue = IN_JoystickGetAxis(i, joy_pitchsensitivity.value, joy_pitchthreshold.value); + if (mouselook) { - // pitch movement detected and pitch movement desired by user - if(dwControlMap[i] == JOY_ABSOLUTE_AXIS) + if (fAxisValue != 0) { - cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value; + // pitch movement detected and pitch movement desired by user + if (dwControlMap[i] == JOY_ABSOLUTE_AXIS) + cl.viewangles[PITCH] += fAxisValue * aspeed * cl_pitchspeed.value; + else + cl.viewangles[PITCH] += fAxisValue * speed * 180.0; + V_StopPitchDrift(); } else { - cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0; + // no pitch movement + // disable pitch return-to-center unless requested by user + // *** this code can be removed when the lookspring bug is fixed + // *** the bug always has the lookspring feature on + if(lookspring.integer == 0) + V_StopPitchDrift(); } - V_StopPitchDrift(); } - else - { - // no pitch movement - // disable pitch return-to-center unless requested by user - // *** this code can be removed when the lookspring bug is fixed - // *** the bug always has the lookspring feature on - if(lookspring.integer == 0) - V_StopPitchDrift(); - } - } - break; + break; - default: - break; + default: + fAxisValue = IN_JoystickGetAxis(i, 1, 0.01); + break; } + + // cache for keyevents + joy_axescache[i].oldmove = joy_axescache[i].move; + joy_axescache[i].move = IN_JoystickGetAxis(i, 1, 0.01); + } + + // run keyevents + if (joy_axiskeyevents.integer) + { + IN_JoystickKeyeventForAxis(AxisForwardIndex, K_DOWNARROW, K_UPARROW); + IN_JoystickKeyeventForAxis(AxisSideIndex, K_RIGHTARROW, K_LEFTARROW); } } @@ -2072,14 +2186,13 @@ static void IN_Init(void) Cvar_RegisterVariable (&joy_yawsensitivity); Cvar_RegisterVariable (&joy_wwhack1); Cvar_RegisterVariable (&joy_wwhack2); + Cvar_RegisterVariable (&joy_axiskeyevents); Cvar_RegisterVariable (&vid_forcerefreshrate); Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f, "applies current joyadv* cvar settings to the joystick driver"); } static void IN_Shutdown(void) { - IN_Activate (false); - #ifdef SUPPORTDIRECTX if (g_pMouse) IDirectInputDevice_Release(g_pMouse); @@ -2090,3 +2203,32 @@ static void IN_Shutdown(void) g_pdi = NULL; #endif } + +size_t VID_ListModes(vid_mode_t *modes, size_t maxcount) +{ + int i; + size_t k; + DEVMODE thismode; + + thismode.dmSize = sizeof(thismode); + thismode.dmDriverExtra = 0; + k = 0; + for(i = 0; EnumDisplaySettings(NULL, i, &thismode); ++i) + { + if(~thismode.dmFields & (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY)) + { + Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n"); + continue; + } + if(k >= maxcount) + break; + modes[k].width = thismode.dmPelsWidth; + modes[k].height = thismode.dmPelsHeight; + modes[k].bpp = thismode.dmBitsPerPel; + modes[k].refreshrate = thismode.dmDisplayFrequency; + modes[k].pixelheight_num = 1; + modes[k].pixelheight_denom = 1; // Win32 apparently does not provide this (FIXME) + ++k; + } + return k; +}