2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // gl_vidnt.c -- NT GL vid component
27 int cl_available = true;
29 int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
30 int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
31 //int (WINAPI *qwglGetPixelFormat)(HDC);
32 BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
33 BOOL (WINAPI *qwglSwapBuffers)(HDC);
34 HGLRC (WINAPI *qwglCreateContext)(HDC);
35 BOOL (WINAPI *qwglDeleteContext)(HGLRC);
36 HGLRC (WINAPI *qwglGetCurrentContext)(VOID);
37 HDC (WINAPI *qwglGetCurrentDC)(VOID);
38 PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
39 BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
40 BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
41 const char *(WINAPI *qwglGetExtensionsStringARB)(HDC hdc);
43 static gl_extensionfunctionlist_t wglfuncs[] =
45 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
46 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
47 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
48 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
49 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
50 {"wglCreateContext", (void **) &qwglCreateContext},
51 {"wglDeleteContext", (void **) &qwglDeleteContext},
52 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
53 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
54 {"wglGetCurrentContext", (void **) &qwglGetCurrentContext},
55 {"wglGetCurrentDC", (void **) &qwglGetCurrentDC},
59 static gl_extensionfunctionlist_t wglswapintervalfuncs[] =
61 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
65 void VID_RestoreGameGamma(void);
66 void VID_GetSystemGamma(void);
67 void VID_RestoreSystemGamma(void);
69 qboolean scr_skipupdate;
71 static DEVMODE gdevmode;
72 static qboolean vid_initialized = false;
73 static qboolean vid_wassuspended = false;
74 static int vid_usingmouse;
75 extern qboolean mouseactive; // from in_win.c
80 //HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
82 static int vid_isfullscreen;
84 //void VID_MenuDraw (void);
85 //void VID_MenuKey (int key);
87 //LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
88 //void AppActivate(BOOL fActive, BOOL minimize);
89 //void ClearAllStates (void);
90 //void VID_UpdateWindowStatus (void);
92 //====================================
94 int window_x, window_y, window_width, window_height;
95 int window_center_x, window_center_y;
97 void IN_ShowMouse (void);
98 void IN_DeactivateMouse (void);
99 void IN_HideMouse (void);
100 void IN_ActivateMouse (void);
101 void IN_MouseEvent (int mstate);
102 void IN_UpdateClipCursor (void);
104 qboolean mouseinitialized;
105 static qboolean dinput;
109 VID_UpdateWindowStatus
112 void VID_UpdateWindowStatus (void)
114 window_center_x = window_x + window_width / 2;
115 window_center_y = window_y + window_height / 2;
117 if (mouseinitialized && mouseactive && !dinput)
120 window_rect.left = window_x;
121 window_rect.top = window_y;
122 window_rect.right = window_x + window_width;
123 window_rect.bottom = window_y + window_height;
124 ClipCursor (&window_rect);
129 //====================================
136 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
140 *width = window_width;
141 *height = window_height;
145 void VID_Finish (void)
149 if (r_render.integer && !scr_skipupdate)
152 hdc = GetDC(mainwindow);
154 ReleaseDC(mainwindow, hdc);
157 // handle the mouse state when windowed if that's changed
158 vid_usemouse = false;
159 if (vid_mouse.integer && !key_consoleactive)
161 if (vid_isfullscreen)
163 if (!vid_activewindow)
164 vid_usemouse = false;
169 vid_usingmouse = true;
178 vid_usingmouse = false;
179 IN_DeactivateMouse ();
185 //==========================================================================
190 qbyte scantokey[128] =
192 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
193 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
194 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
195 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
196 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
197 K_F6 ,K_F7 ,K_F8 ,K_F9 ,K_F10,K_PAUSE,0 ,K_HOME,K_UPARROW,K_PGUP,'-' ,K_LEFTARROW,'5' ,K_RIGHTARROW,'+' ,K_END , // 4
198 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
199 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
200 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
208 Map from windows to quake keynums
211 int MapKey (int key, int virtualkey)
216 if (scantokey[key] == 0)
217 Con_DPrintf("key 0x%02x has no translation\n", key);
218 return scantokey[key];
222 ===================================================================
226 ===================================================================
234 void ClearAllStates (void)
238 // send an up event for each key, to make sure the server clears them all
239 for (i=0 ; i<256 ; i++)
241 Key_Event (i, false);
248 void VID_RestoreGameGamma(void);
249 extern qboolean host_loopactive;
251 void AppActivate(BOOL fActive, BOOL minimize)
252 /****************************************************************************
254 * Function: AppActivate
255 * Parameters: fActive - True if app is activating
257 * Description: If the application is activating, then swap the system
258 * into SYSPAL_NOSTATIC mode so that our palettes will display
261 ****************************************************************************/
263 static BOOL sound_active;
265 vid_activewindow = fActive;
266 vid_hidden = minimize;
268 // enable/disable sound on focus gain/loss
269 if (!vid_activewindow && sound_active)
272 sound_active = false;
274 else if (vid_activewindow && !sound_active)
282 if (vid_isfullscreen)
284 if (vid_wassuspended)
286 vid_wassuspended = false;
287 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
288 ShowWindow(mainwindow, SW_SHOWNORMAL);
291 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
292 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
295 VID_RestoreGameGamma();
300 vid_usingmouse = false;
301 IN_DeactivateMouse ();
303 if (vid_isfullscreen)
305 ChangeDisplaySettings (NULL, 0);
306 vid_wassuspended = true;
308 VID_RestoreSystemGamma();
312 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
314 /* main window procedure */
315 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
318 int fActive, fMinimized, temp;
319 extern unsigned int uiWheelMessage;
321 if ( uMsg == uiWheelMessage )
322 uMsg = WM_MOUSEWHEEL;
327 if (vid_isfullscreen)
328 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
335 window_x = (int) LOWORD(lParam);
336 window_y = (int) HIWORD(lParam);
337 VID_UpdateWindowStatus ();
342 Key_Event (MapKey(lParam, wParam), true);
347 Key_Event (MapKey(lParam, wParam), false);
351 // keep Alt-Space from happening
354 // this is complicated because Win32 seems to pack multiple mouse events into
355 // one update sometimes, so we always check all states and look for events
365 if (wParam & MK_LBUTTON)
368 if (wParam & MK_RBUTTON)
371 if (wParam & MK_MBUTTON)
374 IN_MouseEvent (temp);
378 // JACK: This is the mouse wheel with the Intellimouse
379 // Its delta is either positive or neg, and we generate the proper
382 if ((short) HIWORD(wParam) > 0) {
383 Key_Event(K_MWHEELUP, true);
384 Key_Event(K_MWHEELUP, false);
386 Key_Event(K_MWHEELDOWN, true);
387 Key_Event(K_MWHEELDOWN, false);
395 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
401 fActive = LOWORD(wParam);
402 fMinimized = (BOOL) HIWORD(wParam);
403 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
405 // fix the leftover Alt from any Alt-Tab or the like that switched us away
413 DestroyWindow (mainwindow);
420 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
424 /* pass all unhandled messages to DefWindowProc */
425 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
429 /* return 1 if handled message, 0 if not */
434 //static int grabsysgamma = true;
435 WORD systemgammaramps[3][256], currentgammaramps[3][256];
437 int VID_SetGamma(float prescale, float gamma, float scale, float base)
443 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
444 for (i = 0;i < 256;i++)
445 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
447 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
449 ReleaseDC (NULL, hdc);
450 return i; // return success or failure
453 void VID_RestoreGameGamma(void)
455 VID_UpdateGamma(true);
458 void VID_GetSystemGamma(void)
463 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
465 ReleaseDC (NULL, hdc);
468 void VID_RestoreSystemGamma(void)
473 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
475 ReleaseDC (NULL, hdc);
478 //========================================================
480 //========================================================
483 extern void M_Menu_Options_f (void);
484 extern void M_Print (float cx, float cy, char *str);
485 extern void M_PrintWhite (float cx, float cy, char *str);
486 extern void M_DrawCharacter (float cx, float cy, int num);
487 extern void M_DrawPic (float cx, float cy, char *picname);
489 static int vid_wmodes;
498 #define MAX_COLUMN_SIZE 9
499 #define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 2)
500 #define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
502 static modedesc_t modedescs[MAX_MODEDESCS];
509 void VID_MenuDraw (void)
513 int lnummodes, i, k, column, row;
516 p = Draw_CachePic ("gfx/vidmodes.lmp");
517 M_DrawPic ( (320-p->width)/2, 4, "gfx/vidmodes.lmp");
520 lnummodes = VID_NumModes ();
522 for (i=1 ; (i<lnummodes) && (vid_wmodes < MAX_MODEDESCS) ; i++)
524 ptr = VID_GetModeDescription (i);
525 pv = VID_GetModePtr (i);
529 modedescs[k].modenum = i;
530 modedescs[k].desc = ptr;
531 modedescs[k].iscur = 0;
533 if (i == vid_modenum)
534 modedescs[k].iscur = 1;
542 M_Print (2*8, 36+0*8, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
547 for (i=0 ; i<vid_wmodes ; i++)
549 if (modedescs[i].iscur)
550 M_PrintWhite (column, row, modedescs[i].desc);
552 M_Print (column, row, modedescs[i].desc);
556 if ((i % VID_ROW_SIZE) == (VID_ROW_SIZE - 1))
564 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*2, "Video modes must be set from the");
565 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*3, "command line with -width <width>");
566 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*4, "and -bpp <bits-per-pixel>");
567 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*6, "Select windowed mode with -window");
576 void VID_MenuKey (int key)
581 S_LocalSound ("misc/menu1.wav");
591 static HINSTANCE gldll;
593 int GL_OpenLibrary(const char *name)
595 Con_Printf("Loading GL driver %s\n", name);
597 if (!(gldll = LoadLibrary(name)))
599 Con_Printf("Unable to LoadLibrary %s\n", name);
602 strcpy(gl_driver, name);
606 void GL_CloseLibrary(void)
611 qwglGetProcAddress = NULL;
614 gl_platformextensions = "";
617 void *GL_GetProcAddress(const char *name)
620 if (qwglGetProcAddress != NULL)
621 p = (void *) qwglGetProcAddress(name);
623 p = (void *) GetProcAddress(gldll, name);
631 InitCommonControls();
632 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
634 // Register the frame class
636 wc.lpfnWndProc = (WNDPROC)MainWndProc;
639 wc.hInstance = global_hInstance;
641 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
642 wc.hbrBackground = NULL;
644 wc.lpszClassName = "DarkPlacesWindowClass";
646 if (!RegisterClass (&wc))
647 Sys_Error("Couldn't register window class\n");
650 int VID_InitMode (int fullscreen, int width, int height, int bpp)
656 PIXELFORMATDESCRIPTOR pfd =
658 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
660 PFD_DRAW_TO_WINDOW // support window
661 | PFD_SUPPORT_OPENGL // support OpenGL
662 | PFD_DOUBLEBUFFER , // double buffered
663 PFD_TYPE_RGBA, // RGBA type
664 24, // 24-bit color depth
665 0, 0, 0, 0, 0, 0, // color bits ignored
666 0, // no alpha buffer
667 0, // shift bit ignored
668 0, // no accumulation buffer
669 0, 0, 0, 0, // accum bits ignored
670 32, // 32-bit z-buffer
671 0, // no stencil buffer
672 0, // no auxiliary buffer
673 PFD_MAIN_PLANE, // main layer
675 0, 0, 0 // layer masks ignored
678 DWORD WindowStyle, ExWindowStyle;
680 int CenterX, CenterY;
683 Sys_Error("VID_InitMode called when video is already initialised\n");
685 if (!GL_OpenLibrary("opengl32.dll"))
687 Con_Printf("Unable to load GL driver\n");
691 memset(&gdevmode, 0, sizeof(gdevmode));
693 VID_GetSystemGamma();
695 vid_isfullscreen = false;
698 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
699 gdevmode.dmBitsPerPel = bpp;
700 gdevmode.dmPelsWidth = width;
701 gdevmode.dmPelsHeight = height;
702 gdevmode.dmSize = sizeof (gdevmode);
703 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
706 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
710 vid_isfullscreen = true;
711 WindowStyle = WS_POPUP;
717 i = GetDeviceCaps(hdc, RASTERCAPS);
718 ReleaseDC (NULL, hdc);
722 Con_Printf ("Can't run in non-RGB mode\n");
726 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
733 rect.bottom = height;
734 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
743 CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
744 CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
746 CenterX = max(0, CenterX);
747 CenterY = max(0, CenterY);
749 // x and y may be changed by WM_MOVE messages
752 window_width = width;
753 window_height = height;
754 rect.left += CenterX;
755 rect.right += CenterX;
757 rect.bottom += CenterY;
759 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
763 Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %d, %p) failed\n", ExWindowStyle, gamename, gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
769 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
772 ShowWindow (mainwindow, SW_SHOWDEFAULT);
773 UpdateWindow (mainwindow);
775 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
776 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
778 VID_UpdateWindowStatus ();
780 // now we try to make sure we get the focus on the mode switch, because
781 // sometimes in some systems we don't. We grab the foreground, then
782 // finish setting up, pump all our messages, and sleep for a little while
783 // to let messages finish bouncing around the system, then we put
784 // ourselves at the top of the z order, then grab the foreground again,
785 // Who knows if it helps, but it probably doesn't hurt
786 SetForegroundWindow (mainwindow);
788 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
790 TranslateMessage (&msg);
791 DispatchMessage (&msg);
796 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
798 SetForegroundWindow (mainwindow);
800 // fix the leftover Alt from any Alt-Tab or the like that switched us away
803 hdc = GetDC(mainwindow);
805 if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)
808 Con_Printf("ChoosePixelFormat(%d, %p) failed\n", hdc, &pfd);
812 if (SetPixelFormat(hdc, pixelformat, &pfd) == false)
815 Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", hdc, pixelformat, &pfd);
819 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
822 Con_Printf("wgl functions not found\n");
826 baseRC = qwglCreateContext(hdc);
830 Con_Printf("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
833 if (!qwglMakeCurrent(hdc, baseRC))
836 Con_Printf("wglMakeCurrent(%d, %d) failed\n", hdc, baseRC);
840 qglGetString = GL_GetProcAddress("glGetString");
841 qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB");
842 if (qglGetString == NULL)
845 Con_Printf("glGetString not found\n");
848 gl_renderer = qglGetString(GL_RENDERER);
849 gl_vendor = qglGetString(GL_VENDOR);
850 gl_version = qglGetString(GL_VERSION);
851 gl_extensions = qglGetString(GL_EXTENSIONS);
853 gl_platformextensions = "";
855 if (qwglGetExtensionsStringARB)
856 gl_platformextensions = qwglGetExtensionsStringARB(hdc);
858 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
859 ReleaseDC(mainwindow, hdc);
863 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
864 if (strncasecmp(gl_vendor,"ATI",3)==0)
866 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
869 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
872 //vid_menudrawfn = VID_MenuDraw;
873 //vid_menukeyfn = VID_MenuKey;
875 vid_initialized = true;
879 void VID_Shutdown (void)
886 vid_initialized = false;
887 if (qwglGetCurrentContext)
888 hRC = qwglGetCurrentContext();
889 if (qwglGetCurrentDC)
890 hDC = qwglGetCurrentDC();
893 qwglMakeCurrent(NULL, NULL);
895 if (hRC && qwglDeleteContext)
896 qwglDeleteContext(hRC);
898 // close the library before we get rid of the window
901 if (hDC && mainwindow)
902 ReleaseDC(mainwindow, hDC);
904 if (vid_isfullscreen)
905 ChangeDisplaySettings (NULL, 0);
907 AppActivate(false, false);
909 VID_RestoreSystemGamma();
918 #define DINPUT_BUFFERSIZE 16
919 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
921 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
922 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
926 int mouse_oldbuttonstate;
928 int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
930 static qboolean restore_spi;
931 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
933 unsigned int uiWheelMessage;
934 qboolean mouseactive;
935 //qboolean mouseinitialized;
936 static qboolean mouseparmsvalid, mouseactivatetoggle;
937 static qboolean mouseshowtoggle = 1;
938 static qboolean dinput_acquired;
940 static unsigned int mstate_di;
942 // joystick defines and variables
943 // where should defines be moved?
944 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
945 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
946 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
956 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
959 DWORD dwAxisFlags[JOY_MAX_AXES] =
961 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
964 DWORD dwAxisMap[JOY_MAX_AXES];
965 DWORD dwControlMap[JOY_MAX_AXES];
966 PDWORD pdwRawValue[JOY_MAX_AXES];
968 // none of these cvars are saved over a session
969 // this means that advanced controller configuration needs to be executed
970 // each time. this avoids any problems with getting back to a default usage
971 // or when changing from one controller to another. this way at least something
973 cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
974 cvar_t joy_name = {0, "joyname", "joystick"};
975 cvar_t joy_advanced = {0, "joyadvanced", "0"};
976 cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
977 cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
978 cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
979 cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
980 cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
981 cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
982 cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
983 cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
984 cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
985 cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
986 cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
987 cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
988 cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
989 cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
990 cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
991 cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
993 qboolean joy_avail, joy_advancedinit, joy_haspov;
994 DWORD joy_oldbuttonstate, joy_oldpovstate;
998 DWORD joy_numbuttons;
1000 static LPDIRECTINPUT g_pdi;
1001 static LPDIRECTINPUTDEVICE g_pMouse;
1003 static JOYINFOEX ji;
1005 static HINSTANCE hInstDI;
1007 //static qboolean dinput;
1009 typedef struct MYDATA {
1010 LONG lX; // X axis goes here
1011 LONG lY; // Y axis goes here
1012 LONG lZ; // Z axis goes here
1013 BYTE bButtonA; // One button goes here
1014 BYTE bButtonB; // Another button goes here
1015 BYTE bButtonC; // Another button goes here
1016 BYTE bButtonD; // Another button goes here
1019 static DIOBJECTDATAFORMAT rgodf[] = {
1020 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1021 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1022 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1023 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1024 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1025 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1026 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1029 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
1031 static DIDATAFORMAT df = {
1032 sizeof(DIDATAFORMAT), // this structure
1033 sizeof(DIOBJECTDATAFORMAT), // size of object data format
1034 DIDF_RELAXIS, // absolute axis coordinates
1035 sizeof(MYDATA), // device data size
1036 NUM_OBJECTS, // number of objects
1037 rgodf, // and here they are
1040 // forward-referenced functions
1041 void IN_StartupJoystick (void);
1042 void Joy_AdvancedUpdate_f (void);
1043 void IN_JoyMove (usercmd_t *cmd);
1051 void IN_ShowMouse (void)
1053 if (!mouseshowtoggle)
1056 mouseshowtoggle = 1;
1066 void IN_HideMouse (void)
1068 if (mouseshowtoggle)
1071 mouseshowtoggle = 0;
1081 void IN_ActivateMouse (void)
1084 mouseactivatetoggle = true;
1086 if (mouseinitialized)
1092 if (!dinput_acquired)
1094 IDirectInputDevice_Acquire(g_pMouse);
1095 dinput_acquired = true;
1106 window_rect.left = window_x;
1107 window_rect.top = window_y;
1108 window_rect.right = window_x + window_width;
1109 window_rect.bottom = window_y + window_height;
1111 if (mouseparmsvalid)
1112 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
1114 SetCursorPos (window_center_x, window_center_y);
1115 SetCapture (mainwindow);
1116 ClipCursor (&window_rect);
1129 void IN_DeactivateMouse (void)
1132 mouseactivatetoggle = false;
1134 if (mouseinitialized)
1140 if (dinput_acquired)
1142 IDirectInputDevice_Unacquire(g_pMouse);
1143 dinput_acquired = false;
1150 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1156 mouseactive = false;
1166 qboolean IN_InitDInput (void)
1169 DIPROPDWORD dipdw = {
1171 sizeof(DIPROPDWORD), // diph.dwSize
1172 sizeof(DIPROPHEADER), // diph.dwHeaderSize
1174 DIPH_DEVICE, // diph.dwHow
1176 DINPUT_BUFFERSIZE, // dwData
1181 hInstDI = LoadLibrary("dinput.dll");
1183 if (hInstDI == NULL)
1185 Con_SafePrintf ("Couldn't load dinput.dll\n");
1190 if (!pDirectInputCreate)
1192 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
1194 if (!pDirectInputCreate)
1196 Con_SafePrintf ("Couldn't get DI proc addr\n");
1201 // register with DirectInput and get an IDirectInput to play with.
1202 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
1209 // obtain an interface to the system mouse device.
1210 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
1214 Con_SafePrintf ("Couldn't open DI mouse device\n");
1218 // set the data format to "mouse format".
1219 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
1223 Con_SafePrintf ("Couldn't set DI mouse format\n");
1227 // set the cooperativity level.
1228 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
1229 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
1233 Con_SafePrintf ("Couldn't set DI coop level\n");
1238 // set the buffer size to DINPUT_BUFFERSIZE elements.
1239 // the buffer size is a DWORD property associated with the device
1240 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
1244 Con_SafePrintf ("Couldn't set DI buffersize\n");
1257 void IN_StartupMouse (void)
1259 if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
1262 mouseinitialized = true;
1264 if (COM_CheckParm ("-dinput"))
1266 dinput = IN_InitDInput ();
1270 Con_SafePrintf ("DirectInput initialized\n");
1274 Con_SafePrintf ("DirectInput not initialized\n");
1280 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
1282 if (mouseparmsvalid)
1284 if ( COM_CheckParm ("-noforcemspd") )
1285 newmouseparms[2] = originalmouseparms[2];
1287 if ( COM_CheckParm ("-noforcemaccel") )
1289 newmouseparms[0] = originalmouseparms[0];
1290 newmouseparms[1] = originalmouseparms[1];
1293 if ( COM_CheckParm ("-noforcemparms") )
1295 newmouseparms[0] = originalmouseparms[0];
1296 newmouseparms[1] = originalmouseparms[1];
1297 newmouseparms[2] = originalmouseparms[2];
1304 // if a fullscreen video mode was set before the mouse was initialized,
1305 // set the mouse state appropriately
1306 if (mouseactivatetoggle)
1307 IN_ActivateMouse ();
1318 // joystick variables
1319 Cvar_RegisterVariable (&in_joystick);
1320 Cvar_RegisterVariable (&joy_name);
1321 Cvar_RegisterVariable (&joy_advanced);
1322 Cvar_RegisterVariable (&joy_advaxisx);
1323 Cvar_RegisterVariable (&joy_advaxisy);
1324 Cvar_RegisterVariable (&joy_advaxisz);
1325 Cvar_RegisterVariable (&joy_advaxisr);
1326 Cvar_RegisterVariable (&joy_advaxisu);
1327 Cvar_RegisterVariable (&joy_advaxisv);
1328 Cvar_RegisterVariable (&joy_forwardthreshold);
1329 Cvar_RegisterVariable (&joy_sidethreshold);
1330 Cvar_RegisterVariable (&joy_pitchthreshold);
1331 Cvar_RegisterVariable (&joy_yawthreshold);
1332 Cvar_RegisterVariable (&joy_forwardsensitivity);
1333 Cvar_RegisterVariable (&joy_sidesensitivity);
1334 Cvar_RegisterVariable (&joy_pitchsensitivity);
1335 Cvar_RegisterVariable (&joy_yawsensitivity);
1336 Cvar_RegisterVariable (&joy_wwhack1);
1337 Cvar_RegisterVariable (&joy_wwhack2);
1339 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
1341 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
1344 IN_StartupJoystick ();
1352 void IN_Shutdown (void)
1354 IN_DeactivateMouse ();
1359 IDirectInputDevice_Release(g_pMouse);
1365 IDirectInput_Release(g_pdi);
1376 void IN_MouseEvent (int mstate)
1380 if (mouseactive && !dinput)
1382 // perform button actions
1383 for (i=0 ; i<mouse_buttons ; i++)
1385 if ( (mstate & (1<<i)) &&
1386 !(mouse_oldbuttonstate & (1<<i)) )
1388 Key_Event (K_MOUSE1 + i, true);
1391 if ( !(mstate & (1<<i)) &&
1392 (mouse_oldbuttonstate & (1<<i)) )
1394 Key_Event (K_MOUSE1 + i, false);
1398 mouse_oldbuttonstate = mstate;
1408 void IN_MouseMove (usercmd_t *cmd)
1411 DIDEVICEOBJECTDATA od;
1417 GetCursorPos (¤t_pos);
1418 ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
1431 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
1432 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
1434 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
1436 dinput_acquired = true;
1437 IDirectInputDevice_Acquire(g_pMouse);
1441 /* Unable to read data or no data available */
1442 if (FAILED(hr) || dwElements == 0)
1445 /* Look at the element to see what happened */
1457 case DIMOFS_BUTTON0:
1458 if (od.dwData & 0x80)
1464 case DIMOFS_BUTTON1:
1465 if (od.dwData & 0x80)
1466 mstate_di |= (1<<1);
1468 mstate_di &= ~(1<<1);
1471 case DIMOFS_BUTTON2:
1472 if (od.dwData & 0x80)
1473 mstate_di |= (1<<2);
1475 mstate_di &= ~(1<<2);
1480 // perform button actions
1481 for (i=0 ; i<mouse_buttons ; i++)
1483 if ( (mstate_di & (1<<i)) &&
1484 !(mouse_oldbuttonstate & (1<<i)) )
1486 Key_Event (K_MOUSE1 + i, true);
1489 if ( !(mstate_di & (1<<i)) &&
1490 (mouse_oldbuttonstate & (1<<i)) )
1492 Key_Event (K_MOUSE1 + i, false);
1496 mouse_oldbuttonstate = mstate_di;
1500 GetCursorPos (¤t_pos);
1501 mx = current_pos.x - window_center_x + mx_accum;
1502 my = current_pos.y - window_center_y + my_accum;
1507 IN_Mouse(cmd, mx, my);
1509 // if the mouse has moved, force it to the center, so there's room to move
1510 if (!dinput && (mx || my))
1511 SetCursorPos (window_center_x, window_center_y);
1520 void IN_Move (usercmd_t *cmd)
1522 if (vid_activewindow && !vid_hidden)
1528 cl.viewangles[PITCH] = bound (in_pitch_min.value, cl.viewangles[PITCH], in_pitch_max.value);
1537 void IN_Accumulate (void)
1543 GetCursorPos (¤t_pos);
1545 mx_accum += current_pos.x - window_center_x;
1546 my_accum += current_pos.y - window_center_y;
1548 // force the mouse to the center, so there's room to move
1549 SetCursorPos (window_center_x, window_center_y);
1560 void IN_ClearStates (void)
1566 mouse_oldbuttonstate = 0;
1576 void IN_StartupJoystick (void)
1583 // assume no joystick
1586 // abort startup if user requests no joystick
1587 if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe"))
1590 // verify joystick driver is present
1591 if ((numdevs = joyGetNumDevs ()) == 0)
1593 Con_Printf ("\njoystick not found -- driver not present\n\n");
1597 // cycle through the joystick ids for the first valid one
1598 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
1600 memset (&ji, 0, sizeof(ji));
1601 ji.dwSize = sizeof(ji);
1602 ji.dwFlags = JOY_RETURNCENTERED;
1604 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
1608 // abort startup if we didn't find a valid joystick
1609 if (mmr != JOYERR_NOERROR)
1611 Con_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
1615 // get the capabilities of the selected joystick
1616 // abort startup if command fails
1617 memset (&jc, 0, sizeof(jc));
1618 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
1620 Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
1624 // save the joystick's number of buttons and POV status
1625 joy_numbuttons = jc.wNumButtons;
1626 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
1628 // old button and POV states default to no buttons pressed
1629 joy_oldbuttonstate = joy_oldpovstate = 0;
1631 // mark the joystick as available and advanced initialization not completed
1632 // this is needed as cvars are not available during initialization
1635 joy_advancedinit = false;
1637 Con_Printf ("\njoystick detected\n\n");
1646 PDWORD RawValuePointer (int axis)
1663 return NULL; // LordHavoc: hush compiler warning
1669 Joy_AdvancedUpdate_f
1672 void Joy_AdvancedUpdate_f (void)
1675 // called once by IN_ReadJoystick and by user whenever an update is needed
1676 // cvars are now available
1680 // initialize all the maps
1681 for (i = 0; i < JOY_MAX_AXES; i++)
1683 dwAxisMap[i] = AxisNada;
1684 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
1685 pdwRawValue[i] = RawValuePointer(i);
1688 if( joy_advanced.integer == 0)
1690 // default joystick initialization
1691 // 2 axes only with joystick control
1692 dwAxisMap[JOY_AXIS_X] = AxisTurn;
1693 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
1694 dwAxisMap[JOY_AXIS_Y] = AxisForward;
1695 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
1699 if (strcmp (joy_name.string, "joystick") != 0)
1701 // notify user of advanced controller
1702 Con_Printf ("\n%s configured\n\n", joy_name.string);
1705 // advanced initialization here
1706 // data supplied by user via joy_axisn cvars
1707 dwTemp = (DWORD) joy_advaxisx.value;
1708 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
1709 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
1710 dwTemp = (DWORD) joy_advaxisy.value;
1711 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
1712 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
1713 dwTemp = (DWORD) joy_advaxisz.value;
1714 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
1715 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
1716 dwTemp = (DWORD) joy_advaxisr.value;
1717 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
1718 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
1719 dwTemp = (DWORD) joy_advaxisu.value;
1720 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
1721 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
1722 dwTemp = (DWORD) joy_advaxisv.value;
1723 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
1724 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
1727 // compute the axes to collect from DirectInput
1728 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
1729 for (i = 0; i < JOY_MAX_AXES; i++)
1731 if (dwAxisMap[i] != AxisNada)
1733 joy_flags |= dwAxisFlags[i];
1744 void IN_Commands (void)
1747 DWORD buttonstate, povstate;
1755 // loop through the joystick buttons
1756 // key a joystick event or auxillary event for higher number buttons for each state change
1757 buttonstate = ji.dwButtons;
1758 for (i=0 ; i < (int) joy_numbuttons ; i++)
1760 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
1762 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1763 Key_Event (key_index + i, true);
1766 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
1768 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1769 Key_Event (key_index + i, false);
1772 joy_oldbuttonstate = buttonstate;
1776 // convert POV information into 4 bits of state information
1777 // this avoids any potential problems related to moving from one
1778 // direction to another without going through the center position
1780 if(ji.dwPOV != JOY_POVCENTERED)
1782 if (ji.dwPOV == JOY_POVFORWARD)
1784 if (ji.dwPOV == JOY_POVRIGHT)
1786 if (ji.dwPOV == JOY_POVBACKWARD)
1788 if (ji.dwPOV == JOY_POVLEFT)
1791 // determine which bits have changed and key an auxillary event for each change
1792 for (i=0 ; i < 4 ; i++)
1794 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
1796 Key_Event (K_AUX29 + i, true);
1799 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
1801 Key_Event (K_AUX29 + i, false);
1804 joy_oldpovstate = povstate;
1814 qboolean IN_ReadJoystick (void)
1817 memset (&ji, 0, sizeof(ji));
1818 ji.dwSize = sizeof(ji);
1819 ji.dwFlags = joy_flags;
1821 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1823 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1824 // rather than having 32768 be the zero point, they have the zero point at 32668
1825 // go figure -- anyway, now we get the full resolution out of the device
1826 if (joy_wwhack1.integer != 0.0)
1834 // read error occurred
1835 // turning off the joystick seems too harsh for 1 read error,
1836 // but what should be done?
1847 void IN_JoyMove (usercmd_t *cmd)
1849 float speed, aspeed;
1850 float fAxisValue, fTemp;
1851 int i, mouselook = (in_mlook.state & 1) || freelook.integer;
1853 // complete initialization if first time in
1854 // this is needed as cvars are not available at initialization time
1855 if( joy_advancedinit != true )
1857 Joy_AdvancedUpdate_f();
1858 joy_advancedinit = true;
1861 // verify joystick is available and that the user wants to use it
1862 if (!joy_avail || !in_joystick.integer)
1867 // collect the joystick data, if possible
1868 if (IN_ReadJoystick () != true)
1873 if (in_speed.state & 1)
1874 speed = cl_movespeedkey.value;
1877 // LordHavoc: viewzoom affects sensitivity for sniping
1878 aspeed = speed * host_realframetime * cl.viewzoom;
1880 // loop through the axes
1881 for (i = 0; i < JOY_MAX_AXES; i++)
1883 // get the floating point zero-centered, potentially-inverted data for the current axis
1884 fAxisValue = (float) *pdwRawValue[i];
1885 // move centerpoint to zero
1886 fAxisValue -= 32768.0;
1888 if (joy_wwhack2.integer != 0.0)
1890 if (dwAxisMap[i] == AxisTurn)
1892 // this is a special formula for the Logitech WingMan Warrior
1893 // y=ax^b; where a = 300 and b = 1.3
1894 // also x values are in increments of 800 (so this is factored out)
1895 // then bounds check result to level out excessively high spin rates
1896 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1897 if (fTemp > 14000.0)
1899 // restore direction information
1900 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1904 // convert range from -32768..32767 to -1..1
1905 fAxisValue /= 32768.0;
1907 switch (dwAxisMap[i])
1910 if ((joy_advanced.integer == 0) && mouselook)
1912 // user wants forward control to become look control
1913 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1915 // if mouse invert is on, invert the joystick pitch value
1916 // only absolute control support here (joy_advanced is false)
1917 if (m_pitch.value < 0.0)
1919 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1923 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1929 // no pitch movement
1930 // disable pitch return-to-center unless requested by user
1931 // *** this code can be removed when the lookspring bug is fixed
1932 // *** the bug always has the lookspring feature on
1933 if(lookspring.value == 0.0)
1939 // user wants forward control to be forward control
1940 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1942 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1948 if (fabs(fAxisValue) > joy_sidethreshold.value)
1950 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1955 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
1957 // user wants turn control to become side control
1958 if (fabs(fAxisValue) > joy_sidethreshold.value)
1960 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1965 // user wants turn control to be turn control
1966 if (fabs(fAxisValue) > joy_yawthreshold.value)
1968 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1970 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1974 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1984 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1986 // pitch movement detected and pitch movement desired by user
1987 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1989 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1993 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1999 // no pitch movement
2000 // disable pitch return-to-center unless requested by user
2001 // *** this code can be removed when the lookspring bug is fixed
2002 // *** the bug always has the lookspring feature on
2003 if(lookspring.integer == 0)