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");
649 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
651 // joystick variables
652 Cvar_RegisterVariable (&in_joystick);
653 Cvar_RegisterVariable (&joy_name);
654 Cvar_RegisterVariable (&joy_advanced);
655 Cvar_RegisterVariable (&joy_advaxisx);
656 Cvar_RegisterVariable (&joy_advaxisy);
657 Cvar_RegisterVariable (&joy_advaxisz);
658 Cvar_RegisterVariable (&joy_advaxisr);
659 Cvar_RegisterVariable (&joy_advaxisu);
660 Cvar_RegisterVariable (&joy_advaxisv);
661 Cvar_RegisterVariable (&joy_forwardthreshold);
662 Cvar_RegisterVariable (&joy_sidethreshold);
663 Cvar_RegisterVariable (&joy_pitchthreshold);
664 Cvar_RegisterVariable (&joy_yawthreshold);
665 Cvar_RegisterVariable (&joy_forwardsensitivity);
666 Cvar_RegisterVariable (&joy_sidesensitivity);
667 Cvar_RegisterVariable (&joy_pitchsensitivity);
668 Cvar_RegisterVariable (&joy_yawsensitivity);
669 Cvar_RegisterVariable (&joy_wwhack1);
670 Cvar_RegisterVariable (&joy_wwhack2);
671 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
674 int VID_InitMode (int fullscreen, int width, int height, int bpp)
680 PIXELFORMATDESCRIPTOR pfd =
682 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
684 PFD_DRAW_TO_WINDOW // support window
685 | PFD_SUPPORT_OPENGL // support OpenGL
686 | PFD_DOUBLEBUFFER , // double buffered
687 PFD_TYPE_RGBA, // RGBA type
688 24, // 24-bit color depth
689 0, 0, 0, 0, 0, 0, // color bits ignored
690 0, // no alpha buffer
691 0, // shift bit ignored
692 0, // no accumulation buffer
693 0, 0, 0, 0, // accum bits ignored
694 32, // 32-bit z-buffer
695 0, // no stencil buffer
696 0, // no auxiliary buffer
697 PFD_MAIN_PLANE, // main layer
699 0, 0, 0 // layer masks ignored
702 DWORD WindowStyle, ExWindowStyle;
704 int CenterX, CenterY;
705 const char *gldrivername;
708 Sys_Error("VID_InitMode called when video is already initialised\n");
710 gldrivername = "opengl32.dll";
711 i = COM_CheckParm("-gl_driver");
712 if (i && i < com_argc - 1)
713 gldrivername = com_argv[i + 1];
714 if (!GL_OpenLibrary(gldrivername))
716 Con_Printf("Unable to load GL driver %s\n", gldrivername);
720 memset(&gdevmode, 0, sizeof(gdevmode));
722 VID_GetSystemGamma();
724 vid_isfullscreen = false;
727 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
728 gdevmode.dmBitsPerPel = bpp;
729 gdevmode.dmPelsWidth = width;
730 gdevmode.dmPelsHeight = height;
731 gdevmode.dmSize = sizeof (gdevmode);
732 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
735 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
739 vid_isfullscreen = true;
740 WindowStyle = WS_POPUP;
746 i = GetDeviceCaps(hdc, RASTERCAPS);
747 ReleaseDC (NULL, hdc);
751 Con_Printf ("Can't run in non-RGB mode\n");
755 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
762 rect.bottom = height;
763 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
772 CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
773 CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
775 CenterX = max(0, CenterX);
776 CenterY = max(0, CenterY);
778 // x and y may be changed by WM_MOVE messages
781 window_width = width;
782 window_height = height;
783 rect.left += CenterX;
784 rect.right += CenterX;
786 rect.bottom += CenterY;
788 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
792 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);
798 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
801 ShowWindow (mainwindow, SW_SHOWDEFAULT);
802 UpdateWindow (mainwindow);
804 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
805 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
807 VID_UpdateWindowStatus ();
809 // now we try to make sure we get the focus on the mode switch, because
810 // sometimes in some systems we don't. We grab the foreground, then
811 // finish setting up, pump all our messages, and sleep for a little while
812 // to let messages finish bouncing around the system, then we put
813 // ourselves at the top of the z order, then grab the foreground again,
814 // Who knows if it helps, but it probably doesn't hurt
815 SetForegroundWindow (mainwindow);
817 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
819 TranslateMessage (&msg);
820 DispatchMessage (&msg);
825 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
827 SetForegroundWindow (mainwindow);
829 // fix the leftover Alt from any Alt-Tab or the like that switched us away
832 hdc = GetDC(mainwindow);
834 if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)
837 Con_Printf("ChoosePixelFormat(%d, %p) failed\n", hdc, &pfd);
841 if (SetPixelFormat(hdc, pixelformat, &pfd) == false)
844 Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", hdc, pixelformat, &pfd);
848 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
851 Con_Printf("wgl functions not found\n");
855 baseRC = qwglCreateContext(hdc);
859 Con_Printf("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
862 if (!qwglMakeCurrent(hdc, baseRC))
865 Con_Printf("wglMakeCurrent(%d, %d) failed\n", hdc, baseRC);
869 qglGetString = GL_GetProcAddress("glGetString");
870 qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB");
871 if (qglGetString == NULL)
874 Con_Printf("glGetString not found\n");
877 gl_renderer = qglGetString(GL_RENDERER);
878 gl_vendor = qglGetString(GL_VENDOR);
879 gl_version = qglGetString(GL_VERSION);
880 gl_extensions = qglGetString(GL_EXTENSIONS);
882 gl_platformextensions = "";
884 if (qwglGetExtensionsStringARB)
885 gl_platformextensions = qwglGetExtensionsStringARB(hdc);
887 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
888 ReleaseDC(mainwindow, hdc);
892 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
893 if (strncasecmp(gl_vendor,"ATI",3)==0)
895 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
898 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
901 //vid_menudrawfn = VID_MenuDraw;
902 //vid_menukeyfn = VID_MenuKey;
904 vid_initialized = true;
907 IN_StartupJoystick ();
912 void VID_Shutdown (void)
919 vid_initialized = false;
921 IN_DeactivateMouse ();
925 IDirectInputDevice_Release(g_pMouse);
929 IDirectInput_Release(g_pdi);
932 if (qwglGetCurrentContext)
933 hRC = qwglGetCurrentContext();
935 if (qwglGetCurrentDC)
936 hDC = qwglGetCurrentDC();
939 qwglMakeCurrent(NULL, NULL);
941 if (hRC && qwglDeleteContext)
942 qwglDeleteContext(hRC);
944 // close the library before we get rid of the window
947 if (hDC && mainwindow)
948 ReleaseDC(mainwindow, hDC);
950 if (vid_isfullscreen)
951 ChangeDisplaySettings (NULL, 0);
953 AppActivate(false, false);
955 VID_RestoreSystemGamma();
964 #define DINPUT_BUFFERSIZE 16
965 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
967 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
968 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
972 int mouse_oldbuttonstate;
974 int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
976 static qboolean restore_spi;
977 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
979 unsigned int uiWheelMessage;
980 qboolean mouseactive;
981 //qboolean mouseinitialized;
982 static qboolean mouseparmsvalid, mouseactivatetoggle;
983 static qboolean mouseshowtoggle = 1;
984 static qboolean dinput_acquired;
986 static unsigned int mstate_di;
988 // joystick defines and variables
989 // where should defines be moved?
990 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
991 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
992 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
1002 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
1005 DWORD dwAxisFlags[JOY_MAX_AXES] =
1007 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
1010 DWORD dwAxisMap[JOY_MAX_AXES];
1011 DWORD dwControlMap[JOY_MAX_AXES];
1012 PDWORD pdwRawValue[JOY_MAX_AXES];
1014 // none of these cvars are saved over a session
1015 // this means that advanced controller configuration needs to be executed
1016 // each time. this avoids any problems with getting back to a default usage
1017 // or when changing from one controller to another. this way at least something
1019 cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
1020 cvar_t joy_name = {0, "joyname", "joystick"};
1021 cvar_t joy_advanced = {0, "joyadvanced", "0"};
1022 cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
1023 cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
1024 cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
1025 cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
1026 cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
1027 cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
1028 cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
1029 cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
1030 cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
1031 cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
1032 cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
1033 cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
1034 cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
1035 cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
1036 cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
1037 cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
1039 qboolean joy_avail, joy_advancedinit, joy_haspov;
1040 DWORD joy_oldbuttonstate, joy_oldpovstate;
1044 DWORD joy_numbuttons;
1046 static LPDIRECTINPUT g_pdi;
1047 static LPDIRECTINPUTDEVICE g_pMouse;
1049 static JOYINFOEX ji;
1051 static HINSTANCE hInstDI;
1053 //static qboolean dinput;
1055 typedef struct MYDATA {
1056 LONG lX; // X axis goes here
1057 LONG lY; // Y axis goes here
1058 LONG lZ; // Z axis goes here
1059 BYTE bButtonA; // One button goes here
1060 BYTE bButtonB; // Another button goes here
1061 BYTE bButtonC; // Another button goes here
1062 BYTE bButtonD; // Another button goes here
1065 static DIOBJECTDATAFORMAT rgodf[] = {
1066 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1067 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1068 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1069 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1070 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1071 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1072 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1075 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
1077 static DIDATAFORMAT df = {
1078 sizeof(DIDATAFORMAT), // this structure
1079 sizeof(DIOBJECTDATAFORMAT), // size of object data format
1080 DIDF_RELAXIS, // absolute axis coordinates
1081 sizeof(MYDATA), // device data size
1082 NUM_OBJECTS, // number of objects
1083 rgodf, // and here they are
1086 // forward-referenced functions
1087 void IN_StartupJoystick (void);
1088 void Joy_AdvancedUpdate_f (void);
1089 void IN_JoyMove (usercmd_t *cmd);
1097 void IN_ShowMouse (void)
1099 if (!mouseshowtoggle)
1102 mouseshowtoggle = 1;
1112 void IN_HideMouse (void)
1114 if (mouseshowtoggle)
1117 mouseshowtoggle = 0;
1127 void IN_ActivateMouse (void)
1130 mouseactivatetoggle = true;
1132 if (mouseinitialized)
1138 if (!dinput_acquired)
1140 IDirectInputDevice_Acquire(g_pMouse);
1141 dinput_acquired = true;
1152 window_rect.left = window_x;
1153 window_rect.top = window_y;
1154 window_rect.right = window_x + window_width;
1155 window_rect.bottom = window_y + window_height;
1157 if (mouseparmsvalid)
1158 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
1160 SetCursorPos (window_center_x, window_center_y);
1161 SetCapture (mainwindow);
1162 ClipCursor (&window_rect);
1175 void IN_DeactivateMouse (void)
1178 mouseactivatetoggle = false;
1180 if (mouseinitialized)
1186 if (dinput_acquired)
1188 IDirectInputDevice_Unacquire(g_pMouse);
1189 dinput_acquired = false;
1196 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1202 mouseactive = false;
1212 qboolean IN_InitDInput (void)
1215 DIPROPDWORD dipdw = {
1217 sizeof(DIPROPDWORD), // diph.dwSize
1218 sizeof(DIPROPHEADER), // diph.dwHeaderSize
1220 DIPH_DEVICE, // diph.dwHow
1222 DINPUT_BUFFERSIZE, // dwData
1227 hInstDI = LoadLibrary("dinput.dll");
1229 if (hInstDI == NULL)
1231 Con_SafePrintf ("Couldn't load dinput.dll\n");
1236 if (!pDirectInputCreate)
1238 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
1240 if (!pDirectInputCreate)
1242 Con_SafePrintf ("Couldn't get DI proc addr\n");
1247 // register with DirectInput and get an IDirectInput to play with.
1248 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
1255 // obtain an interface to the system mouse device.
1256 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
1260 Con_SafePrintf ("Couldn't open DI mouse device\n");
1264 // set the data format to "mouse format".
1265 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
1269 Con_SafePrintf ("Couldn't set DI mouse format\n");
1273 // set the cooperativity level.
1274 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
1275 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
1279 Con_SafePrintf ("Couldn't set DI coop level\n");
1284 // set the buffer size to DINPUT_BUFFERSIZE elements.
1285 // the buffer size is a DWORD property associated with the device
1286 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
1290 Con_SafePrintf ("Couldn't set DI buffersize\n");
1303 void IN_StartupMouse (void)
1305 if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
1308 mouseinitialized = true;
1310 if (COM_CheckParm ("-dinput"))
1312 dinput = IN_InitDInput ();
1316 Con_SafePrintf ("DirectInput initialized\n");
1320 Con_SafePrintf ("DirectInput not initialized\n");
1326 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
1328 if (mouseparmsvalid)
1330 if ( COM_CheckParm ("-noforcemspd") )
1331 newmouseparms[2] = originalmouseparms[2];
1333 if ( COM_CheckParm ("-noforcemaccel") )
1335 newmouseparms[0] = originalmouseparms[0];
1336 newmouseparms[1] = originalmouseparms[1];
1339 if ( COM_CheckParm ("-noforcemparms") )
1341 newmouseparms[0] = originalmouseparms[0];
1342 newmouseparms[1] = originalmouseparms[1];
1343 newmouseparms[2] = originalmouseparms[2];
1350 // if a fullscreen video mode was set before the mouse was initialized,
1351 // set the mouse state appropriately
1352 if (mouseactivatetoggle)
1353 IN_ActivateMouse ();
1362 void IN_MouseEvent (int mstate)
1366 if (mouseactive && !dinput)
1368 // perform button actions
1369 for (i=0 ; i<mouse_buttons ; i++)
1371 if ( (mstate & (1<<i)) &&
1372 !(mouse_oldbuttonstate & (1<<i)) )
1374 Key_Event (K_MOUSE1 + i, true);
1377 if ( !(mstate & (1<<i)) &&
1378 (mouse_oldbuttonstate & (1<<i)) )
1380 Key_Event (K_MOUSE1 + i, false);
1384 mouse_oldbuttonstate = mstate;
1394 void IN_MouseMove (usercmd_t *cmd)
1397 DIDEVICEOBJECTDATA od;
1403 GetCursorPos (¤t_pos);
1404 ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
1417 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
1418 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
1420 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
1422 dinput_acquired = true;
1423 IDirectInputDevice_Acquire(g_pMouse);
1427 /* Unable to read data or no data available */
1428 if (FAILED(hr) || dwElements == 0)
1431 /* Look at the element to see what happened */
1443 case DIMOFS_BUTTON0:
1444 if (od.dwData & 0x80)
1450 case DIMOFS_BUTTON1:
1451 if (od.dwData & 0x80)
1452 mstate_di |= (1<<1);
1454 mstate_di &= ~(1<<1);
1457 case DIMOFS_BUTTON2:
1458 if (od.dwData & 0x80)
1459 mstate_di |= (1<<2);
1461 mstate_di &= ~(1<<2);
1466 // perform button actions
1467 for (i=0 ; i<mouse_buttons ; i++)
1469 if ( (mstate_di & (1<<i)) &&
1470 !(mouse_oldbuttonstate & (1<<i)) )
1472 Key_Event (K_MOUSE1 + i, true);
1475 if ( !(mstate_di & (1<<i)) &&
1476 (mouse_oldbuttonstate & (1<<i)) )
1478 Key_Event (K_MOUSE1 + i, false);
1482 mouse_oldbuttonstate = mstate_di;
1486 GetCursorPos (¤t_pos);
1487 mx = current_pos.x - window_center_x + mx_accum;
1488 my = current_pos.y - window_center_y + my_accum;
1493 IN_Mouse(cmd, mx, my);
1495 // if the mouse has moved, force it to the center, so there's room to move
1496 if (!dinput && (mx || my))
1497 SetCursorPos (window_center_x, window_center_y);
1506 void IN_Move (usercmd_t *cmd)
1508 if (vid_activewindow && !vid_hidden)
1521 void IN_Accumulate (void)
1527 GetCursorPos (¤t_pos);
1529 mx_accum += current_pos.x - window_center_x;
1530 my_accum += current_pos.y - window_center_y;
1532 // force the mouse to the center, so there's room to move
1533 SetCursorPos (window_center_x, window_center_y);
1544 void IN_ClearStates (void)
1550 mouse_oldbuttonstate = 0;
1560 void IN_StartupJoystick (void)
1567 // assume no joystick
1570 // abort startup if user requests no joystick
1571 if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe"))
1574 // verify joystick driver is present
1575 if ((numdevs = joyGetNumDevs ()) == 0)
1577 Con_Printf ("\njoystick not found -- driver not present\n\n");
1581 // cycle through the joystick ids for the first valid one
1582 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
1584 memset (&ji, 0, sizeof(ji));
1585 ji.dwSize = sizeof(ji);
1586 ji.dwFlags = JOY_RETURNCENTERED;
1588 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
1592 // abort startup if we didn't find a valid joystick
1593 if (mmr != JOYERR_NOERROR)
1595 Con_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
1599 // get the capabilities of the selected joystick
1600 // abort startup if command fails
1601 memset (&jc, 0, sizeof(jc));
1602 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
1604 Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
1608 // save the joystick's number of buttons and POV status
1609 joy_numbuttons = jc.wNumButtons;
1610 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
1612 // old button and POV states default to no buttons pressed
1613 joy_oldbuttonstate = joy_oldpovstate = 0;
1615 // mark the joystick as available and advanced initialization not completed
1616 // this is needed as cvars are not available during initialization
1619 joy_advancedinit = false;
1621 Con_Printf ("\njoystick detected\n\n");
1630 PDWORD RawValuePointer (int axis)
1647 return NULL; // LordHavoc: hush compiler warning
1653 Joy_AdvancedUpdate_f
1656 void Joy_AdvancedUpdate_f (void)
1659 // called once by IN_ReadJoystick and by user whenever an update is needed
1660 // cvars are now available
1664 // initialize all the maps
1665 for (i = 0; i < JOY_MAX_AXES; i++)
1667 dwAxisMap[i] = AxisNada;
1668 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
1669 pdwRawValue[i] = RawValuePointer(i);
1672 if( joy_advanced.integer == 0)
1674 // default joystick initialization
1675 // 2 axes only with joystick control
1676 dwAxisMap[JOY_AXIS_X] = AxisTurn;
1677 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
1678 dwAxisMap[JOY_AXIS_Y] = AxisForward;
1679 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
1683 if (strcmp (joy_name.string, "joystick") != 0)
1685 // notify user of advanced controller
1686 Con_Printf ("\n%s configured\n\n", joy_name.string);
1689 // advanced initialization here
1690 // data supplied by user via joy_axisn cvars
1691 dwTemp = (DWORD) joy_advaxisx.value;
1692 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
1693 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
1694 dwTemp = (DWORD) joy_advaxisy.value;
1695 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
1696 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
1697 dwTemp = (DWORD) joy_advaxisz.value;
1698 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
1699 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
1700 dwTemp = (DWORD) joy_advaxisr.value;
1701 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
1702 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
1703 dwTemp = (DWORD) joy_advaxisu.value;
1704 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
1705 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
1706 dwTemp = (DWORD) joy_advaxisv.value;
1707 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
1708 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
1711 // compute the axes to collect from DirectInput
1712 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
1713 for (i = 0; i < JOY_MAX_AXES; i++)
1715 if (dwAxisMap[i] != AxisNada)
1717 joy_flags |= dwAxisFlags[i];
1728 void IN_Commands (void)
1731 DWORD buttonstate, povstate;
1739 // loop through the joystick buttons
1740 // key a joystick event or auxillary event for higher number buttons for each state change
1741 buttonstate = ji.dwButtons;
1742 for (i=0 ; i < (int) joy_numbuttons ; i++)
1744 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
1746 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1747 Key_Event (key_index + i, true);
1750 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
1752 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1753 Key_Event (key_index + i, false);
1756 joy_oldbuttonstate = buttonstate;
1760 // convert POV information into 4 bits of state information
1761 // this avoids any potential problems related to moving from one
1762 // direction to another without going through the center position
1764 if(ji.dwPOV != JOY_POVCENTERED)
1766 if (ji.dwPOV == JOY_POVFORWARD)
1768 if (ji.dwPOV == JOY_POVRIGHT)
1770 if (ji.dwPOV == JOY_POVBACKWARD)
1772 if (ji.dwPOV == JOY_POVLEFT)
1775 // determine which bits have changed and key an auxillary event for each change
1776 for (i=0 ; i < 4 ; i++)
1778 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
1780 Key_Event (K_AUX29 + i, true);
1783 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
1785 Key_Event (K_AUX29 + i, false);
1788 joy_oldpovstate = povstate;
1798 qboolean IN_ReadJoystick (void)
1801 memset (&ji, 0, sizeof(ji));
1802 ji.dwSize = sizeof(ji);
1803 ji.dwFlags = joy_flags;
1805 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1807 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1808 // rather than having 32768 be the zero point, they have the zero point at 32668
1809 // go figure -- anyway, now we get the full resolution out of the device
1810 if (joy_wwhack1.integer != 0.0)
1818 // read error occurred
1819 // turning off the joystick seems too harsh for 1 read error,
1820 // but what should be done?
1831 void IN_JoyMove (usercmd_t *cmd)
1833 float speed, aspeed;
1834 float fAxisValue, fTemp;
1835 int i, mouselook = (in_mlook.state & 1) || freelook.integer;
1837 // complete initialization if first time in
1838 // this is needed as cvars are not available at initialization time
1839 if( joy_advancedinit != true )
1841 Joy_AdvancedUpdate_f();
1842 joy_advancedinit = true;
1845 // verify joystick is available and that the user wants to use it
1846 if (!joy_avail || !in_joystick.integer)
1851 // collect the joystick data, if possible
1852 if (IN_ReadJoystick () != true)
1857 if (in_speed.state & 1)
1858 speed = cl_movespeedkey.value;
1861 // LordHavoc: viewzoom affects sensitivity for sniping
1862 aspeed = speed * host_realframetime * cl.viewzoom;
1864 // loop through the axes
1865 for (i = 0; i < JOY_MAX_AXES; i++)
1867 // get the floating point zero-centered, potentially-inverted data for the current axis
1868 fAxisValue = (float) *pdwRawValue[i];
1869 // move centerpoint to zero
1870 fAxisValue -= 32768.0;
1872 if (joy_wwhack2.integer != 0.0)
1874 if (dwAxisMap[i] == AxisTurn)
1876 // this is a special formula for the Logitech WingMan Warrior
1877 // y=ax^b; where a = 300 and b = 1.3
1878 // also x values are in increments of 800 (so this is factored out)
1879 // then bounds check result to level out excessively high spin rates
1880 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1881 if (fTemp > 14000.0)
1883 // restore direction information
1884 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1888 // convert range from -32768..32767 to -1..1
1889 fAxisValue /= 32768.0;
1891 switch (dwAxisMap[i])
1894 if ((joy_advanced.integer == 0) && mouselook)
1896 // user wants forward control to become look control
1897 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1899 // if mouse invert is on, invert the joystick pitch value
1900 // only absolute control support here (joy_advanced is false)
1901 if (m_pitch.value < 0.0)
1903 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1907 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1913 // no pitch movement
1914 // disable pitch return-to-center unless requested by user
1915 // *** this code can be removed when the lookspring bug is fixed
1916 // *** the bug always has the lookspring feature on
1917 if(lookspring.value == 0.0)
1923 // user wants forward control to be forward control
1924 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1926 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1932 if (fabs(fAxisValue) > joy_sidethreshold.value)
1934 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1939 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
1941 // user wants turn control to become side control
1942 if (fabs(fAxisValue) > joy_sidethreshold.value)
1944 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1949 // user wants turn control to be turn control
1950 if (fabs(fAxisValue) > joy_yawthreshold.value)
1952 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1954 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1958 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1968 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1970 // pitch movement detected and pitch movement desired by user
1971 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1973 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1977 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1983 // no pitch movement
1984 // disable pitch return-to-center unless requested by user
1985 // *** this code can be removed when the lookspring bug is fixed
1986 // *** the bug always has the lookspring feature on
1987 if(lookspring.integer == 0)