From bc26d0d6cdd1c28a0a243131468bf5f698dff18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Tue, 12 Feb 2019 15:43:54 +0100 Subject: Platform: Ensure classes match their header filename Also drop some unused files. Renamed: - `platform/iphone/sem_iphone.h` -> `semaphore_iphone.h` (same for `osx`) - `platform/uwp/gl_context_egl.h` -> `context_egl_uwp.h` - in `platform/windows`: `context_gl_win.h`, `crash_handler_win.h`, `godot_win.cpp`, `joypad.h` and `key_mapping_win.h` all renamed to use `windows`. Some classes renamed accordingly too. - `EditorExportAndroid` and `EditorExportUWP` renamed to `EditorExportPlatformAndroid` and `EditorExportPlatformUWP` - `power_android` and `power_osx` renamed to `PowerAndroid` and `PowerOSX` - `OSUWP` renamed to `OS_UWP` Dropped: - `platform/windows/ctxgl_procaddr.h` --- platform/windows/SCsub | 11 +- platform/windows/context_gl_win.cpp | 185 ---------- platform/windows/context_gl_win.h | 76 ---- platform/windows/context_gl_windows.cpp | 185 ++++++++++ platform/windows/context_gl_windows.h | 76 ++++ platform/windows/crash_handler_win.cpp | 216 ----------- platform/windows/crash_handler_win.h | 57 --- platform/windows/crash_handler_windows.cpp | 218 +++++++++++ platform/windows/crash_handler_windows.h | 57 +++ platform/windows/ctxgl_procaddr.cpp | 188 ---------- platform/windows/ctxgl_procaddr.h | 39 -- platform/windows/godot_win.cpp | 198 ---------- platform/windows/godot_windows.cpp | 199 ++++++++++ platform/windows/joypad.cpp | 558 ----------------------------- platform/windows/joypad.h | 148 -------- platform/windows/joypad_windows.cpp | 558 +++++++++++++++++++++++++++++ platform/windows/joypad_windows.h | 149 ++++++++ platform/windows/key_mapping_win.cpp | 253 ------------- platform/windows/key_mapping_win.h | 48 --- platform/windows/key_mapping_windows.cpp | 253 +++++++++++++ platform/windows/key_mapping_windows.h | 48 +++ platform/windows/os_windows.cpp | 6 +- platform/windows/os_windows.h | 8 +- platform/windows/power_windows.h | 6 +- 24 files changed, 1758 insertions(+), 1982 deletions(-) delete mode 100644 platform/windows/context_gl_win.cpp delete mode 100644 platform/windows/context_gl_win.h create mode 100644 platform/windows/context_gl_windows.cpp create mode 100644 platform/windows/context_gl_windows.h delete mode 100644 platform/windows/crash_handler_win.cpp delete mode 100644 platform/windows/crash_handler_win.h create mode 100644 platform/windows/crash_handler_windows.cpp create mode 100644 platform/windows/crash_handler_windows.h delete mode 100644 platform/windows/ctxgl_procaddr.cpp delete mode 100644 platform/windows/ctxgl_procaddr.h delete mode 100644 platform/windows/godot_win.cpp create mode 100644 platform/windows/godot_windows.cpp delete mode 100644 platform/windows/joypad.cpp delete mode 100644 platform/windows/joypad.h create mode 100644 platform/windows/joypad_windows.cpp create mode 100644 platform/windows/joypad_windows.h delete mode 100644 platform/windows/key_mapping_win.cpp delete mode 100644 platform/windows/key_mapping_win.h create mode 100644 platform/windows/key_mapping_windows.cpp create mode 100644 platform/windows/key_mapping_windows.h (limited to 'platform/windows') diff --git a/platform/windows/SCsub b/platform/windows/SCsub index e07d373c4b..892d734734 100644 --- a/platform/windows/SCsub +++ b/platform/windows/SCsub @@ -7,13 +7,12 @@ from platform_methods import run_in_subprocess import platform_windows_builders common_win = [ - "godot_win.cpp", - "context_gl_win.cpp", - "crash_handler_win.cpp", + "godot_windows.cpp", + "context_gl_windows.cpp", + "crash_handler_windows.cpp", "os_windows.cpp", - "ctxgl_procaddr.cpp", - "key_mapping_win.cpp", - "joypad.cpp", + "key_mapping_windows.cpp", + "joypad_windows.cpp", "power_windows.cpp", "windows_terminal_logger.cpp" ] diff --git a/platform/windows/context_gl_win.cpp b/platform/windows/context_gl_win.cpp deleted file mode 100644 index 9d267c699f..0000000000 --- a/platform/windows/context_gl_win.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/*************************************************************************/ -/* context_gl_win.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) - -// Author: Juan Linietsky , (C) 2008 - -#include "context_gl_win.h" - -#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 -#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 -#define WGL_CONTEXT_FLAGS_ARB 0x2094 -#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 -#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 -#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 - -typedef HGLRC(APIENTRY *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int *); - -void ContextGL_Win::release_current() { - - wglMakeCurrent(hDC, NULL); -} - -void ContextGL_Win::make_current() { - - wglMakeCurrent(hDC, hRC); -} - -int ContextGL_Win::get_window_width() { - - return OS::get_singleton()->get_video_mode().width; -} - -int ContextGL_Win::get_window_height() { - - return OS::get_singleton()->get_video_mode().height; -} - -void ContextGL_Win::swap_buffers() { - - SwapBuffers(hDC); -} - -void ContextGL_Win::set_use_vsync(bool p_use) { - - if (wglSwapIntervalEXT) { - wglSwapIntervalEXT(p_use ? 1 : 0); - } - use_vsync = p_use; -} - -bool ContextGL_Win::is_using_vsync() const { - - return use_vsync; -} - -#define _WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 - -Error ContextGL_Win::initialize() { - - static PIXELFORMATDESCRIPTOR pfd = { - sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor - 1, - PFD_DRAW_TO_WINDOW | // Format Must Support Window - PFD_SUPPORT_OPENGL | // Format Must Support OpenGL - PFD_DOUBLEBUFFER, - (BYTE)PFD_TYPE_RGBA, - (BYTE)(OS::get_singleton()->is_layered_allowed() ? 32 : 24), - (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, // Color Bits Ignored - (BYTE)(OS::get_singleton()->is_layered_allowed() ? 8 : 0), // Alpha Buffer - (BYTE)0, // Shift Bit Ignored - (BYTE)0, // No Accumulation Buffer - (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, // Accumulation Bits Ignored - (BYTE)24, // 24Bit Z-Buffer (Depth Buffer) - (BYTE)0, // No Stencil Buffer - (BYTE)0, // No Auxiliary Buffer - (BYTE)PFD_MAIN_PLANE, // Main Drawing Layer - (BYTE)0, // Reserved - 0, 0, 0 // Layer Masks Ignored - }; - - hDC = GetDC(hWnd); - if (!hDC) { - return ERR_CANT_CREATE; // Return FALSE - } - - pixel_format = ChoosePixelFormat(hDC, &pfd); - if (!pixel_format) // Did Windows Find A Matching Pixel Format? - { - return ERR_CANT_CREATE; // Return FALSE - } - - BOOL ret = SetPixelFormat(hDC, pixel_format, &pfd); - if (!ret) // Are We Able To Set The Pixel Format? - { - return ERR_CANT_CREATE; // Return FALSE - } - - hRC = wglCreateContext(hDC); - if (!hRC) // Are We Able To Get A Rendering Context? - { - return ERR_CANT_CREATE; // Return FALSE - } - - wglMakeCurrent(hDC, hRC); - - if (opengl_3_context) { - - int attribs[] = { - WGL_CONTEXT_MAJOR_VERSION_ARB, 3, //we want a 3.3 context - WGL_CONTEXT_MINOR_VERSION_ARB, 3, - //and it shall be forward compatible so that we can only use up to date functionality - WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, - WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /*| _WGL_CONTEXT_DEBUG_BIT_ARB*/, - 0 - }; //zero indicates the end of the array - - PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; //pointer to the method - wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); - - if (wglCreateContextAttribsARB == NULL) //OpenGL 3.0 is not supported - { - wglDeleteContext(hRC); - return ERR_CANT_CREATE; - } - - HGLRC new_hRC = wglCreateContextAttribsARB(hDC, 0, attribs); - if (!new_hRC) { - wglDeleteContext(hRC); - return ERR_CANT_CREATE; // Return false - } - wglMakeCurrent(hDC, NULL); - wglDeleteContext(hRC); - hRC = new_hRC; - - if (!wglMakeCurrent(hDC, hRC)) // Try To Activate The Rendering Context - { - return ERR_CANT_CREATE; // Return FALSE - } - } - - wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); - //glWrapperInit(wrapper_get_proc_address); - - return OK; -} - -ContextGL_Win::ContextGL_Win(HWND hwnd, bool p_opengl_3_context) { - - opengl_3_context = p_opengl_3_context; - hWnd = hwnd; - use_vsync = false; -} - -ContextGL_Win::~ContextGL_Win() { -} - -#endif diff --git a/platform/windows/context_gl_win.h b/platform/windows/context_gl_win.h deleted file mode 100644 index 3076bbb1e8..0000000000 --- a/platform/windows/context_gl_win.h +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************/ -/* context_gl_win.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) - -// Author: Juan Linietsky , (C) 2008 - -#ifndef CONTEXT_GL_WIN_H -#define CONTEXT_GL_WIN_H - -#include "core/error_list.h" -#include "core/os/os.h" -#include "drivers/gl_context/context_gl.h" - -#include - -typedef bool(APIENTRY *PFNWGLSWAPINTERVALEXTPROC)(int interval); - -class ContextGL_Win : public ContextGL { - - HDC hDC; - HGLRC hRC; - unsigned int pixel_format; - HWND hWnd; - bool opengl_3_context; - bool use_vsync; - - PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; - -public: - virtual void release_current(); - - virtual void make_current(); - - virtual int get_window_width(); - virtual int get_window_height(); - virtual void swap_buffers(); - - virtual Error initialize(); - - virtual void set_use_vsync(bool p_use); - virtual bool is_using_vsync() const; - - ContextGL_Win(HWND hwnd, bool p_opengl_3_context); - virtual ~ContextGL_Win(); -}; - -#endif -#endif diff --git a/platform/windows/context_gl_windows.cpp b/platform/windows/context_gl_windows.cpp new file mode 100644 index 0000000000..e715999378 --- /dev/null +++ b/platform/windows/context_gl_windows.cpp @@ -0,0 +1,185 @@ +/*************************************************************************/ +/* context_gl_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) + +// Author: Juan Linietsky , (C) 2008 + +#include "context_gl_windows.h" + +#define WGL_CONTEXT_MAJOR_VERSION_ARB 0x2091 +#define WGL_CONTEXT_MINOR_VERSION_ARB 0x2092 +#define WGL_CONTEXT_FLAGS_ARB 0x2094 +#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 +#define WGL_CONTEXT_PROFILE_MASK_ARB 0x9126 +#define WGL_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 + +typedef HGLRC(APIENTRY *PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int *); + +void ContextGL_Windows::release_current() { + + wglMakeCurrent(hDC, NULL); +} + +void ContextGL_Windows::make_current() { + + wglMakeCurrent(hDC, hRC); +} + +int ContextGL_Windows::get_window_width() { + + return OS::get_singleton()->get_video_mode().width; +} + +int ContextGL_Windows::get_window_height() { + + return OS::get_singleton()->get_video_mode().height; +} + +void ContextGL_Windows::swap_buffers() { + + SwapBuffers(hDC); +} + +void ContextGL_Windows::set_use_vsync(bool p_use) { + + if (wglSwapIntervalEXT) { + wglSwapIntervalEXT(p_use ? 1 : 0); + } + use_vsync = p_use; +} + +bool ContextGL_Windows::is_using_vsync() const { + + return use_vsync; +} + +#define _WGL_CONTEXT_DEBUG_BIT_ARB 0x0001 + +Error ContextGL_Windows::initialize() { + + static PIXELFORMATDESCRIPTOR pfd = { + sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor + 1, + PFD_DRAW_TO_WINDOW | // Format Must Support Window + PFD_SUPPORT_OPENGL | // Format Must Support OpenGL + PFD_DOUBLEBUFFER, + (BYTE)PFD_TYPE_RGBA, + (BYTE)(OS::get_singleton()->is_layered_allowed() ? 32 : 24), + (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, // Color Bits Ignored + (BYTE)(OS::get_singleton()->is_layered_allowed() ? 8 : 0), // Alpha Buffer + (BYTE)0, // Shift Bit Ignored + (BYTE)0, // No Accumulation Buffer + (BYTE)0, (BYTE)0, (BYTE)0, (BYTE)0, // Accumulation Bits Ignored + (BYTE)24, // 24Bit Z-Buffer (Depth Buffer) + (BYTE)0, // No Stencil Buffer + (BYTE)0, // No Auxiliary Buffer + (BYTE)PFD_MAIN_PLANE, // Main Drawing Layer + (BYTE)0, // Reserved + 0, 0, 0 // Layer Masks Ignored + }; + + hDC = GetDC(hWnd); + if (!hDC) { + return ERR_CANT_CREATE; // Return FALSE + } + + pixel_format = ChoosePixelFormat(hDC, &pfd); + if (!pixel_format) // Did Windows Find A Matching Pixel Format? + { + return ERR_CANT_CREATE; // Return FALSE + } + + BOOL ret = SetPixelFormat(hDC, pixel_format, &pfd); + if (!ret) // Are We Able To Set The Pixel Format? + { + return ERR_CANT_CREATE; // Return FALSE + } + + hRC = wglCreateContext(hDC); + if (!hRC) // Are We Able To Get A Rendering Context? + { + return ERR_CANT_CREATE; // Return FALSE + } + + wglMakeCurrent(hDC, hRC); + + if (opengl_3_context) { + + int attribs[] = { + WGL_CONTEXT_MAJOR_VERSION_ARB, 3, //we want a 3.3 context + WGL_CONTEXT_MINOR_VERSION_ARB, 3, + //and it shall be forward compatible so that we can only use up to date functionality + WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, + WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB /*| _WGL_CONTEXT_DEBUG_BIT_ARB*/, + 0 + }; //zero indicates the end of the array + + PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; //pointer to the method + wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB"); + + if (wglCreateContextAttribsARB == NULL) //OpenGL 3.0 is not supported + { + wglDeleteContext(hRC); + return ERR_CANT_CREATE; + } + + HGLRC new_hRC = wglCreateContextAttribsARB(hDC, 0, attribs); + if (!new_hRC) { + wglDeleteContext(hRC); + return ERR_CANT_CREATE; // Return false + } + wglMakeCurrent(hDC, NULL); + wglDeleteContext(hRC); + hRC = new_hRC; + + if (!wglMakeCurrent(hDC, hRC)) // Try To Activate The Rendering Context + { + return ERR_CANT_CREATE; // Return FALSE + } + } + + wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT"); + //glWrapperInit(wrapper_get_proc_address); + + return OK; +} + +ContextGL_Windows::ContextGL_Windows(HWND hwnd, bool p_opengl_3_context) { + + opengl_3_context = p_opengl_3_context; + hWnd = hwnd; + use_vsync = false; +} + +ContextGL_Windows::~ContextGL_Windows() { +} + +#endif diff --git a/platform/windows/context_gl_windows.h b/platform/windows/context_gl_windows.h new file mode 100644 index 0000000000..09801b9146 --- /dev/null +++ b/platform/windows/context_gl_windows.h @@ -0,0 +1,76 @@ +/*************************************************************************/ +/* context_gl_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#if defined(OPENGL_ENABLED) || defined(GLES_ENABLED) + +// Author: Juan Linietsky , (C) 2008 + +#ifndef CONTEXT_GL_WIN_H +#define CONTEXT_GL_WIN_H + +#include "core/error_list.h" +#include "core/os/os.h" +#include "drivers/gl_context/context_gl.h" + +#include + +typedef bool(APIENTRY *PFNWGLSWAPINTERVALEXTPROC)(int interval); + +class ContextGL_Windows : public ContextGL { + + HDC hDC; + HGLRC hRC; + unsigned int pixel_format; + HWND hWnd; + bool opengl_3_context; + bool use_vsync; + + PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; + +public: + virtual void release_current(); + + virtual void make_current(); + + virtual int get_window_width(); + virtual int get_window_height(); + virtual void swap_buffers(); + + virtual Error initialize(); + + virtual void set_use_vsync(bool p_use); + virtual bool is_using_vsync() const; + + ContextGL_Windows(HWND hwnd, bool p_opengl_3_context); + virtual ~ContextGL_Windows(); +}; + +#endif +#endif diff --git a/platform/windows/crash_handler_win.cpp b/platform/windows/crash_handler_win.cpp deleted file mode 100644 index 1d93c6d8dd..0000000000 --- a/platform/windows/crash_handler_win.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************/ -/* crash_handler_win.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "core/project_settings.h" -#include "main/main.h" -#include "os_windows.h" - -#ifdef CRASH_HANDLER_EXCEPTION - -// Backtrace code code based on: https://stackoverflow.com/questions/6205981/windows-c-stack-trace-from-a-running-app - -#include -#include -#include - -#pragma comment(lib, "psapi.lib") -#pragma comment(lib, "dbghelp.lib") - -// Some versions of imagehlp.dll lack the proper packing directives themselves -// so we need to do it. -#pragma pack(push, before_imagehlp, 8) -#include -#pragma pack(pop, before_imagehlp) - -struct module_data { - std::string image_name; - std::string module_name; - void *base_address; - DWORD load_size; -}; - -class symbol { - typedef IMAGEHLP_SYMBOL64 sym_type; - sym_type *sym; - static const int max_name_len = 1024; - -public: - symbol(HANDLE process, DWORD64 address) : - sym((sym_type *)::operator new(sizeof(*sym) + max_name_len)) { - memset(sym, '\0', sizeof(*sym) + max_name_len); - sym->SizeOfStruct = sizeof(*sym); - sym->MaxNameLength = max_name_len; - DWORD64 displacement; - - SymGetSymFromAddr64(process, address, &displacement, sym); - } - - std::string name() { return std::string(sym->Name); } - std::string undecorated_name() { - if (*sym->Name == '\0') - return ""; - std::vector und_name(max_name_len); - UnDecorateSymbolName(sym->Name, &und_name[0], max_name_len, UNDNAME_COMPLETE); - return std::string(&und_name[0], strlen(&und_name[0])); - } -}; - -class get_mod_info { - HANDLE process; - -public: - get_mod_info(HANDLE h) : - process(h) {} - - module_data operator()(HMODULE module) { - module_data ret; - char temp[4096]; - MODULEINFO mi; - - GetModuleInformation(process, module, &mi, sizeof(mi)); - ret.base_address = mi.lpBaseOfDll; - ret.load_size = mi.SizeOfImage; - - GetModuleFileNameEx(process, module, temp, sizeof(temp)); - ret.image_name = temp; - GetModuleBaseName(process, module, temp, sizeof(temp)); - ret.module_name = temp; - std::vector img(ret.image_name.begin(), ret.image_name.end()); - std::vector mod(ret.module_name.begin(), ret.module_name.end()); - SymLoadModule64(process, 0, &img[0], &mod[0], (DWORD64)ret.base_address, ret.load_size); - return ret; - } -}; - -DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) { - HANDLE process = GetCurrentProcess(); - HANDLE hThread = GetCurrentThread(); - DWORD offset_from_symbol = 0; - IMAGEHLP_LINE64 line = { 0 }; - std::vector modules; - DWORD cbNeeded; - std::vector module_handles(1); - - if (OS::get_singleton() == NULL || OS::get_singleton()->is_disable_crash_handler() || IsDebuggerPresent()) { - return EXCEPTION_CONTINUE_SEARCH; - } - - fprintf(stderr, "%s: Program crashed\n", __FUNCTION__); - - if (OS::get_singleton()->get_main_loop()) - OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); - - // Load the symbols: - if (!SymInitialize(process, NULL, false)) - return EXCEPTION_CONTINUE_SEARCH; - - SymSetOptions(SymGetOptions() | SYMOPT_LOAD_LINES | SYMOPT_UNDNAME); - EnumProcessModules(process, &module_handles[0], module_handles.size() * sizeof(HMODULE), &cbNeeded); - module_handles.resize(cbNeeded / sizeof(HMODULE)); - EnumProcessModules(process, &module_handles[0], module_handles.size() * sizeof(HMODULE), &cbNeeded); - std::transform(module_handles.begin(), module_handles.end(), std::back_inserter(modules), get_mod_info(process)); - void *base = modules[0].base_address; - - // Setup stuff: - CONTEXT *context = ep->ContextRecord; - STACKFRAME64 frame; - bool skip_first = false; - - frame.AddrPC.Mode = AddrModeFlat; - frame.AddrStack.Mode = AddrModeFlat; - frame.AddrFrame.Mode = AddrModeFlat; - -#ifdef _M_X64 - frame.AddrPC.Offset = context->Rip; - frame.AddrStack.Offset = context->Rsp; - frame.AddrFrame.Offset = context->Rbp; -#else - frame.AddrPC.Offset = context->Eip; - frame.AddrStack.Offset = context->Esp; - frame.AddrFrame.Offset = context->Ebp; - - // Skip the first one to avoid a duplicate on 32-bit mode - skip_first = true; -#endif - - line.SizeOfStruct = sizeof(line); - IMAGE_NT_HEADERS *h = ImageNtHeader(base); - DWORD image_type = h->FileHeader.Machine; - int n = 0; - String msg = GLOBAL_GET("debug/settings/crash_handler/message"); - - fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); - - do { - if (skip_first) { - skip_first = false; - } else { - if (frame.AddrPC.Offset != 0) { - std::string fnName = symbol(process, frame.AddrPC.Offset).undecorated_name(); - - if (SymGetLineFromAddr64(process, frame.AddrPC.Offset, &offset_from_symbol, &line)) - fprintf(stderr, "[%d] %s (%s:%d)\n", n, fnName.c_str(), line.FileName, line.LineNumber); - else - fprintf(stderr, "[%d] %s\n", n, fnName.c_str()); - } else - fprintf(stderr, "[%d] ???\n", n); - - n++; - } - - if (!StackWalk64(image_type, process, hThread, &frame, context, NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL)) - break; - } while (frame.AddrReturn.Offset != 0 && n < 256); - - fprintf(stderr, "-- END OF BACKTRACE --\n"); - - SymCleanup(process); - - // Pass the exception to the OS - return EXCEPTION_CONTINUE_SEARCH; -} -#endif - -CrashHandler::CrashHandler() { - disabled = false; -} - -CrashHandler::~CrashHandler() { -} - -void CrashHandler::disable() { - if (disabled) - return; - - disabled = true; -} - -void CrashHandler::initialize() { -} diff --git a/platform/windows/crash_handler_win.h b/platform/windows/crash_handler_win.h deleted file mode 100644 index 016612a00e..0000000000 --- a/platform/windows/crash_handler_win.h +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************/ -/* crash_handler_win.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CRASH_HANDLER_WIN_H -#define CRASH_HANDLER_WIN_H - -#include - -// Crash handler exception only enabled with MSVC -#if defined(DEBUG_ENABLED) && defined(MSVC) -#define CRASH_HANDLER_EXCEPTION 1 - -extern DWORD CrashHandlerException(EXCEPTION_POINTERS *ep); -#endif - -class CrashHandler { - - bool disabled; - -public: - void initialize(); - - void disable(); - bool is_disabled() const { return disabled; }; - - CrashHandler(); - ~CrashHandler(); -}; - -#endif diff --git a/platform/windows/crash_handler_windows.cpp b/platform/windows/crash_handler_windows.cpp new file mode 100644 index 0000000000..f93a449c7b --- /dev/null +++ b/platform/windows/crash_handler_windows.cpp @@ -0,0 +1,218 @@ +/*************************************************************************/ +/* crash_handler_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "crash_handler_windows.h" + +#include "core/project_settings.h" +#include "main/main.h" +#include "os_windows.h" + +#ifdef CRASH_HANDLER_EXCEPTION + +// Backtrace code code based on: https://stackoverflow.com/questions/6205981/windows-c-stack-trace-from-a-running-app + +#include +#include +#include + +#pragma comment(lib, "psapi.lib") +#pragma comment(lib, "dbghelp.lib") + +// Some versions of imagehlp.dll lack the proper packing directives themselves +// so we need to do it. +#pragma pack(push, before_imagehlp, 8) +#include +#pragma pack(pop, before_imagehlp) + +struct module_data { + std::string image_name; + std::string module_name; + void *base_address; + DWORD load_size; +}; + +class symbol { + typedef IMAGEHLP_SYMBOL64 sym_type; + sym_type *sym; + static const int max_name_len = 1024; + +public: + symbol(HANDLE process, DWORD64 address) : + sym((sym_type *)::operator new(sizeof(*sym) + max_name_len)) { + memset(sym, '\0', sizeof(*sym) + max_name_len); + sym->SizeOfStruct = sizeof(*sym); + sym->MaxNameLength = max_name_len; + DWORD64 displacement; + + SymGetSymFromAddr64(process, address, &displacement, sym); + } + + std::string name() { return std::string(sym->Name); } + std::string undecorated_name() { + if (*sym->Name == '\0') + return ""; + std::vector und_name(max_name_len); + UnDecorateSymbolName(sym->Name, &und_name[0], max_name_len, UNDNAME_COMPLETE); + return std::string(&und_name[0], strlen(&und_name[0])); + } +}; + +class get_mod_info { + HANDLE process; + +public: + get_mod_info(HANDLE h) : + process(h) {} + + module_data operator()(HMODULE module) { + module_data ret; + char temp[4096]; + MODULEINFO mi; + + GetModuleInformation(process, module, &mi, sizeof(mi)); + ret.base_address = mi.lpBaseOfDll; + ret.load_size = mi.SizeOfImage; + + GetModuleFileNameEx(process, module, temp, sizeof(temp)); + ret.image_name = temp; + GetModuleBaseName(process, module, temp, sizeof(temp)); + ret.module_name = temp; + std::vector img(ret.image_name.begin(), ret.image_name.end()); + std::vector mod(ret.module_name.begin(), ret.module_name.end()); + SymLoadModule64(process, 0, &img[0], &mod[0], (DWORD64)ret.base_address, ret.load_size); + return ret; + } +}; + +DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) { + HANDLE process = GetCurrentProcess(); + HANDLE hThread = GetCurrentThread(); + DWORD offset_from_symbol = 0; + IMAGEHLP_LINE64 line = { 0 }; + std::vector modules; + DWORD cbNeeded; + std::vector module_handles(1); + + if (OS::get_singleton() == NULL || OS::get_singleton()->is_disable_crash_handler() || IsDebuggerPresent()) { + return EXCEPTION_CONTINUE_SEARCH; + } + + fprintf(stderr, "%s: Program crashed\n", __FUNCTION__); + + if (OS::get_singleton()->get_main_loop()) + OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); + + // Load the symbols: + if (!SymInitialize(process, NULL, false)) + return EXCEPTION_CONTINUE_SEARCH; + + SymSetOptions(SymGetOptions() | SYMOPT_LOAD_LINES | SYMOPT_UNDNAME); + EnumProcessModules(process, &module_handles[0], module_handles.size() * sizeof(HMODULE), &cbNeeded); + module_handles.resize(cbNeeded / sizeof(HMODULE)); + EnumProcessModules(process, &module_handles[0], module_handles.size() * sizeof(HMODULE), &cbNeeded); + std::transform(module_handles.begin(), module_handles.end(), std::back_inserter(modules), get_mod_info(process)); + void *base = modules[0].base_address; + + // Setup stuff: + CONTEXT *context = ep->ContextRecord; + STACKFRAME64 frame; + bool skip_first = false; + + frame.AddrPC.Mode = AddrModeFlat; + frame.AddrStack.Mode = AddrModeFlat; + frame.AddrFrame.Mode = AddrModeFlat; + +#ifdef _M_X64 + frame.AddrPC.Offset = context->Rip; + frame.AddrStack.Offset = context->Rsp; + frame.AddrFrame.Offset = context->Rbp; +#else + frame.AddrPC.Offset = context->Eip; + frame.AddrStack.Offset = context->Esp; + frame.AddrFrame.Offset = context->Ebp; + + // Skip the first one to avoid a duplicate on 32-bit mode + skip_first = true; +#endif + + line.SizeOfStruct = sizeof(line); + IMAGE_NT_HEADERS *h = ImageNtHeader(base); + DWORD image_type = h->FileHeader.Machine; + int n = 0; + String msg = GLOBAL_GET("debug/settings/crash_handler/message"); + + fprintf(stderr, "Dumping the backtrace. %ls\n", msg.c_str()); + + do { + if (skip_first) { + skip_first = false; + } else { + if (frame.AddrPC.Offset != 0) { + std::string fnName = symbol(process, frame.AddrPC.Offset).undecorated_name(); + + if (SymGetLineFromAddr64(process, frame.AddrPC.Offset, &offset_from_symbol, &line)) + fprintf(stderr, "[%d] %s (%s:%d)\n", n, fnName.c_str(), line.FileName, line.LineNumber); + else + fprintf(stderr, "[%d] %s\n", n, fnName.c_str()); + } else + fprintf(stderr, "[%d] ???\n", n); + + n++; + } + + if (!StackWalk64(image_type, process, hThread, &frame, context, NULL, SymFunctionTableAccess64, SymGetModuleBase64, NULL)) + break; + } while (frame.AddrReturn.Offset != 0 && n < 256); + + fprintf(stderr, "-- END OF BACKTRACE --\n"); + + SymCleanup(process); + + // Pass the exception to the OS + return EXCEPTION_CONTINUE_SEARCH; +} +#endif + +CrashHandler::CrashHandler() { + disabled = false; +} + +CrashHandler::~CrashHandler() { +} + +void CrashHandler::disable() { + if (disabled) + return; + + disabled = true; +} + +void CrashHandler::initialize() { +} diff --git a/platform/windows/crash_handler_windows.h b/platform/windows/crash_handler_windows.h new file mode 100644 index 0000000000..eba72beb7e --- /dev/null +++ b/platform/windows/crash_handler_windows.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* crash_handler_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef CRASH_HANDLER_WINDOWS_H +#define CRASH_HANDLER_WINDOWS_H + +#include + +// Crash handler exception only enabled with MSVC +#if defined(DEBUG_ENABLED) && defined(MSVC) +#define CRASH_HANDLER_EXCEPTION 1 + +extern DWORD CrashHandlerException(EXCEPTION_POINTERS *ep); +#endif + +class CrashHandler { + + bool disabled; + +public: + void initialize(); + + void disable(); + bool is_disabled() const { return disabled; }; + + CrashHandler(); + ~CrashHandler(); +}; + +#endif // CRASH_HANDLER_WINDOWS_H diff --git a/platform/windows/ctxgl_procaddr.cpp b/platform/windows/ctxgl_procaddr.cpp deleted file mode 100644 index ecff8f7a4d..0000000000 --- a/platform/windows/ctxgl_procaddr.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/*************************************************************************/ -/* ctxgl_procaddr.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifdef OPENGL_ENABLED -#include "ctxgl_procaddr.h" -#include -#include - -static PROC _gl_procs[] = { - (PROC)glCullFace, - (PROC)glFrontFace, - (PROC)glHint, - (PROC)glLineWidth, - (PROC)glPointSize, - (PROC)glPolygonMode, - (PROC)glScissor, - (PROC)glTexParameterf, - (PROC)glTexParameterfv, - (PROC)glTexParameteri, - (PROC)glTexParameteriv, - (PROC)glTexImage1D, - (PROC)glTexImage2D, - (PROC)glDrawBuffer, - (PROC)glClear, - (PROC)glClearColor, - (PROC)glClearStencil, - (PROC)glClearDepth, - (PROC)glStencilMask, - (PROC)glColorMask, - (PROC)glDepthMask, - (PROC)glDisable, - (PROC)glEnable, - (PROC)glFinish, - (PROC)glFlush, - (PROC)glBlendFunc, - (PROC)glLogicOp, - (PROC)glStencilFunc, - (PROC)glStencilOp, - (PROC)glDepthFunc, - (PROC)glPixelStoref, - (PROC)glPixelStorei, - (PROC)glReadBuffer, - (PROC)glReadPixels, - (PROC)glGetBooleanv, - (PROC)glGetDoublev, - (PROC)glGetError, - (PROC)glGetFloatv, - (PROC)glGetIntegerv, - (PROC)glGetString, - (PROC)glGetTexImage, - (PROC)glGetTexParameterfv, - (PROC)glGetTexParameteriv, - (PROC)glGetTexLevelParameterfv, - (PROC)glGetTexLevelParameteriv, - (PROC)glIsEnabled, - (PROC)glDepthRange, - (PROC)glViewport, - /* not detected in ATI */ - (PROC)glDrawArrays, - (PROC)glDrawElements, - (PROC)glGetPointerv, - (PROC)glPolygonOffset, - (PROC)glCopyTexImage1D, - (PROC)glCopyTexImage2D, - (PROC)glCopyTexSubImage1D, - (PROC)glCopyTexSubImage2D, - (PROC)glTexSubImage1D, - (PROC)glTexSubImage2D, - (PROC)glBindTexture, - (PROC)glDeleteTextures, - (PROC)glGenTextures, - (PROC)glIsTexture, - - 0 -}; - -static const char *_gl_proc_names[] = { - "glCullFace", - "glFrontFace", - "glHint", - "glLineWidth", - "glPointSize", - "glPolygonMode", - "glScissor", - "glTexParameterf", - "glTexParameterfv", - "glTexParameteri", - "glTexParameteriv", - "glTexImage1D", - "glTexImage2D", - "glDrawBuffer", - "glClear", - "glClearColor", - "glClearStencil", - "glClearDepth", - "glStencilMask", - "glColorMask", - "glDepthMask", - "glDisable", - "glEnable", - "glFinish", - "glFlush", - "glBlendFunc", - "glLogicOp", - "glStencilFunc", - "glStencilOp", - "glDepthFunc", - "glPixelStoref", - "glPixelStorei", - "glReadBuffer", - "glReadPixels", - "glGetBooleanv", - "glGetDoublev", - "glGetError", - "glGetFloatv", - "glGetIntegerv", - "glGetString", - "glGetTexImage", - "glGetTexParameterfv", - "glGetTexParameteriv", - "glGetTexLevelParameterfv", - "glGetTexLevelParameteriv", - "glIsEnabled", - "glDepthRange", - "glViewport", - /* not detected in ati */ - "glDrawArrays", - "glDrawElements", - "glGetPointerv", - "glPolygonOffset", - "glCopyTexImage1D", - "glCopyTexImage2D", - "glCopyTexSubImage1D", - "glCopyTexSubImage2D", - "glTexSubImage1D", - "glTexSubImage2D", - "glBindTexture", - "glDeleteTextures", - "glGenTextures", - "glIsTexture", - - 0 -}; - -PROC get_gl_proc_address(const char *p_address) { - - PROC proc = wglGetProcAddress((const CHAR *)p_address); - if (!proc) { - - int i = 0; - while (_gl_procs[i]) { - - if (strcmp(p_address, _gl_proc_names[i]) == 0) { - return _gl_procs[i]; - } - i++; - } - } - return proc; -} -#endif diff --git a/platform/windows/ctxgl_procaddr.h b/platform/windows/ctxgl_procaddr.h deleted file mode 100644 index cc40804ae6..0000000000 --- a/platform/windows/ctxgl_procaddr.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************/ -/* ctxgl_procaddr.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CTXGL_PROCADDR_H -#define CTXGL_PROCADDR_H - -#ifdef OPENGL_ENABLED -#include - -PROC get_gl_proc_address(const char *p_address); -#endif -#endif // CTXGL_PROCADDR_H diff --git a/platform/windows/godot_win.cpp b/platform/windows/godot_win.cpp deleted file mode 100644 index 0f5065d816..0000000000 --- a/platform/windows/godot_win.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/*************************************************************************/ -/* godot_win.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "main/main.h" -#include "os_windows.h" -#include -#include - -PCHAR * -CommandLineToArgvA( - PCHAR CmdLine, - int *_argc) { - PCHAR *argv; - PCHAR _argv; - ULONG len; - ULONG argc; - CHAR a; - ULONG i, j; - - BOOLEAN in_QM; - BOOLEAN in_TEXT; - BOOLEAN in_SPACE; - - len = strlen(CmdLine); - i = ((len + 2) / 2) * sizeof(PVOID) + sizeof(PVOID); - - argv = (PCHAR *)GlobalAlloc(GMEM_FIXED, - i + (len + 2) * sizeof(CHAR)); - - _argv = (PCHAR)(((PUCHAR)argv) + i); - - argc = 0; - argv[argc] = _argv; - in_QM = FALSE; - in_TEXT = FALSE; - in_SPACE = TRUE; - i = 0; - j = 0; - - while ((a = CmdLine[i])) { - if (in_QM) { - if (a == '\"') { - in_QM = FALSE; - } else { - _argv[j] = a; - j++; - } - } else { - switch (a) { - case '\"': - in_QM = TRUE; - in_TEXT = TRUE; - if (in_SPACE) { - argv[argc] = _argv + j; - argc++; - } - in_SPACE = FALSE; - break; - case ' ': - case '\t': - case '\n': - case '\r': - if (in_TEXT) { - _argv[j] = '\0'; - j++; - } - in_TEXT = FALSE; - in_SPACE = TRUE; - break; - default: - in_TEXT = TRUE; - if (in_SPACE) { - argv[argc] = _argv + j; - argc++; - } - _argv[j] = a; - j++; - in_SPACE = FALSE; - break; - } - } - i++; - } - _argv[j] = '\0'; - argv[argc] = NULL; - - (*_argc) = argc; - return argv; -} - -char *wc_to_utf8(const wchar_t *wc) { - int ulen = WideCharToMultiByte(CP_UTF8, 0, wc, -1, NULL, 0, NULL, NULL); - char *ubuf = new char[ulen + 1]; - WideCharToMultiByte(CP_UTF8, 0, wc, -1, ubuf, ulen, NULL, NULL); - ubuf[ulen] = 0; - return ubuf; -} - -int widechar_main(int argc, wchar_t **argv) { - - OS_Windows os(NULL); - - setlocale(LC_CTYPE, ""); - - char **argv_utf8 = new char *[argc]; - - for (int i = 0; i < argc; ++i) { - argv_utf8[i] = wc_to_utf8(argv[i]); - } - - Error err = Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]); - - if (err != OK) { - for (int i = 0; i < argc; ++i) { - delete[] argv_utf8[i]; - } - delete[] argv_utf8; - return 255; - } - - if (Main::start()) - os.run(); - Main::cleanup(); - - for (int i = 0; i < argc; ++i) { - delete[] argv_utf8[i]; - } - delete[] argv_utf8; - - return os.get_exit_code(); -}; - -int _main() { - LPWSTR *wc_argv; - int argc; - int result; - - wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc); - - if (NULL == wc_argv) { - wprintf(L"CommandLineToArgvW failed\n"); - return 0; - } - - result = widechar_main(argc, wc_argv); - - LocalFree(wc_argv); - return result; -} - -int main(int _argc, char **_argv) { - // _argc and _argv are ignored - // we are going to use the WideChar version of them instead - -#ifdef CRASH_HANDLER_EXCEPTION - __try { - return _main(); - } __except (CrashHandlerException(GetExceptionInformation())) { - return 1; - } -#else - return _main(); -#endif -} - -HINSTANCE godot_hinstance = NULL; - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { - godot_hinstance = hInstance; - return main(0, NULL); -} diff --git a/platform/windows/godot_windows.cpp b/platform/windows/godot_windows.cpp new file mode 100644 index 0000000000..0b52682c7c --- /dev/null +++ b/platform/windows/godot_windows.cpp @@ -0,0 +1,199 @@ +/*************************************************************************/ +/* godot_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "main/main.h" +#include "os_windows.h" + +#include +#include + +PCHAR * +CommandLineToArgvA( + PCHAR CmdLine, + int *_argc) { + PCHAR *argv; + PCHAR _argv; + ULONG len; + ULONG argc; + CHAR a; + ULONG i, j; + + BOOLEAN in_QM; + BOOLEAN in_TEXT; + BOOLEAN in_SPACE; + + len = strlen(CmdLine); + i = ((len + 2) / 2) * sizeof(PVOID) + sizeof(PVOID); + + argv = (PCHAR *)GlobalAlloc(GMEM_FIXED, + i + (len + 2) * sizeof(CHAR)); + + _argv = (PCHAR)(((PUCHAR)argv) + i); + + argc = 0; + argv[argc] = _argv; + in_QM = FALSE; + in_TEXT = FALSE; + in_SPACE = TRUE; + i = 0; + j = 0; + + while ((a = CmdLine[i])) { + if (in_QM) { + if (a == '\"') { + in_QM = FALSE; + } else { + _argv[j] = a; + j++; + } + } else { + switch (a) { + case '\"': + in_QM = TRUE; + in_TEXT = TRUE; + if (in_SPACE) { + argv[argc] = _argv + j; + argc++; + } + in_SPACE = FALSE; + break; + case ' ': + case '\t': + case '\n': + case '\r': + if (in_TEXT) { + _argv[j] = '\0'; + j++; + } + in_TEXT = FALSE; + in_SPACE = TRUE; + break; + default: + in_TEXT = TRUE; + if (in_SPACE) { + argv[argc] = _argv + j; + argc++; + } + _argv[j] = a; + j++; + in_SPACE = FALSE; + break; + } + } + i++; + } + _argv[j] = '\0'; + argv[argc] = NULL; + + (*_argc) = argc; + return argv; +} + +char *wc_to_utf8(const wchar_t *wc) { + int ulen = WideCharToMultiByte(CP_UTF8, 0, wc, -1, NULL, 0, NULL, NULL); + char *ubuf = new char[ulen + 1]; + WideCharToMultiByte(CP_UTF8, 0, wc, -1, ubuf, ulen, NULL, NULL); + ubuf[ulen] = 0; + return ubuf; +} + +int widechar_main(int argc, wchar_t **argv) { + + OS_Windows os(NULL); + + setlocale(LC_CTYPE, ""); + + char **argv_utf8 = new char *[argc]; + + for (int i = 0; i < argc; ++i) { + argv_utf8[i] = wc_to_utf8(argv[i]); + } + + Error err = Main::setup(argv_utf8[0], argc - 1, &argv_utf8[1]); + + if (err != OK) { + for (int i = 0; i < argc; ++i) { + delete[] argv_utf8[i]; + } + delete[] argv_utf8; + return 255; + } + + if (Main::start()) + os.run(); + Main::cleanup(); + + for (int i = 0; i < argc; ++i) { + delete[] argv_utf8[i]; + } + delete[] argv_utf8; + + return os.get_exit_code(); +}; + +int _main() { + LPWSTR *wc_argv; + int argc; + int result; + + wc_argv = CommandLineToArgvW(GetCommandLineW(), &argc); + + if (NULL == wc_argv) { + wprintf(L"CommandLineToArgvW failed\n"); + return 0; + } + + result = widechar_main(argc, wc_argv); + + LocalFree(wc_argv); + return result; +} + +int main(int _argc, char **_argv) { + // _argc and _argv are ignored + // we are going to use the WideChar version of them instead + +#ifdef CRASH_HANDLER_EXCEPTION + __try { + return _main(); + } __except (CrashHandlerException(GetExceptionInformation())) { + return 1; + } +#else + return _main(); +#endif +} + +HINSTANCE godot_hinstance = NULL; + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { + godot_hinstance = hInstance; + return main(0, NULL); +} diff --git a/platform/windows/joypad.cpp b/platform/windows/joypad.cpp deleted file mode 100644 index 5fafc7c8c0..0000000000 --- a/platform/windows/joypad.cpp +++ /dev/null @@ -1,558 +0,0 @@ -/*************************************************************************/ -/* joypad.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "joypad.h" - -#include -#include - -#ifndef __GNUC__ -#define __builtin_bswap32 _byteswap_ulong -#endif - -DWORD WINAPI _xinput_get_state(DWORD dwUserIndex, XINPUT_STATE *pState) { - return ERROR_DEVICE_NOT_CONNECTED; -} -DWORD WINAPI _xinput_set_state(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration) { - return ERROR_DEVICE_NOT_CONNECTED; -} - -JoypadWindows::JoypadWindows() { -} - -JoypadWindows::JoypadWindows(InputDefault *_input, HWND *hwnd) { - - input = _input; - hWnd = hwnd; - joypad_count = 0; - dinput = NULL; - xinput_dll = NULL; - xinput_get_state = NULL; - xinput_set_state = NULL; - - load_xinput(); - - for (int i = 0; i < JOYPADS_MAX; i++) - attached_joypads[i] = false; - - HRESULT result; - result = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&dinput, NULL); - if (FAILED(result)) { - printf("failed init DINPUT: %ld\n", result); - } - probe_joypads(); -} - -JoypadWindows::~JoypadWindows() { - - close_joypad(); - dinput->Release(); - unload_xinput(); -} - -bool JoypadWindows::have_device(const GUID &p_guid) { - - for (int i = 0; i < JOYPADS_MAX; i++) { - - if (d_joypads[i].guid == p_guid) { - - d_joypads[i].confirmed = true; - return true; - } - } - return false; -} - -// adapted from SDL2, works a lot better than the MSDN version -bool JoypadWindows::is_xinput_device(const GUID *p_guid) { - - static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; - static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; - static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; - - if (p_guid == &IID_ValveStreamingGamepad || p_guid == &IID_X360WiredGamepad || p_guid == &IID_X360WirelessGamepad) - return true; - - PRAWINPUTDEVICELIST dev_list = NULL; - unsigned int dev_list_count = 0; - - if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { - return false; - } - dev_list = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count); - if (!dev_list) return false; - - if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { - free(dev_list); - return false; - } - for (int i = 0; i < dev_list_count; i++) { - - RID_DEVICE_INFO rdi; - char dev_name[128]; - UINT rdiSize = sizeof(rdi); - UINT nameSize = sizeof(dev_name); - - rdi.cbSize = rdiSize; - if ((dev_list[i].dwType == RIM_TYPEHID) && - (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1) && - (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)p_guid->Data1) && - (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) && - (strstr(dev_name, "IG_") != NULL)) { - - free(dev_list); - return true; - } - } - free(dev_list); - return false; -} - -bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) { - - HRESULT hr; - int num = input->get_unused_joy_id(); - - if (have_device(instance->guidInstance) || num == -1) - return false; - - d_joypads[joypad_count] = dinput_gamepad(); - dinput_gamepad *joy = &d_joypads[joypad_count]; - - const DWORD devtype = (instance->dwDevType & 0xFF); - - if ((devtype != DI8DEVTYPE_JOYSTICK) && (devtype != DI8DEVTYPE_GAMEPAD) && (devtype != DI8DEVTYPE_1STPERSON)) { - return false; - } - - hr = dinput->CreateDevice(instance->guidInstance, &joy->di_joy, NULL); - - if (FAILED(hr)) { - return false; - } - - const GUID &guid = instance->guidProduct; - char uid[128]; - sprintf_s(uid, "%08lx%04hx%04hx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", - __builtin_bswap32(guid.Data1), guid.Data2, guid.Data3, - guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], - guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); - - id_to_change = joypad_count; - - joy->di_joy->SetDataFormat(&c_dfDIJoystick2); - joy->di_joy->SetCooperativeLevel(*hWnd, DISCL_FOREGROUND); - joy->di_joy->EnumObjects(objectsCallback, this, 0); - joy->joy_axis.sort(); - - joy->guid = instance->guidInstance; - input->joy_connection_changed(num, true, instance->tszProductName, uid); - joy->attached = true; - joy->id = num; - attached_joypads[num] = true; - joy->confirmed = true; - joypad_count++; - return true; -} - -void JoypadWindows::setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id) { - - if (ob->dwType & DIDFT_AXIS) { - - HRESULT res; - DIPROPRANGE prop_range; - DIPROPDWORD dilong; - DWORD ofs; - if (ob->guidType == GUID_XAxis) - ofs = DIJOFS_X; - else if (ob->guidType == GUID_YAxis) - ofs = DIJOFS_Y; - else if (ob->guidType == GUID_ZAxis) - ofs = DIJOFS_Z; - else if (ob->guidType == GUID_RxAxis) - ofs = DIJOFS_RX; - else if (ob->guidType == GUID_RyAxis) - ofs = DIJOFS_RY; - else if (ob->guidType == GUID_RzAxis) - ofs = DIJOFS_RZ; - else if (ob->guidType == GUID_Slider) - ofs = DIJOFS_SLIDER(0); - else - return; - prop_range.diph.dwSize = sizeof(DIPROPRANGE); - prop_range.diph.dwHeaderSize = sizeof(DIPROPHEADER); - prop_range.diph.dwObj = ob->dwType; - prop_range.diph.dwHow = DIPH_BYID; - prop_range.lMin = -MAX_JOY_AXIS; - prop_range.lMax = +MAX_JOY_AXIS; - - dinput_gamepad &joy = d_joypads[p_joy_id]; - - res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_RANGE, &prop_range.diph); - if (FAILED(res)) - return; - - dilong.diph.dwSize = sizeof(dilong); - dilong.diph.dwHeaderSize = sizeof(dilong.diph); - dilong.diph.dwObj = ob->dwType; - dilong.diph.dwHow = DIPH_BYID; - dilong.dwData = 0; - - res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_DEADZONE, &dilong.diph); - if (FAILED(res)) - return; - - joy.joy_axis.push_back(ofs); - } -} - -BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE *p_instance, void *p_context) { - - JoypadWindows *self = (JoypadWindows *)p_context; - if (self->is_xinput_device(&p_instance->guidProduct)) { - return DIENUM_CONTINUE; - } - self->setup_dinput_joypad(p_instance); - return DIENUM_CONTINUE; -} - -BOOL CALLBACK JoypadWindows::objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context) { - - JoypadWindows *self = (JoypadWindows *)context; - self->setup_joypad_object(instance, self->id_to_change); - - return DIENUM_CONTINUE; -} - -void JoypadWindows::close_joypad(int id) { - - if (id == -1) { - - for (int i = 0; i < JOYPADS_MAX; i++) { - - close_joypad(i); - } - return; - } - - if (!d_joypads[id].attached) return; - - d_joypads[id].di_joy->Unacquire(); - d_joypads[id].di_joy->Release(); - d_joypads[id].attached = false; - attached_joypads[d_joypads[id].id] = false; - d_joypads[id].guid.Data1 = d_joypads[id].guid.Data2 = d_joypads[id].guid.Data3 = 0; - input->joy_connection_changed(d_joypads[id].id, false, ""); - joypad_count--; -} - -void JoypadWindows::probe_joypads() { - - DWORD dwResult; - for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) { - - ZeroMemory(&x_joypads[i].state, sizeof(XINPUT_STATE)); - - dwResult = xinput_get_state(i, &x_joypads[i].state); - if (dwResult == ERROR_SUCCESS) { - - int id = input->get_unused_joy_id(); - if (id != -1 && !x_joypads[i].attached) { - - x_joypads[i].attached = true; - x_joypads[i].id = id; - x_joypads[i].ff_timestamp = 0; - x_joypads[i].ff_end_timestamp = 0; - x_joypads[i].vibrating = false; - attached_joypads[id] = true; - input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__"); - } - } else if (x_joypads[i].attached) { - - x_joypads[i].attached = false; - attached_joypads[x_joypads[i].id] = false; - input->joy_connection_changed(x_joypads[i].id, false, ""); - } - } - - for (int i = 0; i < joypad_count; i++) { - - d_joypads[i].confirmed = false; - } - - dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, this, DIEDFL_ATTACHEDONLY); - - for (int i = 0; i < joypad_count; i++) { - - if (!d_joypads[i].confirmed) { - - close_joypad(i); - } - } -} - -void JoypadWindows::process_joypads() { - - HRESULT hr; - - for (int i = 0; i < XUSER_MAX_COUNT; i++) { - - xinput_gamepad &joy = x_joypads[i]; - if (!joy.attached) { - continue; - } - ZeroMemory(&joy.state, sizeof(XINPUT_STATE)); - - xinput_get_state(i, &joy.state); - if (joy.state.dwPacketNumber != joy.last_packet) { - - int button_mask = XINPUT_GAMEPAD_DPAD_UP; - for (int i = 0; i <= 16; i++) { - - input->joy_button(joy.id, i, joy.state.Gamepad.wButtons & button_mask); - button_mask = button_mask * 2; - } - - input->joy_axis(joy.id, JOY_AXIS_0, axis_correct(joy.state.Gamepad.sThumbLX, true)); - input->joy_axis(joy.id, JOY_AXIS_1, axis_correct(joy.state.Gamepad.sThumbLY, true, false, true)); - input->joy_axis(joy.id, JOY_AXIS_2, axis_correct(joy.state.Gamepad.sThumbRX, true)); - input->joy_axis(joy.id, JOY_AXIS_3, axis_correct(joy.state.Gamepad.sThumbRY, true, false, true)); - input->joy_axis(joy.id, JOY_AXIS_4, axis_correct(joy.state.Gamepad.bLeftTrigger, true, true)); - input->joy_axis(joy.id, JOY_AXIS_5, axis_correct(joy.state.Gamepad.bRightTrigger, true, true)); - joy.last_packet = joy.state.dwPacketNumber; - } - uint64_t timestamp = input->get_joy_vibration_timestamp(joy.id); - if (timestamp > joy.ff_timestamp) { - Vector2 strength = input->get_joy_vibration_strength(joy.id); - float duration = input->get_joy_vibration_duration(joy.id); - if (strength.x == 0 && strength.y == 0) { - joypad_vibration_stop_xinput(i, timestamp); - } else { - joypad_vibration_start_xinput(i, strength.x, strength.y, duration, timestamp); - } - } else if (joy.vibrating && joy.ff_end_timestamp != 0) { - uint64_t current_time = OS::get_singleton()->get_ticks_usec(); - if (current_time >= joy.ff_end_timestamp) - joypad_vibration_stop_xinput(i, current_time); - } - } - - for (int i = 0; i < JOYPADS_MAX; i++) { - - dinput_gamepad *joy = &d_joypads[i]; - - if (!joy->attached) - continue; - - DIJOYSTATE2 js; - hr = joy->di_joy->Poll(); - if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) { - IDirectInputDevice8_Acquire(joy->di_joy); - joy->di_joy->Poll(); - } - - hr = joy->di_joy->GetDeviceState(sizeof(DIJOYSTATE2), &js); - if (FAILED(hr)) { - continue; - } - - post_hat(joy->id, js.rgdwPOV[0]); - - for (int j = 0; j < 128; j++) { - - if (js.rgbButtons[j] & 0x80) { - - if (!joy->last_buttons[j]) { - - input->joy_button(joy->id, j, true); - joy->last_buttons[j] = true; - } - } else { - - if (joy->last_buttons[j]) { - - input->joy_button(joy->id, j, false); - joy->last_buttons[j] = false; - } - } - } - - // on mingw, these constants are not constants - int count = 6; - int axes[] = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z, DIJOFS_RX, DIJOFS_RY, DIJOFS_RZ }; - int values[] = { js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz }; - - for (int j = 0; j < joy->joy_axis.size(); j++) { - - for (int k = 0; k < count; k++) { - if (joy->joy_axis[j] == axes[k]) { - input->joy_axis(joy->id, j, axis_correct(values[k])); - break; - }; - }; - }; - } - return; -} - -void JoypadWindows::post_hat(int p_device, DWORD p_dpad) { - - int dpad_val = 0; - - if (p_dpad == -1) { - dpad_val = InputDefault::HAT_MASK_CENTER; - } - if (p_dpad == 0) { - - dpad_val = InputDefault::HAT_MASK_UP; - - } else if (p_dpad == 4500) { - - dpad_val = (InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_RIGHT); - - } else if (p_dpad == 9000) { - - dpad_val = InputDefault::HAT_MASK_RIGHT; - - } else if (p_dpad == 13500) { - - dpad_val = (InputDefault::HAT_MASK_RIGHT | InputDefault::HAT_MASK_DOWN); - - } else if (p_dpad == 18000) { - - dpad_val = InputDefault::HAT_MASK_DOWN; - - } else if (p_dpad == 22500) { - - dpad_val = (InputDefault::HAT_MASK_DOWN | InputDefault::HAT_MASK_LEFT); - - } else if (p_dpad == 27000) { - - dpad_val = InputDefault::HAT_MASK_LEFT; - - } else if (p_dpad == 31500) { - - dpad_val = (InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_UP); - } - input->joy_hat(p_device, dpad_val); -}; - -InputDefault::JoyAxis JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const { - - InputDefault::JoyAxis jx; - if (Math::abs(p_val) < MIN_JOY_AXIS) { - jx.min = p_trigger ? 0 : -1; - jx.value = 0.0f; - return jx; - } - if (p_xinput) { - - if (p_trigger) { - jx.min = 0; - jx.value = (float)p_val / MAX_TRIGGER; - return jx; - } - jx.min = -1; - if (p_val < 0) { - jx.value = (float)p_val / MAX_JOY_AXIS; - } else { - jx.value = (float)p_val / (MAX_JOY_AXIS - 1); - } - if (p_negate) { - jx.value = -jx.value; - } - return jx; - } - jx.min = -1; - jx.value = (float)p_val / MAX_JOY_AXIS; - return jx; -} - -void JoypadWindows::joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) { - xinput_gamepad &joy = x_joypads[p_device]; - if (joy.attached) { - XINPUT_VIBRATION effect; - effect.wLeftMotorSpeed = (65535 * p_strong_magnitude); - effect.wRightMotorSpeed = (65535 * p_weak_magnitude); - if (xinput_set_state(p_device, &effect) == ERROR_SUCCESS) { - joy.ff_timestamp = p_timestamp; - joy.ff_end_timestamp = p_duration == 0 ? 0 : p_timestamp + (uint64_t)(p_duration * 1000000.0); - joy.vibrating = true; - } - } -} - -void JoypadWindows::joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp) { - xinput_gamepad &joy = x_joypads[p_device]; - if (joy.attached) { - XINPUT_VIBRATION effect; - effect.wLeftMotorSpeed = 0; - effect.wRightMotorSpeed = 0; - if (xinput_set_state(p_device, &effect) == ERROR_SUCCESS) { - joy.ff_timestamp = p_timestamp; - joy.vibrating = false; - } - } -} - -void JoypadWindows::load_xinput() { - - xinput_get_state = &_xinput_get_state; - xinput_set_state = &_xinput_set_state; - xinput_dll = LoadLibrary("XInput1_4.dll"); - if (!xinput_dll) { - xinput_dll = LoadLibrary("XInput1_3.dll"); - if (!xinput_dll) { - xinput_dll = LoadLibrary("XInput9_1_0.dll"); - } - } - - if (!xinput_dll) { - print_verbose("Could not find XInput, using DirectInput only"); - return; - } - - XInputGetState_t func = (XInputGetState_t)GetProcAddress((HMODULE)xinput_dll, "XInputGetState"); - XInputSetState_t set_func = (XInputSetState_t)GetProcAddress((HMODULE)xinput_dll, "XInputSetState"); - if (!func || !set_func) { - unload_xinput(); - return; - } - xinput_get_state = func; - xinput_set_state = set_func; -} - -void JoypadWindows::unload_xinput() { - - if (xinput_dll) { - - FreeLibrary((HMODULE)xinput_dll); - } -} diff --git a/platform/windows/joypad.h b/platform/windows/joypad.h deleted file mode 100644 index 3a6c0cef9f..0000000000 --- a/platform/windows/joypad.h +++ /dev/null @@ -1,148 +0,0 @@ -/*************************************************************************/ -/* joypad.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef JOYPAD_H -#define JOYPAD_H - -#include "os_windows.h" -#define DIRECTINPUT_VERSION 0x0800 -#include -#include // on unix the file is called "xinput.h", on windows I'm sure it won't mind - -#ifndef SAFE_RELEASE // when Windows Media Device M? is not present -#define SAFE_RELEASE(x) \ - if (x != NULL) { \ - x->Release(); \ - x = NULL; \ - } -#endif - -#ifndef XUSER_MAX_COUNT -#define XUSER_MAX_COUNT 4 -#endif - -class JoypadWindows { -public: - JoypadWindows(); - JoypadWindows(InputDefault *_input, HWND *hwnd); - ~JoypadWindows(); - - void probe_joypads(); - void process_joypads(); - -private: - enum { - JOYPADS_MAX = 16, - JOY_AXIS_COUNT = 6, - MIN_JOY_AXIS = 10, - MAX_JOY_AXIS = 32768, - MAX_JOY_BUTTONS = 128, - KEY_EVENT_BUFFER_SIZE = 512, - MAX_TRIGGER = 255 - }; - - struct dinput_gamepad { - - int id; - bool attached; - bool confirmed; - bool last_buttons[MAX_JOY_BUTTONS]; - DWORD last_pad; - - LPDIRECTINPUTDEVICE8 di_joy; - List joy_axis; - GUID guid; - - dinput_gamepad() { - id = -1; - last_pad = -1; - attached = false; - confirmed = false; - - for (int i = 0; i < MAX_JOY_BUTTONS; i++) - last_buttons[i] = false; - } - }; - - struct xinput_gamepad { - - int id; - bool attached; - bool vibrating; - DWORD last_packet; - XINPUT_STATE state; - uint64_t ff_timestamp; - uint64_t ff_end_timestamp; - - xinput_gamepad() { - attached = false; - vibrating = false; - ff_timestamp = 0; - ff_end_timestamp = 0; - last_packet = 0; - } - }; - - typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex, XINPUT_STATE *pState); - typedef DWORD(WINAPI *XInputSetState_t)(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration); - - HWND *hWnd; - HANDLE xinput_dll; - LPDIRECTINPUT8 dinput; - InputDefault *input; - - int id_to_change; - int joypad_count; - bool attached_joypads[JOYPADS_MAX]; - dinput_gamepad d_joypads[JOYPADS_MAX]; - xinput_gamepad x_joypads[XUSER_MAX_COUNT]; - - static BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE *p_instance, void *p_context); - static BOOL CALLBACK objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context); - - void setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id); - void close_joypad(int id = -1); - void load_xinput(); - void unload_xinput(); - - void post_hat(int p_device, DWORD p_dpad); - - bool have_device(const GUID &p_guid); - bool is_xinput_device(const GUID *p_guid); - bool setup_dinput_joypad(const DIDEVICEINSTANCE *instance); - void joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); - void joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp); - - InputDefault::JoyAxis axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const; - XInputGetState_t xinput_get_state; - XInputSetState_t xinput_set_state; -}; - -#endif diff --git a/platform/windows/joypad_windows.cpp b/platform/windows/joypad_windows.cpp new file mode 100644 index 0000000000..5a399cdf90 --- /dev/null +++ b/platform/windows/joypad_windows.cpp @@ -0,0 +1,558 @@ +/*************************************************************************/ +/* joypad_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "joypad_windows.h" + +#include +#include + +#ifndef __GNUC__ +#define __builtin_bswap32 _byteswap_ulong +#endif + +DWORD WINAPI _xinput_get_state(DWORD dwUserIndex, XINPUT_STATE *pState) { + return ERROR_DEVICE_NOT_CONNECTED; +} +DWORD WINAPI _xinput_set_state(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration) { + return ERROR_DEVICE_NOT_CONNECTED; +} + +JoypadWindows::JoypadWindows() { +} + +JoypadWindows::JoypadWindows(InputDefault *_input, HWND *hwnd) { + + input = _input; + hWnd = hwnd; + joypad_count = 0; + dinput = NULL; + xinput_dll = NULL; + xinput_get_state = NULL; + xinput_set_state = NULL; + + load_xinput(); + + for (int i = 0; i < JOYPADS_MAX; i++) + attached_joypads[i] = false; + + HRESULT result; + result = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&dinput, NULL); + if (FAILED(result)) { + printf("failed init DINPUT: %ld\n", result); + } + probe_joypads(); +} + +JoypadWindows::~JoypadWindows() { + + close_joypad(); + dinput->Release(); + unload_xinput(); +} + +bool JoypadWindows::have_device(const GUID &p_guid) { + + for (int i = 0; i < JOYPADS_MAX; i++) { + + if (d_joypads[i].guid == p_guid) { + + d_joypads[i].confirmed = true; + return true; + } + } + return false; +} + +// adapted from SDL2, works a lot better than the MSDN version +bool JoypadWindows::is_xinput_device(const GUID *p_guid) { + + static GUID IID_ValveStreamingGamepad = { MAKELONG(0x28DE, 0x11FF), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_X360WiredGamepad = { MAKELONG(0x045E, 0x02A1), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + static GUID IID_X360WirelessGamepad = { MAKELONG(0x045E, 0x028E), 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + + if (p_guid == &IID_ValveStreamingGamepad || p_guid == &IID_X360WiredGamepad || p_guid == &IID_X360WirelessGamepad) + return true; + + PRAWINPUTDEVICELIST dev_list = NULL; + unsigned int dev_list_count = 0; + + if (GetRawInputDeviceList(NULL, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { + return false; + } + dev_list = (PRAWINPUTDEVICELIST)malloc(sizeof(RAWINPUTDEVICELIST) * dev_list_count); + if (!dev_list) return false; + + if (GetRawInputDeviceList(dev_list, &dev_list_count, sizeof(RAWINPUTDEVICELIST)) == -1) { + free(dev_list); + return false; + } + for (int i = 0; i < dev_list_count; i++) { + + RID_DEVICE_INFO rdi; + char dev_name[128]; + UINT rdiSize = sizeof(rdi); + UINT nameSize = sizeof(dev_name); + + rdi.cbSize = rdiSize; + if ((dev_list[i].dwType == RIM_TYPEHID) && + (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1) && + (MAKELONG(rdi.hid.dwVendorId, rdi.hid.dwProductId) == (LONG)p_guid->Data1) && + (GetRawInputDeviceInfoA(dev_list[i].hDevice, RIDI_DEVICENAME, &dev_name, &nameSize) != (UINT)-1) && + (strstr(dev_name, "IG_") != NULL)) { + + free(dev_list); + return true; + } + } + free(dev_list); + return false; +} + +bool JoypadWindows::setup_dinput_joypad(const DIDEVICEINSTANCE *instance) { + + HRESULT hr; + int num = input->get_unused_joy_id(); + + if (have_device(instance->guidInstance) || num == -1) + return false; + + d_joypads[joypad_count] = dinput_gamepad(); + dinput_gamepad *joy = &d_joypads[joypad_count]; + + const DWORD devtype = (instance->dwDevType & 0xFF); + + if ((devtype != DI8DEVTYPE_JOYSTICK) && (devtype != DI8DEVTYPE_GAMEPAD) && (devtype != DI8DEVTYPE_1STPERSON)) { + return false; + } + + hr = dinput->CreateDevice(instance->guidInstance, &joy->di_joy, NULL); + + if (FAILED(hr)) { + return false; + } + + const GUID &guid = instance->guidProduct; + char uid[128]; + sprintf_s(uid, "%08lx%04hx%04hx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", + __builtin_bswap32(guid.Data1), guid.Data2, guid.Data3, + guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], + guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]); + + id_to_change = joypad_count; + + joy->di_joy->SetDataFormat(&c_dfDIJoystick2); + joy->di_joy->SetCooperativeLevel(*hWnd, DISCL_FOREGROUND); + joy->di_joy->EnumObjects(objectsCallback, this, 0); + joy->joy_axis.sort(); + + joy->guid = instance->guidInstance; + input->joy_connection_changed(num, true, instance->tszProductName, uid); + joy->attached = true; + joy->id = num; + attached_joypads[num] = true; + joy->confirmed = true; + joypad_count++; + return true; +} + +void JoypadWindows::setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id) { + + if (ob->dwType & DIDFT_AXIS) { + + HRESULT res; + DIPROPRANGE prop_range; + DIPROPDWORD dilong; + DWORD ofs; + if (ob->guidType == GUID_XAxis) + ofs = DIJOFS_X; + else if (ob->guidType == GUID_YAxis) + ofs = DIJOFS_Y; + else if (ob->guidType == GUID_ZAxis) + ofs = DIJOFS_Z; + else if (ob->guidType == GUID_RxAxis) + ofs = DIJOFS_RX; + else if (ob->guidType == GUID_RyAxis) + ofs = DIJOFS_RY; + else if (ob->guidType == GUID_RzAxis) + ofs = DIJOFS_RZ; + else if (ob->guidType == GUID_Slider) + ofs = DIJOFS_SLIDER(0); + else + return; + prop_range.diph.dwSize = sizeof(DIPROPRANGE); + prop_range.diph.dwHeaderSize = sizeof(DIPROPHEADER); + prop_range.diph.dwObj = ob->dwType; + prop_range.diph.dwHow = DIPH_BYID; + prop_range.lMin = -MAX_JOY_AXIS; + prop_range.lMax = +MAX_JOY_AXIS; + + dinput_gamepad &joy = d_joypads[p_joy_id]; + + res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_RANGE, &prop_range.diph); + if (FAILED(res)) + return; + + dilong.diph.dwSize = sizeof(dilong); + dilong.diph.dwHeaderSize = sizeof(dilong.diph); + dilong.diph.dwObj = ob->dwType; + dilong.diph.dwHow = DIPH_BYID; + dilong.dwData = 0; + + res = IDirectInputDevice8_SetProperty(joy.di_joy, DIPROP_DEADZONE, &dilong.diph); + if (FAILED(res)) + return; + + joy.joy_axis.push_back(ofs); + } +} + +BOOL CALLBACK JoypadWindows::enumCallback(const DIDEVICEINSTANCE *p_instance, void *p_context) { + + JoypadWindows *self = (JoypadWindows *)p_context; + if (self->is_xinput_device(&p_instance->guidProduct)) { + return DIENUM_CONTINUE; + } + self->setup_dinput_joypad(p_instance); + return DIENUM_CONTINUE; +} + +BOOL CALLBACK JoypadWindows::objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context) { + + JoypadWindows *self = (JoypadWindows *)context; + self->setup_joypad_object(instance, self->id_to_change); + + return DIENUM_CONTINUE; +} + +void JoypadWindows::close_joypad(int id) { + + if (id == -1) { + + for (int i = 0; i < JOYPADS_MAX; i++) { + + close_joypad(i); + } + return; + } + + if (!d_joypads[id].attached) return; + + d_joypads[id].di_joy->Unacquire(); + d_joypads[id].di_joy->Release(); + d_joypads[id].attached = false; + attached_joypads[d_joypads[id].id] = false; + d_joypads[id].guid.Data1 = d_joypads[id].guid.Data2 = d_joypads[id].guid.Data3 = 0; + input->joy_connection_changed(d_joypads[id].id, false, ""); + joypad_count--; +} + +void JoypadWindows::probe_joypads() { + + DWORD dwResult; + for (DWORD i = 0; i < XUSER_MAX_COUNT; i++) { + + ZeroMemory(&x_joypads[i].state, sizeof(XINPUT_STATE)); + + dwResult = xinput_get_state(i, &x_joypads[i].state); + if (dwResult == ERROR_SUCCESS) { + + int id = input->get_unused_joy_id(); + if (id != -1 && !x_joypads[i].attached) { + + x_joypads[i].attached = true; + x_joypads[i].id = id; + x_joypads[i].ff_timestamp = 0; + x_joypads[i].ff_end_timestamp = 0; + x_joypads[i].vibrating = false; + attached_joypads[id] = true; + input->joy_connection_changed(id, true, "XInput Gamepad", "__XINPUT_DEVICE__"); + } + } else if (x_joypads[i].attached) { + + x_joypads[i].attached = false; + attached_joypads[x_joypads[i].id] = false; + input->joy_connection_changed(x_joypads[i].id, false, ""); + } + } + + for (int i = 0; i < joypad_count; i++) { + + d_joypads[i].confirmed = false; + } + + dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, this, DIEDFL_ATTACHEDONLY); + + for (int i = 0; i < joypad_count; i++) { + + if (!d_joypads[i].confirmed) { + + close_joypad(i); + } + } +} + +void JoypadWindows::process_joypads() { + + HRESULT hr; + + for (int i = 0; i < XUSER_MAX_COUNT; i++) { + + xinput_gamepad &joy = x_joypads[i]; + if (!joy.attached) { + continue; + } + ZeroMemory(&joy.state, sizeof(XINPUT_STATE)); + + xinput_get_state(i, &joy.state); + if (joy.state.dwPacketNumber != joy.last_packet) { + + int button_mask = XINPUT_GAMEPAD_DPAD_UP; + for (int i = 0; i <= 16; i++) { + + input->joy_button(joy.id, i, joy.state.Gamepad.wButtons & button_mask); + button_mask = button_mask * 2; + } + + input->joy_axis(joy.id, JOY_AXIS_0, axis_correct(joy.state.Gamepad.sThumbLX, true)); + input->joy_axis(joy.id, JOY_AXIS_1, axis_correct(joy.state.Gamepad.sThumbLY, true, false, true)); + input->joy_axis(joy.id, JOY_AXIS_2, axis_correct(joy.state.Gamepad.sThumbRX, true)); + input->joy_axis(joy.id, JOY_AXIS_3, axis_correct(joy.state.Gamepad.sThumbRY, true, false, true)); + input->joy_axis(joy.id, JOY_AXIS_4, axis_correct(joy.state.Gamepad.bLeftTrigger, true, true)); + input->joy_axis(joy.id, JOY_AXIS_5, axis_correct(joy.state.Gamepad.bRightTrigger, true, true)); + joy.last_packet = joy.state.dwPacketNumber; + } + uint64_t timestamp = input->get_joy_vibration_timestamp(joy.id); + if (timestamp > joy.ff_timestamp) { + Vector2 strength = input->get_joy_vibration_strength(joy.id); + float duration = input->get_joy_vibration_duration(joy.id); + if (strength.x == 0 && strength.y == 0) { + joypad_vibration_stop_xinput(i, timestamp); + } else { + joypad_vibration_start_xinput(i, strength.x, strength.y, duration, timestamp); + } + } else if (joy.vibrating && joy.ff_end_timestamp != 0) { + uint64_t current_time = OS::get_singleton()->get_ticks_usec(); + if (current_time >= joy.ff_end_timestamp) + joypad_vibration_stop_xinput(i, current_time); + } + } + + for (int i = 0; i < JOYPADS_MAX; i++) { + + dinput_gamepad *joy = &d_joypads[i]; + + if (!joy->attached) + continue; + + DIJOYSTATE2 js; + hr = joy->di_joy->Poll(); + if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) { + IDirectInputDevice8_Acquire(joy->di_joy); + joy->di_joy->Poll(); + } + + hr = joy->di_joy->GetDeviceState(sizeof(DIJOYSTATE2), &js); + if (FAILED(hr)) { + continue; + } + + post_hat(joy->id, js.rgdwPOV[0]); + + for (int j = 0; j < 128; j++) { + + if (js.rgbButtons[j] & 0x80) { + + if (!joy->last_buttons[j]) { + + input->joy_button(joy->id, j, true); + joy->last_buttons[j] = true; + } + } else { + + if (joy->last_buttons[j]) { + + input->joy_button(joy->id, j, false); + joy->last_buttons[j] = false; + } + } + } + + // on mingw, these constants are not constants + int count = 6; + int axes[] = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z, DIJOFS_RX, DIJOFS_RY, DIJOFS_RZ }; + int values[] = { js.lX, js.lY, js.lZ, js.lRx, js.lRy, js.lRz }; + + for (int j = 0; j < joy->joy_axis.size(); j++) { + + for (int k = 0; k < count; k++) { + if (joy->joy_axis[j] == axes[k]) { + input->joy_axis(joy->id, j, axis_correct(values[k])); + break; + }; + }; + }; + } + return; +} + +void JoypadWindows::post_hat(int p_device, DWORD p_dpad) { + + int dpad_val = 0; + + if (p_dpad == -1) { + dpad_val = InputDefault::HAT_MASK_CENTER; + } + if (p_dpad == 0) { + + dpad_val = InputDefault::HAT_MASK_UP; + + } else if (p_dpad == 4500) { + + dpad_val = (InputDefault::HAT_MASK_UP | InputDefault::HAT_MASK_RIGHT); + + } else if (p_dpad == 9000) { + + dpad_val = InputDefault::HAT_MASK_RIGHT; + + } else if (p_dpad == 13500) { + + dpad_val = (InputDefault::HAT_MASK_RIGHT | InputDefault::HAT_MASK_DOWN); + + } else if (p_dpad == 18000) { + + dpad_val = InputDefault::HAT_MASK_DOWN; + + } else if (p_dpad == 22500) { + + dpad_val = (InputDefault::HAT_MASK_DOWN | InputDefault::HAT_MASK_LEFT); + + } else if (p_dpad == 27000) { + + dpad_val = InputDefault::HAT_MASK_LEFT; + + } else if (p_dpad == 31500) { + + dpad_val = (InputDefault::HAT_MASK_LEFT | InputDefault::HAT_MASK_UP); + } + input->joy_hat(p_device, dpad_val); +}; + +InputDefault::JoyAxis JoypadWindows::axis_correct(int p_val, bool p_xinput, bool p_trigger, bool p_negate) const { + + InputDefault::JoyAxis jx; + if (Math::abs(p_val) < MIN_JOY_AXIS) { + jx.min = p_trigger ? 0 : -1; + jx.value = 0.0f; + return jx; + } + if (p_xinput) { + + if (p_trigger) { + jx.min = 0; + jx.value = (float)p_val / MAX_TRIGGER; + return jx; + } + jx.min = -1; + if (p_val < 0) { + jx.value = (float)p_val / MAX_JOY_AXIS; + } else { + jx.value = (float)p_val / (MAX_JOY_AXIS - 1); + } + if (p_negate) { + jx.value = -jx.value; + } + return jx; + } + jx.min = -1; + jx.value = (float)p_val / MAX_JOY_AXIS; + return jx; +} + +void JoypadWindows::joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp) { + xinput_gamepad &joy = x_joypads[p_device]; + if (joy.attached) { + XINPUT_VIBRATION effect; + effect.wLeftMotorSpeed = (65535 * p_strong_magnitude); + effect.wRightMotorSpeed = (65535 * p_weak_magnitude); + if (xinput_set_state(p_device, &effect) == ERROR_SUCCESS) { + joy.ff_timestamp = p_timestamp; + joy.ff_end_timestamp = p_duration == 0 ? 0 : p_timestamp + (uint64_t)(p_duration * 1000000.0); + joy.vibrating = true; + } + } +} + +void JoypadWindows::joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp) { + xinput_gamepad &joy = x_joypads[p_device]; + if (joy.attached) { + XINPUT_VIBRATION effect; + effect.wLeftMotorSpeed = 0; + effect.wRightMotorSpeed = 0; + if (xinput_set_state(p_device, &effect) == ERROR_SUCCESS) { + joy.ff_timestamp = p_timestamp; + joy.vibrating = false; + } + } +} + +void JoypadWindows::load_xinput() { + + xinput_get_state = &_xinput_get_state; + xinput_set_state = &_xinput_set_state; + xinput_dll = LoadLibrary("XInput1_4.dll"); + if (!xinput_dll) { + xinput_dll = LoadLibrary("XInput1_3.dll"); + if (!xinput_dll) { + xinput_dll = LoadLibrary("XInput9_1_0.dll"); + } + } + + if (!xinput_dll) { + print_verbose("Could not find XInput, using DirectInput only"); + return; + } + + XInputGetState_t func = (XInputGetState_t)GetProcAddress((HMODULE)xinput_dll, "XInputGetState"); + XInputSetState_t set_func = (XInputSetState_t)GetProcAddress((HMODULE)xinput_dll, "XInputSetState"); + if (!func || !set_func) { + unload_xinput(); + return; + } + xinput_get_state = func; + xinput_set_state = set_func; +} + +void JoypadWindows::unload_xinput() { + + if (xinput_dll) { + + FreeLibrary((HMODULE)xinput_dll); + } +} diff --git a/platform/windows/joypad_windows.h b/platform/windows/joypad_windows.h new file mode 100644 index 0000000000..4af5d9bd6a --- /dev/null +++ b/platform/windows/joypad_windows.h @@ -0,0 +1,149 @@ +/*************************************************************************/ +/* joypad_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef JOYPAD_WINDOWS_H +#define JOYPAD_WINDOWS_H + +#include "os_windows.h" + +#define DIRECTINPUT_VERSION 0x0800 +#include +#include // on unix the file is called "xinput.h", on windows I'm sure it won't mind + +#ifndef SAFE_RELEASE // when Windows Media Device M? is not present +#define SAFE_RELEASE(x) \ + if (x != NULL) { \ + x->Release(); \ + x = NULL; \ + } +#endif + +#ifndef XUSER_MAX_COUNT +#define XUSER_MAX_COUNT 4 +#endif + +class JoypadWindows { +public: + JoypadWindows(); + JoypadWindows(InputDefault *_input, HWND *hwnd); + ~JoypadWindows(); + + void probe_joypads(); + void process_joypads(); + +private: + enum { + JOYPADS_MAX = 16, + JOY_AXIS_COUNT = 6, + MIN_JOY_AXIS = 10, + MAX_JOY_AXIS = 32768, + MAX_JOY_BUTTONS = 128, + KEY_EVENT_BUFFER_SIZE = 512, + MAX_TRIGGER = 255 + }; + + struct dinput_gamepad { + + int id; + bool attached; + bool confirmed; + bool last_buttons[MAX_JOY_BUTTONS]; + DWORD last_pad; + + LPDIRECTINPUTDEVICE8 di_joy; + List joy_axis; + GUID guid; + + dinput_gamepad() { + id = -1; + last_pad = -1; + attached = false; + confirmed = false; + + for (int i = 0; i < MAX_JOY_BUTTONS; i++) + last_buttons[i] = false; + } + }; + + struct xinput_gamepad { + + int id; + bool attached; + bool vibrating; + DWORD last_packet; + XINPUT_STATE state; + uint64_t ff_timestamp; + uint64_t ff_end_timestamp; + + xinput_gamepad() { + attached = false; + vibrating = false; + ff_timestamp = 0; + ff_end_timestamp = 0; + last_packet = 0; + } + }; + + typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex, XINPUT_STATE *pState); + typedef DWORD(WINAPI *XInputSetState_t)(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration); + + HWND *hWnd; + HANDLE xinput_dll; + LPDIRECTINPUT8 dinput; + InputDefault *input; + + int id_to_change; + int joypad_count; + bool attached_joypads[JOYPADS_MAX]; + dinput_gamepad d_joypads[JOYPADS_MAX]; + xinput_gamepad x_joypads[XUSER_MAX_COUNT]; + + static BOOL CALLBACK enumCallback(const DIDEVICEINSTANCE *p_instance, void *p_context); + static BOOL CALLBACK objectsCallback(const DIDEVICEOBJECTINSTANCE *instance, void *context); + + void setup_joypad_object(const DIDEVICEOBJECTINSTANCE *ob, int p_joy_id); + void close_joypad(int id = -1); + void load_xinput(); + void unload_xinput(); + + void post_hat(int p_device, DWORD p_dpad); + + bool have_device(const GUID &p_guid); + bool is_xinput_device(const GUID *p_guid); + bool setup_dinput_joypad(const DIDEVICEINSTANCE *instance); + void joypad_vibration_start_xinput(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration, uint64_t p_timestamp); + void joypad_vibration_stop_xinput(int p_device, uint64_t p_timestamp); + + InputDefault::JoyAxis axis_correct(int p_val, bool p_xinput = false, bool p_trigger = false, bool p_negate = false) const; + XInputGetState_t xinput_get_state; + XInputSetState_t xinput_set_state; +}; + +#endif // JOYPAD_WINDOWS_H diff --git a/platform/windows/key_mapping_win.cpp b/platform/windows/key_mapping_win.cpp deleted file mode 100644 index f9b01e5532..0000000000 --- a/platform/windows/key_mapping_win.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/*************************************************************************/ -/* key_mapping_win.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "key_mapping_win.h" - -#include - -struct _WinTranslatePair { - - unsigned int keysym; - unsigned int keycode; -}; - -static _WinTranslatePair _vk_to_keycode[] = { - - { KEY_BACKSPACE, VK_BACK }, // (0x08) // backspace - { KEY_TAB, VK_TAB }, //(0x09) - - //VK_CLEAR (0x0C) - - { KEY_ENTER, VK_RETURN }, //(0x0D) - - { KEY_SHIFT, VK_SHIFT }, //(0x10) - - { KEY_CONTROL, VK_CONTROL }, //(0x11) - - { KEY_ALT, VK_MENU }, //(0x12) - - { KEY_PAUSE, VK_PAUSE }, //(0x13) - - { KEY_CAPSLOCK, VK_CAPITAL }, //(0x14) - - { KEY_ESCAPE, VK_ESCAPE }, //(0x1B) - - { KEY_SPACE, VK_SPACE }, //(0x20) - - { KEY_PAGEUP, VK_PRIOR }, //(0x21) - - { KEY_PAGEDOWN, VK_NEXT }, //(0x22) - - { KEY_END, VK_END }, //(0x23) - - { KEY_HOME, VK_HOME }, //(0x24) - - { KEY_LEFT, VK_LEFT }, //(0x25) - - { KEY_UP, VK_UP }, //(0x26) - - { KEY_RIGHT, VK_RIGHT }, //(0x27) - - { KEY_DOWN, VK_DOWN }, // (0x28) - - //VK_SELECT (0x29) - - { KEY_PRINT, VK_PRINT }, // (0x2A) - - //VK_EXECUTE (0x2B) - - { KEY_PRINT, VK_SNAPSHOT }, // (0x2C) - - { KEY_INSERT, VK_INSERT }, // (0x2D) - - { KEY_DELETE, VK_DELETE }, // (0x2E) - - { KEY_HELP, VK_HELP }, // (0x2F) - - { KEY_0, (0x30) }, ////0 key - { KEY_1, (0x31) }, ////1 key - { KEY_2, (0x32) }, ////2 key - { KEY_3, (0x33) }, ////3 key - { KEY_4, (0x34) }, ////4 key - { KEY_5, (0x35) }, ////5 key - { KEY_6, (0x36) }, ////6 key - { KEY_7, (0x37) }, ////7 key - { KEY_8, (0x38) }, ////8 key - { KEY_9, (0x39) }, ////9 key - { KEY_A, (0x41) }, ////A key - { KEY_B, (0x42) }, ////B key - { KEY_C, (0x43) }, ////C key - { KEY_D, (0x44) }, ////D key - { KEY_E, (0x45) }, ////E key - { KEY_F, (0x46) }, ////F key - { KEY_G, (0x47) }, ////G key - { KEY_H, (0x48) }, ////H key - { KEY_I, (0x49) }, ////I key - { KEY_J, (0x4A) }, ////J key - { KEY_K, (0x4B) }, ////K key - { KEY_L, (0x4C) }, ////L key - { KEY_M, (0x4D) }, ////M key - { KEY_N, (0x4E) }, ////N key - { KEY_O, (0x4F) }, ////O key - { KEY_P, (0x50) }, ////P key - { KEY_Q, (0x51) }, ////Q key - { KEY_R, (0x52) }, ////R key - { KEY_S, (0x53) }, ////S key - { KEY_T, (0x54) }, ////T key - { KEY_U, (0x55) }, ////U key - { KEY_V, (0x56) }, ////V key - { KEY_W, (0x57) }, ////W key - { KEY_X, (0x58) }, ////X key - { KEY_Y, (0x59) }, ////Y key - { KEY_Z, (0x5A) }, ////Z key - - { KEY_MASK_META, VK_LWIN }, //(0x5B) - { KEY_MASK_META, VK_RWIN }, //(0x5C) - //VK_APPS (0x5D) - { KEY_STANDBY, VK_SLEEP }, //(0x5F) - { KEY_KP_0, VK_NUMPAD0 }, //(0x60) - { KEY_KP_1, VK_NUMPAD1 }, //(0x61) - { KEY_KP_2, VK_NUMPAD2 }, //(0x62) - { KEY_KP_3, VK_NUMPAD3 }, //(0x63) - { KEY_KP_4, VK_NUMPAD4 }, //(0x64) - { KEY_KP_5, VK_NUMPAD5 }, //(0x65) - { KEY_KP_6, VK_NUMPAD6 }, //(0x66) - { KEY_KP_7, VK_NUMPAD7 }, //(0x67) - { KEY_KP_8, VK_NUMPAD8 }, //(0x68) - { KEY_KP_9, VK_NUMPAD9 }, //(0x69) - { KEY_KP_MULTIPLY, VK_MULTIPLY }, // (0x6A) - { KEY_KP_ADD, VK_ADD }, // (0x6B) - //VK_SEPARATOR (0x6C) - { KEY_KP_SUBTRACT, VK_SUBTRACT }, // (0x6D) - { KEY_KP_PERIOD, VK_DECIMAL }, // (0x6E) - { KEY_KP_DIVIDE, VK_DIVIDE }, // (0x6F) - { KEY_F1, VK_F1 }, // (0x70) - { KEY_F2, VK_F2 }, // (0x71) - { KEY_F3, VK_F3 }, // (0x72) - { KEY_F4, VK_F4 }, // (0x73) - { KEY_F5, VK_F5 }, // (0x74) - { KEY_F6, VK_F6 }, // (0x75) - { KEY_F7, VK_F7 }, // (0x76) - { KEY_F8, VK_F8 }, // (0x77) - { KEY_F9, VK_F9 }, // (0x78) - { KEY_F10, VK_F10 }, // (0x79) - { KEY_F11, VK_F11 }, // (0x7A) - { KEY_F12, VK_F12 }, // (0x7B) - { KEY_F13, VK_F13 }, // (0x7C) - { KEY_F14, VK_F14 }, // (0x7D) - { KEY_F15, VK_F15 }, // (0x7E) - { KEY_F16, VK_F16 }, // (0x7F) - { KEY_NUMLOCK, VK_NUMLOCK }, // (0x90) - { KEY_SCROLLLOCK, VK_SCROLL }, // (0x91) - { KEY_SHIFT, VK_LSHIFT }, // (0xA0) - { KEY_SHIFT, VK_RSHIFT }, // (0xA1) - { KEY_CONTROL, VK_LCONTROL }, // (0xA2) - { KEY_CONTROL, VK_RCONTROL }, // (0xA3) - { KEY_MENU, VK_LMENU }, // (0xA4) - { KEY_MENU, VK_RMENU }, // (0xA5) - - { KEY_BACK, VK_BROWSER_BACK }, // (0xA6) - - { KEY_FORWARD, VK_BROWSER_FORWARD }, // (0xA7) - - { KEY_REFRESH, VK_BROWSER_REFRESH }, // (0xA8) - - { KEY_STOP, VK_BROWSER_STOP }, // (0xA9) - - { KEY_SEARCH, VK_BROWSER_SEARCH }, // (0xAA) - - { KEY_FAVORITES, VK_BROWSER_FAVORITES }, // (0xAB) - - { KEY_HOMEPAGE, VK_BROWSER_HOME }, // (0xAC) - - { KEY_VOLUMEMUTE, VK_VOLUME_MUTE }, // (0xAD) - - { KEY_VOLUMEDOWN, VK_VOLUME_DOWN }, // (0xAE) - - { KEY_VOLUMEUP, VK_VOLUME_UP }, // (0xAF) - - { KEY_MEDIANEXT, VK_MEDIA_NEXT_TRACK }, // (0xB0) - - { KEY_MEDIAPREVIOUS, VK_MEDIA_PREV_TRACK }, // (0xB1) - - { KEY_MEDIASTOP, VK_MEDIA_STOP }, // (0xB2) - - //VK_MEDIA_PLAY_PAUSE (0xB3) - - { KEY_LAUNCHMAIL, VK_LAUNCH_MAIL }, // (0xB4) - - { KEY_LAUNCHMEDIA, VK_LAUNCH_MEDIA_SELECT }, // (0xB5) - - { KEY_LAUNCH0, VK_LAUNCH_APP1 }, // (0xB6) - - { KEY_LAUNCH1, VK_LAUNCH_APP2 }, // (0xB7) - - { KEY_SEMICOLON, VK_OEM_1 }, // (0xBA) - - { KEY_EQUAL, VK_OEM_PLUS }, // (0xBB) // Windows 2000/XP: For any country/region, the '+' key - { KEY_COMMA, VK_OEM_COMMA }, // (0xBC) // Windows 2000/XP: For any country/region, the ',' key - { KEY_MINUS, VK_OEM_MINUS }, // (0xBD) // Windows 2000/XP: For any country/region, the '-' key - { KEY_PERIOD, VK_OEM_PERIOD }, // (0xBE) // Windows 2000/XP: For any country/region, the '.' key - { KEY_SLASH, VK_OEM_2 }, // (0xBF) //Windows 2000/XP: For the US standard keyboard, the '/?' key - - { KEY_QUOTELEFT, VK_OEM_3 }, // (0xC0) - { KEY_BRACELEFT, VK_OEM_4 }, // (0xDB) - { KEY_BACKSLASH, VK_OEM_5 }, // (0xDC) - { KEY_BRACERIGHT, VK_OEM_6 }, // (0xDD) - { KEY_APOSTROPHE, VK_OEM_7 }, // (0xDE) - /* -{VK_OEM_8 (0xDF) -{VK_OEM_102 (0xE2) // Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard -*/ - //{ KEY_PLAY, VK_PLAY},// (0xFA) - - { KEY_UNKNOWN, 0 } -}; - -/* -VK_ZOOM (0xFB) -VK_NONAME (0xFC) -VK_PA1 (0xFD) -VK_OEM_CLEAR (0xFE) -*/ - -unsigned int KeyMappingWindows::get_keysym(unsigned int p_code) { - - for (int i = 0; _vk_to_keycode[i].keysym != KEY_UNKNOWN; i++) { - - if (_vk_to_keycode[i].keycode == p_code) { - //printf("outcode: %x\n",_vk_to_keycode[i].keysym); - - return _vk_to_keycode[i].keysym; - } - } - - return KEY_UNKNOWN; -} diff --git a/platform/windows/key_mapping_win.h b/platform/windows/key_mapping_win.h deleted file mode 100644 index e4f8a61d04..0000000000 --- a/platform/windows/key_mapping_win.h +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************/ -/* key_mapping_win.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef KEY_MAPPING_WINDOWS_H -#define KEY_MAPPING_WINDOWS_H - -#include "core/os/keyboard.h" - -#include - -#include - -class KeyMappingWindows { - - KeyMappingWindows(){}; - -public: - static unsigned int get_keysym(unsigned int p_code); -}; - -#endif diff --git a/platform/windows/key_mapping_windows.cpp b/platform/windows/key_mapping_windows.cpp new file mode 100644 index 0000000000..01bbb072bb --- /dev/null +++ b/platform/windows/key_mapping_windows.cpp @@ -0,0 +1,253 @@ +/*************************************************************************/ +/* key_mapping_windows.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "key_mapping_windows.h" + +#include + +struct _WinTranslatePair { + + unsigned int keysym; + unsigned int keycode; +}; + +static _WinTranslatePair _vk_to_keycode[] = { + + { KEY_BACKSPACE, VK_BACK }, // (0x08) // backspace + { KEY_TAB, VK_TAB }, //(0x09) + + //VK_CLEAR (0x0C) + + { KEY_ENTER, VK_RETURN }, //(0x0D) + + { KEY_SHIFT, VK_SHIFT }, //(0x10) + + { KEY_CONTROL, VK_CONTROL }, //(0x11) + + { KEY_ALT, VK_MENU }, //(0x12) + + { KEY_PAUSE, VK_PAUSE }, //(0x13) + + { KEY_CAPSLOCK, VK_CAPITAL }, //(0x14) + + { KEY_ESCAPE, VK_ESCAPE }, //(0x1B) + + { KEY_SPACE, VK_SPACE }, //(0x20) + + { KEY_PAGEUP, VK_PRIOR }, //(0x21) + + { KEY_PAGEDOWN, VK_NEXT }, //(0x22) + + { KEY_END, VK_END }, //(0x23) + + { KEY_HOME, VK_HOME }, //(0x24) + + { KEY_LEFT, VK_LEFT }, //(0x25) + + { KEY_UP, VK_UP }, //(0x26) + + { KEY_RIGHT, VK_RIGHT }, //(0x27) + + { KEY_DOWN, VK_DOWN }, // (0x28) + + //VK_SELECT (0x29) + + { KEY_PRINT, VK_PRINT }, // (0x2A) + + //VK_EXECUTE (0x2B) + + { KEY_PRINT, VK_SNAPSHOT }, // (0x2C) + + { KEY_INSERT, VK_INSERT }, // (0x2D) + + { KEY_DELETE, VK_DELETE }, // (0x2E) + + { KEY_HELP, VK_HELP }, // (0x2F) + + { KEY_0, (0x30) }, ////0 key + { KEY_1, (0x31) }, ////1 key + { KEY_2, (0x32) }, ////2 key + { KEY_3, (0x33) }, ////3 key + { KEY_4, (0x34) }, ////4 key + { KEY_5, (0x35) }, ////5 key + { KEY_6, (0x36) }, ////6 key + { KEY_7, (0x37) }, ////7 key + { KEY_8, (0x38) }, ////8 key + { KEY_9, (0x39) }, ////9 key + { KEY_A, (0x41) }, ////A key + { KEY_B, (0x42) }, ////B key + { KEY_C, (0x43) }, ////C key + { KEY_D, (0x44) }, ////D key + { KEY_E, (0x45) }, ////E key + { KEY_F, (0x46) }, ////F key + { KEY_G, (0x47) }, ////G key + { KEY_H, (0x48) }, ////H key + { KEY_I, (0x49) }, ////I key + { KEY_J, (0x4A) }, ////J key + { KEY_K, (0x4B) }, ////K key + { KEY_L, (0x4C) }, ////L key + { KEY_M, (0x4D) }, ////M key + { KEY_N, (0x4E) }, ////N key + { KEY_O, (0x4F) }, ////O key + { KEY_P, (0x50) }, ////P key + { KEY_Q, (0x51) }, ////Q key + { KEY_R, (0x52) }, ////R key + { KEY_S, (0x53) }, ////S key + { KEY_T, (0x54) }, ////T key + { KEY_U, (0x55) }, ////U key + { KEY_V, (0x56) }, ////V key + { KEY_W, (0x57) }, ////W key + { KEY_X, (0x58) }, ////X key + { KEY_Y, (0x59) }, ////Y key + { KEY_Z, (0x5A) }, ////Z key + + { KEY_MASK_META, VK_LWIN }, //(0x5B) + { KEY_MASK_META, VK_RWIN }, //(0x5C) + //VK_APPS (0x5D) + { KEY_STANDBY, VK_SLEEP }, //(0x5F) + { KEY_KP_0, VK_NUMPAD0 }, //(0x60) + { KEY_KP_1, VK_NUMPAD1 }, //(0x61) + { KEY_KP_2, VK_NUMPAD2 }, //(0x62) + { KEY_KP_3, VK_NUMPAD3 }, //(0x63) + { KEY_KP_4, VK_NUMPAD4 }, //(0x64) + { KEY_KP_5, VK_NUMPAD5 }, //(0x65) + { KEY_KP_6, VK_NUMPAD6 }, //(0x66) + { KEY_KP_7, VK_NUMPAD7 }, //(0x67) + { KEY_KP_8, VK_NUMPAD8 }, //(0x68) + { KEY_KP_9, VK_NUMPAD9 }, //(0x69) + { KEY_KP_MULTIPLY, VK_MULTIPLY }, // (0x6A) + { KEY_KP_ADD, VK_ADD }, // (0x6B) + //VK_SEPARATOR (0x6C) + { KEY_KP_SUBTRACT, VK_SUBTRACT }, // (0x6D) + { KEY_KP_PERIOD, VK_DECIMAL }, // (0x6E) + { KEY_KP_DIVIDE, VK_DIVIDE }, // (0x6F) + { KEY_F1, VK_F1 }, // (0x70) + { KEY_F2, VK_F2 }, // (0x71) + { KEY_F3, VK_F3 }, // (0x72) + { KEY_F4, VK_F4 }, // (0x73) + { KEY_F5, VK_F5 }, // (0x74) + { KEY_F6, VK_F6 }, // (0x75) + { KEY_F7, VK_F7 }, // (0x76) + { KEY_F8, VK_F8 }, // (0x77) + { KEY_F9, VK_F9 }, // (0x78) + { KEY_F10, VK_F10 }, // (0x79) + { KEY_F11, VK_F11 }, // (0x7A) + { KEY_F12, VK_F12 }, // (0x7B) + { KEY_F13, VK_F13 }, // (0x7C) + { KEY_F14, VK_F14 }, // (0x7D) + { KEY_F15, VK_F15 }, // (0x7E) + { KEY_F16, VK_F16 }, // (0x7F) + { KEY_NUMLOCK, VK_NUMLOCK }, // (0x90) + { KEY_SCROLLLOCK, VK_SCROLL }, // (0x91) + { KEY_SHIFT, VK_LSHIFT }, // (0xA0) + { KEY_SHIFT, VK_RSHIFT }, // (0xA1) + { KEY_CONTROL, VK_LCONTROL }, // (0xA2) + { KEY_CONTROL, VK_RCONTROL }, // (0xA3) + { KEY_MENU, VK_LMENU }, // (0xA4) + { KEY_MENU, VK_RMENU }, // (0xA5) + + { KEY_BACK, VK_BROWSER_BACK }, // (0xA6) + + { KEY_FORWARD, VK_BROWSER_FORWARD }, // (0xA7) + + { KEY_REFRESH, VK_BROWSER_REFRESH }, // (0xA8) + + { KEY_STOP, VK_BROWSER_STOP }, // (0xA9) + + { KEY_SEARCH, VK_BROWSER_SEARCH }, // (0xAA) + + { KEY_FAVORITES, VK_BROWSER_FAVORITES }, // (0xAB) + + { KEY_HOMEPAGE, VK_BROWSER_HOME }, // (0xAC) + + { KEY_VOLUMEMUTE, VK_VOLUME_MUTE }, // (0xAD) + + { KEY_VOLUMEDOWN, VK_VOLUME_DOWN }, // (0xAE) + + { KEY_VOLUMEUP, VK_VOLUME_UP }, // (0xAF) + + { KEY_MEDIANEXT, VK_MEDIA_NEXT_TRACK }, // (0xB0) + + { KEY_MEDIAPREVIOUS, VK_MEDIA_PREV_TRACK }, // (0xB1) + + { KEY_MEDIASTOP, VK_MEDIA_STOP }, // (0xB2) + + //VK_MEDIA_PLAY_PAUSE (0xB3) + + { KEY_LAUNCHMAIL, VK_LAUNCH_MAIL }, // (0xB4) + + { KEY_LAUNCHMEDIA, VK_LAUNCH_MEDIA_SELECT }, // (0xB5) + + { KEY_LAUNCH0, VK_LAUNCH_APP1 }, // (0xB6) + + { KEY_LAUNCH1, VK_LAUNCH_APP2 }, // (0xB7) + + { KEY_SEMICOLON, VK_OEM_1 }, // (0xBA) + + { KEY_EQUAL, VK_OEM_PLUS }, // (0xBB) // Windows 2000/XP: For any country/region, the '+' key + { KEY_COMMA, VK_OEM_COMMA }, // (0xBC) // Windows 2000/XP: For any country/region, the ',' key + { KEY_MINUS, VK_OEM_MINUS }, // (0xBD) // Windows 2000/XP: For any country/region, the '-' key + { KEY_PERIOD, VK_OEM_PERIOD }, // (0xBE) // Windows 2000/XP: For any country/region, the '.' key + { KEY_SLASH, VK_OEM_2 }, // (0xBF) //Windows 2000/XP: For the US standard keyboard, the '/?' key + + { KEY_QUOTELEFT, VK_OEM_3 }, // (0xC0) + { KEY_BRACELEFT, VK_OEM_4 }, // (0xDB) + { KEY_BACKSLASH, VK_OEM_5 }, // (0xDC) + { KEY_BRACERIGHT, VK_OEM_6 }, // (0xDD) + { KEY_APOSTROPHE, VK_OEM_7 }, // (0xDE) + /* +{VK_OEM_8 (0xDF) +{VK_OEM_102 (0xE2) // Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard +*/ + //{ KEY_PLAY, VK_PLAY},// (0xFA) + + { KEY_UNKNOWN, 0 } +}; + +/* +VK_ZOOM (0xFB) +VK_NONAME (0xFC) +VK_PA1 (0xFD) +VK_OEM_CLEAR (0xFE) +*/ + +unsigned int KeyMappingWindows::get_keysym(unsigned int p_code) { + + for (int i = 0; _vk_to_keycode[i].keysym != KEY_UNKNOWN; i++) { + + if (_vk_to_keycode[i].keycode == p_code) { + //printf("outcode: %x\n",_vk_to_keycode[i].keysym); + + return _vk_to_keycode[i].keysym; + } + } + + return KEY_UNKNOWN; +} diff --git a/platform/windows/key_mapping_windows.h b/platform/windows/key_mapping_windows.h new file mode 100644 index 0000000000..dbb8c20f1e --- /dev/null +++ b/platform/windows/key_mapping_windows.h @@ -0,0 +1,48 @@ +/*************************************************************************/ +/* key_mapping_windows.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef KEY_MAPPING_WINDOWS_H +#define KEY_MAPPING_WINDOWS_H + +#include "core/os/keyboard.h" + +#include + +#include + +class KeyMappingWindows { + + KeyMappingWindows(){}; + +public: + static unsigned int get_keysym(unsigned int p_code); +}; + +#endif // KEY_MAPPING_WINDOWS_H diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 9ae1be9afd..3de33da8f5 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -43,15 +43,15 @@ #include "drivers/windows/rw_lock_windows.h" #include "drivers/windows/semaphore_windows.h" #include "drivers/windows/thread_windows.h" -#include "joypad.h" +#include "joypad_windows.h" #include "lang_table.h" #include "main/main.h" #include "servers/audio_server.h" #include "servers/visual/visual_server_raster.h" #include "servers/visual/visual_server_wrap_mt.h" #include "windows_terminal_logger.h" -#include +#include #include #include #include @@ -1273,7 +1273,7 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int gl_context = NULL; while (!gl_context) { - gl_context = memnew(ContextGL_Win(hWnd, gles3_context)); + gl_context = memnew(ContextGL_Windows(hWnd, gles3_context)); if (gl_context->initialize() != OK) { memdelete(gl_context); diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index ba84c2098e..8ca58b534a 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -31,16 +31,16 @@ #ifndef OS_WINDOWS_H #define OS_WINDOWS_H -#include "context_gl_win.h" +#include "context_gl_windows.h" #include "core/os/input.h" #include "core/os/os.h" #include "core/project_settings.h" -#include "crash_handler_win.h" +#include "crash_handler_windows.h" #include "drivers/rtaudio/audio_driver_rtaudio.h" #include "drivers/unix/ip_unix.h" #include "drivers/wasapi/audio_driver_wasapi.h" #include "drivers/winmidi/midi_driver_winmidi.h" -#include "key_mapping_win.h" +#include "key_mapping_windows.h" #include "main/input_default.h" #include "power_windows.h" #include "servers/audio_server.h" @@ -87,7 +87,7 @@ class OS_Windows : public OS { int old_x, old_y; Point2i center; #if defined(OPENGL_ENABLED) - ContextGL_Win *gl_context; + ContextGL_Windows *gl_context; #endif VisualServer *visual_server; int pressrc; diff --git a/platform/windows/power_windows.h b/platform/windows/power_windows.h index 4d83d75e00..ef75ce6271 100644 --- a/platform/windows/power_windows.h +++ b/platform/windows/power_windows.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PLATFORM_WINDOWS_POWER_WINDOWS_H_ -#define PLATFORM_WINDOWS_POWER_WINDOWS_H_ +#ifndef POWER_WINDOWS_H +#define POWER_WINDOWS_H #include "core/os/dir_access.h" #include "core/os/file_access.h" @@ -55,4 +55,4 @@ public: int get_power_percent_left(); }; -#endif /* PLATFORM_WINDOWS_POWER_WINDOWS_H_ */ +#endif // POWER_WINDOWS_H -- cgit v1.2.3