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;
111 #define DINPUT_BUFFERSIZE 16
112 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
114 HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
115 LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
119 int mouse_oldbuttonstate;
121 int mouse_x, mouse_y, old_mouse_x, old_mouse_y, mx_accum, my_accum;
123 static qboolean restore_spi;
124 static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1};
126 unsigned int uiWheelMessage;
127 qboolean mouseactive;
128 //qboolean mouseinitialized;
129 static qboolean mouseparmsvalid, mouseactivatetoggle;
130 static qboolean mouseshowtoggle = 1;
131 static qboolean dinput_acquired;
133 static unsigned int mstate_di;
135 // joystick defines and variables
136 // where should defines be moved?
137 #define JOY_ABSOLUTE_AXIS 0x00000000 // control like a joystick
138 #define JOY_RELATIVE_AXIS 0x00000010 // control like a mouse, spinner, trackball
139 #define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
149 AxisNada = 0, AxisForward, AxisLook, AxisSide, AxisTurn
152 DWORD dwAxisFlags[JOY_MAX_AXES] =
154 JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
157 DWORD dwAxisMap[JOY_MAX_AXES];
158 DWORD dwControlMap[JOY_MAX_AXES];
159 PDWORD pdwRawValue[JOY_MAX_AXES];
161 // none of these cvars are saved over a session
162 // this means that advanced controller configuration needs to be executed
163 // each time. this avoids any problems with getting back to a default usage
164 // or when changing from one controller to another. this way at least something
166 cvar_t in_joystick = {CVAR_SAVE, "joystick","0"};
167 cvar_t joy_name = {0, "joyname", "joystick"};
168 cvar_t joy_advanced = {0, "joyadvanced", "0"};
169 cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"};
170 cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"};
171 cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"};
172 cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"};
173 cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"};
174 cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"};
175 cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"};
176 cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"};
177 cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"};
178 cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"};
179 cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"};
180 cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"};
181 cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"};
182 cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"};
183 cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"};
184 cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"};
186 qboolean joy_avail, joy_advancedinit, joy_haspov;
187 DWORD joy_oldbuttonstate, joy_oldpovstate;
191 DWORD joy_numbuttons;
193 static LPDIRECTINPUT g_pdi;
194 static LPDIRECTINPUTDEVICE g_pMouse;
198 static HINSTANCE hInstDI;
200 //static qboolean dinput;
202 typedef struct MYDATA {
203 LONG lX; // X axis goes here
204 LONG lY; // Y axis goes here
205 LONG lZ; // Z axis goes here
206 BYTE bButtonA; // One button goes here
207 BYTE bButtonB; // Another button goes here
208 BYTE bButtonC; // Another button goes here
209 BYTE bButtonD; // Another button goes here
212 static DIOBJECTDATAFORMAT rgodf[] = {
213 { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
214 { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
215 { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
216 { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
217 { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
218 { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
219 { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
222 #define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
224 static DIDATAFORMAT df = {
225 sizeof(DIDATAFORMAT), // this structure
226 sizeof(DIOBJECTDATAFORMAT), // size of object data format
227 DIDF_RELAXIS, // absolute axis coordinates
228 sizeof(MYDATA), // device data size
229 NUM_OBJECTS, // number of objects
230 rgodf, // and here they are
233 // forward-referenced functions
234 void IN_StartupJoystick (void);
235 void Joy_AdvancedUpdate_f (void);
236 void IN_JoyMove (usercmd_t *cmd);
237 void IN_StartupMouse (void);
241 VID_UpdateWindowStatus
244 void VID_UpdateWindowStatus (void)
246 window_center_x = window_x + window_width / 2;
247 window_center_y = window_y + window_height / 2;
249 if (mouseinitialized && mouseactive && !dinput)
252 window_rect.left = window_x;
253 window_rect.top = window_y;
254 window_rect.right = window_x + window_width;
255 window_rect.bottom = window_y + window_height;
256 ClipCursor (&window_rect);
261 //====================================
268 void VID_GetWindowSize (int *x, int *y, int *width, int *height)
272 *width = window_width;
273 *height = window_height;
277 void VID_Finish (void)
281 if (r_render.integer && !scr_skipupdate)
284 hdc = GetDC(mainwindow);
286 ReleaseDC(mainwindow, hdc);
289 // handle the mouse state when windowed if that's changed
290 vid_usemouse = false;
291 if (vid_mouse.integer && !key_consoleactive)
293 if (vid_isfullscreen)
295 if (!vid_activewindow)
296 vid_usemouse = false;
301 vid_usingmouse = true;
310 vid_usingmouse = false;
311 IN_DeactivateMouse ();
317 //==========================================================================
322 qbyte scantokey[128] =
324 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
325 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 , // 0
326 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,13 ,K_CTRL ,'a' ,'s' , // 1
327 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT,'\\' ,'z' ,'x' ,'c' ,'v' , // 2
328 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT,'*' ,K_ALT ,' ' ,0 ,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 , // 3
329 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
330 K_DOWNARROW,K_PGDN,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
331 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
332 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
340 Map from windows to quake keynums
343 int MapKey (int key, int virtualkey)
348 if (scantokey[key] == 0)
349 Con_DPrintf("key 0x%02x has no translation\n", key);
350 return scantokey[key];
354 ===================================================================
358 ===================================================================
366 void ClearAllStates (void)
370 // send an up event for each key, to make sure the server clears them all
371 for (i=0 ; i<256 ; i++)
373 Key_Event (i, false);
380 void VID_RestoreGameGamma(void);
381 extern qboolean host_loopactive;
383 void AppActivate(BOOL fActive, BOOL minimize)
384 /****************************************************************************
386 * Function: AppActivate
387 * Parameters: fActive - True if app is activating
389 * Description: If the application is activating, then swap the system
390 * into SYSPAL_NOSTATIC mode so that our palettes will display
393 ****************************************************************************/
395 static BOOL sound_active;
397 vid_activewindow = fActive;
398 vid_hidden = minimize;
400 // enable/disable sound on focus gain/loss
401 if (!vid_activewindow && sound_active)
404 sound_active = false;
406 else if (vid_activewindow && !sound_active)
414 if (vid_isfullscreen)
416 if (vid_wassuspended)
418 vid_wassuspended = false;
419 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
420 ShowWindow(mainwindow, SW_SHOWNORMAL);
423 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
424 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
427 VID_RestoreGameGamma();
432 vid_usingmouse = false;
433 IN_DeactivateMouse ();
435 if (vid_isfullscreen)
437 ChangeDisplaySettings (NULL, 0);
438 vid_wassuspended = true;
440 VID_RestoreSystemGamma();
444 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
446 /* main window procedure */
447 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
450 int fActive, fMinimized, temp;
451 extern unsigned int uiWheelMessage;
453 if ( uMsg == uiWheelMessage )
454 uMsg = WM_MOUSEWHEEL;
459 if (vid_isfullscreen)
460 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
467 window_x = (int) LOWORD(lParam);
468 window_y = (int) HIWORD(lParam);
469 VID_UpdateWindowStatus ();
474 Key_Event (MapKey(lParam, wParam), true);
479 Key_Event (MapKey(lParam, wParam), false);
483 // keep Alt-Space from happening
486 // this is complicated because Win32 seems to pack multiple mouse events into
487 // one update sometimes, so we always check all states and look for events
497 if (wParam & MK_LBUTTON)
500 if (wParam & MK_RBUTTON)
503 if (wParam & MK_MBUTTON)
506 IN_MouseEvent (temp);
510 // JACK: This is the mouse wheel with the Intellimouse
511 // Its delta is either positive or neg, and we generate the proper
514 if ((short) HIWORD(wParam) > 0) {
515 Key_Event(K_MWHEELUP, true);
516 Key_Event(K_MWHEELUP, false);
518 Key_Event(K_MWHEELDOWN, true);
519 Key_Event(K_MWHEELDOWN, false);
527 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
533 fActive = LOWORD(wParam);
534 fMinimized = (BOOL) HIWORD(wParam);
535 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
537 // fix the leftover Alt from any Alt-Tab or the like that switched us away
543 // PostQuitMessage (0);
547 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
551 /* pass all unhandled messages to DefWindowProc */
552 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
556 /* return 1 if handled message, 0 if not */
561 //static int grabsysgamma = true;
562 WORD systemgammaramps[3][256], currentgammaramps[3][256];
564 int VID_SetGamma(float prescale, float gamma, float scale, float base)
570 BuildGammaTable16(prescale, gamma, scale, base, ¤tgammaramps[0][0]);
571 for (i = 0;i < 256;i++)
572 currentgammaramps[1][i] = currentgammaramps[2][i] = currentgammaramps[0][i];
574 i = SetDeviceGammaRamp(hdc, ¤tgammaramps[0][0]);
576 ReleaseDC (NULL, hdc);
577 return i; // return success or failure
580 void VID_RestoreGameGamma(void)
582 VID_UpdateGamma(true);
585 void VID_GetSystemGamma(void)
590 GetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
592 ReleaseDC (NULL, hdc);
595 void VID_RestoreSystemGamma(void)
600 SetDeviceGammaRamp(hdc, &systemgammaramps[0][0]);
602 ReleaseDC (NULL, hdc);
605 //========================================================
607 //========================================================
610 extern void M_Menu_Options_f (void);
611 extern void M_Print (float cx, float cy, char *str);
612 extern void M_PrintWhite (float cx, float cy, char *str);
613 extern void M_DrawCharacter (float cx, float cy, int num);
614 extern void M_DrawPic (float cx, float cy, char *picname);
616 static int vid_wmodes;
625 #define MAX_COLUMN_SIZE 9
626 #define MODE_AREA_HEIGHT (MAX_COLUMN_SIZE + 2)
627 #define MAX_MODEDESCS (MAX_COLUMN_SIZE*3)
629 static modedesc_t modedescs[MAX_MODEDESCS];
636 void VID_MenuDraw (void)
640 int lnummodes, i, k, column, row;
643 p = Draw_CachePic ("gfx/vidmodes.lmp");
644 M_DrawPic ( (320-p->width)/2, 4, "gfx/vidmodes.lmp");
647 lnummodes = VID_NumModes ();
649 for (i=1 ; (i<lnummodes) && (vid_wmodes < MAX_MODEDESCS) ; i++)
651 ptr = VID_GetModeDescription (i);
652 pv = VID_GetModePtr (i);
656 modedescs[k].modenum = i;
657 modedescs[k].desc = ptr;
658 modedescs[k].iscur = 0;
660 if (i == vid_modenum)
661 modedescs[k].iscur = 1;
669 M_Print (2*8, 36+0*8, "Fullscreen Modes (WIDTHxHEIGHTxBPP)");
674 for (i=0 ; i<vid_wmodes ; i++)
676 if (modedescs[i].iscur)
677 M_PrintWhite (column, row, modedescs[i].desc);
679 M_Print (column, row, modedescs[i].desc);
683 if ((i % VID_ROW_SIZE) == (VID_ROW_SIZE - 1))
691 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*2, "Video modes must be set from the");
692 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*3, "command line with -width <width>");
693 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*4, "and -bpp <bits-per-pixel>");
694 M_Print (3*8, 36 + MODE_AREA_HEIGHT * 8 + 8*6, "Select windowed mode with -window");
703 void VID_MenuKey (int key)
708 S_LocalSound ("misc/menu1.wav");
718 static HINSTANCE gldll;
720 int GL_OpenLibrary(const char *name)
722 Con_Printf("Loading GL driver %s\n", name);
724 if (!(gldll = LoadLibrary(name)))
726 Con_Printf("Unable to LoadLibrary %s\n", name);
729 strcpy(gl_driver, name);
733 void GL_CloseLibrary(void)
738 qwglGetProcAddress = NULL;
741 gl_platformextensions = "";
744 void *GL_GetProcAddress(const char *name)
747 if (qwglGetProcAddress != NULL)
748 p = (void *) qwglGetProcAddress(name);
750 p = (void *) GetProcAddress(gldll, name);
754 static void IN_Init(void);
759 InitCommonControls();
760 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON2));
762 // Register the frame class
764 wc.lpfnWndProc = (WNDPROC)MainWndProc;
767 wc.hInstance = global_hInstance;
769 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
770 wc.hbrBackground = NULL;
772 wc.lpszClassName = "DarkPlacesWindowClass";
774 if (!RegisterClass (&wc))
775 Sys_Error("Couldn't register window class\n");
780 int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil)
786 PIXELFORMATDESCRIPTOR pfd =
788 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
790 PFD_DRAW_TO_WINDOW // support window
791 | PFD_SUPPORT_OPENGL // support OpenGL
792 | PFD_DOUBLEBUFFER , // double buffered
793 PFD_TYPE_RGBA, // RGBA type
794 24, // 24-bit color depth
795 0, 0, 0, 0, 0, 0, // color bits ignored
796 0, // no alpha buffer
797 0, // shift bit ignored
798 0, // no accumulation buffer
799 0, 0, 0, 0, // accum bits ignored
800 32, // 32-bit z-buffer
801 0, // no stencil buffer
802 0, // no auxiliary buffer
803 PFD_MAIN_PLANE, // main layer
805 0, 0, 0 // layer masks ignored
808 DWORD WindowStyle, ExWindowStyle;
810 int CenterX, CenterY;
811 const char *gldrivername;
814 Sys_Error("VID_InitMode called when video is already initialised\n");
816 // if stencil is enabled, ask for alpha too
819 pfd.cStencilBits = 8;
824 pfd.cStencilBits = 0;
828 gldrivername = "opengl32.dll";
829 i = COM_CheckParm("-gl_driver");
830 if (i && i < com_argc - 1)
831 gldrivername = com_argv[i + 1];
832 if (!GL_OpenLibrary(gldrivername))
834 Con_Printf("Unable to load GL driver %s\n", gldrivername);
838 memset(&gdevmode, 0, sizeof(gdevmode));
840 VID_GetSystemGamma();
842 vid_isfullscreen = false;
845 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
846 gdevmode.dmBitsPerPel = bpp;
847 gdevmode.dmPelsWidth = width;
848 gdevmode.dmPelsHeight = height;
849 gdevmode.dmSize = sizeof (gdevmode);
850 if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
853 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
857 vid_isfullscreen = true;
858 WindowStyle = WS_POPUP;
864 i = GetDeviceCaps(hdc, RASTERCAPS);
865 ReleaseDC (NULL, hdc);
869 Con_Printf ("Can't run in non-RGB mode\n");
873 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
880 rect.bottom = height;
881 AdjustWindowRectEx(&rect, WindowStyle, false, 0);
890 CenterX = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
891 CenterY = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
893 CenterX = max(0, CenterX);
894 CenterY = max(0, CenterY);
896 // x and y may be changed by WM_MOVE messages
899 window_width = width;
900 window_height = height;
901 rect.left += CenterX;
902 rect.right += CenterX;
904 rect.bottom += CenterY;
906 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
909 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);
916 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
919 ShowWindow (mainwindow, SW_SHOWDEFAULT);
920 UpdateWindow (mainwindow);
922 SendMessage (mainwindow, WM_SETICON, (WPARAM)true, (LPARAM)hIcon);
923 SendMessage (mainwindow, WM_SETICON, (WPARAM)false, (LPARAM)hIcon);
925 VID_UpdateWindowStatus ();
927 // now we try to make sure we get the focus on the mode switch, because
928 // sometimes in some systems we don't. We grab the foreground, then
929 // finish setting up, pump all our messages, and sleep for a little while
930 // to let messages finish bouncing around the system, then we put
931 // ourselves at the top of the z order, then grab the foreground again,
932 // Who knows if it helps, but it probably doesn't hurt
933 SetForegroundWindow (mainwindow);
935 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
937 TranslateMessage (&msg);
938 DispatchMessage (&msg);
943 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
945 SetForegroundWindow (mainwindow);
947 // fix the leftover Alt from any Alt-Tab or the like that switched us away
950 hdc = GetDC(mainwindow);
952 if ((pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0)
955 Con_Printf("ChoosePixelFormat(%d, %p) failed\n", hdc, &pfd);
959 if (SetPixelFormat(hdc, pixelformat, &pfd) == false)
962 Con_Printf("SetPixelFormat(%d, %d, %p) failed\n", hdc, pixelformat, &pfd);
966 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
969 Con_Printf("wgl functions not found\n");
973 baseRC = qwglCreateContext(hdc);
977 Con_Printf("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
980 if (!qwglMakeCurrent(hdc, baseRC))
983 Con_Printf("wglMakeCurrent(%d, %d) failed\n", hdc, baseRC);
987 qglGetString = GL_GetProcAddress("glGetString");
988 qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB");
989 if (qglGetString == NULL)
992 Con_Printf("glGetString not found\n");
995 gl_renderer = qglGetString(GL_RENDERER);
996 gl_vendor = qglGetString(GL_VENDOR);
997 gl_version = qglGetString(GL_VERSION);
998 gl_extensions = qglGetString(GL_EXTENSIONS);
1000 gl_platformextensions = "";
1002 if (qwglGetExtensionsStringARB)
1003 gl_platformextensions = qwglGetExtensionsStringARB(hdc);
1005 gl_videosyncavailable = GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, NULL, false);
1006 ReleaseDC(mainwindow, hdc);
1010 // LordHavoc: special differences for ATI (broken 8bit color when also using 32bit? weird!)
1011 if (strncasecmp(gl_vendor,"ATI",3)==0)
1013 if (strncasecmp(gl_renderer,"Rage Pro",8)==0)
1016 if (strncasecmp(gl_renderer,"Matrox G200 Direct3D",20)==0) // a D3D driver for GL? sigh...
1019 //vid_menudrawfn = VID_MenuDraw;
1020 //vid_menukeyfn = VID_MenuKey;
1022 vid_initialized = true;
1025 IN_StartupJoystick ();
1030 static void IN_Shutdown(void);
1031 void VID_Shutdown (void)
1036 vid_initialized = false;
1038 if (qwglGetCurrentContext)
1039 hRC = qwglGetCurrentContext();
1040 if (qwglGetCurrentDC)
1041 hDC = qwglGetCurrentDC();
1042 if (qwglMakeCurrent)
1043 qwglMakeCurrent(NULL, NULL);
1044 if (hRC && qwglDeleteContext)
1045 qwglDeleteContext(hRC);
1046 // close the library before we get rid of the window
1048 if (hDC && mainwindow)
1049 ReleaseDC(mainwindow, hDC);
1050 if (vid_isfullscreen)
1051 ChangeDisplaySettings (NULL, 0);
1052 vid_isfullscreen = false;
1053 AppActivate(false, false);
1054 VID_RestoreSystemGamma();
1056 DestroyWindow(mainwindow);
1066 void IN_ShowMouse (void)
1068 if (!mouseshowtoggle)
1071 mouseshowtoggle = 1;
1081 void IN_HideMouse (void)
1083 if (mouseshowtoggle)
1086 mouseshowtoggle = 0;
1096 void IN_ActivateMouse (void)
1099 mouseactivatetoggle = true;
1101 if (mouseinitialized)
1107 if (!dinput_acquired)
1109 IDirectInputDevice_Acquire(g_pMouse);
1110 dinput_acquired = true;
1121 window_rect.left = window_x;
1122 window_rect.top = window_y;
1123 window_rect.right = window_x + window_width;
1124 window_rect.bottom = window_y + window_height;
1126 if (mouseparmsvalid)
1127 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0);
1129 SetCursorPos (window_center_x, window_center_y);
1130 SetCapture (mainwindow);
1131 ClipCursor (&window_rect);
1144 void IN_DeactivateMouse (void)
1147 mouseactivatetoggle = false;
1149 if (mouseinitialized)
1155 if (dinput_acquired)
1157 IDirectInputDevice_Unacquire(g_pMouse);
1158 dinput_acquired = false;
1165 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1171 mouseactive = false;
1181 qboolean IN_InitDInput (void)
1184 DIPROPDWORD dipdw = {
1186 sizeof(DIPROPDWORD), // diph.dwSize
1187 sizeof(DIPROPHEADER), // diph.dwHeaderSize
1189 DIPH_DEVICE, // diph.dwHow
1191 DINPUT_BUFFERSIZE, // dwData
1196 hInstDI = LoadLibrary("dinput.dll");
1198 if (hInstDI == NULL)
1200 Con_SafePrintf ("Couldn't load dinput.dll\n");
1205 if (!pDirectInputCreate)
1207 pDirectInputCreate = (void *)GetProcAddress(hInstDI,"DirectInputCreateA");
1209 if (!pDirectInputCreate)
1211 Con_SafePrintf ("Couldn't get DI proc addr\n");
1216 // register with DirectInput and get an IDirectInput to play with.
1217 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
1224 // obtain an interface to the system mouse device.
1225 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
1229 Con_SafePrintf ("Couldn't open DI mouse device\n");
1233 // set the data format to "mouse format".
1234 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
1238 Con_SafePrintf ("Couldn't set DI mouse format\n");
1242 // set the cooperativity level.
1243 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
1244 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
1248 Con_SafePrintf ("Couldn't set DI coop level\n");
1253 // set the buffer size to DINPUT_BUFFERSIZE elements.
1254 // the buffer size is a DWORD property associated with the device
1255 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
1259 Con_SafePrintf ("Couldn't set DI buffersize\n");
1272 void IN_StartupMouse (void)
1274 if (COM_CheckParm ("-nomouse") || COM_CheckParm("-safe"))
1277 mouseinitialized = true;
1279 if (COM_CheckParm ("-dinput"))
1281 dinput = IN_InitDInput ();
1285 Con_SafePrintf ("DirectInput initialized\n");
1289 Con_SafePrintf ("DirectInput not initialized\n");
1295 mouseparmsvalid = SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0);
1297 if (mouseparmsvalid)
1299 if ( COM_CheckParm ("-noforcemspd") )
1300 newmouseparms[2] = originalmouseparms[2];
1302 if ( COM_CheckParm ("-noforcemaccel") )
1304 newmouseparms[0] = originalmouseparms[0];
1305 newmouseparms[1] = originalmouseparms[1];
1308 if ( COM_CheckParm ("-noforcemparms") )
1310 newmouseparms[0] = originalmouseparms[0];
1311 newmouseparms[1] = originalmouseparms[1];
1312 newmouseparms[2] = originalmouseparms[2];
1319 // if a fullscreen video mode was set before the mouse was initialized,
1320 // set the mouse state appropriately
1321 if (mouseactivatetoggle)
1322 IN_ActivateMouse ();
1331 void IN_MouseEvent (int mstate)
1335 if (mouseactive && !dinput)
1337 // perform button actions
1338 for (i=0 ; i<mouse_buttons ; i++)
1340 if ( (mstate & (1<<i)) &&
1341 !(mouse_oldbuttonstate & (1<<i)) )
1343 Key_Event (K_MOUSE1 + i, true);
1346 if ( !(mstate & (1<<i)) &&
1347 (mouse_oldbuttonstate & (1<<i)) )
1349 Key_Event (K_MOUSE1 + i, false);
1353 mouse_oldbuttonstate = mstate;
1363 void IN_MouseMove (usercmd_t *cmd)
1366 DIDEVICEOBJECTDATA od;
1372 GetCursorPos (¤t_pos);
1373 ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y);
1386 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
1387 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
1389 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
1391 dinput_acquired = true;
1392 IDirectInputDevice_Acquire(g_pMouse);
1396 /* Unable to read data or no data available */
1397 if (FAILED(hr) || dwElements == 0)
1400 /* Look at the element to see what happened */
1412 case DIMOFS_BUTTON0:
1413 if (od.dwData & 0x80)
1419 case DIMOFS_BUTTON1:
1420 if (od.dwData & 0x80)
1421 mstate_di |= (1<<1);
1423 mstate_di &= ~(1<<1);
1426 case DIMOFS_BUTTON2:
1427 if (od.dwData & 0x80)
1428 mstate_di |= (1<<2);
1430 mstate_di &= ~(1<<2);
1435 // perform button actions
1436 for (i=0 ; i<mouse_buttons ; i++)
1438 if ( (mstate_di & (1<<i)) &&
1439 !(mouse_oldbuttonstate & (1<<i)) )
1441 Key_Event (K_MOUSE1 + i, true);
1444 if ( !(mstate_di & (1<<i)) &&
1445 (mouse_oldbuttonstate & (1<<i)) )
1447 Key_Event (K_MOUSE1 + i, false);
1451 mouse_oldbuttonstate = mstate_di;
1455 GetCursorPos (¤t_pos);
1456 mx = current_pos.x - window_center_x + mx_accum;
1457 my = current_pos.y - window_center_y + my_accum;
1462 IN_Mouse(cmd, mx, my);
1464 // if the mouse has moved, force it to the center, so there's room to move
1465 if (!dinput && (mx || my))
1466 SetCursorPos (window_center_x, window_center_y);
1475 void IN_Move (usercmd_t *cmd)
1477 if (vid_activewindow && !vid_hidden)
1490 void IN_Accumulate (void)
1496 GetCursorPos (¤t_pos);
1498 mx_accum += current_pos.x - window_center_x;
1499 my_accum += current_pos.y - window_center_y;
1501 // force the mouse to the center, so there's room to move
1502 SetCursorPos (window_center_x, window_center_y);
1513 void IN_ClearStates (void)
1519 mouse_oldbuttonstate = 0;
1529 void IN_StartupJoystick (void)
1536 // assume no joystick
1539 // abort startup if user requests no joystick
1540 if (COM_CheckParm ("-nojoy") || COM_CheckParm("-safe"))
1543 // verify joystick driver is present
1544 if ((numdevs = joyGetNumDevs ()) == 0)
1546 Con_Printf ("\njoystick not found -- driver not present\n\n");
1550 // cycle through the joystick ids for the first valid one
1551 for (joy_id=0 ; joy_id<numdevs ; joy_id++)
1553 memset (&ji, 0, sizeof(ji));
1554 ji.dwSize = sizeof(ji);
1555 ji.dwFlags = JOY_RETURNCENTERED;
1557 if ((mmr = joyGetPosEx (joy_id, &ji)) == JOYERR_NOERROR)
1561 // abort startup if we didn't find a valid joystick
1562 if (mmr != JOYERR_NOERROR)
1564 Con_Printf ("\njoystick not found -- no valid joysticks (%x)\n\n", mmr);
1568 // get the capabilities of the selected joystick
1569 // abort startup if command fails
1570 memset (&jc, 0, sizeof(jc));
1571 if ((mmr = joyGetDevCaps (joy_id, &jc, sizeof(jc))) != JOYERR_NOERROR)
1573 Con_Printf ("\njoystick not found -- invalid joystick capabilities (%x)\n\n", mmr);
1577 // save the joystick's number of buttons and POV status
1578 joy_numbuttons = jc.wNumButtons;
1579 joy_haspov = jc.wCaps & JOYCAPS_HASPOV;
1581 // old button and POV states default to no buttons pressed
1582 joy_oldbuttonstate = joy_oldpovstate = 0;
1584 // mark the joystick as available and advanced initialization not completed
1585 // this is needed as cvars are not available during initialization
1588 joy_advancedinit = false;
1590 Con_Printf ("\njoystick detected\n\n");
1599 PDWORD RawValuePointer (int axis)
1616 return NULL; // LordHavoc: hush compiler warning
1622 Joy_AdvancedUpdate_f
1625 void Joy_AdvancedUpdate_f (void)
1628 // called once by IN_ReadJoystick and by user whenever an update is needed
1629 // cvars are now available
1633 // initialize all the maps
1634 for (i = 0; i < JOY_MAX_AXES; i++)
1636 dwAxisMap[i] = AxisNada;
1637 dwControlMap[i] = JOY_ABSOLUTE_AXIS;
1638 pdwRawValue[i] = RawValuePointer(i);
1641 if( joy_advanced.integer == 0)
1643 // default joystick initialization
1644 // 2 axes only with joystick control
1645 dwAxisMap[JOY_AXIS_X] = AxisTurn;
1646 // dwControlMap[JOY_AXIS_X] = JOY_ABSOLUTE_AXIS;
1647 dwAxisMap[JOY_AXIS_Y] = AxisForward;
1648 // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS;
1652 if (strcmp (joy_name.string, "joystick") != 0)
1654 // notify user of advanced controller
1655 Con_Printf ("\n%s configured\n\n", joy_name.string);
1658 // advanced initialization here
1659 // data supplied by user via joy_axisn cvars
1660 dwTemp = (DWORD) joy_advaxisx.value;
1661 dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f;
1662 dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS;
1663 dwTemp = (DWORD) joy_advaxisy.value;
1664 dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f;
1665 dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS;
1666 dwTemp = (DWORD) joy_advaxisz.value;
1667 dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f;
1668 dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS;
1669 dwTemp = (DWORD) joy_advaxisr.value;
1670 dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f;
1671 dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS;
1672 dwTemp = (DWORD) joy_advaxisu.value;
1673 dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f;
1674 dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS;
1675 dwTemp = (DWORD) joy_advaxisv.value;
1676 dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f;
1677 dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS;
1680 // compute the axes to collect from DirectInput
1681 joy_flags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNPOV;
1682 for (i = 0; i < JOY_MAX_AXES; i++)
1684 if (dwAxisMap[i] != AxisNada)
1686 joy_flags |= dwAxisFlags[i];
1697 void IN_Commands (void)
1700 DWORD buttonstate, povstate;
1708 // loop through the joystick buttons
1709 // key a joystick event or auxillary event for higher number buttons for each state change
1710 buttonstate = ji.dwButtons;
1711 for (i=0 ; i < (int) joy_numbuttons ; i++)
1713 if ( (buttonstate & (1<<i)) && !(joy_oldbuttonstate & (1<<i)) )
1715 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1716 Key_Event (key_index + i, true);
1719 if ( !(buttonstate & (1<<i)) && (joy_oldbuttonstate & (1<<i)) )
1721 key_index = (i < 4) ? K_JOY1 : K_AUX1;
1722 Key_Event (key_index + i, false);
1725 joy_oldbuttonstate = buttonstate;
1729 // convert POV information into 4 bits of state information
1730 // this avoids any potential problems related to moving from one
1731 // direction to another without going through the center position
1733 if(ji.dwPOV != JOY_POVCENTERED)
1735 if (ji.dwPOV == JOY_POVFORWARD)
1737 if (ji.dwPOV == JOY_POVRIGHT)
1739 if (ji.dwPOV == JOY_POVBACKWARD)
1741 if (ji.dwPOV == JOY_POVLEFT)
1744 // determine which bits have changed and key an auxillary event for each change
1745 for (i=0 ; i < 4 ; i++)
1747 if ( (povstate & (1<<i)) && !(joy_oldpovstate & (1<<i)) )
1749 Key_Event (K_AUX29 + i, true);
1752 if ( !(povstate & (1<<i)) && (joy_oldpovstate & (1<<i)) )
1754 Key_Event (K_AUX29 + i, false);
1757 joy_oldpovstate = povstate;
1767 qboolean IN_ReadJoystick (void)
1770 memset (&ji, 0, sizeof(ji));
1771 ji.dwSize = sizeof(ji);
1772 ji.dwFlags = joy_flags;
1774 if (joyGetPosEx (joy_id, &ji) == JOYERR_NOERROR)
1776 // this is a hack -- there is a bug in the Logitech WingMan Warrior DirectInput Driver
1777 // rather than having 32768 be the zero point, they have the zero point at 32668
1778 // go figure -- anyway, now we get the full resolution out of the device
1779 if (joy_wwhack1.integer != 0.0)
1787 // read error occurred
1788 // turning off the joystick seems too harsh for 1 read error,
1789 // but what should be done?
1800 void IN_JoyMove (usercmd_t *cmd)
1802 float speed, aspeed;
1803 float fAxisValue, fTemp;
1804 int i, mouselook = (in_mlook.state & 1) || freelook.integer;
1806 // complete initialization if first time in
1807 // this is needed as cvars are not available at initialization time
1808 if( joy_advancedinit != true )
1810 Joy_AdvancedUpdate_f();
1811 joy_advancedinit = true;
1814 // verify joystick is available and that the user wants to use it
1815 if (!joy_avail || !in_joystick.integer)
1820 // collect the joystick data, if possible
1821 if (IN_ReadJoystick () != true)
1826 if (in_speed.state & 1)
1827 speed = cl_movespeedkey.value;
1830 // LordHavoc: viewzoom affects sensitivity for sniping
1831 aspeed = speed * host_realframetime * cl.viewzoom;
1833 // loop through the axes
1834 for (i = 0; i < JOY_MAX_AXES; i++)
1836 // get the floating point zero-centered, potentially-inverted data for the current axis
1837 fAxisValue = (float) *pdwRawValue[i];
1838 // move centerpoint to zero
1839 fAxisValue -= 32768.0;
1841 if (joy_wwhack2.integer != 0.0)
1843 if (dwAxisMap[i] == AxisTurn)
1845 // this is a special formula for the Logitech WingMan Warrior
1846 // y=ax^b; where a = 300 and b = 1.3
1847 // also x values are in increments of 800 (so this is factored out)
1848 // then bounds check result to level out excessively high spin rates
1849 fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3);
1850 if (fTemp > 14000.0)
1852 // restore direction information
1853 fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp;
1857 // convert range from -32768..32767 to -1..1
1858 fAxisValue /= 32768.0;
1860 switch (dwAxisMap[i])
1863 if ((joy_advanced.integer == 0) && mouselook)
1865 // user wants forward control to become look control
1866 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1868 // if mouse invert is on, invert the joystick pitch value
1869 // only absolute control support here (joy_advanced is false)
1870 if (m_pitch.value < 0.0)
1872 cl.viewangles[PITCH] -= (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1876 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1882 // no pitch movement
1883 // disable pitch return-to-center unless requested by user
1884 // *** this code can be removed when the lookspring bug is fixed
1885 // *** the bug always has the lookspring feature on
1886 if(lookspring.value == 0.0)
1892 // user wants forward control to be forward control
1893 if (fabs(fAxisValue) > joy_forwardthreshold.value)
1895 cmd->forwardmove += (fAxisValue * joy_forwardsensitivity.value) * speed * cl_forwardspeed.value;
1901 if (fabs(fAxisValue) > joy_sidethreshold.value)
1903 cmd->sidemove += (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1908 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
1910 // user wants turn control to become side control
1911 if (fabs(fAxisValue) > joy_sidethreshold.value)
1913 cmd->sidemove -= (fAxisValue * joy_sidesensitivity.value) * speed * cl_sidespeed.value;
1918 // user wants turn control to be turn control
1919 if (fabs(fAxisValue) > joy_yawthreshold.value)
1921 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1923 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * aspeed * cl_yawspeed.value;
1927 cl.viewangles[YAW] += (fAxisValue * joy_yawsensitivity.value) * speed * 180.0;
1937 if (fabs(fAxisValue) > joy_pitchthreshold.value)
1939 // pitch movement detected and pitch movement desired by user
1940 if(dwControlMap[i] == JOY_ABSOLUTE_AXIS)
1942 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * aspeed * cl_pitchspeed.value;
1946 cl.viewangles[PITCH] += (fAxisValue * joy_pitchsensitivity.value) * speed * 180.0;
1952 // no pitch movement
1953 // disable pitch return-to-center unless requested by user
1954 // *** this code can be removed when the lookspring bug is fixed
1955 // *** the bug always has the lookspring feature on
1956 if(lookspring.integer == 0)
1968 static void IN_Init(void)
1970 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
1972 // joystick variables
1973 Cvar_RegisterVariable (&in_joystick);
1974 Cvar_RegisterVariable (&joy_name);
1975 Cvar_RegisterVariable (&joy_advanced);
1976 Cvar_RegisterVariable (&joy_advaxisx);
1977 Cvar_RegisterVariable (&joy_advaxisy);
1978 Cvar_RegisterVariable (&joy_advaxisz);
1979 Cvar_RegisterVariable (&joy_advaxisr);
1980 Cvar_RegisterVariable (&joy_advaxisu);
1981 Cvar_RegisterVariable (&joy_advaxisv);
1982 Cvar_RegisterVariable (&joy_forwardthreshold);
1983 Cvar_RegisterVariable (&joy_sidethreshold);
1984 Cvar_RegisterVariable (&joy_pitchthreshold);
1985 Cvar_RegisterVariable (&joy_yawthreshold);
1986 Cvar_RegisterVariable (&joy_forwardsensitivity);
1987 Cvar_RegisterVariable (&joy_sidesensitivity);
1988 Cvar_RegisterVariable (&joy_pitchsensitivity);
1989 Cvar_RegisterVariable (&joy_yawsensitivity);
1990 Cvar_RegisterVariable (&joy_wwhack1);
1991 Cvar_RegisterVariable (&joy_wwhack2);
1992 Cmd_AddCommand ("joyadvancedupdate", Joy_AdvancedUpdate_f);
1995 static void IN_Shutdown(void)
1997 IN_DeactivateMouse ();
2001 IDirectInputDevice_Release(g_pMouse);
2005 IDirectInput_Release(g_pdi);