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, int stencil)
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");
711 pfd.cStencilBits = 8;
713 pfd.cStencilBits = 0;
715 gldrivername = "opengl32.dll";
716 i = COM_CheckParm("-gl_driver");
717 if (i && i < com_argc - 1)
718 gldrivername = com_argv[i + 1];
719 if (!GL_OpenLibrary(gldrivername))
721 Con_Printf("Unable to load GL driver %s\n", gldrivername);
725 memset(&gdevmode, 0, sizeof(gdevmode));
727 VID_GetSystemGamma();
729 vid_isfullscreen = false;
732 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
733 gdevmode.dmBitsPerPel = bpp;
734 gdevmode.dmPelsWidth = width;
735 gdevmode.dmPelsHeight = height;
736 gdevmode.dmSize = sizeof (gdevmode);
737 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
740 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
744 vid_isfullscreen = true;
745 WindowStyle = WS_POPUP;
751 i = GetDeviceCaps(hdc, RASTERCAPS);
752 ReleaseDC (NULL, hdc);
756 Con_Printf ("Can't run in non-RGB mode\n");
760 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
767 rect.bottom = height;
768 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
777 CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
778 CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
780 CenterX = max(0, CenterX);
781 CenterY = max(0, CenterY);
783 // x and y may be changed by WM_MOVE messages
786 window_width = width;
787 window_height = height;
788 rect.left += CenterX;
789 rect.right += CenterX;
791 rect.bottom += CenterY;
793 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
797 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);
803 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
806 ShowWindow (mainwindow, SW_SHOWDEFAULT);
807 UpdateWindow (mainwindow);
809 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
810 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
812 VID_UpdateWindowStatus ();
814 // now we try to make sure we get the focus on the mode switch, because
815 // sometimes in some systems we don't. We grab the foreground, then
816 // finish setting up, pump all our messages, and sleep for a little while
817 // to let messages finish bouncing around the system, then we put
818 // ourselves at the top of the z order, then grab the foreground again,
819 // Who knows if it helps, but it probably doesn't hurt
820 SetForegroundWindow (mainwindow);
822 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
824 TranslateMessage (&msg);
825 DispatchMessage (&msg);
830 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
832 SetForegroundWindow (mainwindow);
834 // fix the leftover Alt from any Alt-Tab or the like that switched us away
837 hdc = GetDC(mainwindow);
839 if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)
842 Con_Printf("ChoosePixelFormat(%d, %p) failed\n", hdc, &pfd);
846 if (SetPixelFormat(hdc, pixelformat, &pfd) == false)
849 Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", hdc, pixelformat, &pfd);
853 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
856 Con_Printf("wgl functions not found\n");
860 baseRC = qwglCreateContext(hdc);
864 Con_Printf("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
867 if (!qwglMakeCurrent(hdc, baseRC))
870 Con_Printf("wglMakeCurrent(%d, %d) failed\n", hdc, baseRC);
874 qglGetString = GL_GetProcAddress("glGetString");
875 qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB");
876 if (qglGetString == NULL)
879 Con_Printf("glGetString not found\n");
882 gl_renderer = qglGetString(GL_RENDERER);
883 gl_vendor = qglGetString(GL_VENDOR);
884 gl_version = qglGetString(GL_VERSION);
885 gl_extensions = qglGetString(GL_EXTENSIONS);
887 gl_platformextensions = "";
889 if (qwglGetExtensionsStringARB)
890 gl_platformextensions = qwglGetExtensionsStringARB(hdc);
892 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
893 ReleaseDC(mainwindow, hdc);
897 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
898 if (strncasecmp(gl_vendor,"ATI",3)==0)
900 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
903 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
906 //vid_menudrawfn = VID_MenuDraw;
907 //vid_menukeyfn = VID_MenuKey;
909 vid_initialized = true;
912 IN_StartupJoystick ();
917 void VID_Shutdown (void)
924 vid_initialized = false;
926 IN_DeactivateMouse ();
930 IDirectInputDevice_Release(g_pMouse);
934 IDirectInput_Release(g_pdi);
937 if (qwglGetCurrentContext)
938 hRC = qwglGetCurrentContext();
940 if (qwglGetCurrentDC)
941 hDC = qwglGetCurrentDC();
944 qwglMakeCurrent(NULL, NULL);
946 if (hRC && qwglDeleteContext)
947 qwglDeleteContext(hRC);
949 // close the library before we get rid of the window
952 if (hDC && mainwindow)
953 ReleaseDC(mainwindow, hDC);
955 if (vid_isfullscreen)
956 ChangeDisplaySettings (NULL, 0);
958 AppActivate(false, false);
960 VID_RestoreSystemGamma();
969 #define DINPUT_BUFFERSIZE 16
970 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
972 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
973 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
977 int mouse_oldbuttonstate;
979 int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
981 static qboolean restore_spi;
982 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
984 unsigned int uiWheelMessage;
985 qboolean mouseactive;
986 //qboolean mouseinitialized;
987 static qboolean mouseparmsvalid, mouseactivatetoggle;
988 static qboolean mouseshowtoggle = 1;
989 static qboolean dinput_acquired;
991 static unsigned int mstate_di;
993 // joystick defines and variables
994 // where should defines be moved?
995 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
996 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
997 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
1000 #define JOY_AXIS_Z 2
1001 #define JOY_AXIS_R 3
1002 #define JOY_AXIS_U 4
1003 #define JOY_AXIS_V 5
1007 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
1010 DWORD dwAxisFlags[JOY_MAX_AXES] =
1012 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
1015 DWORD dwAxisMap[JOY_MAX_AXES];
1016 DWORD dwControlMap[JOY_MAX_AXES];
1017 PDWORD pdwRawValue[JOY_MAX_AXES];
1019 // none of these cvars are saved over a session
1020 // this means that advanced controller configuration needs to be executed
1021 // each time. this avoids any problems with getting back to a default usage
1022 // or when changing from one controller to another. this way at least something
1024 cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
1025 cvar_t joy_name = {0, "joyname", "joystick"};
1026 cvar_t joy_advanced = {0, "joyadvanced", "0"};
1027 cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
1028 cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
1029 cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
1030 cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
1031 cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
1032 cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
1033 cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
1034 cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
1035 cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
1036 cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
1037 cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
1038 cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
1039 cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
1040 cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
1041 cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
1042 cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
1044 qboolean joy_avail, joy_advancedinit, joy_haspov;
1045 DWORD joy_oldbuttonstate, joy_oldpovstate;
1049 DWORD joy_numbuttons;
1051 static LPDIRECTINPUT g_pdi;
1052 static LPDIRECTINPUTDEVICE g_pMouse;
1054 static JOYINFOEX ji;
1056 static HINSTANCE hInstDI;
1058 //static qboolean dinput;
1060 typedef struct MYDATA {
1061 LONG lX; // X axis goes here
1062 LONG lY; // Y axis goes here
1063 LONG lZ; // Z axis goes here
1064 BYTE bButtonA; // One button goes here
1065 BYTE bButtonB; // Another button goes here
1066 BYTE bButtonC; // Another button goes here
1067 BYTE bButtonD; // Another button goes here
1070 static DIOBJECTDATAFORMAT rgodf[] = {
1071 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1072 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1073 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
1074 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1075 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1076 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1077 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
1080 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
1082 static DIDATAFORMAT df = {
1083 sizeof(DIDATAFORMAT), // this structure
1084 sizeof(DIOBJECTDATAFORMAT), // size of object data format
1085 DIDF_RELAXIS, // absolute axis coordinates
1086 sizeof(MYDATA), // device data size
1087 NUM_OBJECTS, // number of objects
1088 rgodf, // and here they are
1091 // forward-referenced functions
1092 void IN_StartupJoystick (void);
1093 void Joy_AdvancedUpdate_f (void);
1094 void IN_JoyMove (usercmd_t *cmd);
1102 void IN_ShowMouse (void)
1104 if (!mouseshowtoggle)
1107 mouseshowtoggle = 1;
1117 void IN_HideMouse (void)
1119 if (mouseshowtoggle)
1122 mouseshowtoggle = 0;
1132 void IN_ActivateMouse (void)
1135 mouseactivatetoggle = true;
1137 if (mouseinitialized)
1143 if (!dinput_acquired)
1145 IDirectInputDevice_Acquire(g_pMouse);
1146 dinput_acquired = true;
1157 window_rect.left = window_x;
1158 window_rect.top = window_y;
1159 window_rect.right = window_x + window_width;
1160 window_rect.bottom = window_y + window_height;
1162 if (mouseparmsvalid)
1163 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
1165 SetCursorPos (window_center_x, window_center_y);
1166 SetCapture (mainwindow);
1167 ClipCursor (&window_rect);
1180 void IN_DeactivateMouse (void)
1183 mouseactivatetoggle = false;
1185 if (mouseinitialized)
1191 if (dinput_acquired)
1193 IDirectInputDevice_Unacquire(g_pMouse);
1194 dinput_acquired = false;
1201 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1207 mouseactive = false;
1217 qboolean IN_InitDInput (void)
1220 DIPROPDWORD dipdw = {
1222 sizeof(DIPROPDWORD), // diph.dwSize
1223 sizeof(DIPROPHEADER), // diph.dwHeaderSize
1225 DIPH_DEVICE, // diph.dwHow
1227 DINPUT_BUFFERSIZE, // dwData
1232 hInstDI = LoadLibrary("dinput.dll");
1234 if (hInstDI == NULL)
1236 Con_SafePrintf ("Couldn't load dinput.dll\n");
1241 if (!pDirectInputCreate)
1243 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
1245 if (!pDirectInputCreate)
1247 Con_SafePrintf ("Couldn't get DI proc addr\n");
1252 // register with DirectInput and get an IDirectInput to play with.
1253 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
1260 // obtain an interface to the system mouse device.
1261 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
1265 Con_SafePrintf ("Couldn't open DI mouse device\n");
1269 // set the data format to "mouse format".
1270 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
1274 Con_SafePrintf ("Couldn't set DI mouse format\n");
1278 // set the cooperativity level.
1279 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
1280 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
1284 Con_SafePrintf ("Couldn't set DI coop level\n");
1289 // set the buffer size to DINPUT_BUFFERSIZE elements.
1290 // the buffer size is a DWORD property associated with the device
1291 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
1295 Con_SafePrintf ("Couldn't set DI buffersize\n");
1308 void IN_StartupMouse (void)
1310 if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
1313 mouseinitialized = true;
1315 if (COM_CheckParm ("-dinput"))
1317 dinput = IN_InitDInput ();
1321 Con_SafePrintf ("DirectInput initialized\n");
1325 Con_SafePrintf ("DirectInput not initialized\n");
1331 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
1333 if (mouseparmsvalid)
1335 if ( COM_CheckParm ("-noforcemspd") )
1336 newmouseparms[2] = originalmouseparms[2];
1338 if ( COM_CheckParm ("-noforcemaccel") )
1340 newmouseparms[0] = originalmouseparms[0];
1341 newmouseparms[1] = originalmouseparms[1];
1344 if ( COM_CheckParm ("-noforcemparms") )
1346 newmouseparms[0] = originalmouseparms[0];
1347 newmouseparms[1] = originalmouseparms[1];
1348 newmouseparms[2] = originalmouseparms[2];
1355 // if a fullscreen video mode was set before the mouse was initialized,
1356 // set the mouse state appropriately
1357 if (mouseactivatetoggle)
1358 IN_ActivateMouse ();
1367 void IN_MouseEvent (int mstate)
1371 if (mouseactive && !dinput)
1373 // perform button actions
1374 for (i=0 ; i<mouse_buttons ; i++)
1376 if ( (mstate & (1<<i)) &&
1377 !(mouse_oldbuttonstate & (1<<i)) )
1379 Key_Event (K_MOUSE1 + i, true);
1382 if ( !(mstate & (1<<i)) &&
1383 (mouse_oldbuttonstate & (1<<i)) )
1385 Key_Event (K_MOUSE1 + i, false);
1389 mouse_oldbuttonstate = mstate;
1399 void IN_MouseMove (usercmd_t *cmd)
1402 DIDEVICEOBJECTDATA od;
1408 GetCursorPos (¤t_pos);
1409 ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
1422 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
1423 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
1425 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
1427 dinput_acquired = true;
1428 IDirectInputDevice_Acquire(g_pMouse);
1432 /* Unable to read data or no data available */
1433 if (FAILED(hr) || dwElements == 0)
1436 /* Look at the element to see what happened */
1448 case DIMOFS_BUTTON0:
1449 if (od.dwData & 0x80)
1455 case DIMOFS_BUTTON1:
1456 if (od.dwData & 0x80)
1457 mstate_di |= (1<<1);
1459 mstate_di &= ~(1<<1);
1462 case DIMOFS_BUTTON2:
1463 if (od.dwData & 0x80)
1464 mstate_di |= (1<<2);
1466 mstate_di &= ~(1<<2);
1471 // perform button actions
1472 for (i=0 ; i<mouse_buttons ; i++)
1474 if ( (mstate_di & (1<<i)) &&
1475 !(mouse_oldbuttonstate & (1<<i)) )
1477 Key_Event (K_MOUSE1 + i, true);
1480 if ( !(mstate_di & (1<<i)) &&
1481 (mouse_oldbuttonstate & (1<<i)) )
1483 Key_Event (K_MOUSE1 + i, false);
1487 mouse_oldbuttonstate = mstate_di;
1491 GetCursorPos (¤t_pos);
1492 mx = current_pos.x - window_center_x + mx_accum;
1493 my = current_pos.y - window_center_y + my_accum;
1498 IN_Mouse(cmd, mx, my);
1500 // if the mouse has moved, force it to the center, so there's room to move
1501 if (!dinput && (mx || my))
1502 SetCursorPos (window_center_x, window_center_y);
1511 void IN_Move (usercmd_t *cmd)
1513 if (vid_activewindow && !vid_hidden)
1526 void IN_Accumulate (void)
1532 GetCursorPos (¤t_pos);
1534 mx_accum += current_pos.x - window_center_x;
1535 my_accum += current_pos.y - window_center_y;
1537 // force the mouse to the center, so there's room to move
1538 SetCursorPos (window_center_x, window_center_y);
1549 void IN_ClearStates (void)
1555 mouse_oldbuttonstate = 0;
1565 void IN_StartupJoystick (void)
1572 // assume no joystick
1575 // abort startup if user requests no joystick
1576 if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe"))
1579 // verify joystick driver is present
1580 if ((numdevs = joyGetNumDevs ()) == 0)
1582 Con_Printf ("\njoystick not found -- driver not present\n\n");
1586 // cycle through the joystick ids for the first valid one
1587 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
1589 memset (&ji, 0, sizeof(ji));
1590 ji.dwSize = sizeof(ji);
1591 ji.dwFlags = JOY_RETURNCENTERED;
1593 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
1597 // abort startup if we didn't find a valid joystick
1598 if (mmr != JOYERR_NOERROR)
1600 Con_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
1604 // get the capabilities of the selected joystick
1605 // abort startup if command fails
1606 memset (&jc, 0, sizeof(jc));
1607 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
1609 Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
1613 // save the joystick's number of buttons and POV status
1614 joy_numbuttons = jc.wNumButtons;
1615 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
1617 // old button and POV states default to no buttons pressed
1618 joy_oldbuttonstate = joy_oldpovstate = 0;
1620 // mark the joystick as available and advanced initialization not completed
1621 // this is needed as cvars are not available during initialization
1624 joy_advancedinit = false;
1626 Con_Printf ("\njoystick detected\n\n");
1635 PDWORD RawValuePointer (int axis)
1652 return NULL; // LordHavoc: hush compiler warning
1658 Joy_AdvancedUpdate_f
1661 void Joy_AdvancedUpdate_f (void)
1664 // called once by IN_ReadJoystick and by user whenever an update is needed
1665 // cvars are now available
1669 // initialize all the maps
1670 for (i = 0; i < JOY_MAX_AXES; i++)
1672 dwAxisMap[i] = AxisNada;
1673 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
1674 pdwRawValue[i] = RawValuePointer(i);
1677 if( joy_advanced.integer == 0)
1679 // default joystick initialization
1680 // 2 axes only with joystick control
1681 dwAxisMap[JOY_AXIS_X] = AxisTurn;
1682 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
1683 dwAxisMap[JOY_AXIS_Y] = AxisForward;
1684 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
1688 if (strcmp (joy_name.string, "joystick") != 0)
1690 // notify user of advanced controller
1691 Con_Printf ("\n%s configured\n\n", joy_name.string);
1694 // advanced initialization here
1695 // data supplied by user via joy_axisn cvars
1696 dwTemp = (DWORD) joy_advaxisx.value;
1697 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
1698 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
1699 dwTemp = (DWORD) joy_advaxisy.value;
1700 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
1701 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
1702 dwTemp = (DWORD) joy_advaxisz.value;
1703 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
1704 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
1705 dwTemp = (DWORD) joy_advaxisr.value;
1706 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
1707 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
1708 dwTemp = (DWORD) joy_advaxisu.value;
1709 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
1710 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
1711 dwTemp = (DWORD) joy_advaxisv.value;
1712 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
1713 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
1716 // compute the axes to collect from DirectInput
1717 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
1718 for (i = 0; i < JOY_MAX_AXES; i++)
1720 if (dwAxisMap[i] != AxisNada)
1722 joy_flags |= dwAxisFlags[i];
1733 void IN_Commands (void)
1736 DWORD buttonstate, povstate;
1744 // loop through the joystick buttons
1745 // key a joystick event or auxillary event for higher number buttons for each state change
1746 buttonstate = ji.dwButtons;
1747 for (i=0 ; i < (int) joy_numbuttons ; i++)
1749 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
1751 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1752 Key_Event (key_index + i, true);
1755 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
1757 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1758 Key_Event (key_index + i, false);
1761 joy_oldbuttonstate = buttonstate;
1765 // convert POV information into 4 bits of state information
1766 // this avoids any potential problems related to moving from one
1767 // direction to another without going through the center position
1769 if(ji.dwPOV != JOY_POVCENTERED)
1771 if (ji.dwPOV == JOY_POVFORWARD)
1773 if (ji.dwPOV == JOY_POVRIGHT)
1775 if (ji.dwPOV == JOY_POVBACKWARD)
1777 if (ji.dwPOV == JOY_POVLEFT)
1780 // determine which bits have changed and key an auxillary event for each change
1781 for (i=0 ; i < 4 ; i++)
1783 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
1785 Key_Event (K_AUX29 + i, true);
1788 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
1790 Key_Event (K_AUX29 + i, false);
1793 joy_oldpovstate = povstate;
1803 qboolean IN_ReadJoystick (void)
1806 memset (&ji, 0, sizeof(ji));
1807 ji.dwSize = sizeof(ji);
1808 ji.dwFlags = joy_flags;
1810 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1812 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1813 // rather than having 32768 be the zero point, they have the zero point at 32668
1814 // go figure -- anyway, now we get the full resolution out of the device
1815 if (joy_wwhack1.integer != 0.0)
1823 // read error occurred
1824 // turning off the joystick seems too harsh for 1 read error,
1825 // but what should be done?
1836 void IN_JoyMove (usercmd_t *cmd)
1838 float speed, aspeed;
1839 float fAxisValue, fTemp;
1840 int i, mouselook = (in_mlook.state & 1) || freelook.integer;
1842 // complete initialization if first time in
1843 // this is needed as cvars are not available at initialization time
1844 if( joy_advancedinit != true )
1846 Joy_AdvancedUpdate_f();
1847 joy_advancedinit = true;
1850 // verify joystick is available and that the user wants to use it
1851 if (!joy_avail || !in_joystick.integer)
1856 // collect the joystick data, if possible
1857 if (IN_ReadJoystick () != true)
1862 if (in_speed.state & 1)
1863 speed = cl_movespeedkey.value;
1866 // LordHavoc: viewzoom affects sensitivity for sniping
1867 aspeed = speed * host_realframetime * cl.viewzoom;
1869 // loop through the axes
1870 for (i = 0; i < JOY_MAX_AXES; i++)
1872 // get the floating point zero-centered, potentially-inverted data for the current axis
1873 fAxisValue = (float) *pdwRawValue[i];
1874 // move centerpoint to zero
1875 fAxisValue -= 32768.0;
1877 if (joy_wwhack2.integer != 0.0)
1879 if (dwAxisMap[i] == AxisTurn)
1881 // this is a special formula for the Logitech WingMan Warrior
1882 // y=ax^b; where a = 300 and b = 1.3
1883 // also x values are in increments of 800 (so this is factored out)
1884 // then bounds check result to level out excessively high spin rates
1885 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1886 if (fTemp > 14000.0)
1888 // restore direction information
1889 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1893 // convert range from -32768..32767 to -1..1
1894 fAxisValue /= 32768.0;
1896 switch (dwAxisMap[i])
1899 if ((joy_advanced.integer == 0) && mouselook)
1901 // user wants forward control to become look control
1902 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1904 // if mouse invert is on, invert the joystick pitch value
1905 // only absolute control support here (joy_advanced is false)
1906 if (m_pitch.value < 0.0)
1908 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1912 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1918 // no pitch movement
1919 // disable pitch return-to-center unless requested by user
1920 // *** this code can be removed when the lookspring bug is fixed
1921 // *** the bug always has the lookspring feature on
1922 if(lookspring.value == 0.0)
1928 // user wants forward control to be forward control
1929 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1931 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1937 if (fabs(fAxisValue) > joy_sidethreshold.value)
1939 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1944 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
1946 // user wants turn control to become side control
1947 if (fabs(fAxisValue) > joy_sidethreshold.value)
1949 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1954 // user wants turn control to be turn control
1955 if (fabs(fAxisValue) > joy_yawthreshold.value)
1957 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1959 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1963 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1973 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1975 // pitch movement detected and pitch movement desired by user
1976 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1978 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1982 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1988 // no pitch movement
1989 // disable pitch return-to-center unless requested by user
1990 // *** this code can be removed when the lookspring bug is fixed
1991 // *** the bug always has the lookspring feature on
1992 if(lookspring.integer == 0)