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 getextensionsstringfuncs[] =
45 {"wglGetExtensionsString", (void **) &qwglGetExtensionsStringARB},
49 static gl_extensionfunctionlist_t wglfuncs[] =
51 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
52 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
53 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
54 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
55 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
56 {"wglCreateContext", (void **) &qwglCreateContext},
57 {"wglDeleteContext", (void **) &qwglDeleteContext},
58 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
59 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
60 {"wglGetCurrentContext", (void **) &qwglGetCurrentContext},
61 {"wglGetCurrentDC", (void **) &qwglGetCurrentDC},
65 static gl_extensionfunctionlist_t wglswapintervalfuncs[] =
67 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
71 void VID_RestoreGameGamma(void);
72 void VID_GetSystemGamma(void);
73 void VID_RestoreSystemGamma(void);
75 qboolean scr_skipupdate;
77 static DEVMODE gdevmode;
78 static qboolean vid_initialized = false;
79 static qboolean vid_wassuspended = false;
80 static int vid_usingmouse;
81 extern qboolean mouseactive; // from in_win.c
86 //HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
88 static int vid_isfullscreen;
90 //void VID_MenuDraw (void);
91 //void VID_MenuKey (int key);
93 //LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
94 //void AppActivate(BOOL fActive, BOOL minimize);
95 //void ClearAllStates (void);
96 //void VID_UpdateWindowStatus (void);
98 //====================================
100 int window_x, window_y, window_width, window_height;
101 int window_center_x, window_center_y;
103 void IN_ShowMouse (void);
104 void IN_DeactivateMouse (void);
105 void IN_HideMouse (void);
106 void IN_ActivateMouse (void);
107 void IN_MouseEvent (int mstate);
108 void IN_UpdateClipCursor (void);
110 qboolean mouseinitialized;
111 static qboolean dinput;
115 VID_UpdateWindowStatus
118 void VID_UpdateWindowStatus (void)
120 window_center_x = window_x + window_width / 2;
121 window_center_y = window_y + window_height / 2;
123 if (mouseinitialized && mouseactive && !dinput)
126 window_rect.left = window_x;
127 window_rect.top = window_y;
128 window_rect.right = window_x + window_width;
129 window_rect.bottom = window_y + window_height;
130 ClipCursor (&window_rect);
135 //====================================
142 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
146 *width = window_width;
147 *height = window_height;
151 void VID_Finish (void)
155 if (r_render.integer && !scr_skipupdate)
158 hdc = GetDC(mainwindow);
160 ReleaseDC(mainwindow, hdc);
163 // handle the mouse state when windowed if that's changed
164 vid_usemouse = false;
165 if (vid_mouse.integer && !key_consoleactive)
167 if (vid_isfullscreen)
169 if (!vid_activewindow)
170 vid_usemouse = false;
175 vid_usingmouse = true;
184 vid_usingmouse = false;
185 IN_DeactivateMouse ();
191 //==========================================================================
196 qbyte scantokey[128] =
198 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
199 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
200 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
201 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
202 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
203 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
204 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
205 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
206 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
214 Map from windows to quake keynums
217 int MapKey (int key, int virtualkey)
222 if (scantokey[key] == 0)
223 Con_DPrintf("key 0x%02x has no translation\n", key);
224 return scantokey[key];
228 ===================================================================
232 ===================================================================
240 void ClearAllStates (void)
244 // send an up event for each key, to make sure the server clears them all
245 for (i=0 ; i<256 ; i++)
247 Key_Event (i, false);
254 void VID_RestoreGameGamma(void);
255 extern qboolean host_loopactive;
257 void AppActivate(BOOL fActive, BOOL minimize)
258 /****************************************************************************
260 * Function: AppActivate
261 * Parameters: fActive - True if app is activating
263 * Description: If the application is activating, then swap the system
264 * into SYSPAL_NOSTATIC mode so that our palettes will display
267 ****************************************************************************/
269 static BOOL sound_active;
271 vid_activewindow = fActive;
272 vid_hidden = minimize;
274 // enable/disable sound on focus gain/loss
275 if (!vid_activewindow && sound_active)
278 sound_active = false;
280 else if (vid_activewindow && !sound_active)
288 if (vid_isfullscreen)
290 if (vid_wassuspended)
292 vid_wassuspended = false;
293 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
294 ShowWindow(mainwindow, SW_SHOWNORMAL);
297 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
298 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
301 VID_RestoreGameGamma();
306 vid_usingmouse = false;
307 IN_DeactivateMouse ();
309 if (vid_isfullscreen)
311 ChangeDisplaySettings (NULL, 0);
312 vid_wassuspended = true;
314 VID_RestoreSystemGamma();
318 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
320 /* main window procedure */
321 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
324 int fActive, fMinimized, temp;
325 extern unsigned int uiWheelMessage;
327 if ( uMsg == uiWheelMessage )
328 uMsg = WM_MOUSEWHEEL;
333 if (vid_isfullscreen)
334 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
341 window_x = (int) LOWORD(lParam);
342 window_y = (int) HIWORD(lParam);
343 VID_UpdateWindowStatus ();
348 Key_Event (MapKey(lParam, wParam), true);
353 Key_Event (MapKey(lParam, wParam), false);
357 // keep Alt-Space from happening
360 // this is complicated because Win32 seems to pack multiple mouse events into
361 // one update sometimes, so we always check all states and look for events
371 if (wParam & MK_LBUTTON)
374 if (wParam & MK_RBUTTON)
377 if (wParam & MK_MBUTTON)
380 IN_MouseEvent (temp);
384 // JACK: This is the mouse wheel with the Intellimouse
385 // Its delta is either positive or neg, and we generate the proper
388 if ((short) HIWORD(wParam) > 0) {
389 Key_Event(K_MWHEELUP, true);
390 Key_Event(K_MWHEELUP, false);
392 Key_Event(K_MWHEELDOWN, true);
393 Key_Event(K_MWHEELDOWN, false);
401 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
407 fActive = LOWORD(wParam);
408 fMinimized = (BOOL) HIWORD(wParam);
409 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
411 // fix the leftover Alt from any Alt-Tab or the like that switched us away
419 DestroyWindow (mainwindow);
426 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
430 /* pass all unhandled messages to DefWindowProc */
431 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
435 /* return 1 if handled message, 0 if not */
440 //static int grabsysgamma = true;
441 WORD systemgammaramps[3][256], currentgammaramps[3][256];
443 int VID_SetGamma(float prescale, float gamma, float scale, float base)
449 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
450 for (i = 0;i < 256;i++)
451 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
453 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
455 ReleaseDC (NULL, hdc);
456 return i; // return success or failure
459 void VID_RestoreGameGamma(void)
461 VID_UpdateGamma(true);
464 void VID_GetSystemGamma(void)
469 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
471 ReleaseDC (NULL, hdc);
474 void VID_RestoreSystemGamma(void)
479 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
481 ReleaseDC (NULL, hdc);
484 //========================================================
486 //========================================================
489 extern void M_Menu_Options_f (void);
490 extern void M_Print (float cx, float cy, char *str);
491 extern void M_PrintWhite (float cx, float cy, char *str);
492 extern void M_DrawCharacter (float cx, float cy, int num);
493 extern void M_DrawPic (float cx, float cy, char *picname);
495 static int vid_wmodes;
504 #define MAX_COLUMN_SIZE 9
505 #define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 2)
506 #define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
508 static modedesc_t modedescs[MAX_MODEDESCS];
515 void VID_MenuDraw (void)
519 int lnummodes, i, k, column, row;
522 p = Draw_CachePic ("gfx/vidmodes.lmp");
523 M_DrawPic ( (320-p->width)/2, 4, "gfx/vidmodes.lmp");
526 lnummodes = VID_NumModes ();
528 for (i=1 ; (i<lnummodes) && (vid_wmodes < MAX_MODEDESCS) ; i++)
530 ptr = VID_GetModeDescription (i);
531 pv = VID_GetModePtr (i);
535 modedescs[k].modenum = i;
536 modedescs[k].desc = ptr;
537 modedescs[k].iscur = 0;
539 if (i == vid_modenum)
540 modedescs[k].iscur = 1;
548 M_Print (2*8, 36+0*8, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
553 for (i=0 ; i<vid_wmodes ; i++)
555 if (modedescs[i].iscur)
556 M_PrintWhite (column, row, modedescs[i].desc);
558 M_Print (column, row, modedescs[i].desc);
562 if ((i % VID_ROW_SIZE) == (VID_ROW_SIZE - 1))
570 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*2, "Video modes must be set from the");
571 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*3, "command line with -width <width>");
572 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*4, "and -bpp <bits-per-pixel>");
573 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*6, "Select windowed mode with -window");
582 void VID_MenuKey (int key)
587 S_LocalSound ("misc/menu1.wav");
597 static HINSTANCE gldll;
599 int GL_OpenLibrary(const char *name)
601 Con_Printf("Loading GL driver %s\n", name);
603 if (!(gldll = LoadLibrary(name)))
605 Con_Printf("Unable to LoadLibrary %s\n", name);
608 strcpy(gl_driver, name);
612 void GL_CloseLibrary(void)
617 qwglGetProcAddress = NULL;
620 gl_platformextensions = "";
623 void *GL_GetProcAddress(const char *name)
626 if (qwglGetProcAddress != NULL)
627 p = (void *) qwglGetProcAddress(name);
629 p = (void *) GetProcAddress(gldll, name);
637 InitCommonControls();
638 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
640 // Register the frame class
642 wc.lpfnWndProc = (WNDPROC)MainWndProc;
645 wc.hInstance = global_hInstance;
647 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
648 wc.hbrBackground = NULL;
650 wc.lpszClassName = "DarkPlacesWindowClass";
652 if (!RegisterClass (&wc))
653 Sys_Error("Couldn't register window class\n");
656 int VID_InitMode (int fullscreen, int width, int height, int bpp)
662 PIXELFORMATDESCRIPTOR pfd =
664 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
666 PFD_DRAW_TO_WINDOW // support window
667 | PFD_SUPPORT_OPENGL // support OpenGL
668 | PFD_DOUBLEBUFFER , // double buffered
669 PFD_TYPE_RGBA, // RGBA type
670 24, // 24-bit color depth
671 0, 0, 0, 0, 0, 0, // color bits ignored
672 0, // no alpha buffer
673 0, // shift bit ignored
674 0, // no accumulation buffer
675 0, 0, 0, 0, // accum bits ignored
676 32, // 32-bit z-buffer
677 0, // no stencil buffer
678 0, // no auxiliary buffer
679 PFD_MAIN_PLANE, // main layer
681 0, 0, 0 // layer masks ignored
684 DWORD WindowStyle, ExWindowStyle;
686 int CenterX, CenterY;
689 Sys_Error("VID_InitMode called when video is already initialised\n");
691 if (!GL_OpenLibrary("opengl32.dll"))
693 Con_Printf("Unable to load GL driver\n");
697 memset(&gdevmode, 0, sizeof(gdevmode));
699 VID_GetSystemGamma();
701 vid_isfullscreen = false;
704 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
705 gdevmode.dmBitsPerPel = bpp;
706 gdevmode.dmPelsWidth = width;
707 gdevmode.dmPelsHeight = height;
708 gdevmode.dmSize = sizeof (gdevmode);
709 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
712 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
716 vid_isfullscreen = true;
717 WindowStyle = WS_POPUP;
723 i = GetDeviceCaps(hdc, RASTERCAPS);
724 ReleaseDC (NULL, hdc);
728 Con_Printf ("Can't run in non-RGB mode\n");
732 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
739 rect.bottom = height;
740 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
749 CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
750 CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
752 CenterX = max(0, CenterX);
753 CenterY = max(0, CenterY);
755 // x and y may be changed by WM_MOVE messages
758 window_width = width;
759 window_height = height;
760 rect.left += CenterX;
761 rect.right += CenterX;
763 rect.bottom += CenterY;
765 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
769 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);
775 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
778 ShowWindow (mainwindow, SW_SHOWDEFAULT);
779 UpdateWindow (mainwindow);
781 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
782 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
784 VID_UpdateWindowStatus ();
786 // now we try to make sure we get the focus on the mode switch, because
787 // sometimes in some systems we don't. We grab the foreground, then
788 // finish setting up, pump all our messages, and sleep for a little while
789 // to let messages finish bouncing around the system, then we put
790 // ourselves at the top of the z order, then grab the foreground again,
791 // Who knows if it helps, but it probably doesn't hurt
792 SetForegroundWindow (mainwindow);
794 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
796 TranslateMessage (&msg);
797 DispatchMessage (&msg);
802 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
804 SetForegroundWindow (mainwindow);
806 // fix the leftover Alt from any Alt-Tab or the like that switched us away
809 hdc = GetDC(mainwindow);
811 if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)
814 Con_Printf("ChoosePixelFormat(%d, %p) failed\n", hdc, &pfd);
818 if (SetPixelFormat(hdc, pixelformat, &pfd) == false)
821 Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", hdc, pixelformat, &pfd);
825 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
828 Con_Printf("wgl functions not found\n");
832 baseRC = qwglCreateContext(hdc);
836 Con_Printf("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
839 if (!qwglMakeCurrent(hdc, baseRC))
842 Con_Printf("wglMakeCurrent(%d, %d) failed\n", hdc, baseRC);
846 qglGetString = GL_GetProcAddress("glGetString");
847 if (qglGetString == NULL)
850 Con_Printf("glGetString not found\n");
853 gl_renderer = qglGetString(GL_RENDERER);
854 gl_vendor = qglGetString(GL_VENDOR);
855 gl_version = qglGetString(GL_VERSION);
856 gl_extensions = qglGetString(GL_EXTENSIONS);
858 gl_platformextensions = "";
860 if (GL_CheckExtension("WGL_ARB_extensions_string", getextensionsstringfuncs, NULL, false))
861 gl_platformextensions = qwglGetExtensionsStringARB(hdc);
863 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
864 ReleaseDC(mainwindow, hdc);
868 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
869 if (strncasecmp(gl_vendor,"ATI",3)==0)
871 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
874 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
877 //vid_menudrawfn = VID_MenuDraw;
878 //vid_menukeyfn = VID_MenuKey;
880 vid_initialized = true;
884 void VID_Shutdown (void)
891 vid_initialized = false;
892 if (qwglGetCurrentContext)
893 hRC = qwglGetCurrentContext();
894 if (qwglGetCurrentDC)
895 hDC = qwglGetCurrentDC();
898 qwglMakeCurrent(NULL, NULL);
900 if (hRC && qwglDeleteContext)
901 qwglDeleteContext(hRC);
903 // close the library before we get rid of the window
906 if (hDC && mainwindow)
907 ReleaseDC(mainwindow, hDC);
909 if (vid_isfullscreen)
910 ChangeDisplaySettings (NULL, 0);
912 AppActivate(false, false);
914 VID_RestoreSystemGamma();
923 #define DINPUT_BUFFERSIZE 16
924 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
926 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
927 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
931 int mouse_oldbuttonstate;
933 int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
935 static qboolean restore_spi;
936 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
938 unsigned int uiWheelMessage;
939 qboolean mouseactive;
940 //qboolean mouseinitialized;
941 static qboolean mouseparmsvalid, mouseactivatetoggle;
942 static qboolean mouseshowtoggle = 1;
943 static qboolean dinput_acquired;
945 static unsigned int mstate_di;
947 // joystick defines and variables
948 // where should defines be moved?
949 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
950 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
951 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
961 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
964 DWORD dwAxisFlags[JOY_MAX_AXES] =
966 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
969 DWORD dwAxisMap[JOY_MAX_AXES];
970 DWORD dwControlMap[JOY_MAX_AXES];
971 PDWORD pdwRawValue[JOY_MAX_AXES];
973 // none of these cvars are saved over a session
974 // this means that advanced controller configuration needs to be executed
975 // each time. this avoids any problems with getting back to a default usage
976 // or when changing from one controller to another. this way at least something
978 cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
979 cvar_t joy_name = {0, "joyname", "joystick"};
980 cvar_t joy_advanced = {0, "joyadvanced", "0"};
981 cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
982 cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
983 cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
984 cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
985 cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
986 cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
987 cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
988 cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
989 cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
990 cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
991 cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
992 cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
993 cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
994 cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
995 cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
996 cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
998 qboolean joy_avail, joy_advancedinit, joy_haspov;
999 DWORD joy_oldbuttonstate, joy_oldpovstate;
1003 DWORD joy_numbuttons;
1005 static LPDIRECTINPUT g_pdi;
1006 static LPDIRECTINPUTDEVICE g_pMouse;
1008 static JOYINFOEX ji;
1010 static HINSTANCE hInstDI;
1012 //static qboolean dinput;
1014 typedef struct MYDATA {
1015 LONG lX; // X axis goes here
1016 LONG lY; // Y axis goes here
1017 LONG lZ; // Z axis goes here
1018 BYTE bButtonA; // One button goes here
1019 BYTE bButtonB; // Another button goes here
1020 BYTE bButtonC; // Another button goes here
1021 BYTE bButtonD; // Another button goes here
1024 static DIOBJECTDATAFORMAT rgodf[] = {
1025 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1026 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1027 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1028 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1029 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1030 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1031 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1034 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
1036 static DIDATAFORMAT df = {
1037 sizeof(DIDATAFORMAT), // this structure
1038 sizeof(DIOBJECTDATAFORMAT), // size of object data format
1039 DIDF_RELAXIS, // absolute axis coordinates
1040 sizeof(MYDATA), // device data size
1041 NUM_OBJECTS, // number of objects
1042 rgodf, // and here they are
1045 // forward-referenced functions
1046 void IN_StartupJoystick (void);
1047 void Joy_AdvancedUpdate_f (void);
1048 void IN_JoyMove (usercmd_t *cmd);
1056 void IN_ShowMouse (void)
1058 if (!mouseshowtoggle)
1061 mouseshowtoggle = 1;
1071 void IN_HideMouse (void)
1073 if (mouseshowtoggle)
1076 mouseshowtoggle = 0;
1086 void IN_ActivateMouse (void)
1089 mouseactivatetoggle = true;
1091 if (mouseinitialized)
1097 if (!dinput_acquired)
1099 IDirectInputDevice_Acquire(g_pMouse);
1100 dinput_acquired = true;
1111 window_rect.left = window_x;
1112 window_rect.top = window_y;
1113 window_rect.right = window_x + window_width;
1114 window_rect.bottom = window_y + window_height;
1116 if (mouseparmsvalid)
1117 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
1119 SetCursorPos (window_center_x, window_center_y);
1120 SetCapture (mainwindow);
1121 ClipCursor (&window_rect);
1134 void IN_DeactivateMouse (void)
1137 mouseactivatetoggle = false;
1139 if (mouseinitialized)
1145 if (dinput_acquired)
1147 IDirectInputDevice_Unacquire(g_pMouse);
1148 dinput_acquired = false;
1155 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1161 mouseactive = false;
1171 qboolean IN_InitDInput (void)
1174 DIPROPDWORD dipdw = {
1176 sizeof(DIPROPDWORD), // diph.dwSize
1177 sizeof(DIPROPHEADER), // diph.dwHeaderSize
1179 DIPH_DEVICE, // diph.dwHow
1181 DINPUT_BUFFERSIZE, // dwData
1186 hInstDI = LoadLibrary("dinput.dll");
1188 if (hInstDI == NULL)
1190 Con_SafePrintf ("Couldn't load dinput.dll\n");
1195 if (!pDirectInputCreate)
1197 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
1199 if (!pDirectInputCreate)
1201 Con_SafePrintf ("Couldn't get DI proc addr\n");
1206 // register with DirectInput and get an IDirectInput to play with.
1207 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
1214 // obtain an interface to the system mouse device.
1215 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
1219 Con_SafePrintf ("Couldn't open DI mouse device\n");
1223 // set the data format to "mouse format".
1224 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
1228 Con_SafePrintf ("Couldn't set DI mouse format\n");
1232 // set the cooperativity level.
1233 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
1234 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
1238 Con_SafePrintf ("Couldn't set DI coop level\n");
1243 // set the buffer size to DINPUT_BUFFERSIZE elements.
1244 // the buffer size is a DWORD property associated with the device
1245 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
1249 Con_SafePrintf ("Couldn't set DI buffersize\n");
1262 void IN_StartupMouse (void)
1264 if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
1267 mouseinitialized = true;
1269 if (COM_CheckParm ("-dinput"))
1271 dinput = IN_InitDInput ();
1275 Con_SafePrintf ("DirectInput initialized\n");
1279 Con_SafePrintf ("DirectInput not initialized\n");
1285 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
1287 if (mouseparmsvalid)
1289 if ( COM_CheckParm ("-noforcemspd") )
1290 newmouseparms[2] = originalmouseparms[2];
1292 if ( COM_CheckParm ("-noforcemaccel") )
1294 newmouseparms[0] = originalmouseparms[0];
1295 newmouseparms[1] = originalmouseparms[1];
1298 if ( COM_CheckParm ("-noforcemparms") )
1300 newmouseparms[0] = originalmouseparms[0];
1301 newmouseparms[1] = originalmouseparms[1];
1302 newmouseparms[2] = originalmouseparms[2];
1309 // if a fullscreen video mode was set before the mouse was initialized,
1310 // set the mouse state appropriately
1311 if (mouseactivatetoggle)
1312 IN_ActivateMouse ();
1323 // joystick variables
1324 Cvar_RegisterVariable (&in_joystick);
1325 Cvar_RegisterVariable (&joy_name);
1326 Cvar_RegisterVariable (&joy_advanced);
1327 Cvar_RegisterVariable (&joy_advaxisx);
1328 Cvar_RegisterVariable (&joy_advaxisy);
1329 Cvar_RegisterVariable (&joy_advaxisz);
1330 Cvar_RegisterVariable (&joy_advaxisr);
1331 Cvar_RegisterVariable (&joy_advaxisu);
1332 Cvar_RegisterVariable (&joy_advaxisv);
1333 Cvar_RegisterVariable (&joy_forwardthreshold);
1334 Cvar_RegisterVariable (&joy_sidethreshold);
1335 Cvar_RegisterVariable (&joy_pitchthreshold);
1336 Cvar_RegisterVariable (&joy_yawthreshold);
1337 Cvar_RegisterVariable (&joy_forwardsensitivity);
1338 Cvar_RegisterVariable (&joy_sidesensitivity);
1339 Cvar_RegisterVariable (&joy_pitchsensitivity);
1340 Cvar_RegisterVariable (&joy_yawsensitivity);
1341 Cvar_RegisterVariable (&joy_wwhack1);
1342 Cvar_RegisterVariable (&joy_wwhack2);
1344 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
1346 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
1349 IN_StartupJoystick ();
1357 void IN_Shutdown (void)
1359 IN_DeactivateMouse ();
1364 IDirectInputDevice_Release(g_pMouse);
1370 IDirectInput_Release(g_pdi);
1381 void IN_MouseEvent (int mstate)
1385 if (mouseactive && !dinput)
1387 // perform button actions
1388 for (i=0 ; i<mouse_buttons ; i++)
1390 if ( (mstate & (1<<i)) &&
1391 !(mouse_oldbuttonstate & (1<<i)) )
1393 Key_Event (K_MOUSE1 + i, true);
1396 if ( !(mstate & (1<<i)) &&
1397 (mouse_oldbuttonstate & (1<<i)) )
1399 Key_Event (K_MOUSE1 + i, false);
1403 mouse_oldbuttonstate = mstate;
1413 void IN_MouseMove (usercmd_t *cmd)
1416 DIDEVICEOBJECTDATA od;
1422 GetCursorPos (¤t_pos);
1423 ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
1436 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
1437 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
1439 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
1441 dinput_acquired = true;
1442 IDirectInputDevice_Acquire(g_pMouse);
1446 /* Unable to read data or no data available */
1447 if (FAILED(hr) || dwElements == 0)
1450 /* Look at the element to see what happened */
1462 case DIMOFS_BUTTON0:
1463 if (od.dwData & 0x80)
1469 case DIMOFS_BUTTON1:
1470 if (od.dwData & 0x80)
1471 mstate_di |= (1<<1);
1473 mstate_di &= ~(1<<1);
1476 case DIMOFS_BUTTON2:
1477 if (od.dwData & 0x80)
1478 mstate_di |= (1<<2);
1480 mstate_di &= ~(1<<2);
1485 // perform button actions
1486 for (i=0 ; i<mouse_buttons ; i++)
1488 if ( (mstate_di & (1<<i)) &&
1489 !(mouse_oldbuttonstate & (1<<i)) )
1491 Key_Event (K_MOUSE1 + i, true);
1494 if ( !(mstate_di & (1<<i)) &&
1495 (mouse_oldbuttonstate & (1<<i)) )
1497 Key_Event (K_MOUSE1 + i, false);
1501 mouse_oldbuttonstate = mstate_di;
1505 GetCursorPos (¤t_pos);
1506 mx = current_pos.x - window_center_x + mx_accum;
1507 my = current_pos.y - window_center_y + my_accum;
1512 IN_Mouse(cmd, mx, my);
1514 // if the mouse has moved, force it to the center, so there's room to move
1515 if (!dinput && (mx || my))
1516 SetCursorPos (window_center_x, window_center_y);
1525 void IN_Move (usercmd_t *cmd)
1527 if (vid_activewindow && !vid_hidden)
1533 cl.viewangles[PITCH] = bound (in_pitch_min.value, cl.viewangles[PITCH], in_pitch_max.value);
1542 void IN_Accumulate (void)
1548 GetCursorPos (¤t_pos);
1550 mx_accum += current_pos.x - window_center_x;
1551 my_accum += current_pos.y - window_center_y;
1553 // force the mouse to the center, so there's room to move
1554 SetCursorPos (window_center_x, window_center_y);
1565 void IN_ClearStates (void)
1571 mouse_oldbuttonstate = 0;
1581 void IN_StartupJoystick (void)
1588 // assume no joystick
1591 // abort startup if user requests no joystick
1592 if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe"))
1595 // verify joystick driver is present
1596 if ((numdevs = joyGetNumDevs ()) == 0)
1598 Con_Printf ("\njoystick not found -- driver not present\n\n");
1602 // cycle through the joystick ids for the first valid one
1603 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
1605 memset (&ji, 0, sizeof(ji));
1606 ji.dwSize = sizeof(ji);
1607 ji.dwFlags = JOY_RETURNCENTERED;
1609 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
1613 // abort startup if we didn't find a valid joystick
1614 if (mmr != JOYERR_NOERROR)
1616 Con_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
1620 // get the capabilities of the selected joystick
1621 // abort startup if command fails
1622 memset (&jc, 0, sizeof(jc));
1623 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
1625 Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
1629 // save the joystick's number of buttons and POV status
1630 joy_numbuttons = jc.wNumButtons;
1631 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
1633 // old button and POV states default to no buttons pressed
1634 joy_oldbuttonstate = joy_oldpovstate = 0;
1636 // mark the joystick as available and advanced initialization not completed
1637 // this is needed as cvars are not available during initialization
1640 joy_advancedinit = false;
1642 Con_Printf ("\njoystick detected\n\n");
1651 PDWORD RawValuePointer (int axis)
1668 return NULL; // LordHavoc: hush compiler warning
1674 Joy_AdvancedUpdate_f
1677 void Joy_AdvancedUpdate_f (void)
1680 // called once by IN_ReadJoystick and by user whenever an update is needed
1681 // cvars are now available
1685 // initialize all the maps
1686 for (i = 0; i < JOY_MAX_AXES; i++)
1688 dwAxisMap[i] = AxisNada;
1689 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
1690 pdwRawValue[i] = RawValuePointer(i);
1693 if( joy_advanced.integer == 0)
1695 // default joystick initialization
1696 // 2 axes only with joystick control
1697 dwAxisMap[JOY_AXIS_X] = AxisTurn;
1698 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
1699 dwAxisMap[JOY_AXIS_Y] = AxisForward;
1700 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
1704 if (strcmp (joy_name.string, "joystick") != 0)
1706 // notify user of advanced controller
1707 Con_Printf ("\n%s configured\n\n", joy_name.string);
1710 // advanced initialization here
1711 // data supplied by user via joy_axisn cvars
1712 dwTemp = (DWORD) joy_advaxisx.value;
1713 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
1714 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
1715 dwTemp = (DWORD) joy_advaxisy.value;
1716 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
1717 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
1718 dwTemp = (DWORD) joy_advaxisz.value;
1719 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
1720 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
1721 dwTemp = (DWORD) joy_advaxisr.value;
1722 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
1723 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
1724 dwTemp = (DWORD) joy_advaxisu.value;
1725 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
1726 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
1727 dwTemp = (DWORD) joy_advaxisv.value;
1728 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
1729 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
1732 // compute the axes to collect from DirectInput
1733 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
1734 for (i = 0; i < JOY_MAX_AXES; i++)
1736 if (dwAxisMap[i] != AxisNada)
1738 joy_flags |= dwAxisFlags[i];
1749 void IN_Commands (void)
1752 DWORD buttonstate, povstate;
1760 // loop through the joystick buttons
1761 // key a joystick event or auxillary event for higher number buttons for each state change
1762 buttonstate = ji.dwButtons;
1763 for (i=0 ; i < (int) joy_numbuttons ; i++)
1765 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
1767 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1768 Key_Event (key_index + i, true);
1771 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
1773 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1774 Key_Event (key_index + i, false);
1777 joy_oldbuttonstate = buttonstate;
1781 // convert POV information into 4 bits of state information
1782 // this avoids any potential problems related to moving from one
1783 // direction to another without going through the center position
1785 if(ji.dwPOV != JOY_POVCENTERED)
1787 if (ji.dwPOV == JOY_POVFORWARD)
1789 if (ji.dwPOV == JOY_POVRIGHT)
1791 if (ji.dwPOV == JOY_POVBACKWARD)
1793 if (ji.dwPOV == JOY_POVLEFT)
1796 // determine which bits have changed and key an auxillary event for each change
1797 for (i=0 ; i < 4 ; i++)
1799 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
1801 Key_Event (K_AUX29 + i, true);
1804 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
1806 Key_Event (K_AUX29 + i, false);
1809 joy_oldpovstate = povstate;
1819 qboolean IN_ReadJoystick (void)
1822 memset (&ji, 0, sizeof(ji));
1823 ji.dwSize = sizeof(ji);
1824 ji.dwFlags = joy_flags;
1826 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1828 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1829 // rather than having 32768 be the zero point, they have the zero point at 32668
1830 // go figure -- anyway, now we get the full resolution out of the device
1831 if (joy_wwhack1.integer != 0.0)
1839 // read error occurred
1840 // turning off the joystick seems too harsh for 1 read error,
1841 // but what should be done?
1852 void IN_JoyMove (usercmd_t *cmd)
1854 float speed, aspeed;
1855 float fAxisValue, fTemp;
1856 int i, mouselook = (in_mlook.state & 1) || freelook.integer;
1858 // complete initialization if first time in
1859 // this is needed as cvars are not available at initialization time
1860 if( joy_advancedinit != true )
1862 Joy_AdvancedUpdate_f();
1863 joy_advancedinit = true;
1866 // verify joystick is available and that the user wants to use it
1867 if (!joy_avail || !in_joystick.integer)
1872 // collect the joystick data, if possible
1873 if (IN_ReadJoystick () != true)
1878 if (in_speed.state & 1)
1879 speed = cl_movespeedkey.value;
1882 // LordHavoc: viewzoom affects sensitivity for sniping
1883 aspeed = speed * host_realframetime * cl.viewzoom;
1885 // loop through the axes
1886 for (i = 0; i < JOY_MAX_AXES; i++)
1888 // get the floating point zero-centered, potentially-inverted data for the current axis
1889 fAxisValue = (float) *pdwRawValue[i];
1890 // move centerpoint to zero
1891 fAxisValue -= 32768.0;
1893 if (joy_wwhack2.integer != 0.0)
1895 if (dwAxisMap[i] == AxisTurn)
1897 // this is a special formula for the Logitech WingMan Warrior
1898 // y=ax^b; where a = 300 and b = 1.3
1899 // also x values are in increments of 800 (so this is factored out)
1900 // then bounds check result to level out excessively high spin rates
1901 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1902 if (fTemp > 14000.0)
1904 // restore direction information
1905 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1909 // convert range from -32768..32767 to -1..1
1910 fAxisValue /= 32768.0;
1912 switch (dwAxisMap[i])
1915 if ((joy_advanced.integer == 0) && mouselook)
1917 // user wants forward control to become look control
1918 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1920 // if mouse invert is on, invert the joystick pitch value
1921 // only absolute control support here (joy_advanced is false)
1922 if (m_pitch.value < 0.0)
1924 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1928 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1934 // no pitch movement
1935 // disable pitch return-to-center unless requested by user
1936 // *** this code can be removed when the lookspring bug is fixed
1937 // *** the bug always has the lookspring feature on
1938 if(lookspring.value == 0.0)
1944 // user wants forward control to be forward control
1945 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1947 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1953 if (fabs(fAxisValue) > joy_sidethreshold.value)
1955 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1960 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
1962 // user wants turn control to become side control
1963 if (fabs(fAxisValue) > joy_sidethreshold.value)
1965 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1970 // user wants turn control to be turn control
1971 if (fabs(fAxisValue) > joy_yawthreshold.value)
1973 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1975 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1979 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1989 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1991 // pitch movement detected and pitch movement desired by user
1992 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1994 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1998 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
2004 // no pitch movement
2005 // disable pitch return-to-center unless requested by user
2006 // *** this code can be removed when the lookspring bug is fixed
2007 // *** the bug always has the lookspring feature on
2008 if(lookspring.integer == 0)