diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index d19fed0f..fbcc8a0a 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -214,19 +214,10 @@ if (WIN32) add_definitions(-D_WIN32_WINNT=0x0501) set(sys_libs ${sys_libs} - dinput8 - ksuser - dxguid winmm iphlpapi wsock32 ) - - if (MINGW) - list(APPEND sys_libs dxerr8) - else() - list(APPEND sys_libs dxerr) - endif() endif() message(STATUS "Building ${CMAKE_BUILD_TYPE} for ${os}.${cpu}") @@ -655,17 +646,15 @@ elseif (WIN32) set(src_sys_base sys/cpu.cpp sys/threads.cpp + sys/glimp.cpp + sys/events.cpp sys/sys_local.cpp sys/win32/win_cpu.cpp -# sys/win32/win_gamma.cpp - sys/win32/win_glimp.cpp sys/win32/win_input.cpp sys/win32/win_main.cpp sys/win32/win_net.cpp sys/win32/win_shared.cpp sys/win32/win_syscon.cpp - sys/win32/win_taskkeyhook.cpp - sys/win32/win_wndproc.cpp ) set(src_sys_core diff --git a/neo/idlib/precompiled.h b/neo/idlib/precompiled.h index 6dde9926..400917a6 100644 --- a/neo/idlib/precompiled.h +++ b/neo/idlib/precompiled.h @@ -44,9 +44,6 @@ If you have questions concerning this license or the applicable additional terms #include #include -#define DIRECTINPUT_VERSION 0x0800 // was 0x0700 with the old mssdk -#include - #pragma warning(disable : 4100) // unreferenced formal parameter #pragma warning(disable : 4244) // conversion to smaller type, possible loss of data #pragma warning(disable : 4714) // function marked as __forceinline not inlined diff --git a/neo/renderer/draw_exp.cpp b/neo/renderer/draw_exp.cpp index 3f71eb5a..812aab72 100644 --- a/neo/renderer/draw_exp.cpp +++ b/neo/renderer/draw_exp.cpp @@ -55,6 +55,9 @@ polygon offset factor causes occasional texture holes from highly angled texture */ +// WGL_ARB_pixel_format +static PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; + // WGL_ARB_pixel_format static PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB; static PFNWGLGETPIXELFORMATATTRIBFVARBPROC wglGetPixelFormatAttribfvARB; @@ -523,6 +526,9 @@ void R_Exp_Allocate( void ) { initialized = true; + // WGL_ARB_pixel_format + wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)GLimp_ExtensionPointer("wglChoosePixelFormatARB"); + // WGL_ARB_pixel_format wglGetPixelFormatAttribivARB = (PFNWGLGETPIXELFORMATATTRIBIVARBPROC)GLimp_ExtensionPointer("wglGetPixelFormatAttribivARB"); wglGetPixelFormatAttribfvARB = (PFNWGLGETPIXELFORMATATTRIBFVARBPROC)GLimp_ExtensionPointer("wglGetPixelFormatAttribfvARB"); diff --git a/neo/sys/events.cpp b/neo/sys/events.cpp index 902807fd..babd13eb 100644 --- a/neo/sys/events.cpp +++ b/neo/sys/events.cpp @@ -307,8 +307,11 @@ void Sys_ShutdownInput() { Sys_InitScanTable =========== */ +// Windows has its own version due to the tools +#ifndef _WIN32 void Sys_InitScanTable() { } +#endif /* =============== diff --git a/neo/sys/glimp.cpp b/neo/sys/glimp.cpp index d4ccc553..f5370dec 100644 --- a/neo/sys/glimp.cpp +++ b/neo/sys/glimp.cpp @@ -34,6 +34,10 @@ If you have questions concerning this license or the applicable additional terms #include "renderer/tr_local.h" +#ifdef _WIN32 +#include "sys/win32/win_local.h" +#endif + idCVar sys_videoRam("sys_videoRam", "0", CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_INTEGER, "Texture memory on the video card (in megabytes) - 0: autodetect", 0, 512); /* @@ -162,6 +166,25 @@ bool GLimp_Init(glimpParms_t parms) { glConfig.wgl_extensions_string = ""; +#ifdef _WIN32 + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)GLimp_ExtensionPointer("wglGetExtensionsStringARB"); + + if (wglGetExtensionsStringARB) + glConfig.wgl_extensions_string = (const char *)wglGetExtensionsStringARB(wglGetCurrentDC()); + + // the editors still rely on these vars + SDL_SysWMinfo info; + SDL_VERSION(&info.version); + + if (SDL_GetWMInfo(&info)) { + win32.hDC = wglGetCurrentDC(); + win32.hGLRC = info.hglrc; + } + + win32.pixelformat = GetPixelFormat(win32.hDC); + DescribePixelFormat(win32.hDC, win32.pixelformat, sizeof(win32.pfd), &win32.pfd); +#endif + return true; } diff --git a/neo/sys/win32/win_gamma.cpp b/neo/sys/win32/win_gamma.cpp deleted file mode 100644 index 7ab7e873..00000000 --- a/neo/sys/win32/win_gamma.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* -=========================================================================== - -Doom 3 GPL Source Code -Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. - -This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). - -Doom 3 Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 Source Code. If not, see . - -In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ -/* -** WIN_GAMMA.C -*/ - -#include - -#include "renderer/tr_local.h" - -#include "sys/win32/win_local.h" - -static unsigned short s_oldHardwareGamma[3][256]; - -/* -** WG_GetOldGammaRamp -** -*/ -void WG_GetOldGammaRamp( void ) -{ - HDC hDC; - - hDC = GetDC( GetDesktopWindow() ); - GetDeviceGammaRamp( hDC, s_oldHardwareGamma ); - ReleaseDC( GetDesktopWindow(), hDC ); - - -/* -** GLimp_SetGamma -** -*/ -void GLimp_SetGamma( unsigned char red[256], unsigned char green[256], unsigned char blue[256] ) -{ - unsigned short table[3][256]; - int i; - - if ( !glw_state.hDC ) - { - return; - } - - for ( i = 0; i < 256; i++ ) - { - table[0][i] = ( ( ( unsigned short ) red[i] ) << 8 ) | red[i]; - table[1][i] = ( ( ( unsigned short ) green[i] ) << 8 ) | green[i]; - table[2][i] = ( ( ( unsigned short ) blue[i] ) << 8 ) | blue[i]; - } - - if ( !SetDeviceGammaRamp( glw_state.hDC, table ) ) { - common->Printf( "WARNING: SetDeviceGammaRamp failed.\n" ); - } -} - -/* -** WG_RestoreGamma -*/ -void WG_RestoreGamma( void ) -{ - HDC hDC; - - // if we never read in a reasonable looking - // table, don't write it out - if ( s_oldHardwareGamma[0][255] == 0 ) { - return; - } - - hDC = GetDC( GetDesktopWindow() ); - SetDeviceGammaRamp( hDC, s_oldHardwareGamma ); - ReleaseDC( GetDesktopWindow(), hDC ); -} - diff --git a/neo/sys/win32/win_glimp.cpp b/neo/sys/win32/win_glimp.cpp deleted file mode 100644 index 62ce5fcb..00000000 --- a/neo/sys/win32/win_glimp.cpp +++ /dev/null @@ -1,1005 +0,0 @@ -/* -=========================================================================== - -Doom 3 GPL Source Code -Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. - -This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). - -Doom 3 Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 Source Code. If not, see . - -In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ -/* -** WIN_GLIMP.C -** -** This file contains ALL Win32 specific stuff having to do with the -** OpenGL refresh. When a port is being made the following functions -** must be implemented by the port: -** -** GLimp_SwapBuffers -** GLimp_Init -** GLimp_Shutdown -** GLimp_SetGamma -** -** Note that the GLW_xxx functions are Windows specific GL-subsystem -** related functions that are relevant ONLY to win_glimp.c -*/ - -#include "sys/platform.h" -#include "framework/Licensee.h" -#include "sys/win32/rc/AFEditor_resource.h" -#include "sys/win32/rc/doom_resource.h" -#include "renderer/tr_local.h" - -#include "sys/win32/win_local.h" - -// WGL_ARB_extensions_string -static PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB; - -// WGL_EXT_swap_interval -PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; - -// WGL_ARB_pixel_format -PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; - -/* ARB_pixel_format */ -#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000 -#define WGL_DRAW_TO_WINDOW_ARB 0x2001 -#define WGL_DRAW_TO_BITMAP_ARB 0x2002 -#define WGL_ACCELERATION_ARB 0x2003 -#define WGL_NEED_PALETTE_ARB 0x2004 -#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005 -#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006 -#define WGL_SWAP_METHOD_ARB 0x2007 -#define WGL_NUMBER_OVERLAYS_ARB 0x2008 -#define WGL_NUMBER_UNDERLAYS_ARB 0x2009 -#define WGL_TRANSPARENT_ARB 0x200A -#define WGL_SHARE_DEPTH_ARB 0x200C -#define WGL_SHARE_STENCIL_ARB 0x200D -#define WGL_SHARE_ACCUM_ARB 0x200E -#define WGL_SUPPORT_GDI_ARB 0x200F -#define WGL_SUPPORT_OPENGL_ARB 0x2010 -#define WGL_DOUBLE_BUFFER_ARB 0x2011 -#define WGL_STEREO_ARB 0x2012 -#define WGL_PIXEL_TYPE_ARB 0x2013 -#define WGL_COLOR_BITS_ARB 0x2014 -#define WGL_RED_BITS_ARB 0x2015 -#define WGL_RED_SHIFT_ARB 0x2016 -#define WGL_GREEN_BITS_ARB 0x2017 -#define WGL_GREEN_SHIFT_ARB 0x2018 -#define WGL_BLUE_BITS_ARB 0x2019 -#define WGL_BLUE_SHIFT_ARB 0x201A -#define WGL_ALPHA_BITS_ARB 0x201B -#define WGL_ALPHA_SHIFT_ARB 0x201C -#define WGL_ACCUM_BITS_ARB 0x201D -#define WGL_ACCUM_RED_BITS_ARB 0x201E -#define WGL_ACCUM_GREEN_BITS_ARB 0x201F -#define WGL_ACCUM_BLUE_BITS_ARB 0x2020 -#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021 -#define WGL_DEPTH_BITS_ARB 0x2022 -#define WGL_STENCIL_BITS_ARB 0x2023 -#define WGL_AUX_BUFFERS_ARB 0x2024 -#define WGL_NO_ACCELERATION_ARB 0x2025 -#define WGL_GENERIC_ACCELERATION_ARB 0x2026 -#define WGL_FULL_ACCELERATION_ARB 0x2027 -#define WGL_SWAP_EXCHANGE_ARB 0x2028 -#define WGL_SWAP_COPY_ARB 0x2029 -#define WGL_SWAP_UNDEFINED_ARB 0x202A -#define WGL_TYPE_RGBA_ARB 0x202B -#define WGL_TYPE_COLORINDEX_ARB 0x202C -#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037 -#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038 -#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039 -#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A -#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B - -/* ARB_multisample */ -#define WGL_SAMPLE_BUFFERS_ARB 0x2041 -#define WGL_SAMPLES_ARB 0x2042 - -/* -======================== -GLimp_GetOldGammaRamp -======================== -*/ -static void GLimp_SaveGamma( void ) { - HDC hDC; - BOOL success; - - hDC = GetDC( GetDesktopWindow() ); - success = GetDeviceGammaRamp( hDC, win32.oldHardwareGamma ); - common->DPrintf( "...getting default gamma ramp: %s\n", success ? "success" : "failed" ); - ReleaseDC( GetDesktopWindow(), hDC ); -} - -/* -======================== -GLimp_RestoreGamma -======================== -*/ -static void GLimp_RestoreGamma( void ) { - HDC hDC; - BOOL success; - - // if we never read in a reasonable looking - // table, don't write it out - if ( win32.oldHardwareGamma[0][255] == 0 ) { - return; - } - - hDC = GetDC( GetDesktopWindow() ); - success = SetDeviceGammaRamp( hDC, win32.oldHardwareGamma ); - common->DPrintf ( "...restoring hardware gamma: %s\n", success ? "success" : "failed" ); - ReleaseDC( GetDesktopWindow(), hDC ); -} - - -/* -======================== -GLimp_SetGamma - -The renderer calls this when the user adjusts r_gamma or r_brightness -======================== -*/ -void GLimp_SetGamma( unsigned short red[256], unsigned short green[256], unsigned short blue[256] ) { - unsigned short table[3][256]; - int i; - - if ( !win32.hDC ) { - return; - } - - for ( i = 0; i < 256; i++ ) { - table[0][i] = red[i]; - table[1][i] = green[i]; - table[2][i] = blue[i]; - } - - if ( !SetDeviceGammaRamp( win32.hDC, table ) ) { - common->Printf( "WARNING: SetDeviceGammaRamp failed.\n" ); - } -} - -/* -============================================================================= - -WglExtension Grabbing - -This is gross -- creating a window just to get a context to get the wgl extensions - -============================================================================= -*/ - -/* -==================== -FakeWndProc - -Only used to get wglExtensions -==================== -*/ -LONG WINAPI FakeWndProc ( - HWND hWnd, - UINT uMsg, - WPARAM wParam, - LPARAM lParam) { - - if ( uMsg == WM_DESTROY ) { - PostQuitMessage(0); - } - - if ( uMsg != WM_CREATE ) { - return DefWindowProc(hWnd, uMsg, wParam, lParam); - } - - const static PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), - 1, - PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, - PFD_TYPE_RGBA, - 24, - 0, 0, 0, 0, 0, 0, - 8, 0, - 0, 0, 0, 0, - 24, 8, - 0, - PFD_MAIN_PLANE, - 0, - 0, - 0, - 0, - }; - int pixelFormat; - HDC hDC; - HGLRC hGLRC; - - hDC = GetDC(hWnd); - - // Set up OpenGL - pixelFormat = ChoosePixelFormat(hDC, &pfd); - SetPixelFormat(hDC, pixelFormat, &pfd); - hGLRC = qwglCreateContext(hDC); - qwglMakeCurrent(hDC, hGLRC); - - // free things - wglMakeCurrent(NULL, NULL); - wglDeleteContext(hGLRC); - ReleaseDC(hWnd, hDC); - - return DefWindowProc(hWnd, uMsg, wParam, lParam); -} - - -/* -================== -GLW_GetWGLExtensionsWithFakeWindow -================== -*/ -void GLW_CheckWGLExtensions( HDC hDC ) { - wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) - GLimp_ExtensionPointer("wglGetExtensionsStringARB"); - if ( wglGetExtensionsStringARB ) { - glConfig.wgl_extensions_string = (const char *) wglGetExtensionsStringARB(hDC); - } else { - glConfig.wgl_extensions_string = ""; - } - - // WGL_EXT_swap_control - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC) GLimp_ExtensionPointer( "wglSwapIntervalEXT" ); - r_swapInterval.SetModified(); // force a set next frame - - // WGL_ARB_pixel_format - wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)GLimp_ExtensionPointer("wglChoosePixelFormatARB"); -} - -/* -================== -GLW_GetWGLExtensionsWithFakeWindow -================== -*/ -static void GLW_GetWGLExtensionsWithFakeWindow( void ) { - HWND hWnd; - MSG msg; - - // Create a window for the sole purpose of getting - // a valid context to get the wglextensions - hWnd = CreateWindow(WIN32_FAKE_WINDOW_CLASS_NAME, GAME_NAME, - WS_OVERLAPPEDWINDOW, - 40, 40, - 640, - 480, - NULL, NULL, win32.hInstance, NULL ); - if ( !hWnd ) { - common->FatalError( "GLW_GetWGLExtensionsWithFakeWindow: Couldn't create fake window" ); - } - - HDC hDC = GetDC( hWnd ); - HGLRC gRC = wglCreateContext( hDC ); - wglMakeCurrent( hDC, gRC ); - GLW_CheckWGLExtensions( hDC ); - wglDeleteContext( gRC ); - ReleaseDC( hWnd, hDC ); - - DestroyWindow( hWnd ); - while ( GetMessage( &msg, NULL, 0, 0 ) ) { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } -} - -//============================================================================= - -/* -==================== -GLW_InitDriver - -Set the pixelformat for the window before it is -shown, and create the rendering context -==================== -*/ -static bool GLW_InitDriver( glimpParms_t parms ) { - PIXELFORMATDESCRIPTOR src = - { - sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd - 1, // version number - PFD_DRAW_TO_WINDOW | // support window - PFD_SUPPORT_OPENGL | // support OpenGL - PFD_DOUBLEBUFFER, // double buffered - PFD_TYPE_RGBA, // RGBA type - 32, // 32-bit color depth - 0, 0, 0, 0, 0, 0, // color bits ignored - 8, // 8 bit destination alpha - 0, // shift bit ignored - 0, // no accumulation buffer - 0, 0, 0, 0, // accum bits ignored - 24, // 24-bit z-buffer - 8, // 8-bit stencil buffer - 0, // no auxiliary buffer - PFD_MAIN_PLANE, // main layer - 0, // reserved - 0, 0, 0 // layer masks ignored - }; - - common->Printf( "Initializing OpenGL driver\n" ); - - // - // get a DC for our window if we don't already have one allocated - // - if ( win32.hDC == NULL ) { - common->Printf( "...getting DC: " ); - - if ( ( win32.hDC = GetDC( win32.hWnd ) ) == NULL ) { - common->Printf( "^3failed^0\n" ); - return false; - } - common->Printf( "succeeded\n" ); - } - - // the multisample path uses the wgl - if ( wglChoosePixelFormatARB && parms.multiSamples > 1 ) { - int iAttributes[20]; - FLOAT fAttributes[] = {0, 0}; - UINT numFormats; - - // FIXME: specify all the other stuff - iAttributes[0] = WGL_SAMPLE_BUFFERS_ARB; - iAttributes[1] = 1; - iAttributes[2] = WGL_SAMPLES_ARB; - iAttributes[3] = parms.multiSamples; - iAttributes[4] = WGL_DOUBLE_BUFFER_ARB; - iAttributes[5] = TRUE; - iAttributes[6] = WGL_STENCIL_BITS_ARB; - iAttributes[7] = 8; - iAttributes[8] = WGL_DEPTH_BITS_ARB; - iAttributes[9] = 24; - iAttributes[10] = WGL_RED_BITS_ARB; - iAttributes[11] = 8; - iAttributes[12] = WGL_BLUE_BITS_ARB; - iAttributes[13] = 8; - iAttributes[14] = WGL_GREEN_BITS_ARB; - iAttributes[15] = 8; - iAttributes[16] = WGL_ALPHA_BITS_ARB; - iAttributes[17] = 8; - iAttributes[18] = 0; - iAttributes[19] = 0; - - wglChoosePixelFormatARB( win32.hDC, iAttributes, fAttributes, 1, &win32.pixelformat, &numFormats ); - } else { - // this is the "classic" choose pixel format path - - // eventually we may need to have more fallbacks, but for - // now, ask for everything - if ( parms.stereo ) { - common->Printf( "...attempting to use stereo\n" ); - src.dwFlags |= PFD_STEREO; - } - - // - // choose, set, and describe our desired pixel format. If we're - // using a minidriver then we need to bypass the GDI functions, - // otherwise use the GDI functions. - // - if ( ( win32.pixelformat = ChoosePixelFormat( win32.hDC, &src ) ) == 0 ) { - common->Printf( "...^3GLW_ChoosePFD failed^0\n"); - return false; - } - common->Printf( "...PIXELFORMAT %d selected\n", win32.pixelformat ); - } - - // get the full info - DescribePixelFormat( win32.hDC, win32.pixelformat, sizeof( win32.pfd ), &win32.pfd ); - glConfig.colorBits = win32.pfd.cColorBits; - glConfig.depthBits = win32.pfd.cDepthBits; - glConfig.stencilBits = win32.pfd.cStencilBits; - - // XP seems to set this incorrectly - if ( !glConfig.stencilBits ) { - glConfig.stencilBits = 8; - } - - // the same SetPixelFormat is used either way - if ( SetPixelFormat( win32.hDC, win32.pixelformat, &win32.pfd ) == FALSE ) { - common->Printf( "...^3SetPixelFormat failed^0\n", win32.hDC ); - return false; - } - - // - // startup the OpenGL subsystem by creating a context and making it current - // - common->Printf( "...creating GL context: " ); - if ( ( win32.hGLRC = qwglCreateContext( win32.hDC ) ) == 0 ) { - common->Printf( "^3failed^0\n" ); - return false; - } - common->Printf( "succeeded\n" ); - - common->Printf( "...making context current: " ); - if ( !qwglMakeCurrent( win32.hDC, win32.hGLRC ) ) { - qwglDeleteContext( win32.hGLRC ); - win32.hGLRC = NULL; - common->Printf( "^3failed^0\n" ); - return false; - } - common->Printf( "succeeded\n" ); - - return true; -} - -/* -==================== -GLW_CreateWindowClasses -==================== -*/ -static void GLW_CreateWindowClasses( void ) { - WNDCLASS wc; - - // - // register the window class if necessary - // - if ( win32.windowClassRegistered ) { - return; - } - - memset( &wc, 0, sizeof( wc ) ); - - wc.style = 0; - wc.lpfnWndProc = (WNDPROC) MainWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = win32.hInstance; - wc.hIcon = LoadIcon( win32.hInstance, MAKEINTRESOURCE(IDI_ICON1)); - wc.hCursor = LoadCursor (NULL,IDC_ARROW); - wc.hbrBackground = (struct HBRUSH__ *)COLOR_GRAYTEXT; - wc.lpszMenuName = 0; - wc.lpszClassName = WIN32_WINDOW_CLASS_NAME; - - if ( !RegisterClass( &wc ) ) { - common->FatalError( "GLW_CreateWindow: could not register window class" ); - } - common->Printf( "...registered window class\n" ); - - // now register the fake window class that is only used - // to get wgl extensions - wc.style = 0; - wc.lpfnWndProc = (WNDPROC) FakeWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = win32.hInstance; - wc.hIcon = LoadIcon( win32.hInstance, MAKEINTRESOURCE(IDI_ICON1)); - wc.hCursor = LoadCursor (NULL,IDC_ARROW); - wc.hbrBackground = (struct HBRUSH__ *)COLOR_GRAYTEXT; - wc.lpszMenuName = 0; - wc.lpszClassName = WIN32_FAKE_WINDOW_CLASS_NAME; - - if ( !RegisterClass( &wc ) ) { - common->FatalError( "GLW_CreateWindow: could not register window class" ); - } - common->Printf( "...registered fake window class\n" ); - - win32.windowClassRegistered = true; -} - -/* -======================= -GLW_CreateWindow - -Responsible for creating the Win32 window. -If cdsFullscreen is true, it won't have a border -======================= -*/ -static bool GLW_CreateWindow( glimpParms_t parms ) { - int stylebits; - int x, y, w, h; - int exstyle; - - // - // compute width and height - // - if ( parms.fullScreen ) { - exstyle = WS_EX_TOPMOST; - stylebits = WS_POPUP|WS_VISIBLE|WS_SYSMENU; - - x = 0; - y = 0; - w = parms.width; - h = parms.height; - } else { - RECT r; - - // adjust width and height for window border - r.bottom = parms.height; - r.left = 0; - r.top = 0; - r.right = parms.width; - - exstyle = 0; - stylebits = WINDOW_STYLE|WS_SYSMENU; - AdjustWindowRect (&r, stylebits, FALSE); - - w = r.right - r.left; - h = r.bottom - r.top; - - x = win32.win_xpos.GetInteger(); - y = win32.win_ypos.GetInteger(); - - // adjust window coordinates if necessary - // so that the window is completely on screen - if ( x + w > win32.desktopWidth ) { - x = ( win32.desktopWidth - w ); - } - if ( y + h > win32.desktopHeight ) { - y = ( win32.desktopHeight - h ); - } - if ( x < 0 ) { - x = 0; - } - if ( y < 0 ) { - y = 0; - } - } - - win32.hWnd = CreateWindowEx ( - exstyle, - WIN32_WINDOW_CLASS_NAME, - GAME_NAME, - stylebits, - x, y, w, h, - NULL, - NULL, - win32.hInstance, - NULL); - - if ( !win32.hWnd ) { - common->Printf( "^3GLW_CreateWindow() - Couldn't create window^0\n" ); - return false; - } - - ::SetTimer( win32.hWnd, 0, 100, NULL ); - - ShowWindow( win32.hWnd, SW_SHOW ); - UpdateWindow( win32.hWnd ); - common->Printf( "...created window @ %d,%d (%dx%d)\n", x, y, w, h ); - - if ( !GLW_InitDriver( parms ) ) { - ShowWindow( win32.hWnd, SW_HIDE ); - DestroyWindow( win32.hWnd ); - win32.hWnd = NULL; - return false; - } - - SetForegroundWindow( win32.hWnd ); - SetFocus( win32.hWnd ); - - glConfig.isFullscreen = parms.fullScreen; - - return true; -} - - - -static void PrintCDSError( int value ) { - switch ( value ) { - case DISP_CHANGE_RESTART: - common->Printf( "restart required\n" ); - break; - case DISP_CHANGE_BADPARAM: - common->Printf( "bad param\n" ); - break; - case DISP_CHANGE_BADFLAGS: - common->Printf( "bad flags\n" ); - break; - case DISP_CHANGE_FAILED: - common->Printf( "DISP_CHANGE_FAILED\n" ); - break; - case DISP_CHANGE_BADMODE: - common->Printf( "bad mode\n" ); - break; - case DISP_CHANGE_NOTUPDATED: - common->Printf( "not updated\n" ); - break; - default: - common->Printf( "unknown error %d\n", value ); - break; - } -} - - -/* -=================== -GLW_SetFullScreen -=================== -*/ -static bool GLW_SetFullScreen( glimpParms_t parms ) { -#if 0 - // for some reason, bounds checker claims that windows is - // writing past the bounds of dm in the get display frequency call - union { - DEVMODE dm; - byte filler[1024]; - } hack; -#endif - DEVMODE dm; - int cdsRet; - - DEVMODE devmode; - int modeNum; - bool matched; - - // first make sure the user is not trying to select a mode that his card/monitor can't handle - matched = false; - for ( modeNum = 0 ; ; modeNum++ ) { - if ( !EnumDisplaySettings( NULL, modeNum, &devmode ) ) { - if ( matched ) { - // we got a resolution match, but not a frequency match - // so disable the frequency requirement - common->Printf( "...^3%dhz is unsupported at %dx%d^0\n", parms.displayHz, parms.width, parms.height ); - parms.displayHz = 0; - break; - } - common->Printf( "...^3%dx%d is unsupported in 32 bit^0\n", parms.width, parms.height ); - return false; - } - if ( (int)devmode.dmPelsWidth >= parms.width - && (int)devmode.dmPelsHeight >= parms.height - && devmode.dmBitsPerPel == 32 ) { - - matched = true; - - if ( parms.displayHz == 0 || devmode.dmDisplayFrequency == parms.displayHz ) { - break; - } - } - } - - memset( &dm, 0, sizeof( dm ) ); - dm.dmSize = sizeof( dm ); - - dm.dmPelsWidth = parms.width; - dm.dmPelsHeight = parms.height; - dm.dmBitsPerPel = 32; - dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - - if ( parms.displayHz != 0 ) { - dm.dmDisplayFrequency = parms.displayHz; - dm.dmFields |= DM_DISPLAYFREQUENCY; - } - - common->Printf( "...calling CDS: " ); - - // try setting the exact mode requested, because some drivers don't report - // the low res modes in EnumDisplaySettings, but still work - if ( ( cdsRet = ChangeDisplaySettings( &dm, CDS_FULLSCREEN ) ) == DISP_CHANGE_SUCCESSFUL ) { - common->Printf( "ok\n" ); - win32.cdsFullscreen = true; - return true; - } - - // - // the exact mode failed, so scan EnumDisplaySettings for the next largest mode - // - common->Printf( "^3failed^0, " ); - - PrintCDSError( cdsRet ); - - common->Printf( "...trying next higher resolution:" ); - - // we could do a better matching job here... - for ( modeNum = 0 ; ; modeNum++ ) { - if ( !EnumDisplaySettings( NULL, modeNum, &devmode ) ) { - break; - } - if ( (int)devmode.dmPelsWidth >= parms.width - && (int)devmode.dmPelsHeight >= parms.height - && devmode.dmBitsPerPel == 32 ) { - - if ( ( cdsRet = ChangeDisplaySettings( &devmode, CDS_FULLSCREEN ) ) == DISP_CHANGE_SUCCESSFUL ) { - common->Printf( "ok\n" ); - win32.cdsFullscreen = true; - - return true; - } - break; - } - } - - common->Printf( "\n...^3no high res mode found^0\n" ); - return false; -} - -/* -=================== -GLimp_Init - -This is the platform specific OpenGL initialization function. It -is responsible for loading OpenGL, initializing it, -creating a window of the appropriate size, doing -fullscreen manipulations, etc. Its overall responsibility is -to make sure that a functional OpenGL subsystem is operating -when it returns to the ref. - -If there is any failure, the renderer will revert back to safe -parameters and try again. -=================== -*/ -bool GLimp_Init( glimpParms_t parms ) { - HDC hDC; - - common->Printf( "Initializing OpenGL subsystem\n" ); - - // check our desktop attributes - hDC = GetDC( GetDesktopWindow() ); - win32.desktopBitsPixel = GetDeviceCaps( hDC, BITSPIXEL ); - win32.desktopWidth = GetDeviceCaps( hDC, HORZRES ); - win32.desktopHeight = GetDeviceCaps( hDC, VERTRES ); - ReleaseDC( GetDesktopWindow(), hDC ); - - // we can't run in a window unless it is 32 bpp - if ( win32.desktopBitsPixel < 32 && !parms.fullScreen ) { - common->Printf("^3Windowed mode requires 32 bit desktop depth^0\n"); - return false; - } - - // save the hardware gamma so it can be - // restored on exit - GLimp_SaveGamma(); - - // create our window classes if we haven't already - GLW_CreateWindowClasses(); - - // this will load the dll and set all our qgl* function pointers, - // but doesn't create a window - - // getting the wgl extensions involves creating a fake window to get a context, - // which is pretty disgusting, and seems to mess with the AGP VAR allocation - GLW_GetWGLExtensionsWithFakeWindow(); - - // try to change to fullscreen - if ( parms.fullScreen ) { - if ( !GLW_SetFullScreen( parms ) ) { - GLimp_Shutdown(); - return false; - } - } - - // try to create a window with the correct pixel format - // and init the renderer context - if ( !GLW_CreateWindow( parms ) ) { - GLimp_Shutdown(); - return false; - } - - // wglSwapinterval, etc - GLW_CheckWGLExtensions( win32.hDC ); - - return true; -} - - -/* -=================== -GLimp_SetScreenParms - -Sets up the screen based on passed parms.. -=================== -*/ -bool GLimp_SetScreenParms( glimpParms_t parms ) { - int exstyle; - int stylebits; - int x, y, w, h; - DEVMODE dm; - - memset( &dm, 0, sizeof( dm ) ); - dm.dmSize = sizeof( dm ); - dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; - if ( parms.displayHz != 0 ) { - dm.dmDisplayFrequency = parms.displayHz; - dm.dmFields |= DM_DISPLAYFREQUENCY; - } - - win32.cdsFullscreen = parms.fullScreen; - glConfig.isFullscreen = parms.fullScreen; - - if ( parms.fullScreen ) { - exstyle = WS_EX_TOPMOST; - stylebits = WS_POPUP|WS_VISIBLE|WS_SYSMENU; - SetWindowLong( win32.hWnd, GWL_STYLE, stylebits ); - SetWindowLong( win32.hWnd, GWL_EXSTYLE, exstyle ); - dm.dmPelsWidth = parms.width; - dm.dmPelsHeight = parms.height; - dm.dmBitsPerPel = 32; - x = y = w = h = 0; - } else { - RECT r; - - // adjust width and height for window border - r.bottom = parms.height; - r.left = 0; - r.top = 0; - r.right = parms.width; - - w = r.right - r.left; - h = r.bottom - r.top; - - x = win32.win_xpos.GetInteger(); - y = win32.win_ypos.GetInteger(); - - // adjust window coordinates if necessary - // so that the window is completely on screen - if ( x + w > win32.desktopWidth ) { - x = ( win32.desktopWidth - w ); - } - if ( y + h > win32.desktopHeight ) { - y = ( win32.desktopHeight - h ); - } - if ( x < 0 ) { - x = 0; - } - if ( y < 0 ) { - y = 0; - } - dm.dmPelsWidth = win32.desktopWidth; - dm.dmPelsHeight = win32.desktopHeight; - dm.dmBitsPerPel = win32.desktopBitsPixel; - exstyle = 0; - stylebits = WINDOW_STYLE|WS_SYSMENU; - AdjustWindowRect (&r, stylebits, FALSE); - SetWindowLong( win32.hWnd, GWL_STYLE, stylebits ); - SetWindowLong( win32.hWnd, GWL_EXSTYLE, exstyle ); - common->Printf( "%i %i %i %i\n", x, y, w, h ); - } - bool ret = ( ChangeDisplaySettings( &dm, parms.fullScreen ? CDS_FULLSCREEN : 0 ) == DISP_CHANGE_SUCCESSFUL ); - SetWindowPos( win32.hWnd, parms.fullScreen ? HWND_TOPMOST : HWND_NOTOPMOST, x, y, w, h, parms.fullScreen ? SWP_NOSIZE | SWP_NOMOVE : SWP_SHOWWINDOW ); - return ret; -} - -/* -=================== -GLimp_Shutdown - -This routine does all OS specific shutdown procedures for the OpenGL -subsystem. -=================== -*/ -void GLimp_Shutdown( void ) { - const char *success[] = { "failed", "success" }; - int retVal; - - common->Printf( "Shutting down OpenGL subsystem\n" ); - - // set current context to NULL - retVal = qwglMakeCurrent( NULL, NULL ) != 0; - common->Printf( "...wglMakeCurrent( NULL, NULL ): %s\n", success[retVal] ); - - // delete HGLRC - if ( win32.hGLRC ) { - retVal = qwglDeleteContext( win32.hGLRC ) != 0; - common->Printf( "...deleting GL context: %s\n", success[retVal] ); - win32.hGLRC = NULL; - } - - // release DC - if ( win32.hDC ) { - retVal = ReleaseDC( win32.hWnd, win32.hDC ) != 0; - common->Printf( "...releasing DC: %s\n", success[retVal] ); - win32.hDC = NULL; - } - - // destroy window - if ( win32.hWnd ) { - common->Printf( "...destroying window\n" ); - ShowWindow( win32.hWnd, SW_HIDE ); - DestroyWindow( win32.hWnd ); - win32.hWnd = NULL; - } - - // reset display settings - if ( win32.cdsFullscreen ) { - common->Printf( "...resetting display\n" ); - ChangeDisplaySettings( 0, 0 ); - win32.cdsFullscreen = false; - } - - // restore gamma - GLimp_RestoreGamma(); -} - - -/* -===================== -GLimp_SwapBuffers -===================== -*/ -void GLimp_SwapBuffers( void ) { - // - // wglSwapinterval is a windows-private extension, - // so we must check for it here instead of portably - // - if ( r_swapInterval.IsModified() ) { - r_swapInterval.ClearModified(); - - if ( wglSwapIntervalEXT ) { - wglSwapIntervalEXT( r_swapInterval.GetInteger() ); - } - } - - qwglSwapBuffers( win32.hDC ); - -//Sys_DebugPrintf( "*** SwapBuffers() ***\n" ); -} - -/* -=========================================================== - -SMP acceleration - -=========================================================== -*/ - -//#define REALLOC_DC - -/* -=================== -GLimp_ActivateContext - -=================== -*/ -void GLimp_ActivateContext( void ) { - if ( !qwglMakeCurrent( win32.hDC, win32.hGLRC ) ) { - win32.wglErrors++; - } -} - -/* -=================== -GLimp_DeactivateContext - -=================== -*/ -void GLimp_DeactivateContext( void ) { - qglFinish(); - if ( !qwglMakeCurrent( win32.hDC, NULL ) ) { - win32.wglErrors++; - } -#ifdef REALLOC_DC - // makeCurrent NULL frees the DC, so get another - if ( ( win32.hDC = GetDC( win32.hWnd ) ) == NULL ) { - win32.wglErrors++; - } -#endif - -} - -/* -=================== -GLimp_ExtensionPointer - -Returns a function pointer for an OpenGL extension entry point -=================== -*/ -GLExtension_t GLimp_ExtensionPointer( const char *name ) { - void (*proc)(void); - - proc = (GLExtension_t)qwglGetProcAddress( name ); - - if ( !proc ) { - common->Printf( "Couldn't find proc address for: %s\n", name ); - } - - return proc; -} - diff --git a/neo/sys/win32/win_input.cpp b/neo/sys/win32/win_input.cpp index fa31b473..5eedef0f 100644 --- a/neo/sys/win32/win_input.cpp +++ b/neo/sys/win32/win_input.cpp @@ -32,33 +32,6 @@ If you have questions concerning this license or the applicable additional terms #include "sys/win32/win_local.h" -#define DINPUT_BUFFERSIZE 256 - -#define CHAR_FIRSTREPEAT 200 -#define CHAR_REPEAT 100 - -typedef struct MYDATA { - LONG lX; // X axis goes here - LONG lY; // Y axis goes here - LONG lZ; // Z axis goes here - BYTE bButtonA; // One button goes here - BYTE bButtonB; // Another button goes here - BYTE bButtonC; // Another button goes here - BYTE bButtonD; // Another button goes here -} MYDATA; - -static DIOBJECTDATAFORMAT rgodf[] = { - { &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,}, - { &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,}, - { &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, - { 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,}, -}; - -//========================================================================== - static const unsigned char s_scantokey[256] = { // 0 1 2 3 4 5 6 7 // 8 9 A B C D E F @@ -261,450 +234,6 @@ static const unsigned char *keyScanTable = s_scantokey; // scan codes instead of just the first 128. static unsigned char rightAltKey = K_ALT; -#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0])) - -static DIDATAFORMAT df = { - sizeof(DIDATAFORMAT), // this structure - sizeof(DIOBJECTDATAFORMAT), // size of object data format - DIDF_RELAXIS, // absolute axis coordinates - sizeof(MYDATA), // device data size - NUM_OBJECTS, // number of objects - rgodf, // and here they are -}; - -/* -============================================================ - -DIRECT INPUT KEYBOARD CONTROL - -============================================================ -*/ - -bool IN_StartupKeyboard( void ) { - HRESULT hr; - bool bExclusive; - bool bForeground; - bool bImmediate; - bool bDisableWindowsKey; - DWORD dwCoopFlags; - - if (!win32.g_pdi) { - common->Printf("keyboard: DirectInput has not been started\n"); - return false; - } - - if (win32.g_pKeyboard) { - win32.g_pKeyboard->Release(); - win32.g_pKeyboard = NULL; - } - - // Detrimine where the buffer would like to be allocated - bExclusive = false; - bForeground = true; - bImmediate = false; - bDisableWindowsKey = true; - - if( bExclusive ) - dwCoopFlags = DISCL_EXCLUSIVE; - else - dwCoopFlags = DISCL_NONEXCLUSIVE; - - if( bForeground ) - dwCoopFlags |= DISCL_FOREGROUND; - else - dwCoopFlags |= DISCL_BACKGROUND; - - // Disabling the windows key is only allowed only if we are in foreground nonexclusive - if( bDisableWindowsKey && !bExclusive && bForeground ) - dwCoopFlags |= DISCL_NOWINKEY; - - // Obtain an interface to the system keyboard device. - if( FAILED( hr = win32.g_pdi->CreateDevice( GUID_SysKeyboard, &win32.g_pKeyboard, NULL ) ) ) { - common->Printf("keyboard: couldn't find a keyboard device\n"); - return false; - } - - // Set the data format to "keyboard format" - a predefined data format - // - // A data format specifies which controls on a device we - // are interested in, and how they should be reported. - // - // This tells DirectInput that we will be passing an array - // of 256 bytes to IDirectInputDevice::GetDeviceState. - if( FAILED( hr = win32.g_pKeyboard->SetDataFormat( &c_dfDIKeyboard ) ) ) - return false; - - // Set the cooperativity level to let DirectInput know how - // this device should interact with the system and with other - // DirectInput applications. - hr = win32.g_pKeyboard->SetCooperativeLevel( win32.hWnd, dwCoopFlags ); - if( hr == DIERR_UNSUPPORTED && !bForeground && bExclusive ) { - common->Printf("keyboard: SetCooperativeLevel() returned DIERR_UNSUPPORTED.\nFor security reasons, background exclusive keyboard access is not allowed.\n"); - return false; - } - - if( FAILED(hr) ) { - return false; - } - - if( !bImmediate ) { - // IMPORTANT STEP TO USE BUFFERED DEVICE DATA! - // - // DirectInput uses unbuffered I/O (buffer size = 0) by default. - // If you want to read buffered data, you need to set a nonzero - // buffer size. - // - // Set the buffer size to DINPUT_BUFFERSIZE (defined above) elements. - // - // The buffer size is a DWORD property associated with the device. - DIPROPDWORD dipdw; - - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = DINPUT_BUFFERSIZE; // Arbitary buffer size - - if( FAILED( hr = win32.g_pKeyboard->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) ) - return false; - } - - // Acquire the newly created device - win32.g_pKeyboard->Acquire(); - - common->Printf( "keyboard: DirectInput initialized.\n"); - return true; -} - -/* -======= -MapKey - -Map from windows to quake keynums - -FIXME: scan code tables should include the upper 128 scan codes instead - of having to special-case them here. The current code makes it difficult - to special-case conversions for non-US keyboards. Currently the only - special-case is for right alt. -======= -*/ -int IN_DIMapKey (int key) { - if ( key>=128 ) { - switch ( key ) { - case DIK_HOME: - return K_HOME; - case DIK_UPARROW: - return K_UPARROW; - case DIK_PGUP: - return K_PGUP; - case DIK_LEFTARROW: - return K_LEFTARROW; - case DIK_RIGHTARROW: - return K_RIGHTARROW; - case DIK_END: - return K_END; - case DIK_DOWNARROW: - return K_DOWNARROW; - case DIK_PGDN: - return K_PGDN; - case DIK_INSERT: - return K_INS; - case DIK_DELETE: - return K_DEL; - case DIK_RMENU: - return rightAltKey; - case DIK_RCONTROL: - return K_CTRL; - case DIK_NUMPADENTER: - return K_KP_ENTER; - case DIK_NUMPADEQUALS: - return K_KP_EQUALS; - case DIK_PAUSE: - return K_PAUSE; - case DIK_DIVIDE: - return K_KP_SLASH; - case DIK_LWIN: - return K_LWIN; - case DIK_RWIN: - return K_RWIN; - case DIK_APPS: - return K_MENU; - case DIK_SYSRQ: - return K_PRINT_SCR; - default: - return 0; - } - } else { - switch (key) { - case DIK_NUMPAD7: - return K_KP_HOME; - case DIK_NUMPAD8: - return K_KP_UPARROW; - case DIK_NUMPAD9: - return K_KP_PGUP; - case DIK_NUMPAD4: - return K_KP_LEFTARROW; - case DIK_NUMPAD5: - return K_KP_5; - case DIK_NUMPAD6: - return K_KP_RIGHTARROW; - case DIK_NUMPAD1: - return K_KP_END; - case DIK_NUMPAD2: - return K_KP_DOWNARROW; - case DIK_NUMPAD3: - return K_KP_PGDN; - case DIK_NUMPAD0: - return K_KP_INS; - case DIK_DECIMAL: - return K_KP_DEL; - case DIK_SUBTRACT: - return K_KP_MINUS; - case DIK_ADD: - return K_KP_PLUS; - case DIK_NUMLOCK: - return K_KP_NUMLOCK; - case DIK_MULTIPLY: - return K_KP_STAR; - default: - return keyScanTable[key]; - } - } -} - - -/* -========================== -IN_DeactivateKeyboard -========================== -*/ -void IN_DeactivateKeyboard( void ) { - if (!win32.g_pKeyboard) { - return; - } - win32.g_pKeyboard->Unacquire( ); -} - -/* -============================================================ - -DIRECT INPUT MOUSE CONTROL - -============================================================ -*/ - -/* -======================== -IN_InitDirectInput -======================== -*/ - -void IN_InitDirectInput( void ) { - HRESULT hr; - - common->Printf( "Initializing DirectInput...\n" ); - - if ( win32.g_pdi != NULL ) { - win32.g_pdi->Release(); // if the previous window was destroyed we need to do this - win32.g_pdi = NULL; - } - - // Register with the DirectInput subsystem and get a pointer - // to a IDirectInput interface we can use. - // Create the base DirectInput object - if ( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&win32.g_pdi, NULL ) ) ) { - common->Printf ("DirectInputCreate failed\n"); - } -} - -/* -======================== -IN_InitDIMouse -======================== -*/ -bool IN_InitDIMouse( void ) { - HRESULT hr; - - if ( win32.g_pdi == NULL) { - return false; - } - - // obtain an interface to the system mouse device. - hr = win32.g_pdi->CreateDevice( GUID_SysMouse, &win32.g_pMouse, NULL); - - if (FAILED(hr)) { - common->Printf ("mouse: Couldn't open DI mouse device\n"); - return false; - } - - // Set the data format to "mouse format" - a predefined data format - // - // A data format specifies which controls on a device we - // are interested in, and how they should be reported. - // - // This tells DirectInput that we will be passing a - // DIMOUSESTATE2 structure to IDirectInputDevice::GetDeviceState. - if( FAILED( hr = win32.g_pMouse->SetDataFormat( &c_dfDIMouse2 ) ) ) { - common->Printf ("mouse: Couldn't set DI mouse format\n"); - return false; - } - - // set the cooperativity level. - hr = win32.g_pMouse->SetCooperativeLevel( win32.hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); - - if (FAILED(hr)) { - common->Printf ("mouse: Couldn't set DI coop level\n"); - return false; - } - - - // IMPORTANT STEP TO USE BUFFERED DEVICE DATA! - // - // DirectInput uses unbuffered I/O (buffer size = 0) by default. - // If you want to read buffered data, you need to set a nonzero - // buffer size. - // - // Set the buffer size to SAMPLE_BUFFER_SIZE (defined above) elements. - // - // The buffer size is a DWORD property associated with the device. - DIPROPDWORD dipdw; - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = DINPUT_BUFFERSIZE; // Arbitary buffer size - - if( FAILED( hr = win32.g_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) ) { - common->Printf ("mouse: Couldn't set DI buffersize\n"); - return false; - } - - IN_ActivateMouse(); - - // clear any pending samples - Sys_PollMouseInputEvents(); - - common->Printf( "mouse: DirectInput initialized.\n"); - return true; -} - - -/* -========================== -IN_ActivateMouse -========================== -*/ -void IN_ActivateMouse( void ) { - int i; - HRESULT hr; - - if ( !win32.in_mouse.GetBool() || win32.mouseGrabbed || !win32.g_pMouse ) { - return; - } - - win32.mouseGrabbed = true; - for ( i = 0; i < 10; i++ ) { - if ( ::ShowCursor( false ) < 0 ) { - break; - } - } - - // we may fail to reacquire if the window has been recreated - hr = win32.g_pMouse->Acquire(); - if (FAILED(hr)) { - return; - } - - // set the cooperativity level. - hr = win32.g_pMouse->SetCooperativeLevel( win32.hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND); -} - -/* -========================== -IN_DeactivateMouse -========================== -*/ -void IN_DeactivateMouse( void ) { - int i; - - if (!win32.g_pMouse || !win32.mouseGrabbed ) { - return; - } - - win32.g_pMouse->Unacquire(); - - for ( i = 0; i < 10; i++ ) { - if ( ::ShowCursor( true ) >= 0 ) { - break; - } - } - win32.mouseGrabbed = false; -} - -/* -========================== -IN_DeactivateMouseIfWindowed -========================== -*/ -void IN_DeactivateMouseIfWindowed( void ) { - if ( !win32.cdsFullscreen ) { - IN_DeactivateMouse(); - } -} - -/* -============================================================ - - MOUSE CONTROL - -============================================================ -*/ - - -/* -=========== -Sys_ShutdownInput -=========== -*/ -void Sys_ShutdownInput( void ) { - IN_DeactivateMouse(); - IN_DeactivateKeyboard(); - if ( win32.g_pKeyboard ) { - win32.g_pKeyboard->Release(); - win32.g_pKeyboard = NULL; - } - - if ( win32.g_pMouse ) { - win32.g_pMouse->Release(); - win32.g_pMouse = NULL; - } - - if ( win32.g_pdi ) { - win32.g_pdi->Release(); - win32.g_pdi = NULL; - } -} - -/* -=========== -Sys_InitInput -=========== -*/ -void Sys_InitInput( void ) { - common->Printf ("\n------- Input Initialization -------\n"); - IN_InitDirectInput(); - if ( win32.in_mouse.GetBool() ) { - IN_InitDIMouse(); - // don't grab the mouse on initialization - Sys_GrabMouseCursor( false ); - } else { - common->Printf ("Mouse control not active.\n"); - } - IN_StartupKeyboard(); - common->Printf ("------------------------------------\n"); - win32.in_mouse.ClearModified(); -} - /* =========== Sys_InitScanTable @@ -830,301 +359,3 @@ int Win_MapKey (int key) return result; } - -/* -=============== -Sys_GetConsoleKey -=============== -*/ -unsigned char Sys_GetConsoleKey( bool shifted ) { - return keyScanTable[41 + ( shifted ? 128 : 0 )]; -} - -/* -================== -IN_Frame - -Called every frame, even if not generating commands -================== -*/ -void IN_Frame( void ) { - bool shouldGrab = true; - - if ( !win32.in_mouse.GetBool() ) { - shouldGrab = false; - } - // if fullscreen, we always want the mouse - if ( !win32.cdsFullscreen ) { - if ( win32.mouseReleased ) { - shouldGrab = false; - } - if ( win32.movingWindow ) { - shouldGrab = false; - } - if ( !win32.activeApp ) { - shouldGrab = false; - } - } - - if ( shouldGrab != win32.mouseGrabbed ) { - if ( win32.mouseGrabbed ) { - IN_DeactivateMouse(); - } else { - IN_ActivateMouse(); - -#if 0 // if we can't reacquire, try reinitializing - if ( !IN_InitDIMouse() ) { - win32.in_mouse.SetBool( false ); - return; - } -#endif - } - } -} - - -void Sys_GrabMouseCursor( bool grabIt ) { -#ifndef ID_DEDICATED - win32.mouseReleased = !grabIt; - if ( !grabIt ) { - // release it right now - IN_Frame(); - } -#endif -} - -//===================================================================================== - -static DIDEVICEOBJECTDATA polled_didod[ DINPUT_BUFFERSIZE ]; // Receives buffered data - -static int diFetch; -static byte toggleFetch[2][ 256 ]; - - -#if 1 -// I tried doing the full-state get to address a keyboard problem on one system, -// but it didn't make any difference - -/* -==================== -Sys_PollKeyboardInputEvents -==================== -*/ -int Sys_PollKeyboardInputEvents( void ) { - DWORD dwElements; - HRESULT hr; - - if( win32.g_pKeyboard == NULL ) { - return 0; - } - - dwElements = DINPUT_BUFFERSIZE; - hr = win32.g_pKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), - polled_didod, &dwElements, 0 ); - if( hr != DI_OK ) - { - // We got an error or we got DI_BUFFEROVERFLOW. - // - // Either way, it means that continuous contact with the - // device has been lost, either due to an external - // interruption, or because the buffer overflowed - // and some events were lost. - hr = win32.g_pKeyboard->Acquire(); - - - - // nuke the garbage - if (!FAILED(hr)) { - //Bug 951: The following command really clears the garbage input. - //The original will still process keys in the buffer and was causing - //some problems. - win32.g_pKeyboard->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), NULL, &dwElements, 0 ); - dwElements = 0; - } - // hr may be DIERR_OTHERAPPHASPRIO or other errors. This - // may occur when the app is minimized or in the process of - // switching, so just try again later - } - - if( FAILED(hr) ) { - return 0; - } - - return dwElements; -} - -#else - -/* -==================== -Sys_PollKeyboardInputEvents - -Fake events by getting the entire device state -and checking transitions -==================== -*/ -int Sys_PollKeyboardInputEvents( void ) { - HRESULT hr; - - if( win32.g_pKeyboard == NULL ) { - return 0; - } - - hr = win32.g_pKeyboard->GetDeviceState( sizeof( toggleFetch[ diFetch ] ), toggleFetch[ diFetch ] ); - if( hr != DI_OK ) - { - // We got an error or we got DI_BUFFEROVERFLOW. - // - // Either way, it means that continuous contact with the - // device has been lost, either due to an external - // interruption, or because the buffer overflowed - // and some events were lost. - hr = win32.g_pKeyboard->Acquire(); - - // nuke the garbage - if (!FAILED(hr)) { - hr = win32.g_pKeyboard->GetDeviceState( sizeof( toggleFetch[ diFetch ] ), toggleFetch[ diFetch ] ); - } - // hr may be DIERR_OTHERAPPHASPRIO or other errors. This - // may occur when the app is minimized or in the process of - // switching, so just try again later - } - - if( FAILED(hr) ) { - return 0; - } - - // build faked events - int numChanges = 0; - - for ( int i = 0 ; i < 256 ; i++ ) { - if ( toggleFetch[0][i] != toggleFetch[1][i] ) { - polled_didod[ numChanges ].dwOfs = i; - polled_didod[ numChanges ].dwData = toggleFetch[ diFetch ][i] ? 0x80 : 0; - numChanges++; - } - } - - diFetch ^= 1; - - return numChanges; -} - -#endif - -/* -==================== -Sys_PollKeyboardInputEvents -==================== -*/ -int Sys_ReturnKeyboardInputEvent( const int n, int &ch, bool &state ) { - ch = IN_DIMapKey( polled_didod[ n ].dwOfs ); - state = (polled_didod[ n ].dwData & 0x80) == 0x80; - if ( ch == K_PRINT_SCR || ch == K_CTRL || ch == K_ALT || ch == K_RIGHT_ALT ) { - // for windows, add a keydown event for print screen here, since - // windows doesn't send keydown events to the WndProc for this key. - // ctrl and alt are handled here to get around windows sending ctrl and - // alt messages when the right-alt is pressed on non-US 102 keyboards. - Sys_QueEvent( GetTickCount(), SE_KEY, ch, state, 0, NULL ); - } - return ch; -} - - -void Sys_EndKeyboardInputEvents( void ) { -} - -void Sys_QueMouseEvents( int dwElements ) { - int i, value; - - for( i = 0; i < dwElements; i++ ) { - int diaction = polled_didod[i].dwOfs; - - if ( diaction >= DIMOFS_BUTTON0 && diaction <= DIMOFS_BUTTON7 ) { - value = (polled_didod[i].dwData & 0x80) == 0x80; - Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, K_MOUSE1 + ( diaction - DIMOFS_BUTTON0 ), value, 0, NULL ); - } else if (diaction == DIMOFS_X) { - value = polled_didod[i].dwData; - Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, value, 0, 0, NULL ); - } else if (diaction == DIMOFS_Y) { - value = polled_didod[i].dwData; - Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_MOUSE, 0, value, 0, NULL ); - } else if (diaction == DIMOFS_Z) { - value = ( (int) polled_didod[i].dwData ) / WHEEL_DELTA; - int key = value < 0 ? K_MWHEELDOWN : K_MWHEELUP; - value = abs( value ); - while( value-- > 0 ) { - Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, true, 0, NULL ); - Sys_QueEvent( polled_didod[i].dwTimeStamp, SE_KEY, key, false, 0, NULL ); - } - } - } -} - -//===================================================================================== - -int Sys_PollMouseInputEvents( void ) { - DWORD dwElements; - HRESULT hr; - - if ( !win32.g_pMouse || !win32.mouseGrabbed ) { - return 0; - } - - dwElements = DINPUT_BUFFERSIZE; - hr = win32.g_pMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), polled_didod, &dwElements, 0 ); - - if( hr != DI_OK ) { - hr = win32.g_pMouse->Acquire(); - // clear the garbage - if (!FAILED(hr)) { - win32.g_pMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), polled_didod, &dwElements, 0 ); - } - } - - if( FAILED(hr) ) { - return 0; - } - - Sys_QueMouseEvents( dwElements ); - - return dwElements; -} - -int Sys_ReturnMouseInputEvent( const int n, int &action, int &value ) { - int diaction = polled_didod[n].dwOfs; - - if ( diaction >= DIMOFS_BUTTON0 && diaction <= DIMOFS_BUTTON7 ) { - value = (polled_didod[n].dwData & 0x80) == 0x80; - action = M_ACTION1 + ( diaction - DIMOFS_BUTTON0 ); - return 1; - } - - if ( diaction == DIMOFS_X) { - value = polled_didod[n].dwData; - action = M_DELTAX; - return 1; - } - if ( diaction == DIMOFS_Y) { - value = polled_didod[n].dwData; - action = M_DELTAY; - return 1; - } - if ( diaction == DIMOFS_Z) { - // mouse wheel actions are impulses, without a specific up / down - value = ( (int) polled_didod[n].dwData ) / WHEEL_DELTA; - action = M_DELTAZ; - // a value of zero here should never happen - if ( value == 0 ) { - return 0; - } - return 1; - } - return 0; -} - -void Sys_EndMouseInputEvents( void ) { } - -unsigned char Sys_MapCharForKey( int key ) { - return (unsigned char)key; -} diff --git a/neo/sys/win32/win_local.h b/neo/sys/win32/win_local.h index 5ac443cb..61f32938 100644 --- a/neo/sys/win32/win_local.h +++ b/neo/sys/win32/win_local.h @@ -38,9 +38,7 @@ If you have questions concerning this license or the applicable additional terms #include #include #include - -#define DIRECTINPUT_VERSION 0x0800 // was 0x0700 with the old mssdk -#include +#include #include @@ -48,18 +46,10 @@ If you have questions concerning this license or the applicable additional terms #include "renderer/wglext.h" // windows OpenGL extensions #include "sys/sys_public.h" -// WGL_EXT_swap_interval -extern PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; - -// WGL_ARB_pixel_format -extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB; - #define MAX_OSPATH 256 #define WINDOW_STYLE (WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_VISIBLE | WS_THICKFRAME) -void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr ); - void Sys_CreateConsole( void ); void Sys_DestroyConsole( void ); @@ -70,24 +60,6 @@ void Win_SetErrorText( const char *text ); const unsigned char *Win_GetScanTable( void ); int Win_MapKey (int key); - -// Input subsystem - -void IN_Init (void); -void IN_Shutdown (void); -// add additional non keyboard / non mouse movement on top of the keyboard move cmd - -void IN_DeactivateMouseIfWindowed( void ); -void IN_DeactivateMouse( void ); -void IN_ActivateMouse( void ); - -void IN_Frame( void ); - -int IN_DIMapKey( int key ); - -void DisableTaskKeys( BOOL bDisable, BOOL bBeep, BOOL bTaskMgr ); - - // window procedure LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -97,56 +69,23 @@ struct Win32Vars_t { HWND hWnd; HINSTANCE hInstance; - bool activeApp; // changed with WM_ACTIVATE messages - bool mouseReleased; // when the game has the console down or is doing a long operation - bool movingWindow; // inhibit mouse grab when dragging the window - bool mouseGrabbed; // current state of grab and hide - OSVERSIONINFOEX osversion; // when we get a windows message, we store the time off so keyboard processing // can know the exact time of an event (not really needed now that we use async direct input) int sysMsgTime; - bool windowClassRegistered; - - WNDPROC wndproc; - HDC hDC; // handle to device context HGLRC hGLRC; // handle to GL rendering context PIXELFORMATDESCRIPTOR pfd; int pixelformat; - int desktopBitsPixel; - int desktopWidth, desktopHeight; - - bool cdsFullscreen; - - unsigned short oldHardwareGamma[3][256]; - // desktop gamma is saved here for restoration at exit - static idCVar sys_arch; - static idCVar in_mouse; - static idCVar win_allowAltTab; - static idCVar win_notaskkeys; static idCVar win_username; - static idCVar win_xpos; // archived X coordinate of window position - static idCVar win_ypos; // archived Y coordinate of window position static idCVar win_outputDebugString; static idCVar win_outputEditString; static idCVar win_viewlog; - static idCVar win_timerUpdate; static idCVar win_allowMultipleInstances; - - HINSTANCE hInstDI; // direct input - - LPDIRECTINPUT8 g_pdi; - LPDIRECTINPUTDEVICE8 g_pMouse; - LPDIRECTINPUTDEVICE8 g_pKeyboard; - - int wglErrors; - // SMP acceleration vars - }; extern Win32Vars_t win32; diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index 1ddfc3b5..fa76f45a 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -53,16 +53,10 @@ If you have questions concerning this license or the applicable additional terms #include idCVar Win32Vars_t::sys_arch( "sys_arch", "", CVAR_SYSTEM | CVAR_INIT, "" ); -idCVar Win32Vars_t::in_mouse( "in_mouse", "1", CVAR_SYSTEM | CVAR_BOOL, "enable mouse input" ); -idCVar Win32Vars_t::win_allowAltTab( "win_allowAltTab", "0", CVAR_SYSTEM | CVAR_BOOL, "allow Alt-Tab when fullscreen" ); -idCVar Win32Vars_t::win_notaskkeys( "win_notaskkeys", "0", CVAR_SYSTEM | CVAR_INTEGER, "disable windows task keys" ); idCVar Win32Vars_t::win_username( "win_username", "", CVAR_SYSTEM | CVAR_INIT, "windows user name" ); -idCVar Win32Vars_t::win_xpos( "win_xpos", "3", CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_INTEGER, "horizontal position of window" ); -idCVar Win32Vars_t::win_ypos( "win_ypos", "22", CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_INTEGER, "vertical position of window" ); idCVar Win32Vars_t::win_outputDebugString( "win_outputDebugString", "0", CVAR_SYSTEM | CVAR_BOOL, "" ); idCVar Win32Vars_t::win_outputEditString( "win_outputEditString", "1", CVAR_SYSTEM | CVAR_BOOL, "" ); idCVar Win32Vars_t::win_viewlog( "win_viewlog", "0", CVAR_SYSTEM | CVAR_INTEGER, "" ); -idCVar Win32Vars_t::win_timerUpdate( "win_timerUpdate", "0", CVAR_SYSTEM | CVAR_BOOL, "allows the game to be updated while dragging the window" ); idCVar Win32Vars_t::win_allowMultipleInstances( "win_allowMultipleInstances", "0", CVAR_SYSTEM | CVAR_BOOL, "allow multiple instances running concurrently" ); Win32Vars_t win32; @@ -581,165 +575,6 @@ void Sys_DLL_Unload( uintptr_t dllHandle ) { } } -/* -======================================================================== - -EVENT LOOP - -======================================================================== -*/ - -#define MAX_QUED_EVENTS 256 -#define MASK_QUED_EVENTS ( MAX_QUED_EVENTS - 1 ) - -sysEvent_t eventQue[MAX_QUED_EVENTS]; -int eventHead = 0; -int eventTail = 0; - -/* -================ -Sys_QueEvent - -Ptr should either be null, or point to a block of data that can -be freed by the game later. -================ -*/ -void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr ) { - sysEvent_t *ev; - - ev = &eventQue[ eventHead & MASK_QUED_EVENTS ]; - - if ( eventHead - eventTail >= MAX_QUED_EVENTS ) { - common->Printf("Sys_QueEvent: overflow\n"); - // we are discarding an event, but don't leak memory - if ( ev->evPtr ) { - Mem_Free( ev->evPtr ); - } - eventTail++; - } - - eventHead++; - - ev->evType = type; - ev->evValue = value; - ev->evValue2 = value2; - ev->evPtrLength = ptrLength; - ev->evPtr = ptr; -} - -/* -============= -Sys_PumpEvents - -This allows windows to be moved during renderbump -============= -*/ -void Sys_PumpEvents( void ) { - MSG msg; - - // pump the message loop - while( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) { - if ( !GetMessage( &msg, NULL, 0, 0 ) ) { - common->Quit(); - } - - // save the msg time, because wndprocs don't have access to the timestamp - if ( win32.sysMsgTime && win32.sysMsgTime > (int)msg.time ) { - // don't ever let the event times run backwards -// common->Printf( "Sys_PumpEvents: win32.sysMsgTime (%i) > msg.time (%i)\n", win32.sysMsgTime, msg.time ); - } else { - win32.sysMsgTime = msg.time; - } - -#ifdef ID_ALLOW_TOOLS - if ( GUIEditorHandleMessage ( &msg ) ) { - continue; - } -#endif - - TranslateMessage (&msg); - DispatchMessage (&msg); - } -} - -/* -================ -Sys_GenerateEvents -================ -*/ -void Sys_GenerateEvents( void ) { - static int entered = false; - char *s; - - if ( entered ) { - return; - } - entered = true; - - // pump the message loop - Sys_PumpEvents(); - - // make sure mouse and joystick are only called once a frame - IN_Frame(); - - // check for console commands - s = Sys_ConsoleInput(); - if ( s ) { - char *b; - int len; - - len = strlen( s ) + 1; - b = (char *)Mem_Alloc( len ); - strcpy( b, s ); - Sys_QueEvent( 0, SE_CONSOLE, 0, 0, len, b ); - } - - entered = false; -} - -/* -================ -Sys_ClearEvents -================ -*/ -void Sys_ClearEvents( void ) { - eventHead = eventTail = 0; -} - -/* -================ -Sys_GetEvent -================ -*/ -sysEvent_t Sys_GetEvent( void ) { - sysEvent_t ev; - - // return if we have data - if ( eventHead > eventTail ) { - eventTail++; - return eventQue[ ( eventTail - 1 ) & MASK_QUED_EVENTS ]; - } - - // return the empty event - memset( &ev, 0, sizeof( ev ) ); - - return ev; -} - -//================================================================ - -/* -================= -Sys_In_Restart_f - -Restart the input subsystem -================= -*/ -void Sys_In_Restart_f( const idCmdArgs &args ) { - Sys_ShutdownInput(); - Sys_InitInput(); -} - /* ================ Sys_AlreadyRunning @@ -780,7 +615,6 @@ void Sys_Init( void ) { // get WM_TIMER messages pumped every millisecond // SetTimer( NULL, 0, 100, NULL ); - cmdSystem->AddCommand( "in_restart", Sys_In_Restart_f, CMD_FL_SYSTEM, "restarts the input system" ); #ifdef DEBUG cmdSystem->AddCommand( "createResourceIDs", CreateResourceIDs_f, CMD_FL_TOOL, "assigns resource IDs in _resouce.h files" ); #endif @@ -957,12 +791,6 @@ int main(int argc, char *argv[]) { common->Printf( Sys_FPU_GetState() ); #endif -#ifndef ID_DEDICATED - if ( win32.win_notaskkeys.GetInteger() ) { - DisableTaskKeys( TRUE, FALSE, /*( win32.win_notaskkeys.GetInteger() == 2 )*/ FALSE ); - } -#endif - // hide or show the early console as necessary if ( win32.win_viewlog.GetInteger() || com_skipRenderer.GetBool() || idAsyncNetwork::serverDedicated.GetInteger() ) { Sys_ShowConsole( 1, true ); diff --git a/neo/sys/win32/win_shared.cpp b/neo/sys/win32/win_shared.cpp index 826344a2..e448e49f 100644 --- a/neo/sys/win32/win_shared.cpp +++ b/neo/sys/win32/win_shared.cpp @@ -39,14 +39,6 @@ If you have questions concerning this license or the applicable additional terms #include #include -#if !defined(ID_DEDICATED) && !defined(__MINGW32__) -#include -#include -#include - -#pragma comment (lib, "wbemuuid.lib") -#endif - /* ================ Sys_GetSystemRam @@ -84,68 +76,6 @@ int Sys_GetDriveFreeSpace( const char *path ) { } -/* -================ -Sys_GetVideoRam -returns in megabytes -================ -*/ -int Sys_GetVideoRam( void ) { -#if defined(ID_DEDICATED) - return 0; -#elif !defined(_MFC_VER) - // no (MinGW, VS Express etc.), so assume the min. req. 64Mb - return 64; -#else - unsigned int retSize = 64; - - CComPtr spLoc = NULL; - HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID * ) &spLoc ); - if ( hr != S_OK || spLoc == NULL ) { - return retSize; - } - - CComBSTR bstrNamespace( _T( "\\\\.\\root\\CIMV2" ) ); - CComPtr spServices; - - // Connect to CIM - hr = spLoc->ConnectServer( bstrNamespace, NULL, NULL, 0, NULL, 0, 0, &spServices ); - if ( hr != WBEM_S_NO_ERROR ) { - return retSize; - } - - // Switch the security level to IMPERSONATE so that provider will grant access to system-level objects. - hr = CoSetProxyBlanket( spServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE ); - if ( hr != S_OK ) { - return retSize; - } - - // Get the vid controller - CComPtr spEnumInst = NULL; - hr = spServices->CreateInstanceEnum( CComBSTR( "Win32_VideoController" ), WBEM_FLAG_SHALLOW, NULL, &spEnumInst ); - if ( hr != WBEM_S_NO_ERROR || spEnumInst == NULL ) { - return retSize; - } - - ULONG uNumOfInstances = 0; - CComPtr spInstance = NULL; - hr = spEnumInst->Next( 10000, 1, &spInstance, &uNumOfInstances ); - - if ( hr == S_OK && spInstance ) { - // Get properties from the object - CComVariant varSize; - hr = spInstance->Get( CComBSTR( _T( "AdapterRAM" ) ), 0, &varSize, 0, 0 ); - if ( hr == S_OK ) { - retSize = varSize.intVal / ( 1024 * 1024 ); - if ( retSize == 0 ) { - retSize = 64; - } - } - } - return retSize; -#endif -} - /* ================ Sys_GetCurrentMemoryStatus diff --git a/neo/sys/win32/win_taskkeyhook.cpp b/neo/sys/win32/win_taskkeyhook.cpp deleted file mode 100644 index 6b3360f0..00000000 --- a/neo/sys/win32/win_taskkeyhook.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/* -=========================================================================== - -Doom 3 GPL Source Code -Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. - -This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). - -Doom 3 Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 Source Code. If not, see . - -In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ - -#include "sys/platform.h" - -#include "sys/win32/win_local.h" - -// -// This file implements the low-level keyboard hook that traps the task keys. -// - -// Magic registry key/value for "Remove Task Manager" policy. -LPCTSTR KEY_DisableTaskMgr = "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; -LPCTSTR VAL_DisableTaskMgr = "DisableTaskMgr"; - -// The section is SHARED among all instances of this DLL. -// A low-level keyboard hook is always a system-wide hook. -#pragma data_seg (".mydata") -HHOOK g_hHookKbdLL = NULL; // hook handle -BOOL g_bBeep = FALSE; // beep on illegal key -#pragma data_seg () -#pragma comment(linker, "/SECTION:.mydata,RWS") // tell linker: make it shared - -/* -================ -MyTaskKeyHookLL - - Low-level keyboard hook: - Trap task-switching keys by returning without passing along. -================ -*/ -LRESULT CALLBACK MyTaskKeyHookLL( int nCode, WPARAM wp, LPARAM lp ) { - KBDLLHOOKSTRUCT *pkh = (KBDLLHOOKSTRUCT *) lp; - - if ( nCode == HC_ACTION ) { - BOOL bCtrlKeyDown = GetAsyncKeyState( VK_CONTROL)>>((sizeof(SHORT) * 8) - 1 ); - - if ( ( pkh->vkCode == VK_ESCAPE && bCtrlKeyDown ) // Ctrl+Esc - || ( pkh->vkCode == VK_TAB && pkh->flags & LLKHF_ALTDOWN ) // Alt+TAB - || ( pkh->vkCode == VK_ESCAPE && pkh->flags & LLKHF_ALTDOWN ) // Alt+Esc - || ( pkh->vkCode == VK_LWIN || pkh->vkCode == VK_RWIN ) // Start Menu - ) { - - if ( g_bBeep && ( wp == WM_SYSKEYDOWN || wp == WM_KEYDOWN ) ) { - MessageBeep( 0 ); // beep on downstroke if requested - } - return 1; // return without processing the key strokes - } - } - return CallNextHookEx( g_hHookKbdLL, nCode, wp, lp ); -} - -/* -================ -AreTaskKeysDisabled - - Are task keys disabled--ie, is hook installed? - Note: This assumes there's no other hook that does the same thing! -================ -*/ -BOOL AreTaskKeysDisabled() { - return g_hHookKbdLL != NULL; -} - -/* -================ -IsTaskMgrDisabled -================ -*/ -BOOL IsTaskMgrDisabled() { - HKEY hk; - - if ( RegOpenKey( HKEY_CURRENT_USER, KEY_DisableTaskMgr, &hk ) != ERROR_SUCCESS ) { - return FALSE; // no key ==> not disabled - } - - DWORD val = 0; - DWORD len = 4; - return RegQueryValueEx( hk, VAL_DisableTaskMgr, NULL, NULL, (BYTE*)&val, &len ) == ERROR_SUCCESS && val == 1; -} - -/* -================ -DisableTaskKeys -================ -*/ -void DisableTaskKeys( BOOL bDisable, BOOL bBeep, BOOL bTaskMgr ) { - - // task keys (Ctrl+Esc, Alt-Tab, etc.) - if ( bDisable ) { - if ( !g_hHookKbdLL ) { - g_hHookKbdLL = SetWindowsHookEx( WH_KEYBOARD_LL, MyTaskKeyHookLL, win32.hInstance, 0 ); - } - } else if ( g_hHookKbdLL != NULL ) { - UnhookWindowsHookEx( g_hHookKbdLL ); - g_hHookKbdLL = NULL; - } - g_bBeep = bBeep; - - // task manager (Ctrl+Alt+Del) - if ( bTaskMgr ) { - HKEY hk; - if ( RegOpenKey( HKEY_CURRENT_USER, KEY_DisableTaskMgr, &hk ) != ERROR_SUCCESS ) { - RegCreateKey( HKEY_CURRENT_USER, KEY_DisableTaskMgr, &hk ); - } - if ( bDisable ) { - // disable TM: set policy = 1 - DWORD val = 1; - RegSetValueEx( hk, VAL_DisableTaskMgr, NULL, REG_DWORD, (BYTE*)&val, sizeof(val) ); - } else { - // enable TM: remove policy - RegDeleteValue( hk,VAL_DisableTaskMgr ); - } - } -} diff --git a/neo/sys/win32/win_wndproc.cpp b/neo/sys/win32/win_wndproc.cpp deleted file mode 100644 index f779abbb..00000000 --- a/neo/sys/win32/win_wndproc.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* -=========================================================================== - -Doom 3 GPL Source Code -Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. - -This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code"). - -Doom 3 Source Code is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Doom 3 Source Code is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Doom 3 Source Code. If not, see . - -In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below. - -If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. - -=========================================================================== -*/ - -#include "sys/platform.h" -#include "framework/Session.h" -#include "framework/KeyInput.h" -#include "renderer/tr_local.h" - -#include "sys/win32/win_local.h" - -LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); - -static bool s_alttab_disabled; - -static void WIN_DisableAltTab( void ) { - if ( s_alttab_disabled || win32.win_allowAltTab.GetBool() ) { - return; - } - if ( !idStr::Icmp( cvarSystem->GetCVarString( "sys_arch" ), "winnt" ) ) { - RegisterHotKey( 0, 0, MOD_ALT, VK_TAB ); - } else { - BOOL old; - - SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 ); - } - s_alttab_disabled = true; -} - -static void WIN_EnableAltTab( void ) { - if ( !s_alttab_disabled || win32.win_allowAltTab.GetBool() ) { - return; - } - if ( !idStr::Icmp( cvarSystem->GetCVarString( "sys_arch" ), "winnt" ) ) { - UnregisterHotKey( 0, 0 ); - } else { - BOOL old; - - SystemParametersInfo( SPI_SCREENSAVERRUNNING, 0, &old, 0 ); - } - - s_alttab_disabled = false; -} - -void WIN_Sizing(WORD side, RECT *rect) -{ - if ( !glConfig.isInitialized || glConfig.vidHeight <= 0 || glConfig.vidWidth <= 0 ) { - return; - } - - if ( idKeyInput::IsDown( K_CTRL ) ) { - return; - } - - int width = rect->right - rect->left; - int height = rect->bottom - rect->top; - - // Adjust width/height for window decoration - RECT decoRect = { 0, 0, 0, 0 }; - AdjustWindowRect( &decoRect, WINDOW_STYLE|WS_SYSMENU, FALSE ); - int decoWidth = decoRect.right - decoRect.left; - int decoHeight = decoRect.bottom - decoRect.top; - - width -= decoWidth; - height -= decoHeight; - - // Clamp to a minimum size - int minWidth = 160; - int minHeight = minWidth * SCREEN_HEIGHT / SCREEN_WIDTH; - - if ( width < minWidth ) { - width = minWidth; - } - if ( height < minHeight ) { - height = minHeight; - } - - // Set the new size - switch ( side ) { - case WMSZ_LEFT: - rect->left = rect->right - width - decoWidth; - rect->bottom = rect->top + ( width * SCREEN_HEIGHT / SCREEN_WIDTH ) + decoHeight; - break; - case WMSZ_RIGHT: - rect->right = rect->left + width + decoWidth; - rect->bottom = rect->top + ( width * SCREEN_HEIGHT / SCREEN_WIDTH ) + decoHeight; - break; - case WMSZ_BOTTOM: - case WMSZ_BOTTOMRIGHT: - rect->bottom = rect->top + height + decoHeight; - rect->right = rect->left + ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) + decoWidth; - break; - case WMSZ_TOP: - case WMSZ_TOPRIGHT: - rect->top = rect->bottom - height - decoHeight; - rect->right = rect->left + ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) + decoWidth; - break; - case WMSZ_BOTTOMLEFT: - rect->bottom = rect->top + height + decoHeight; - rect->left = rect->right - ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) - decoWidth; - break; - case WMSZ_TOPLEFT: - rect->top = rect->bottom - height - decoHeight; - rect->left = rect->right - ( height * SCREEN_WIDTH / SCREEN_HEIGHT ) - decoWidth; - break; - } -} - -//========================================================================== - -// Keep this in sync with the one in win_input.cpp -// This one is used in the menu, the other one is used in game - -static byte s_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 - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', - 'o', 'p', '[', ']', K_ENTER,K_CTRL, 'a', 's', // 1 - 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', - '\'', '`', K_SHIFT, '\\', 'z', 'x', 'c', 'v', // 2 - 'b', 'n', 'm', ',', '.', '/', K_SHIFT, K_KP_STAR, - K_ALT, ' ', K_CAPSLOCK,K_F1, K_F2, K_F3, K_F4, K_F5, // 3 - K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, K_SCROLL, K_HOME, - K_UPARROW, K_PGUP, K_KP_MINUS,K_LEFTARROW,K_KP_5, K_RIGHTARROW,K_KP_PLUS,K_END, // 4 - K_DOWNARROW,K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11, - K_F12, 0, 0, K_LWIN, K_RWIN, K_MENU, 0, 0, // 5 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, // 6 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 // 7 -}; - -static byte s_scantoshift[128] = -{ -// 0 1 2 3 4 5 6 7 -// 8 9 A B C D E F - 0, 27, '!', '@', '#', '$', '%', '^', - '&', '*', '(', ')', '_', '+', K_BACKSPACE, 9, // 0 - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', - 'O', 'P', '{', '}', K_ENTER,K_CTRL, 'A', 'S', // 1 - 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', - '|' , '~', K_SHIFT, '\\', 'Z', 'X', 'C', 'V', // 2 - 'B', 'N', 'M', '<', '>', '?', K_SHIFT, K_KP_STAR, - K_ALT, ' ', K_CAPSLOCK,K_F1, K_F2, K_F3, K_F4, K_F5, // 3 - K_F6, K_F7, K_F8, K_F9, K_F10, K_PAUSE, K_SCROLL, K_HOME, - K_UPARROW, K_PGUP, K_KP_MINUS,K_LEFTARROW,K_KP_5, K_RIGHTARROW,K_KP_PLUS,K_END, // 4 - K_DOWNARROW,K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11, - K_F12, 0, 0, K_LWIN, K_RWIN, K_MENU, 0, 0, // 5 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, // 6 - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 // 7 -}; - - - -/* -==================== -MainWndProc - -main window procedure -==================== -*/ -LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - int key; - switch( uMsg ) { - case WM_WINDOWPOSCHANGED: - if (glConfig.isInitialized) { - RECT rect; - if (::GetClientRect(win32.hWnd, &rect)) { - glConfig.vidWidth = rect.right - rect.left; - glConfig.vidHeight = rect.bottom - rect.top; - } - } - break; - - case WM_CREATE: - - win32.hWnd = hWnd; - - if ( win32.cdsFullscreen ) { - WIN_DisableAltTab(); - } else { - WIN_EnableAltTab(); - } - - break; - - case WM_DESTROY: - // let sound and input know about this? - win32.hWnd = NULL; - if ( win32.cdsFullscreen ) { - WIN_EnableAltTab(); - } - break; - - case WM_CLOSE: - cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "quit" ); - break; - - case WM_ACTIVATE: - // if we got here because of an alt-tab or maximize, - // we should activate immediately. If we are here because - // the mouse was clicked on a title bar or drag control, - // don't activate until the mouse button is released - { - int fActive, fMinimized; - - fActive = LOWORD(wParam); - fMinimized = (BOOL) HIWORD(wParam); - - win32.activeApp = (fActive != WA_INACTIVE); - if ( win32.activeApp ) { - idKeyInput::ClearStates(); - com_editorActive = false; - Sys_GrabMouseCursor( true ); - } - - if ( fActive == WA_INACTIVE ) { - win32.movingWindow = false; - } - - // start playing the game sound world - session->SetPlayingSoundWorld(); - - // we do not actually grab or release the mouse here, - // that will be done next time through the main loop - } - break; - - case WM_MOVE: { - int xPos, yPos; - RECT r; - int style; - - if (!win32.cdsFullscreen ) - { - xPos = (short) LOWORD(lParam); // horizontal position - yPos = (short) HIWORD(lParam); // vertical position - - r.left = 0; - r.top = 0; - r.right = 1; - r.bottom = 1; - - style = GetWindowLong( hWnd, GWL_STYLE ); - AdjustWindowRect( &r, style, FALSE ); - - win32.win_xpos.SetInteger( xPos + r.left ); - win32.win_ypos.SetInteger( yPos + r.top ); - win32.win_xpos.ClearModified(); - win32.win_ypos.ClearModified(); - } - break; - } - case WM_TIMER: { - if ( win32.win_timerUpdate.GetBool() ) { - common->Frame(); - } - break; - } - case WM_SYSCOMMAND: - if ( wParam == SC_SCREENSAVE || wParam == SC_KEYMENU ) { - return 0; - } - break; - - case WM_SYSKEYDOWN: - if ( wParam == 13 ) { // alt-enter toggles full-screen - cvarSystem->SetCVarBool( "r_fullscreen", !renderSystem->IsFullScreen() ); - cmdSystem->BufferCommandText( CMD_EXEC_APPEND, "vid_restart\n" ); - return 0; - } - // fall through for other keys - case WM_KEYDOWN: - key = Win_MapKey( lParam ); - if ( key == K_CTRL || key == K_ALT || key == K_RIGHT_ALT ) { - // let direct-input handle this because windows sends Alt-Gr - // as two events (ctrl then alt) - break; - } - Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, true, 0, NULL ); - break; - - case WM_SYSKEYUP: - case WM_KEYUP: - key = Win_MapKey( lParam ); - if ( key == K_PRINT_SCR ) { - // don't queue printscreen keys. Since windows doesn't send us key - // down events for this, we handle queueing them with DirectInput - break; - } else if ( key == K_CTRL || key == K_ALT || key == K_RIGHT_ALT ) { - // let direct-input handle this because windows sends Alt-Gr - // as two events (ctrl then alt) - break; - } - Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, false, 0, NULL ); - break; - - case WM_CHAR: - Sys_QueEvent( win32.sysMsgTime, SE_CHAR, wParam, 0, 0, NULL ); - break; - - case WM_NCLBUTTONDOWN: -// win32.movingWindow = true; - break; - - case WM_ENTERSIZEMOVE: - win32.movingWindow = true; - break; - - case WM_EXITSIZEMOVE: - win32.movingWindow = false; - break; - - case WM_SIZING: - WIN_Sizing(wParam, (RECT *)lParam); - break; - - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_MOUSEMOVE: { - break; - } - case WM_MOUSEWHEEL: { - int delta = GET_WHEEL_DELTA_WPARAM( wParam ) / WHEEL_DELTA; - int key = delta < 0 ? K_MWHEELDOWN : K_MWHEELUP; - delta = abs( delta ); - while( delta-- > 0 ) { - Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, true, 0, NULL ); - Sys_QueEvent( win32.sysMsgTime, SE_KEY, key, false, 0, NULL ); - } - break; - } - } - - return DefWindowProc( hWnd, uMsg, wParam, lParam ); -}