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
28 extern void S_BlockSound (void);
29 extern void S_UnblockSound (void);
30 extern HINSTANCE global_hInstance;
34 #define WM_MOUSEWHEEL 0x020A
37 // Tell startup code that we have a client
38 int cl_available = true;
40 int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
41 int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
42 //int (WINAPI *qwglGetPixelFormat)(HDC);
43 BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
44 BOOL (WINAPI *qwglSwapBuffers)(HDC);
45 HGLRC (WINAPI *qwglCreateContext)(HDC);
46 BOOL (WINAPI *qwglDeleteContext)(HGLRC);
47 HGLRC (WINAPI *qwglGetCurrentContext)(VOID);
48 HDC (WINAPI *qwglGetCurrentDC)(VOID);
49 PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
50 BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
51 BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
52 const char *(WINAPI *qwglGetExtensionsStringARB)(HDC hdc);
54 static dllfunction_t wglfuncs[] =
56 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
57 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
58 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
59 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
60 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
61 {"wglCreateContext", (void **) &qwglCreateContext},
62 {"wglDeleteContext", (void **) &qwglDeleteContext},
63 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
64 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
65 {"wglGetCurrentContext", (void **) &qwglGetCurrentContext},
66 {"wglGetCurrentDC", (void **) &qwglGetCurrentDC},
70 static dllfunction_t wglswapintervalfuncs[] =
72 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
76 qboolean scr_skipupdate;
78 static DEVMODE gdevmode;
79 static qboolean vid_initialized = false;
80 static qboolean vid_wassuspended = false;
81 static int vid_usingmouse;
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;
117 #define DINPUT_BUFFERSIZE 16
118 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
120 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
121 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
123 // LordHavoc: thanks to backslash for this support for mouse buttons 4 and 5
124 /* backslash :: imouse explorer buttons */
125 /* These are #ifdefed out for non-Win2K in the February 2001 version of
126 MS's platform SDK, but we need them for compilation. . . */
127 #ifndef WM_XBUTTONDOWN
128 #define WM_XBUTTONDOWN 0x020B
129 #define WM_XBUTTONUP 0x020C
132 #define MK_XBUTTON1 0x0020
133 #define MK_XBUTTON2 0x0040
134 // LordHavoc: lets hope this allows more buttons in the future...
135 #define MK_XBUTTON3 0x0080
136 #define MK_XBUTTON4 0x0100
137 #define MK_XBUTTON5 0x0200
138 #define MK_XBUTTON6 0x0400
139 #define MK_XBUTTON7 0x0800
145 int mouse_oldbuttonstate;
147 int mouse_x, mouse_y, old_mouse_x, old_mouse_y;
149 static qboolean restore_spi;
150 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
152 unsigned int uiWheelMessage;
153 qboolean mouseactive;
154 //qboolean mouseinitialized;
155 static qboolean mouseparmsvalid, mouseactivatetoggle;
156 static qboolean mouseshowtoggle = 1;
157 static qboolean dinput_acquired;
159 static unsigned int mstate_di;
161 // joystick defines and variables
162 // where should defines be moved?
163 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
164 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
165 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
175 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
178 DWORD dwAxisFlags[JOY_MAX_AXES] =
180 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
183 DWORD dwAxisMap[JOY_MAX_AXES];
184 DWORD dwControlMap[JOY_MAX_AXES];
185 PDWORD pdwRawValue[JOY_MAX_AXES];
187 // none of these cvars are saved over a session
188 // this means that advanced controller configuration needs to be executed
189 // each time. this avoids any problems with getting back to a default usage
190 // or when changing from one controller to another. this way at least something
192 cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
193 cvar_t joy_name = {0, "joyname", "joystick"};
194 cvar_t joy_advanced = {0, "joyadvanced", "0"};
195 cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
196 cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
197 cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
198 cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
199 cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
200 cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
201 cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
202 cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
203 cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
204 cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
205 cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
206 cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
207 cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
208 cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
209 cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
210 cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
212 qboolean joy_avail, joy_advancedinit, joy_haspov;
213 DWORD joy_oldbuttonstate, joy_oldpovstate;
217 DWORD joy_numbuttons;
219 static LPDIRECTINPUT g_pdi;
220 static LPDIRECTINPUTDEVICE g_pMouse;
224 static HINSTANCE hInstDI;
226 //static qboolean dinput;
228 typedef struct MYDATA {
229 LONG lX; // X axis goes here
230 LONG lY; // Y axis goes here
231 LONG lZ; // Z axis goes here
232 BYTE bButtonA; // One button goes here
233 BYTE bButtonB; // Another button goes here
234 BYTE bButtonC; // Another button goes here
235 BYTE bButtonD; // Another button goes here
238 static DIOBJECTDATAFORMAT rgodf[] = {
239 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
240 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
241 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
242 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
243 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
244 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
245 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
248 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
250 static DIDATAFORMAT df = {
251 sizeof(DIDATAFORMAT), // this structure
252 sizeof(DIOBJECTDATAFORMAT), // size of object data format
253 DIDF_RELAXIS, // absolute axis coordinates
254 sizeof(MYDATA), // device data size
255 NUM_OBJECTS, // number of objects
256 rgodf, // and here they are
259 // forward-referenced functions
260 void IN_StartupJoystick (void);
261 void Joy_AdvancedUpdate_f (void);
262 void IN_JoyMove (usercmd_t *cmd);
263 void IN_StartupMouse (void);
267 VID_UpdateWindowStatus
270 void VID_UpdateWindowStatus (void)
272 window_center_x = window_x + window_width / 2;
273 window_center_y = window_y + window_height / 2;
275 if (mouseinitialized && mouseactive && !dinput)
278 window_rect.left = window_x;
279 window_rect.top = window_y;
280 window_rect.right = window_x + window_width;
281 window_rect.bottom = window_y + window_height;
282 ClipCursor (&window_rect);
287 //====================================
294 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
298 *width = window_width;
299 *height = window_height;
303 void VID_Finish (void)
307 static int old_vsync = -1;
309 if (old_vsync != vid_vsync.integer)
311 old_vsync = bound(0, vid_vsync.integer, 1);
312 Cvar_SetValueQuick(&vid_vsync, old_vsync);
313 if (gl_videosyncavailable)
314 qwglSwapIntervalEXT (old_vsync);
317 if (r_render.integer && !scr_skipupdate)
319 if (r_speeds.integer || gl_finish.integer)
321 hdc = GetDC(mainwindow);
323 ReleaseDC(mainwindow, hdc);
326 // handle the mouse state when windowed if that's changed
327 vid_usemouse = false;
328 if (vid_mouse.integer && !key_consoleactive)
330 if (vid_isfullscreen)
332 if (!vid_activewindow)
333 vid_usemouse = false;
338 vid_usingmouse = true;
347 vid_usingmouse = false;
348 IN_DeactivateMouse ();
354 //==========================================================================
359 qbyte scantokey[128] =
361 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
362 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 ,//0
363 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' ,//1
364 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT ,'\\' ,'z' ,'x' ,'c' ,'v' ,//2
365 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 ,//3
366 K_F6 ,K_F7 ,K_F8 ,K_F9 ,K_F10,K_PAUSE,0 ,K_HOME,K_UPARROW,K_PGUP,K_KP_MINUS,K_LEFTARROW,K_KP_5,K_RIGHTARROW,K_KP_PLUS ,K_END,//4
367 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,//5
368 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,//6
369 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 //7
377 Map from windows to quake keynums
380 static int MapKey (int key, int virtualkey)
383 int modified = (key >> 16) & 255;
384 qboolean is_extended = false;
386 if (modified < 128 && scantokey[modified])
387 result = scantokey[modified];
391 Con_DPrintf("key 0x%02x (0x%8x, 0x%8x) has no translation\n", modified, key, virtualkey);
408 return K_KP_LEFTARROW;
410 return K_KP_RIGHTARROW;
414 return K_KP_DOWNARROW;
441 ===================================================================
445 ===================================================================
453 void ClearAllStates (void)
459 extern qboolean host_loopactive;
461 void AppActivate(BOOL fActive, BOOL minimize)
462 /****************************************************************************
464 * Function: AppActivate
465 * Parameters: fActive - True if app is activating
467 * Description: If the application is activating, then swap the system
468 * into SYSPAL_NOSTATIC mode so that our palettes will display
471 ****************************************************************************/
473 static BOOL sound_active;
475 vid_activewindow = fActive;
476 vid_hidden = minimize;
478 // enable/disable sound on focus gain/loss
479 if (!vid_activewindow && sound_active)
482 sound_active = false;
484 else if (vid_activewindow && !sound_active)
492 if (vid_isfullscreen)
494 if (vid_wassuspended)
496 vid_wassuspended = false;
497 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
498 ShowWindow(mainwindow, SW_SHOWNORMAL);
501 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
502 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
508 vid_usingmouse = false;
509 IN_DeactivateMouse ();
511 if (vid_isfullscreen)
513 ChangeDisplaySettings (NULL, 0);
514 vid_wassuspended = true;
516 VID_RestoreSystemGamma();
520 //TODO: move it around in vid_wgl.c since I dont think this is the right position
521 void Sys_SendKeyEvents (void)
525 while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
527 // we always update if there are any event, even if we're paused
530 if (!GetMessage (&msg, NULL, 0, 0))
533 TranslateMessage (&msg);
534 DispatchMessage (&msg);
538 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
540 /* main window procedure */
541 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
544 int fActive, fMinimized, temp;
548 qboolean down = false;
550 extern unsigned int uiWheelMessage;
552 if ( uMsg == uiWheelMessage )
553 uMsg = WM_MOUSEWHEEL;
558 if (vid_isfullscreen)
559 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
566 window_x = (int) LOWORD(lParam);
567 window_y = (int) HIWORD(lParam);
568 VID_UpdateWindowStatus ();
576 vkey = MapKey(lParam, wParam);
577 GetKeyboardState (state);
578 // alt/ctrl/shift tend to produce funky ToAscii values,
579 // and if it's not a single character we don't know care about it
580 if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0) != 1)
582 Key_Event (vkey, asciichar[0], down);
586 // keep Alt-Space from happening
589 // this is complicated because Win32 seems to pack multiple mouse events into
590 // one update sometimes, so we always check all states and look for events
597 case WM_XBUTTONDOWN: // backslash :: imouse explorer buttons
598 case WM_XBUTTONUP: // backslash :: imouse explorer buttons
602 if (wParam & MK_LBUTTON)
605 if (wParam & MK_RBUTTON)
608 if (wParam & MK_MBUTTON)
611 /* backslash :: imouse explorer buttons */
612 if (wParam & MK_XBUTTON1)
615 if (wParam & MK_XBUTTON2)
619 // LordHavoc: lets hope this allows more buttons in the future...
620 if (wParam & MK_XBUTTON3)
622 if (wParam & MK_XBUTTON4)
624 if (wParam & MK_XBUTTON5)
626 if (wParam & MK_XBUTTON6)
628 if (wParam & MK_XBUTTON7)
631 IN_MouseEvent (temp);
635 // JACK: This is the mouse wheel with the Intellimouse
636 // Its delta is either positive or neg, and we generate the proper
639 if ((short) HIWORD(wParam) > 0) {
640 Key_Event(K_MWHEELUP, 0, true);
641 Key_Event(K_MWHEELUP, 0, false);
643 Key_Event(K_MWHEELDOWN, 0, true);
644 Key_Event(K_MWHEELDOWN, 0, false);
652 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
658 fActive = LOWORD(wParam);
659 fMinimized = (BOOL) HIWORD(wParam);
660 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
662 // fix the leftover Alt from any Alt-Tab or the like that switched us away
668 // PostQuitMessage (0);
672 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
676 /* pass all unhandled messages to DefWindowProc */
677 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
681 /* return 1 if handled message, 0 if not */
685 int VID_SetGamma(unsigned short *ramps)
687 HDC hdc = GetDC (NULL);
688 int i = SetDeviceGammaRamp(hdc, ramps);
689 ReleaseDC (NULL, hdc);
690 return i; // return success or failure
693 int VID_GetGamma(unsigned short *ramps)
695 HDC hdc = GetDC (NULL);
696 int i = GetDeviceGammaRamp(hdc, ramps);
697 ReleaseDC (NULL, hdc);
698 return i; // return success or failure
701 static HINSTANCE gldll;
703 int GL_OpenLibrary(const char *name)
705 Con_Printf("Loading OpenGL driver %s\n", name);
707 if (!(gldll = LoadLibrary(name)))
709 Con_Printf("Unable to LoadLibrary %s\n", name);
712 strcpy(gl_driver, name);
716 void GL_CloseLibrary(void)
721 qwglGetProcAddress = NULL;
724 gl_platformextensions = "";
727 void *GL_GetProcAddress(const char *name)
730 if (qwglGetProcAddress != NULL)
731 p = (void *) qwglGetProcAddress(name);
733 p = (void *) GetProcAddress(gldll, name);
737 static void IN_Init(void);
742 InitCommonControls();
743 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON1));
745 // Register the frame class
747 wc.lpfnWndProc = (WNDPROC)MainWndProc;
750 wc.hInstance = global_hInstance;
752 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
753 wc.hbrBackground = NULL;
755 wc.lpszClassName = "DarkPlacesWindowClass";
757 if (!RegisterClass (&wc))
758 Sys_Error("Couldn't register window class\n");
763 int VID_InitMode (int fullscreen, int width, int height, int bpp)
769 PIXELFORMATDESCRIPTOR pfd =
771 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
773 PFD_DRAW_TO_WINDOW // support window
774 | PFD_SUPPORT_OPENGL // support OpenGL
775 | PFD_DOUBLEBUFFER , // double buffered
776 PFD_TYPE_RGBA, // RGBA type
777 24, // 24-bit color depth
778 0, 0, 0, 0, 0, 0, // color bits ignored
779 0, // no alpha buffer
780 0, // shift bit ignored
781 0, // no accumulation buffer
782 0, 0, 0, 0, // accum bits ignored
783 32, // 32-bit z-buffer
784 0, // no stencil buffer
785 0, // no auxiliary buffer
786 PFD_MAIN_PLANE, // main layer
788 0, 0, 0 // layer masks ignored
791 DWORD WindowStyle, ExWindowStyle;
793 int CenterX, CenterY;
794 const char *gldrivername;
798 Sys_Error("VID_InitMode called when video is already initialised\n");
800 // if stencil is enabled, ask for alpha too
803 pfd.cStencilBits = 8;
808 pfd.cStencilBits = 0;
812 gldrivername = "opengl32.dll";
813 // COMMANDLINEOPTION: Windows WGL: -gl_driver <drivername> selects a GL driver library, default is opengl32.dll, useful only for 3dfxogl.dll or 3dfxvgl.dll, if you don't know what this is for, you don't need it
814 i = COM_CheckParm("-gl_driver");
815 if (i && i < com_argc - 1)
816 gldrivername = com_argv[i + 1];
817 if (!GL_OpenLibrary(gldrivername))
819 Con_Printf("Unable to load GL driver %s\n", gldrivername);
823 memset(&gdevmode, 0, sizeof(gdevmode));
825 vid_isfullscreen = false;
828 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
829 gdevmode.dmBitsPerPel = bpp;
830 gdevmode.dmPelsWidth = width;
831 gdevmode.dmPelsHeight = height;
832 gdevmode.dmSize = sizeof (gdevmode);
833 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
836 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
840 vid_isfullscreen = true;
841 WindowStyle = WS_POPUP;
842 ExWindowStyle = WS_EX_TOPMOST;
847 i = GetDeviceCaps(hdc, RASTERCAPS);
848 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
849 ReleaseDC (NULL, hdc);
853 Con_Print("Can't run in non-RGB mode\n");
859 Con_Print("A higher desktop depth is required to run this video mode\n");
863 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
870 rect.bottom = height;
871 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
880 CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
881 CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
883 CenterX = max(0, CenterX);
884 CenterY = max(0, CenterY);
886 // x and y may be changed by WM_MOVE messages
889 window_width = width;
890 window_height = height;
891 rect.left += CenterX;
892 rect.right += CenterX;
894 rect.bottom += CenterY;
896 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
899 Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %d, %p) failed\n", ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
906 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
909 ShowWindow (mainwindow, SW_SHOWDEFAULT);
910 UpdateWindow (mainwindow);
912 VID_UpdateWindowStatus ();
914 // now we try to make sure we get the focus on the mode switch, because
915 // sometimes in some systems we don't. We grab the foreground, then
916 // finish setting up, pump all our messages, and sleep for a little while
917 // to let messages finish bouncing around the system, then we put
918 // ourselves at the top of the z order, then grab the foreground again,
919 // Who knows if it helps, but it probably doesn't hurt
920 SetForegroundWindow (mainwindow);
922 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
924 TranslateMessage (&msg);
925 DispatchMessage (&msg);
930 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
932 SetForegroundWindow (mainwindow);
934 // fix the leftover Alt from any Alt-Tab or the like that switched us away
937 hdc = GetDC(mainwindow);
939 if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)
942 Con_Printf("ChoosePixelFormat(%d, %p) failed\n", hdc, &pfd);
946 if (SetPixelFormat(hdc, pixelformat, &pfd) == false)
949 Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", hdc, pixelformat, &pfd);
953 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
956 Con_Print("wgl functions not found\n");
960 baseRC = qwglCreateContext(hdc);
964 Con_Print("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
967 if (!qwglMakeCurrent(hdc, baseRC))
970 Con_Printf("wglMakeCurrent(%d, %d) failed\n", hdc, baseRC);
974 qglGetString = GL_GetProcAddress("glGetString");
975 qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB");
976 if (qglGetString == NULL)
979 Con_Print("glGetString not found\n");
982 gl_renderer = qglGetString(GL_RENDERER);
983 gl_vendor = qglGetString(GL_VENDOR);
984 gl_version = qglGetString(GL_VERSION);
985 gl_extensions = qglGetString(GL_EXTENSIONS);
987 gl_platformextensions = "";
989 gl_videosyncavailable = false;
991 if (qwglGetExtensionsStringARB)
992 gl_platformextensions = qwglGetExtensionsStringARB(hdc);
994 // COMMANDLINEOPTION: Windows WGL: -novideosync disables WGL_EXT_swap_control
995 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);
996 ReleaseDC(mainwindow, hdc);
1000 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
1001 if (strncasecmp(gl_vendor,"ATI",3)==0)
1003 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1006 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1009 //vid_menudrawfn = VID_MenuDraw;
1010 //vid_menukeyfn = VID_MenuKey;
1012 vid_initialized = true;
1015 IN_StartupJoystick ();
1020 static void IN_Shutdown(void);
1021 void VID_Shutdown (void)
1026 if(vid_initialized == false)
1029 VID_RestoreSystemGamma();
1031 vid_initialized = false;
1033 if (qwglGetCurrentContext)
1034 hRC = qwglGetCurrentContext();
1035 if (qwglGetCurrentDC)
1036 hDC = qwglGetCurrentDC();
1037 if (qwglMakeCurrent)
1038 qwglMakeCurrent(NULL, NULL);
1039 if (hRC && qwglDeleteContext)
1040 qwglDeleteContext(hRC);
1041 // close the library before we get rid of the window
1043 if (hDC && mainwindow)
1044 ReleaseDC(mainwindow, hDC);
1045 AppActivate(false, false);
1047 DestroyWindow(mainwindow);
1049 if (vid_isfullscreen)
1050 ChangeDisplaySettings (NULL, 0);
1051 vid_isfullscreen = false;
1060 void IN_ShowMouse (void)
1062 if (!mouseshowtoggle)
1065 mouseshowtoggle = 1;
1075 void IN_HideMouse (void)
1077 if (mouseshowtoggle)
1080 mouseshowtoggle = 0;
1090 void IN_ActivateMouse (void)
1093 mouseactivatetoggle = true;
1095 if (mouseinitialized)
1101 if (!dinput_acquired)
1103 IDirectInputDevice_Acquire(g_pMouse);
1104 dinput_acquired = true;
1115 window_rect.left = window_x;
1116 window_rect.top = window_y;
1117 window_rect.right = window_x + window_width;
1118 window_rect.bottom = window_y + window_height;
1120 if (mouseparmsvalid)
1121 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
1123 SetCursorPos (window_center_x, window_center_y);
1124 SetCapture (mainwindow);
1125 ClipCursor (&window_rect);
1138 void IN_DeactivateMouse (void)
1141 mouseactivatetoggle = false;
1143 if (mouseinitialized)
1149 if (dinput_acquired)
1151 IDirectInputDevice_Unacquire(g_pMouse);
1152 dinput_acquired = false;
1159 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1165 mouseactive = false;
1175 qboolean IN_InitDInput (void)
1178 DIPROPDWORD dipdw = {
1180 sizeof(DIPROPDWORD), // diph.dwSize
1181 sizeof(DIPROPHEADER), // diph.dwHeaderSize
1183 DIPH_DEVICE, // diph.dwHow
1185 DINPUT_BUFFERSIZE, // dwData
1190 hInstDI = LoadLibrary("dinput.dll");
1192 if (hInstDI == NULL)
1194 Con_SafePrint("Couldn't load dinput.dll\n");
1199 if (!pDirectInputCreate)
1201 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
1203 if (!pDirectInputCreate)
1205 Con_SafePrint("Couldn't get DI proc addr\n");
1210 // register with DirectInput and get an IDirectInput to play with.
1211 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
1218 // obtain an interface to the system mouse device.
1219 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
1223 Con_SafePrint("Couldn't open DI mouse device\n");
1227 // set the data format to "mouse format".
1228 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
1232 Con_SafePrint("Couldn't set DI mouse format\n");
1236 // set the cooperativity level.
1237 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
1238 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
1242 Con_SafePrint("Couldn't set DI coop level\n");
1247 // set the buffer size to DINPUT_BUFFERSIZE elements.
1248 // the buffer size is a DWORD property associated with the device
1249 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
1253 Con_SafePrint("Couldn't set DI buffersize\n");
1266 void IN_StartupMouse (void)
1268 if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
1271 mouseinitialized = true;
1273 // COMMANDLINEOPTION: Windows Input: -dinput uses DirectInput (instead of GDI) for mouse/joystick input, may be more precise or responsive, but probably not
1274 if (COM_CheckParm ("-dinput"))
1276 dinput = IN_InitDInput ();
1280 Con_SafePrint("DirectInput initialized\n");
1284 Con_SafePrint("DirectInput not initialized\n");
1290 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
1292 if (mouseparmsvalid)
1294 // COMMANDLINEOPTION: Windows GDI Input: -noforcemspd disables setting of mouse speed (ignored with -dinput, windows only)
1295 if ( COM_CheckParm ("-noforcemspd") )
1296 newmouseparms[2] = originalmouseparms[2];
1298 // COMMANDLINEOPTION: Windows GDI Input: -noforcemaccel disables setting of mouse acceleration (ignored with -dinput, windows only)
1299 if ( COM_CheckParm ("-noforcemaccel") )
1301 newmouseparms[0] = originalmouseparms[0];
1302 newmouseparms[1] = originalmouseparms[1];
1305 // COMMANDLINEOPTION: Windows GDI Input: -noforcemparms disables setting of mouse parameters (ignored with -dinput, windows only)
1306 if ( COM_CheckParm ("-noforcemparms") )
1308 newmouseparms[0] = originalmouseparms[0];
1309 newmouseparms[1] = originalmouseparms[1];
1310 newmouseparms[2] = originalmouseparms[2];
1317 // if a fullscreen video mode was set before the mouse was initialized,
1318 // set the mouse state appropriately
1319 if (mouseactivatetoggle)
1320 IN_ActivateMouse ();
1329 void IN_MouseEvent (int mstate)
1333 if (mouseactive && !dinput)
1335 // perform button actions
1336 for (i=0 ; i<mouse_buttons ; i++)
1338 if ( (mstate & (1<<i)) &&
1339 !(mouse_oldbuttonstate & (1<<i)) )
1341 Key_Event (K_MOUSE1 + i, 0, true);
1344 if ( !(mstate & (1<<i)) &&
1345 (mouse_oldbuttonstate & (1<<i)) )
1347 Key_Event (K_MOUSE1 + i, 0, false);
1351 mouse_oldbuttonstate = mstate;
1361 void IN_MouseMove (usercmd_t *cmd)
1364 DIDEVICEOBJECTDATA od;
1370 GetCursorPos (¤t_pos);
1371 //ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
1372 IN_Mouse( cmd, 0, 0 );
1385 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
1386 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
1388 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
1390 dinput_acquired = true;
1391 IDirectInputDevice_Acquire(g_pMouse);
1395 /* Unable to read data or no data available */
1396 if (FAILED(hr) || dwElements == 0)
1399 /* Look at the element to see what happened */
1411 case DIMOFS_BUTTON0:
1412 if (od.dwData & 0x80)
1418 case DIMOFS_BUTTON1:
1419 if (od.dwData & 0x80)
1420 mstate_di |= (1<<1);
1422 mstate_di &= ~(1<<1);
1425 case DIMOFS_BUTTON2:
1426 if (od.dwData & 0x80)
1427 mstate_di |= (1<<2);
1429 mstate_di &= ~(1<<2);
1434 // perform button actions
1435 for (i=0 ; i<mouse_buttons ; i++)
1437 if ( (mstate_di & (1<<i)) &&
1438 !(mouse_oldbuttonstate & (1<<i)) )
1440 Key_Event (K_MOUSE1 + i, 0, true);
1443 if ( !(mstate_di & (1<<i)) &&
1444 (mouse_oldbuttonstate & (1<<i)) )
1446 Key_Event (K_MOUSE1 + i, 0, false);
1450 mouse_oldbuttonstate = mstate_di;
1454 GetCursorPos (¤t_pos);
1455 mx = current_pos.x - window_center_x;
1456 my = current_pos.y - window_center_y;
1459 IN_Mouse(cmd, mx, my);
1461 // if the mouse has moved, force it to the center, so there's room to move
1462 if (!dinput && (mx || my))
1463 SetCursorPos (window_center_x, window_center_y);
1472 void IN_Move (usercmd_t *cmd)
1474 if (vid_activewindow && !vid_hidden)
1487 void IN_ClearStates (void)
1490 mouse_oldbuttonstate = 0;
1499 void IN_StartupJoystick (void)
1506 // assume no joystick
1509 // abort startup if user requests no joystick
1510 // COMMANDLINEOPTION: Windows Input: -nojoy disables joystick support, may be a small speed increase
1511 if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe"))
1514 // verify joystick driver is present
1515 if ((numdevs = joyGetNumDevs ()) == 0)
1517 Con_Print("\njoystick not found -- driver not present\n\n");
1521 // cycle through the joystick ids for the first valid one
1522 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
1524 memset (&ji, 0, sizeof(ji));
1525 ji.dwSize = sizeof(ji);
1526 ji.dwFlags = JOY_RETURNCENTERED;
1528 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
1532 // abort startup if we didn't find a valid joystick
1533 if (mmr != JOYERR_NOERROR)
1535 Con_Printf("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
1539 // get the capabilities of the selected joystick
1540 // abort startup if command fails
1541 memset (&jc, 0, sizeof(jc));
1542 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
1544 Con_Printf("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
1548 // save the joystick's number of buttons and POV status
1549 joy_numbuttons = jc.wNumButtons;
1550 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
1552 // old button and POV states default to no buttons pressed
1553 joy_oldbuttonstate = joy_oldpovstate = 0;
1555 // mark the joystick as available and advanced initialization not completed
1556 // this is needed as cvars are not available during initialization
1559 joy_advancedinit = false;
1561 Con_Print("\njoystick detected\n\n");
1570 PDWORD RawValuePointer (int axis)
1587 return NULL; // LordHavoc: hush compiler warning
1593 Joy_AdvancedUpdate_f
1596 void Joy_AdvancedUpdate_f (void)
1599 // called once by IN_ReadJoystick and by user whenever an update is needed
1600 // cvars are now available
1604 // initialize all the maps
1605 for (i = 0; i < JOY_MAX_AXES; i++)
1607 dwAxisMap[i] = AxisNada;
1608 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
1609 pdwRawValue[i] = RawValuePointer(i);
1612 if( joy_advanced.integer == 0)
1614 // default joystick initialization
1615 // 2 axes only with joystick control
1616 dwAxisMap[JOY_AXIS_X] = AxisTurn;
1617 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
1618 dwAxisMap[JOY_AXIS_Y] = AxisForward;
1619 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
1623 if (strcmp (joy_name.string, "joystick") != 0)
1625 // notify user of advanced controller
1626 Con_Printf("\n%s configured\n\n", joy_name.string);
1629 // advanced initialization here
1630 // data supplied by user via joy_axisn cvars
1631 dwTemp = (DWORD) joy_advaxisx.value;
1632 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
1633 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
1634 dwTemp = (DWORD) joy_advaxisy.value;
1635 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
1636 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
1637 dwTemp = (DWORD) joy_advaxisz.value;
1638 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
1639 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
1640 dwTemp = (DWORD) joy_advaxisr.value;
1641 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
1642 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
1643 dwTemp = (DWORD) joy_advaxisu.value;
1644 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
1645 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
1646 dwTemp = (DWORD) joy_advaxisv.value;
1647 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
1648 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
1651 // compute the axes to collect from DirectInput
1652 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
1653 for (i = 0; i < JOY_MAX_AXES; i++)
1655 if (dwAxisMap[i] != AxisNada)
1657 joy_flags |= dwAxisFlags[i];
1667 void IN_Commands (void)
1670 DWORD buttonstate, povstate;
1678 // loop through the joystick buttons
1679 // key a joystick event or auxillary event for higher number buttons for each state change
1680 buttonstate = ji.dwButtons;
1681 for (i=0 ; i < (int) joy_numbuttons ; i++)
1683 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
1685 key_index = (i < 16) ? K_JOY1 : K_AUX1;
1686 Key_Event (key_index + i, 0, true);
1689 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
1691 key_index = (i < 16) ? K_JOY1 : K_AUX1;
1692 Key_Event (key_index + i, 0, false);
1695 joy_oldbuttonstate = buttonstate;
1699 // convert POV information into 4 bits of state information
1700 // this avoids any potential problems related to moving from one
1701 // direction to another without going through the center position
1703 if(ji.dwPOV != JOY_POVCENTERED)
1705 if (ji.dwPOV == JOY_POVFORWARD)
1707 if (ji.dwPOV == JOY_POVRIGHT)
1709 if (ji.dwPOV == JOY_POVBACKWARD)
1711 if (ji.dwPOV == JOY_POVLEFT)
1714 // determine which bits have changed and key an auxillary event for each change
1715 for (i=0 ; i < 4 ; i++)
1717 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
1719 Key_Event (K_AUX29 + i, 0, true);
1722 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
1724 Key_Event (K_AUX29 + i, 0, false);
1727 joy_oldpovstate = povstate;
1737 qboolean IN_ReadJoystick (void)
1740 memset (&ji, 0, sizeof(ji));
1741 ji.dwSize = sizeof(ji);
1742 ji.dwFlags = joy_flags;
1744 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1746 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1747 // rather than having 32768 be the zero point, they have the zero point at 32668
1748 // go figure -- anyway, now we get the full resolution out of the device
1749 if (joy_wwhack1.integer != 0.0)
1757 // read error occurred
1758 // turning off the joystick seems too harsh for 1 read error,
1759 // but what should be done?
1770 void IN_JoyMove (usercmd_t *cmd)
1772 float speed, aspeed;
1773 float fAxisValue, fTemp;
1774 int i, mouselook = (in_mlook.state & 1) || freelook.integer;
1776 // complete initialization if first time in
1777 // this is needed as cvars are not available at initialization time
1778 if( joy_advancedinit != true )
1780 Joy_AdvancedUpdate_f();
1781 joy_advancedinit = true;
1784 // verify joystick is available and that the user wants to use it
1785 if (!joy_avail || !in_joystick.integer)
1790 // collect the joystick data, if possible
1791 if (IN_ReadJoystick () != true)
1796 if (in_speed.state & 1)
1797 speed = cl_movespeedkey.value;
1800 // LordHavoc: viewzoom affects sensitivity for sniping
1801 aspeed = speed * host_realframetime * cl.viewzoom;
1803 // loop through the axes
1804 for (i = 0; i < JOY_MAX_AXES; i++)
1806 // get the floating point zero-centered, potentially-inverted data for the current axis
1807 fAxisValue = (float) *pdwRawValue[i];
1808 // move centerpoint to zero
1809 fAxisValue -= 32768.0;
1811 if (joy_wwhack2.integer != 0.0)
1813 if (dwAxisMap[i] == AxisTurn)
1815 // this is a special formula for the Logitech WingMan Warrior
1816 // y=ax^b; where a = 300 and b = 1.3
1817 // also x values are in increments of 800 (so this is factored out)
1818 // then bounds check result to level out excessively high spin rates
1819 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1820 if (fTemp > 14000.0)
1822 // restore direction information
1823 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1827 // convert range from -32768..32767 to -1..1
1828 fAxisValue /= 32768.0;
1830 switch (dwAxisMap[i])
1833 if ((joy_advanced.integer == 0) && mouselook)
1835 // user wants forward control to become look control
1836 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1838 // if mouse invert is on, invert the joystick pitch value
1839 // only absolute control support here (joy_advanced is false)
1840 if (m_pitch.value < 0.0)
1842 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1846 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1852 // no pitch movement
1853 // disable pitch return-to-center unless requested by user
1854 // *** this code can be removed when the lookspring bug is fixed
1855 // *** the bug always has the lookspring feature on
1856 if(lookspring.value == 0.0)
1862 // user wants forward control to be forward control
1863 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1865 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1871 if (fabs(fAxisValue) > joy_sidethreshold.value)
1873 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1878 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
1880 // user wants turn control to become side control
1881 if (fabs(fAxisValue) > joy_sidethreshold.value)
1883 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1888 // user wants turn control to be turn control
1889 if (fabs(fAxisValue) > joy_yawthreshold.value)
1891 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1893 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1897 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1907 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1909 // pitch movement detected and pitch movement desired by user
1910 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1912 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1916 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1922 // no pitch movement
1923 // disable pitch return-to-center unless requested by user
1924 // *** this code can be removed when the lookspring bug is fixed
1925 // *** the bug always has the lookspring feature on
1926 if(lookspring.integer == 0)
1938 static void IN_Init(void)
1940 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
1942 // joystick variables
1943 Cvar_RegisterVariable (&in_joystick);
1944 Cvar_RegisterVariable (&joy_name);
1945 Cvar_RegisterVariable (&joy_advanced);
1946 Cvar_RegisterVariable (&joy_advaxisx);
1947 Cvar_RegisterVariable (&joy_advaxisy);
1948 Cvar_RegisterVariable (&joy_advaxisz);
1949 Cvar_RegisterVariable (&joy_advaxisr);
1950 Cvar_RegisterVariable (&joy_advaxisu);
1951 Cvar_RegisterVariable (&joy_advaxisv);
1952 Cvar_RegisterVariable (&joy_forwardthreshold);
1953 Cvar_RegisterVariable (&joy_sidethreshold);
1954 Cvar_RegisterVariable (&joy_pitchthreshold);
1955 Cvar_RegisterVariable (&joy_yawthreshold);
1956 Cvar_RegisterVariable (&joy_forwardsensitivity);
1957 Cvar_RegisterVariable (&joy_sidesensitivity);
1958 Cvar_RegisterVariable (&joy_pitchsensitivity);
1959 Cvar_RegisterVariable (&joy_yawsensitivity);
1960 Cvar_RegisterVariable (&joy_wwhack1);
1961 Cvar_RegisterVariable (&joy_wwhack2);
1962 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
1965 static void IN_Shutdown(void)
1967 IN_DeactivateMouse ();
1971 IDirectInputDevice_Release(g_pMouse);
1975 IDirectInput_Release(g_pdi);