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;
88 //HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
90 static int vid_isfullscreen;
92 //void VID_MenuDraw (void);
93 //void VID_MenuKey (int key);
95 //LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
96 //void AppActivate(BOOL fActive, BOOL minimize);
97 //void ClearAllStates (void);
98 //void VID_UpdateWindowStatus (void);
100 //====================================
102 int window_x, window_y, window_width, window_height;
103 int window_center_x, window_center_y;
105 void IN_ShowMouse (void);
106 void IN_DeactivateMouse (void);
107 void IN_HideMouse (void);
108 void IN_ActivateMouse (void);
109 void IN_MouseEvent (int mstate);
110 void IN_UpdateClipCursor (void);
112 qboolean mouseinitialized;
113 static qboolean dinput;
119 #define DINPUT_BUFFERSIZE 16
120 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
122 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
123 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
125 // LordHavoc: thanks to backslash for this support for mouse buttons 4 and 5
126 /* backslash :: imouse explorer buttons */
127 /* These are #ifdefed out for non-Win2K in the February 2001 version of
128 MS's platform SDK, but we need them for compilation. . . */
129 #ifndef WM_XBUTTONDOWN
130 #define WM_XBUTTONDOWN 0x020B
131 #define WM_XBUTTONUP 0x020C
134 #define MK_XBUTTON1 0x0020
135 #define MK_XBUTTON2 0x0040
136 // LordHavoc: lets hope this allows more buttons in the future...
137 #define MK_XBUTTON3 0x0080
138 #define MK_XBUTTON4 0x0100
139 #define MK_XBUTTON5 0x0200
140 #define MK_XBUTTON6 0x0400
141 #define MK_XBUTTON7 0x0800
147 int mouse_oldbuttonstate;
149 int mouse_x, mouse_y, old_mouse_x, old_mouse_y;
151 static qboolean restore_spi;
152 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
154 unsigned int uiWheelMessage;
155 qboolean mouseactive;
156 //qboolean mouseinitialized;
157 static qboolean mouseparmsvalid, mouseactivatetoggle;
158 static qboolean mouseshowtoggle = 1;
159 static qboolean dinput_acquired;
161 static unsigned int mstate_di;
163 // joystick defines and variables
164 // where should defines be moved?
165 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
166 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
167 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
177 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
180 DWORD dwAxisFlags[JOY_MAX_AXES] =
182 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
185 DWORD dwAxisMap[JOY_MAX_AXES];
186 DWORD dwControlMap[JOY_MAX_AXES];
187 PDWORD pdwRawValue[JOY_MAX_AXES];
189 // none of these cvars are saved over a session
190 // this means that advanced controller configuration needs to be executed
191 // each time. this avoids any problems with getting back to a default usage
192 // or when changing from one controller to another. this way at least something
194 cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
195 cvar_t joy_name = {0, "joyname", "joystick"};
196 cvar_t joy_advanced = {0, "joyadvanced", "0"};
197 cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
198 cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
199 cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
200 cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
201 cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
202 cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
203 cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
204 cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
205 cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
206 cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
207 cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
208 cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
209 cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
210 cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
211 cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
212 cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
214 qboolean joy_avail, joy_advancedinit, joy_haspov;
215 DWORD joy_oldbuttonstate, joy_oldpovstate;
219 DWORD joy_numbuttons;
221 static LPDIRECTINPUT g_pdi;
222 static LPDIRECTINPUTDEVICE g_pMouse;
226 static HINSTANCE hInstDI;
228 //static qboolean dinput;
230 typedef struct MYDATA {
231 LONG lX; // X axis goes here
232 LONG lY; // Y axis goes here
233 LONG lZ; // Z axis goes here
234 BYTE bButtonA; // One button goes here
235 BYTE bButtonB; // Another button goes here
236 BYTE bButtonC; // Another button goes here
237 BYTE bButtonD; // Another button goes here
240 static DIOBJECTDATAFORMAT rgodf[] = {
241 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
242 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
243 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
244 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
245 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
246 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
247 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
250 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
252 static DIDATAFORMAT df = {
253 sizeof(DIDATAFORMAT), // this structure
254 sizeof(DIOBJECTDATAFORMAT), // size of object data format
255 DIDF_RELAXIS, // absolute axis coordinates
256 sizeof(MYDATA), // device data size
257 NUM_OBJECTS, // number of objects
258 rgodf, // and here they are
261 // forward-referenced functions
262 void IN_StartupJoystick (void);
263 void Joy_AdvancedUpdate_f (void);
264 void IN_JoyMove (usercmd_t *cmd);
265 void IN_StartupMouse (void);
269 VID_UpdateWindowStatus
272 void VID_UpdateWindowStatus (void)
274 window_center_x = window_x + window_width / 2;
275 window_center_y = window_y + window_height / 2;
277 if (mouseinitialized && mouseactive && !dinput)
280 window_rect.left = window_x;
281 window_rect.top = window_y;
282 window_rect.right = window_x + window_width;
283 window_rect.bottom = window_y + window_height;
284 ClipCursor (&window_rect);
289 //====================================
296 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
300 *width = window_width;
301 *height = window_height;
305 void VID_Finish (void)
308 static int old_vsync = -1;
310 if (old_vsync != vid_vsync.integer)
312 old_vsync = bound(0, vid_vsync.integer, 1);
313 Cvar_SetValueQuick(&vid_vsync, old_vsync);
314 if (gl_videosyncavailable)
315 qwglSwapIntervalEXT (old_vsync);
318 if (r_render.integer && !scr_skipupdate)
320 if (r_speeds.integer || gl_finish.integer)
325 // handle the mouse state when windowed if that's changed
326 vid_usemouse = false;
327 if (vid_mouse.integer && !key_consoleactive)
329 if (vid_isfullscreen)
331 if (!vid_activewindow)
332 vid_usemouse = false;
337 vid_usingmouse = true;
346 vid_usingmouse = false;
347 IN_DeactivateMouse ();
353 //==========================================================================
358 qbyte scantokey[128] =
360 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
361 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 ,//0
362 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' ,//1
363 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT ,'\\' ,'z' ,'x' ,'c' ,'v' ,//2
364 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 ,//3
365 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
366 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,//5
367 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,//6
368 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 //7
376 Map from windows to quake keynums
379 static int MapKey (int key, int virtualkey)
382 int modified = (key >> 16) & 255;
383 qboolean is_extended = false;
385 if (modified < 128 && scantokey[modified])
386 result = scantokey[modified];
390 Con_DPrintf("key 0x%02x (0x%8x, 0x%8x) has no translation\n", modified, key, virtualkey);
407 return K_KP_LEFTARROW;
409 return K_KP_RIGHTARROW;
413 return K_KP_DOWNARROW;
440 ===================================================================
444 ===================================================================
452 void ClearAllStates (void)
458 extern qboolean host_loopactive;
460 void AppActivate(BOOL fActive, BOOL minimize)
461 /****************************************************************************
463 * Function: AppActivate
464 * Parameters: fActive - True if app is activating
466 * Description: If the application is activating, then swap the system
467 * into SYSPAL_NOSTATIC mode so that our palettes will display
470 ****************************************************************************/
472 static BOOL sound_active;
474 vid_activewindow = fActive;
475 vid_hidden = minimize;
477 // enable/disable sound on focus gain/loss
478 if (!vid_activewindow && sound_active)
481 sound_active = false;
483 else if (vid_activewindow && !sound_active)
491 if (vid_isfullscreen)
493 if (vid_wassuspended)
495 vid_wassuspended = false;
496 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
497 ShowWindow(mainwindow, SW_SHOWNORMAL);
500 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
501 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
507 vid_usingmouse = false;
508 IN_DeactivateMouse ();
510 if (vid_isfullscreen)
512 ChangeDisplaySettings (NULL, 0);
513 vid_wassuspended = true;
515 VID_RestoreSystemGamma();
519 //TODO: move it around in vid_wgl.c since I dont think this is the right position
520 void Sys_SendKeyEvents (void)
524 while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
526 // we always update if there are any event, even if we're paused
529 if (!GetMessage (&msg, NULL, 0, 0))
532 TranslateMessage (&msg);
533 DispatchMessage (&msg);
537 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
539 /* main window procedure */
540 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
543 int fActive, fMinimized, temp;
547 qboolean down = false;
549 extern unsigned int uiWheelMessage;
551 if ( uMsg == uiWheelMessage )
552 uMsg = WM_MOUSEWHEEL;
557 if (vid_isfullscreen)
558 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
565 window_x = (int) LOWORD(lParam);
566 window_y = (int) HIWORD(lParam);
567 VID_UpdateWindowStatus ();
575 vkey = MapKey(lParam, wParam);
576 GetKeyboardState (state);
577 // alt/ctrl/shift tend to produce funky ToAscii values,
578 // and if it's not a single character we don't know care about it
579 if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0) != 1)
581 Key_Event (vkey, asciichar[0], down);
585 // keep Alt-Space from happening
588 // this is complicated because Win32 seems to pack multiple mouse events into
589 // one update sometimes, so we always check all states and look for events
596 case WM_XBUTTONDOWN: // backslash :: imouse explorer buttons
597 case WM_XBUTTONUP: // backslash :: imouse explorer buttons
601 if (wParam & MK_LBUTTON)
604 if (wParam & MK_RBUTTON)
607 if (wParam & MK_MBUTTON)
610 /* backslash :: imouse explorer buttons */
611 if (wParam & MK_XBUTTON1)
614 if (wParam & MK_XBUTTON2)
618 // LordHavoc: lets hope this allows more buttons in the future...
619 if (wParam & MK_XBUTTON3)
621 if (wParam & MK_XBUTTON4)
623 if (wParam & MK_XBUTTON5)
625 if (wParam & MK_XBUTTON6)
627 if (wParam & MK_XBUTTON7)
630 IN_MouseEvent (temp);
634 // JACK: This is the mouse wheel with the Intellimouse
635 // Its delta is either positive or neg, and we generate the proper
638 if ((short) HIWORD(wParam) > 0) {
639 Key_Event(K_MWHEELUP, 0, true);
640 Key_Event(K_MWHEELUP, 0, false);
642 Key_Event(K_MWHEELDOWN, 0, true);
643 Key_Event(K_MWHEELDOWN, 0, false);
651 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
657 fActive = LOWORD(wParam);
658 fMinimized = (BOOL) HIWORD(wParam);
659 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
661 // fix the leftover Alt from any Alt-Tab or the like that switched us away
667 // PostQuitMessage (0);
671 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
675 /* pass all unhandled messages to DefWindowProc */
676 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
680 /* return 1 if handled message, 0 if not */
684 int VID_SetGamma(unsigned short *ramps)
686 HDC hdc = GetDC (NULL);
687 int i = SetDeviceGammaRamp(hdc, ramps);
688 ReleaseDC (NULL, hdc);
689 return i; // return success or failure
692 int VID_GetGamma(unsigned short *ramps)
694 HDC hdc = GetDC (NULL);
695 int i = GetDeviceGammaRamp(hdc, ramps);
696 ReleaseDC (NULL, hdc);
697 return i; // return success or failure
700 static HINSTANCE gldll;
702 int GL_OpenLibrary(const char *name)
704 Con_Printf("Loading OpenGL driver %s\n", name);
706 if (!(gldll = LoadLibrary(name)))
708 Con_Printf("Unable to LoadLibrary %s\n", name);
711 strcpy(gl_driver, name);
715 void GL_CloseLibrary(void)
720 qwglGetProcAddress = NULL;
723 gl_platformextensions = "";
726 void *GL_GetProcAddress(const char *name)
729 if (qwglGetProcAddress != NULL)
730 p = (void *) qwglGetProcAddress(name);
732 p = (void *) GetProcAddress(gldll, name);
736 static void IN_Init(void);
741 InitCommonControls();
742 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON1));
744 // Register the frame class
746 wc.lpfnWndProc = (WNDPROC)MainWndProc;
749 wc.hInstance = global_hInstance;
751 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
752 wc.hbrBackground = NULL;
754 wc.lpszClassName = "DarkPlacesWindowClass";
756 if (!RegisterClass (&wc))
757 Sys_Error("Couldn't register window class\n");
762 int VID_InitMode (int fullscreen, int width, int height, int bpp)
768 PIXELFORMATDESCRIPTOR pfd =
770 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
772 PFD_DRAW_TO_WINDOW // support window
773 | PFD_SUPPORT_OPENGL // support OpenGL
774 | PFD_DOUBLEBUFFER , // double buffered
775 PFD_TYPE_RGBA, // RGBA type
776 24, // 24-bit color depth
777 0, 0, 0, 0, 0, 0, // color bits ignored
778 0, // no alpha buffer
779 0, // shift bit ignored
780 0, // no accumulation buffer
781 0, 0, 0, 0, // accum bits ignored
782 32, // 32-bit z-buffer
783 0, // no stencil buffer
784 0, // no auxiliary buffer
785 PFD_MAIN_PLANE, // main layer
787 0, 0, 0 // layer masks ignored
790 DWORD WindowStyle, ExWindowStyle;
791 int CenterX, CenterY;
792 const char *gldrivername;
796 Sys_Error("VID_InitMode called when video is already initialised\n");
798 // if stencil is enabled, ask for alpha too
801 pfd.cStencilBits = 8;
806 pfd.cStencilBits = 0;
810 gldrivername = "opengl32.dll";
811 // 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
812 i = COM_CheckParm("-gl_driver");
813 if (i && i < com_argc - 1)
814 gldrivername = com_argv[i + 1];
815 if (!GL_OpenLibrary(gldrivername))
817 Con_Printf("Unable to load GL driver %s\n", gldrivername);
821 memset(&gdevmode, 0, sizeof(gdevmode));
823 vid_isfullscreen = false;
826 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
827 gdevmode.dmBitsPerPel = bpp;
828 gdevmode.dmPelsWidth = width;
829 gdevmode.dmPelsHeight = height;
830 gdevmode.dmSize = sizeof (gdevmode);
831 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
834 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
838 vid_isfullscreen = true;
839 WindowStyle = WS_POPUP;
840 ExWindowStyle = WS_EX_TOPMOST;
845 i = GetDeviceCaps(hdc, RASTERCAPS);
846 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
847 ReleaseDC (NULL, hdc);
851 Con_Print("Can't run in non-RGB mode\n");
857 Con_Print("A higher desktop depth is required to run this video mode\n");
861 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
868 rect.bottom = height;
869 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
878 CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
879 CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
881 CenterX = max(0, CenterX);
882 CenterY = max(0, CenterY);
884 // x and y may be changed by WM_MOVE messages
887 window_width = width;
888 window_height = height;
889 rect.left += CenterX;
890 rect.right += CenterX;
892 rect.bottom += CenterY;
894 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
897 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);
904 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
907 ShowWindow (mainwindow, SW_SHOWDEFAULT);
908 UpdateWindow (mainwindow);
910 VID_UpdateWindowStatus ();
912 // now we try to make sure we get the focus on the mode switch, because
913 // sometimes in some systems we don't. We grab the foreground, then
914 // finish setting up, pump all our messages, and sleep for a little while
915 // to let messages finish bouncing around the system, then we put
916 // ourselves at the top of the z order, then grab the foreground again,
917 // Who knows if it helps, but it probably doesn't hurt
918 SetForegroundWindow (mainwindow);
920 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
922 TranslateMessage (&msg);
923 DispatchMessage (&msg);
928 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
930 SetForegroundWindow (mainwindow);
932 // fix the leftover Alt from any Alt-Tab or the like that switched us away
935 baseDC = GetDC(mainwindow);
937 if ((pixelformat = ChoosePixelFormat(baseDC, &pfd)) == 0)
940 Con_Printf("ChoosePixelFormat(%d, %p) failed\n", baseDC, &pfd);
944 if (SetPixelFormat(baseDC, pixelformat, &pfd) == false)
947 Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", baseDC, pixelformat, &pfd);
951 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
954 Con_Print("wgl functions not found\n");
958 baseRC = qwglCreateContext(baseDC);
962 Con_Print("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
965 if (!qwglMakeCurrent(baseDC, baseRC))
968 Con_Printf("wglMakeCurrent(%d, %d) failed\n", baseDC, baseRC);
972 qglGetString = GL_GetProcAddress("glGetString");
973 qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB");
974 if (qglGetString == NULL)
977 Con_Print("glGetString not found\n");
980 gl_renderer = qglGetString(GL_RENDERER);
981 gl_vendor = qglGetString(GL_VENDOR);
982 gl_version = qglGetString(GL_VERSION);
983 gl_extensions = qglGetString(GL_EXTENSIONS);
985 gl_platformextensions = "";
987 gl_videosyncavailable = false;
989 if (qwglGetExtensionsStringARB)
990 gl_platformextensions = qwglGetExtensionsStringARB(baseDC);
992 // COMMANDLINEOPTION: Windows WGL: -novideosync disables WGL_EXT_swap_control
993 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);
994 //ReleaseDC(mainwindow, hdc);
998 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
999 if (strncasecmp(gl_vendor,"ATI",3)==0)
1001 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1004 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1007 //vid_menudrawfn = VID_MenuDraw;
1008 //vid_menukeyfn = VID_MenuKey;
1010 vid_initialized = true;
1013 IN_StartupJoystick ();
1018 static void IN_Shutdown(void);
1019 void VID_Shutdown (void)
1021 if(vid_initialized == false)
1024 VID_RestoreSystemGamma();
1026 vid_initialized = false;
1028 if (qwglMakeCurrent)
1029 qwglMakeCurrent(NULL, NULL);
1030 if (baseRC && qwglDeleteContext)
1031 qwglDeleteContext(baseRC);
1032 // close the library before we get rid of the window
1034 if (baseDC && mainwindow)
1035 ReleaseDC(mainwindow, baseDC);
1036 AppActivate(false, false);
1038 DestroyWindow(mainwindow);
1040 if (vid_isfullscreen)
1041 ChangeDisplaySettings (NULL, 0);
1042 vid_isfullscreen = false;
1051 void IN_ShowMouse (void)
1053 if (!mouseshowtoggle)
1056 mouseshowtoggle = 1;
1066 void IN_HideMouse (void)
1068 if (mouseshowtoggle)
1071 mouseshowtoggle = 0;
1081 void IN_ActivateMouse (void)
1084 mouseactivatetoggle = true;
1086 if (mouseinitialized)
1092 if (!dinput_acquired)
1094 IDirectInputDevice_Acquire(g_pMouse);
1095 dinput_acquired = true;
1106 window_rect.left = window_x;
1107 window_rect.top = window_y;
1108 window_rect.right = window_x + window_width;
1109 window_rect.bottom = window_y + window_height;
1111 if (mouseparmsvalid)
1112 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
1114 SetCursorPos (window_center_x, window_center_y);
1115 SetCapture (mainwindow);
1116 ClipCursor (&window_rect);
1129 void IN_DeactivateMouse (void)
1132 mouseactivatetoggle = false;
1134 if (mouseinitialized)
1140 if (dinput_acquired)
1142 IDirectInputDevice_Unacquire(g_pMouse);
1143 dinput_acquired = false;
1150 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1156 mouseactive = false;
1166 qboolean IN_InitDInput (void)
1169 DIPROPDWORD dipdw = {
1171 sizeof(DIPROPDWORD), // diph.dwSize
1172 sizeof(DIPROPHEADER), // diph.dwHeaderSize
1174 DIPH_DEVICE, // diph.dwHow
1176 DINPUT_BUFFERSIZE, // dwData
1181 hInstDI = LoadLibrary("dinput.dll");
1183 if (hInstDI == NULL)
1185 Con_SafePrint("Couldn't load dinput.dll\n");
1190 if (!pDirectInputCreate)
1192 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
1194 if (!pDirectInputCreate)
1196 Con_SafePrint("Couldn't get DI proc addr\n");
1201 // register with DirectInput and get an IDirectInput to play with.
1202 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
1209 // obtain an interface to the system mouse device.
1210 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
1214 Con_SafePrint("Couldn't open DI mouse device\n");
1218 // set the data format to "mouse format".
1219 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
1223 Con_SafePrint("Couldn't set DI mouse format\n");
1227 // set the cooperativity level.
1228 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
1229 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
1233 Con_SafePrint("Couldn't set DI coop level\n");
1238 // set the buffer size to DINPUT_BUFFERSIZE elements.
1239 // the buffer size is a DWORD property associated with the device
1240 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
1244 Con_SafePrint("Couldn't set DI buffersize\n");
1257 void IN_StartupMouse (void)
1259 if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
1262 mouseinitialized = true;
1264 // COMMANDLINEOPTION: Windows Input: -dinput uses DirectInput (instead of GDI) for mouse/joystick input, may be more precise or responsive, but probably not
1265 if (COM_CheckParm ("-dinput"))
1267 dinput = IN_InitDInput ();
1271 Con_SafePrint("DirectInput initialized\n");
1275 Con_SafePrint("DirectInput not initialized\n");
1281 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
1283 if (mouseparmsvalid)
1285 // COMMANDLINEOPTION: Windows GDI Input: -noforcemspd disables setting of mouse speed (ignored with -dinput, windows only)
1286 if ( COM_CheckParm ("-noforcemspd") )
1287 newmouseparms[2] = originalmouseparms[2];
1289 // COMMANDLINEOPTION: Windows GDI Input: -noforcemaccel disables setting of mouse acceleration (ignored with -dinput, windows only)
1290 if ( COM_CheckParm ("-noforcemaccel") )
1292 newmouseparms[0] = originalmouseparms[0];
1293 newmouseparms[1] = originalmouseparms[1];
1296 // COMMANDLINEOPTION: Windows GDI Input: -noforcemparms disables setting of mouse parameters (ignored with -dinput, windows only)
1297 if ( COM_CheckParm ("-noforcemparms") )
1299 newmouseparms[0] = originalmouseparms[0];
1300 newmouseparms[1] = originalmouseparms[1];
1301 newmouseparms[2] = originalmouseparms[2];
1308 // if a fullscreen video mode was set before the mouse was initialized,
1309 // set the mouse state appropriately
1310 if (mouseactivatetoggle)
1311 IN_ActivateMouse ();
1320 void IN_MouseEvent (int mstate)
1324 if (mouseactive && !dinput)
1326 // perform button actions
1327 for (i=0 ; i<mouse_buttons ; i++)
1329 if ( (mstate & (1<<i)) &&
1330 !(mouse_oldbuttonstate & (1<<i)) )
1332 Key_Event (K_MOUSE1 + i, 0, true);
1335 if ( !(mstate & (1<<i)) &&
1336 (mouse_oldbuttonstate & (1<<i)) )
1338 Key_Event (K_MOUSE1 + i, 0, false);
1342 mouse_oldbuttonstate = mstate;
1352 void IN_MouseMove (usercmd_t *cmd)
1355 DIDEVICEOBJECTDATA od;
1361 GetCursorPos (¤t_pos);
1362 //ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
1363 IN_Mouse( cmd, 0, 0 );
1376 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
1377 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
1379 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
1381 dinput_acquired = true;
1382 IDirectInputDevice_Acquire(g_pMouse);
1386 /* Unable to read data or no data available */
1387 if (FAILED(hr) || dwElements == 0)
1390 /* Look at the element to see what happened */
1402 case DIMOFS_BUTTON0:
1403 if (od.dwData & 0x80)
1409 case DIMOFS_BUTTON1:
1410 if (od.dwData & 0x80)
1411 mstate_di |= (1<<1);
1413 mstate_di &= ~(1<<1);
1416 case DIMOFS_BUTTON2:
1417 if (od.dwData & 0x80)
1418 mstate_di |= (1<<2);
1420 mstate_di &= ~(1<<2);
1425 // perform button actions
1426 for (i=0 ; i<mouse_buttons ; i++)
1428 if ( (mstate_di & (1<<i)) &&
1429 !(mouse_oldbuttonstate & (1<<i)) )
1431 Key_Event (K_MOUSE1 + i, 0, true);
1434 if ( !(mstate_di & (1<<i)) &&
1435 (mouse_oldbuttonstate & (1<<i)) )
1437 Key_Event (K_MOUSE1 + i, 0, false);
1441 mouse_oldbuttonstate = mstate_di;
1445 GetCursorPos (¤t_pos);
1446 mx = current_pos.x - window_center_x;
1447 my = current_pos.y - window_center_y;
1450 IN_Mouse(cmd, mx, my);
1452 // if the mouse has moved, force it to the center, so there's room to move
1453 if (!dinput && (mx || my))
1454 SetCursorPos (window_center_x, window_center_y);
1463 void IN_Move (usercmd_t *cmd)
1465 if (vid_activewindow && !vid_hidden)
1478 void IN_ClearStates (void)
1481 mouse_oldbuttonstate = 0;
1490 void IN_StartupJoystick (void)
1497 // assume no joystick
1500 // abort startup if user requests no joystick
1501 // COMMANDLINEOPTION: Windows Input: -nojoy disables joystick support, may be a small speed increase
1502 if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe"))
1505 // verify joystick driver is present
1506 if ((numdevs = joyGetNumDevs ()) == 0)
1508 Con_Print("\njoystick not found -- driver not present\n\n");
1512 // cycle through the joystick ids for the first valid one
1513 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
1515 memset (&ji, 0, sizeof(ji));
1516 ji.dwSize = sizeof(ji);
1517 ji.dwFlags = JOY_RETURNCENTERED;
1519 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
1523 // abort startup if we didn't find a valid joystick
1524 if (mmr != JOYERR_NOERROR)
1526 Con_Printf("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
1530 // get the capabilities of the selected joystick
1531 // abort startup if command fails
1532 memset (&jc, 0, sizeof(jc));
1533 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
1535 Con_Printf("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
1539 // save the joystick's number of buttons and POV status
1540 joy_numbuttons = jc.wNumButtons;
1541 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
1543 // old button and POV states default to no buttons pressed
1544 joy_oldbuttonstate = joy_oldpovstate = 0;
1546 // mark the joystick as available and advanced initialization not completed
1547 // this is needed as cvars are not available during initialization
1550 joy_advancedinit = false;
1552 Con_Print("\njoystick detected\n\n");
1561 PDWORD RawValuePointer (int axis)
1578 return NULL; // LordHavoc: hush compiler warning
1584 Joy_AdvancedUpdate_f
1587 void Joy_AdvancedUpdate_f (void)
1590 // called once by IN_ReadJoystick and by user whenever an update is needed
1591 // cvars are now available
1595 // initialize all the maps
1596 for (i = 0; i < JOY_MAX_AXES; i++)
1598 dwAxisMap[i] = AxisNada;
1599 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
1600 pdwRawValue[i] = RawValuePointer(i);
1603 if( joy_advanced.integer == 0)
1605 // default joystick initialization
1606 // 2 axes only with joystick control
1607 dwAxisMap[JOY_AXIS_X] = AxisTurn;
1608 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
1609 dwAxisMap[JOY_AXIS_Y] = AxisForward;
1610 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
1614 if (strcmp (joy_name.string, "joystick") != 0)
1616 // notify user of advanced controller
1617 Con_Printf("\n%s configured\n\n", joy_name.string);
1620 // advanced initialization here
1621 // data supplied by user via joy_axisn cvars
1622 dwTemp = (DWORD) joy_advaxisx.value;
1623 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
1624 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
1625 dwTemp = (DWORD) joy_advaxisy.value;
1626 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
1627 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
1628 dwTemp = (DWORD) joy_advaxisz.value;
1629 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
1630 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
1631 dwTemp = (DWORD) joy_advaxisr.value;
1632 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
1633 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
1634 dwTemp = (DWORD) joy_advaxisu.value;
1635 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
1636 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
1637 dwTemp = (DWORD) joy_advaxisv.value;
1638 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
1639 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
1642 // compute the axes to collect from DirectInput
1643 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
1644 for (i = 0; i < JOY_MAX_AXES; i++)
1646 if (dwAxisMap[i] != AxisNada)
1648 joy_flags |= dwAxisFlags[i];
1658 void IN_Commands (void)
1661 DWORD buttonstate, povstate;
1669 // loop through the joystick buttons
1670 // key a joystick event or auxillary event for higher number buttons for each state change
1671 buttonstate = ji.dwButtons;
1672 for (i=0 ; i < (int) joy_numbuttons ; i++)
1674 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
1676 key_index = (i < 16) ? K_JOY1 : K_AUX1;
1677 Key_Event (key_index + i, 0, true);
1680 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
1682 key_index = (i < 16) ? K_JOY1 : K_AUX1;
1683 Key_Event (key_index + i, 0, false);
1686 joy_oldbuttonstate = buttonstate;
1690 // convert POV information into 4 bits of state information
1691 // this avoids any potential problems related to moving from one
1692 // direction to another without going through the center position
1694 if(ji.dwPOV != JOY_POVCENTERED)
1696 if (ji.dwPOV == JOY_POVFORWARD)
1698 if (ji.dwPOV == JOY_POVRIGHT)
1700 if (ji.dwPOV == JOY_POVBACKWARD)
1702 if (ji.dwPOV == JOY_POVLEFT)
1705 // determine which bits have changed and key an auxillary event for each change
1706 for (i=0 ; i < 4 ; i++)
1708 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
1710 Key_Event (K_AUX29 + i, 0, true);
1713 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
1715 Key_Event (K_AUX29 + i, 0, false);
1718 joy_oldpovstate = povstate;
1728 qboolean IN_ReadJoystick (void)
1731 memset (&ji, 0, sizeof(ji));
1732 ji.dwSize = sizeof(ji);
1733 ji.dwFlags = joy_flags;
1735 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1737 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1738 // rather than having 32768 be the zero point, they have the zero point at 32668
1739 // go figure -- anyway, now we get the full resolution out of the device
1740 if (joy_wwhack1.integer != 0.0)
1748 // read error occurred
1749 // turning off the joystick seems too harsh for 1 read error,
1750 // but what should be done?
1761 void IN_JoyMove (usercmd_t *cmd)
1763 float speed, aspeed;
1764 float fAxisValue, fTemp;
1765 int i, mouselook = (in_mlook.state & 1) || freelook.integer;
1767 // complete initialization if first time in
1768 // this is needed as cvars are not available at initialization time
1769 if( joy_advancedinit != true )
1771 Joy_AdvancedUpdate_f();
1772 joy_advancedinit = true;
1775 // verify joystick is available and that the user wants to use it
1776 if (!joy_avail || !in_joystick.integer)
1781 // collect the joystick data, if possible
1782 if (IN_ReadJoystick () != true)
1787 if (in_speed.state & 1)
1788 speed = cl_movespeedkey.value;
1791 // LordHavoc: viewzoom affects sensitivity for sniping
1792 aspeed = speed * host_realframetime * cl.viewzoom;
1794 // loop through the axes
1795 for (i = 0; i < JOY_MAX_AXES; i++)
1797 // get the floating point zero-centered, potentially-inverted data for the current axis
1798 fAxisValue = (float) *pdwRawValue[i];
1799 // move centerpoint to zero
1800 fAxisValue -= 32768.0;
1802 if (joy_wwhack2.integer != 0.0)
1804 if (dwAxisMap[i] == AxisTurn)
1806 // this is a special formula for the Logitech WingMan Warrior
1807 // y=ax^b; where a = 300 and b = 1.3
1808 // also x values are in increments of 800 (so this is factored out)
1809 // then bounds check result to level out excessively high spin rates
1810 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1811 if (fTemp > 14000.0)
1813 // restore direction information
1814 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1818 // convert range from -32768..32767 to -1..1
1819 fAxisValue /= 32768.0;
1821 switch (dwAxisMap[i])
1824 if ((joy_advanced.integer == 0) && mouselook)
1826 // user wants forward control to become look control
1827 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1829 // if mouse invert is on, invert the joystick pitch value
1830 // only absolute control support here (joy_advanced is false)
1831 if (m_pitch.value < 0.0)
1833 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1837 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1843 // no pitch movement
1844 // disable pitch return-to-center unless requested by user
1845 // *** this code can be removed when the lookspring bug is fixed
1846 // *** the bug always has the lookspring feature on
1847 if(lookspring.value == 0.0)
1853 // user wants forward control to be forward control
1854 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1856 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1862 if (fabs(fAxisValue) > joy_sidethreshold.value)
1864 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1869 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
1871 // user wants turn control to become side control
1872 if (fabs(fAxisValue) > joy_sidethreshold.value)
1874 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1879 // user wants turn control to be turn control
1880 if (fabs(fAxisValue) > joy_yawthreshold.value)
1882 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1884 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1888 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1898 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1900 // pitch movement detected and pitch movement desired by user
1901 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1903 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1907 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1913 // no pitch movement
1914 // disable pitch return-to-center unless requested by user
1915 // *** this code can be removed when the lookspring bug is fixed
1916 // *** the bug always has the lookspring feature on
1917 if(lookspring.integer == 0)
1929 static void IN_Init(void)
1931 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
1933 // joystick variables
1934 Cvar_RegisterVariable (&in_joystick);
1935 Cvar_RegisterVariable (&joy_name);
1936 Cvar_RegisterVariable (&joy_advanced);
1937 Cvar_RegisterVariable (&joy_advaxisx);
1938 Cvar_RegisterVariable (&joy_advaxisy);
1939 Cvar_RegisterVariable (&joy_advaxisz);
1940 Cvar_RegisterVariable (&joy_advaxisr);
1941 Cvar_RegisterVariable (&joy_advaxisu);
1942 Cvar_RegisterVariable (&joy_advaxisv);
1943 Cvar_RegisterVariable (&joy_forwardthreshold);
1944 Cvar_RegisterVariable (&joy_sidethreshold);
1945 Cvar_RegisterVariable (&joy_pitchthreshold);
1946 Cvar_RegisterVariable (&joy_yawthreshold);
1947 Cvar_RegisterVariable (&joy_forwardsensitivity);
1948 Cvar_RegisterVariable (&joy_sidesensitivity);
1949 Cvar_RegisterVariable (&joy_pitchsensitivity);
1950 Cvar_RegisterVariable (&joy_yawsensitivity);
1951 Cvar_RegisterVariable (&joy_wwhack1);
1952 Cvar_RegisterVariable (&joy_wwhack2);
1953 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
1956 static void IN_Shutdown(void)
1958 IN_DeactivateMouse ();
1962 IDirectInputDevice_Release(g_pMouse);
1966 IDirectInput_Release(g_pdi);