X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=vid_wgl.c;h=faf8ff606a5890e25b9dc9abb5694fb4ed5d0809;hb=658d44cb461c2c60ce86ab48efa918f242c33196;hp=7c415bba527f96d23011ae8bea2eeb48032902ca;hpb=df8727697622029dd7a03047999ffc19b49e44ea;p=xonotic%2Fdarkplaces.git diff --git a/vid_wgl.c b/vid_wgl.c index 7c415bba..faf8ff60 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -19,11 +19,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // gl_vidnt.c -- NT GL vid component +// we don't need a very new dinput +#define DIRECTINPUT_VERSION 0x0300 + #include "quakedef.h" #include +#include #include #include "resource.h" #include +#include extern void S_BlockSound (void); extern void S_UnblockSound (void); @@ -37,6 +42,8 @@ extern HINSTANCE global_hInstance; // Tell startup code that we have a client int cl_available = true; +qboolean vid_supportrefreshrate = true; + static int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *); static int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR); //static int (WINAPI *qwglGetPixelFormat)(HDC); @@ -78,7 +85,6 @@ static qboolean vid_initialized = false; static qboolean vid_wassuspended = false; static qboolean vid_usingmouse = false; static qboolean vid_usingvsync = false; -static qboolean vid_usemouse = false; static qboolean vid_usevsync = false; static HICON hIcon; @@ -102,8 +108,7 @@ static qboolean vid_isfullscreen; //==================================== -static int window_x, window_y, window_width, window_height; -static int window_center_x, window_center_y; +static int window_x, window_y; static void IN_Activate (qboolean grab); @@ -112,8 +117,6 @@ static qboolean dinput; // input code -#include - #define DINPUT_BUFFERSIZE 16 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d) @@ -144,10 +147,10 @@ static int mouse_buttons; static int mouse_oldbuttonstate; static qboolean restore_spi; -static int originalmouseparms[3], newmouseparms[3] = {0, 0, 1}; +static int originalmouseparms[3], newmouseparms[3] = {0, 0, 0}; static unsigned int uiWheelMessage; -static qboolean mouseparmsvalid, mouseactivatetoggle; +static qboolean mouseparmsvalid; static qboolean dinput_acquired; static unsigned int mstate_di; @@ -183,25 +186,25 @@ static PDWORD pdwRawValue[JOY_MAX_AXES]; // each time. this avoids any problems with getting back to a default usage // or when changing from one controller to another. this way at least something // works. -static cvar_t in_joystick = {CVAR_SAVE, "joystick","0"}; -static cvar_t joy_name = {0, "joyname", "joystick"}; -static cvar_t joy_advanced = {0, "joyadvanced", "0"}; -static cvar_t joy_advaxisx = {0, "joyadvaxisx", "0"}; -static cvar_t joy_advaxisy = {0, "joyadvaxisy", "0"}; -static cvar_t joy_advaxisz = {0, "joyadvaxisz", "0"}; -static cvar_t joy_advaxisr = {0, "joyadvaxisr", "0"}; -static cvar_t joy_advaxisu = {0, "joyadvaxisu", "0"}; -static cvar_t joy_advaxisv = {0, "joyadvaxisv", "0"}; -static cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15"}; -static cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15"}; -static cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15"}; -static cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15"}; -static cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0"}; -static cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0"}; -static cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0"}; -static cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0"}; -static cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0"}; -static cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0"}; +static cvar_t in_joystick = {CVAR_SAVE, "joystick","0", "enables joysticks"}; +static cvar_t joy_name = {0, "joyname", "joystick", "name of joystick to use (informational only, used only by joyadvanced 1 mode)"}; +static cvar_t joy_advanced = {0, "joyadvanced", "0", "use more than 2 axis joysticks (configuring this is very technical)"}; +static cvar_t joy_advaxisx = {0, "joyadvaxisx", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisy = {0, "joyadvaxisy", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisz = {0, "joyadvaxisz", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisr = {0, "joyadvaxisr", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisu = {0, "joyadvaxisu", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_advaxisv = {0, "joyadvaxisv", "0", "axis mapping for joyadvanced 1 mode"}; +static cvar_t joy_forwardthreshold = {0, "joyforwardthreshold", "0.15", "minimum joystick movement necessary to move forward"}; +static cvar_t joy_sidethreshold = {0, "joysidethreshold", "0.15", "minimum joystick movement necessary to move sideways (strafing)"}; +static cvar_t joy_pitchthreshold = {0, "joypitchthreshold", "0.15", "minimum joystick movement necessary to look up/down"}; +static cvar_t joy_yawthreshold = {0, "joyyawthreshold", "0.15", "minimum joystick movement necessary to turn left/right"}; +static cvar_t joy_forwardsensitivity = {0, "joyforwardsensitivity", "-1.0", "how fast the joystick moves forward"}; +static cvar_t joy_sidesensitivity = {0, "joysidesensitivity", "-1.0", "how fast the joystick moves sideways (strafing)"}; +static cvar_t joy_pitchsensitivity = {0, "joypitchsensitivity", "1.0", "how fast the joystick looks up/down"}; +static cvar_t joy_yawsensitivity = {0, "joyyawsensitivity", "-1.0", "how fast the joystick turns left/right"}; +static cvar_t joy_wwhack1 = {0, "joywwhack1", "0.0", "special hack for wingman warrior"}; +static cvar_t joy_wwhack2 = {0, "joywwhack2", "0.0", "special hack for wingman warrior"}; static qboolean joy_avail, joy_advancedinit, joy_haspov; static DWORD joy_oldbuttonstate, joy_oldpovstate; @@ -256,46 +259,13 @@ static void Joy_AdvancedUpdate_f (void); static void IN_JoyMove (void); static void IN_StartupMouse (void); -/* -================ -VID_UpdateWindowStatus -================ -*/ -static void VID_UpdateWindowStatus (void) -{ - window_center_x = window_x + window_width / 2; - window_center_y = window_y + window_height / 2; - - if (mouseinitialized && vid_usingmouse && !dinput_acquired) - { - RECT window_rect; - window_rect.left = window_x; - window_rect.top = window_y; - window_rect.right = window_x + window_width; - window_rect.bottom = window_y + window_height; - ClipCursor (&window_rect); - } -} - //==================================== -/* -================= -VID_GetWindowSize -================= -*/ -void VID_GetWindowSize (int *x, int *y, int *width, int *height) +void VID_Finish (qboolean allowmousegrab) { - *x = 0; - *y = 0; - *width = window_width; - *height = window_height; -} - + qboolean vid_usemouse; -void VID_Finish (void) -{ vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable; if (vid_usingvsync != vid_usevsync && gl_videosyncavailable) { @@ -305,28 +275,13 @@ void VID_Finish (void) // handle the mouse state when windowed if that's changed vid_usemouse = false; - if (vid_mouse.integer && !key_consoleactive && !cls.demoplayback) + if (allowmousegrab && vid_mouse.integer && !key_consoleactive && !cls.demoplayback) vid_usemouse = true; if (vid_isfullscreen) vid_usemouse = true; if (!vid_activewindow) vid_usemouse = false; - if (vid_usemouse) - { - if (!vid_usingmouse) - { - vid_usingmouse = true; - IN_Activate (true); - } - } - else - { - if (vid_usingmouse) - { - vid_usingmouse = false; - IN_Activate (false); - } - } + IN_Activate(vid_usemouse); if (r_render.integer && !vid_hidden) { @@ -334,6 +289,8 @@ void VID_Finish (void) qglFinish(); SwapBuffers(baseDC); } + + VID_UpdateGamma(false, 256); } //========================================================================== @@ -341,7 +298,7 @@ void VID_Finish (void) -static qbyte scantokey[128] = +static unsigned char scantokey[128] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 ,27 ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,9 ,//0 @@ -489,7 +446,6 @@ void AppActivate(BOOL fActive, BOOL minimize) if (!fActive) { - vid_usingmouse = false; IN_Activate (false); if (vid_isfullscreen) { @@ -517,6 +473,26 @@ void Sys_SendKeyEvents (void) LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +static keynum_t buttonremap[16] = +{ + K_MOUSE1, + K_MOUSE2, + K_MOUSE3, + K_MOUSE4, + K_MOUSE5, + K_MOUSE6, + K_MOUSE7, + K_MOUSE8, + K_MOUSE9, + K_MOUSE10, + K_MOUSE11, + K_MOUSE12, + K_MOUSE13, + K_MOUSE14, + K_MOUSE15, + K_MOUSE16, +}; + /* main window procedure */ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -525,6 +501,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) char state[256]; char asciichar[4]; int vkey; + int charlength; qboolean down = false; if ( uMsg == uiWheelMessage ) @@ -543,7 +520,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOVE: window_x = (int) LOWORD(lParam); window_y = (int) HIWORD(lParam); - VID_UpdateWindowStatus (); + IN_Activate(false); break; case WM_KEYDOWN: @@ -555,8 +532,12 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) GetKeyboardState (state); // alt/ctrl/shift tend to produce funky ToAscii values, // and if it's not a single character we don't know care about it - if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0) != 1) + charlength = ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0); + if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0) asciichar[0] = 0; + else if( charlength == 2 ) { + asciichar[0] = asciichar[1]; + } Key_Event (vkey, asciichar[0], down); break; @@ -610,9 +591,9 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { // perform button actions int i; - for (i=0 ; i= 32) @@ -810,10 +791,11 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) vid_isfullscreen = false; if (fullscreen) { - gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; + gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; gdevmode.dmBitsPerPel = bpp; gdevmode.dmPelsWidth = width; gdevmode.dmPelsHeight = height; + gdevmode.dmDisplayFrequency = refreshrate; gdevmode.dmSize = sizeof (gdevmode); if (ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { @@ -871,8 +853,6 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) // x and y may be changed by WM_MOVE messages window_x = CenterX; window_y = CenterY; - window_width = width; - window_height = height; rect.left += CenterX; rect.right += CenterX; rect.top += CenterY; @@ -894,8 +874,6 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) ShowWindow (mainwindow, SW_SHOWDEFAULT); UpdateWindow (mainwindow); - VID_UpdateWindowStatus (); - // now we try to make sure we get the focus on the mode switch, because // sometimes in some systems we don't. We grab the foreground, then // finish setting up, pump all our messages, and sleep for a little while @@ -956,14 +934,14 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) return false; } - qglGetString = GL_GetProcAddress("glGetString"); - qwglGetExtensionsStringARB = GL_GetProcAddress("wglGetExtensionsStringARB"); - if (qglGetString == NULL) + if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL) { VID_Shutdown(); Con_Print("glGetString not found\n"); return false; } + if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL) + Con_Print("wglGetExtensionsStringARB not found\n"); gl_renderer = qglGetString(GL_RENDERER); gl_vendor = qglGetString(GL_VENDOR); gl_version = qglGetString(GL_VERSION); @@ -1001,6 +979,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp) IN_StartupMouse (); IN_StartupJoystick (); + if (gl_videosyncavailable) + { + vid_usevsync = vid_vsync.integer; + vid_usingvsync = vid_vsync.integer; + qwglSwapIntervalEXT (vid_usevsync); + } + return true; } @@ -1031,12 +1016,6 @@ void VID_Shutdown (void) vid_isfullscreen = false; } - -/* -=========== -IN_Activate -=========== -*/ static void IN_Activate (qboolean grab) { if (!mouseinitialized) @@ -1044,45 +1023,51 @@ static void IN_Activate (qboolean grab) if (grab) { - mouseactivatetoggle = true; - if (dinput && g_pMouse) - { - IDirectInputDevice_Acquire(g_pMouse); - dinput_acquired = true; - } - else + if (!vid_usingmouse) { - RECT window_rect; - window_rect.left = window_x; - window_rect.top = window_y; - window_rect.right = window_x + window_width; - window_rect.bottom = window_y + window_height; - if (mouseparmsvalid) - restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0); - SetCursorPos (window_center_x, window_center_y); - SetCapture (mainwindow); - ClipCursor (&window_rect); + vid_usingmouse = true; + cl_ignoremousemove = true; + if (dinput && g_pMouse) + { + IDirectInputDevice_Acquire(g_pMouse); + dinput_acquired = true; + } + else + { + RECT window_rect; + window_rect.left = window_x; + window_rect.top = window_y; + window_rect.right = window_x + vid.width; + window_rect.bottom = window_y + vid.height; + if (mouseparmsvalid) + restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0); + SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2)); + SetCapture (mainwindow); + ClipCursor (&window_rect); + } + ShowCursor (false); } - vid_usingmouse = true; - ShowCursor (false); } else { - mouseactivatetoggle = false; - if (dinput_acquired) - { - IDirectInputDevice_Unacquire(g_pMouse); - dinput_acquired = false; - } - else + if (vid_usingmouse) { - if (restore_spi) - SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0); - ClipCursor (NULL); - ReleaseCapture (); + vid_usingmouse = false; + cl_ignoremousemove = true; + if (dinput_acquired) + { + IDirectInputDevice_Unacquire(g_pMouse); + dinput_acquired = false; + } + else + { + if (restore_spi) + SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0); + ClipCursor (NULL); + ReleaseCapture (); + } + ShowCursor (true); } - vid_usingmouse = false; - ShowCursor (true); } } @@ -1224,11 +1209,6 @@ static void IN_StartupMouse (void) } mouse_buttons = 10; - -// if a fullscreen video mode was set before the mouse was initialized, -// set the mouse state appropriately - if (mouseactivatetoggle) - IN_Activate (true); } @@ -1310,9 +1290,9 @@ static void IN_MouseMove (void) } // perform button actions - for (i=0 ; i