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/android/export/export.cpp | 12 +- platform/android/os_android.cpp | 2 +- platform/android/os_android.h | 2 +- platform/android/power_android.cpp | 12 +- platform/android/power_android.h | 13 +- platform/iphone/SCsub | 2 +- platform/iphone/os_iphone.cpp | 3 +- platform/iphone/power_iphone.h | 6 +- platform/iphone/sem_iphone.cpp | 111 ------ platform/iphone/sem_iphone.h | 59 --- platform/iphone/semaphore_iphone.cpp | 112 ++++++ platform/iphone/semaphore_iphone.h | 59 +++ platform/osx/SCsub | 2 +- platform/osx/crash_handler_osx.h | 2 +- platform/osx/crash_handler_osx.mm | 4 +- platform/osx/os_osx.h | 3 +- platform/osx/os_osx.mm | 4 +- platform/osx/power_osx.cpp | 16 +- platform/osx/power_osx.h | 13 +- platform/osx/sem_osx.cpp | 106 ------ platform/osx/sem_osx.h | 59 --- platform/osx/semaphore_osx.cpp | 107 ++++++ platform/osx/semaphore_osx.h | 59 +++ platform/server/SCsub | 2 +- platform/server/os_server.cpp | 2 +- platform/server/os_server.h | 4 +- platform/uwp/SCsub | 4 +- platform/uwp/app.cpp | 10 +- platform/uwp/app.h | 2 +- platform/uwp/context_egl_uwp.cpp | 221 ++++++++++++ platform/uwp/context_egl_uwp.h | 87 +++++ platform/uwp/export/export.cpp | 20 +- platform/uwp/gl_context_egl.cpp | 221 ------------ platform/uwp/gl_context_egl.h | 86 ----- platform/uwp/os_uwp.cpp | 170 ++++----- platform/uwp/os_uwp.h | 16 +- platform/uwp/power_uwp.h | 6 +- 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 +- platform/x11/crash_handler_x11.cpp | 9 +- platform/x11/crash_handler_x11.h | 2 +- platform/x11/power_x11.h | 6 +- 64 files changed, 2581 insertions(+), 2795 deletions(-) delete mode 100644 platform/iphone/sem_iphone.cpp delete mode 100644 platform/iphone/sem_iphone.h create mode 100644 platform/iphone/semaphore_iphone.cpp create mode 100644 platform/iphone/semaphore_iphone.h delete mode 100644 platform/osx/sem_osx.cpp delete mode 100644 platform/osx/sem_osx.h create mode 100644 platform/osx/semaphore_osx.cpp create mode 100644 platform/osx/semaphore_osx.h create mode 100644 platform/uwp/context_egl_uwp.cpp create mode 100644 platform/uwp/context_egl_uwp.h delete mode 100644 platform/uwp/gl_context_egl.cpp delete mode 100644 platform/uwp/gl_context_egl.h 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 diff --git a/platform/android/export/export.cpp b/platform/android/export/export.cpp index f293eef2ba..60cc33e6bf 100644 --- a/platform/android/export/export.cpp +++ b/platform/android/export/export.cpp @@ -206,9 +206,9 @@ static const LauncherIcon launcher_icons[] = { { "launcher_icons/mdpi_48x48", "res/drawable-mdpi-v4/icon.png" } }; -class EditorExportAndroid : public EditorExportPlatform { +class EditorExportPlatformAndroid : public EditorExportPlatform { - GDCLASS(EditorExportAndroid, EditorExportPlatform) + GDCLASS(EditorExportPlatformAndroid, EditorExportPlatform) Ref logo; Ref run_icon; @@ -235,7 +235,7 @@ class EditorExportAndroid : public EditorExportPlatform { static void _device_poll_thread(void *ud) { - EditorExportAndroid *ea = (EditorExportAndroid *)ud; + EditorExportPlatformAndroid *ea = (EditorExportPlatformAndroid *)ud; while (!ea->quit_request) { @@ -1925,7 +1925,7 @@ public: virtual void resolve_platform_feature_priorities(const Ref &p_preset, Set &p_features) { } - EditorExportAndroid() { + EditorExportPlatformAndroid() { Ref img = memnew(Image(_android_logo)); logo.instance(); @@ -1941,7 +1941,7 @@ public: device_thread = Thread::create(_device_poll_thread, this); } - ~EditorExportAndroid() { + ~EditorExportPlatformAndroid() { quit_request = true; Thread::wait_to_finish(device_thread); memdelete(device_lock); @@ -1969,6 +1969,6 @@ void register_android_exporter() { EDITOR_DEF("export/android/timestamping_authority_url", ""); EDITOR_DEF("export/android/shutdown_adb_on_exit", true); - Ref exporter = Ref(memnew(EditorExportAndroid)); + Ref exporter = Ref(memnew(EditorExportPlatformAndroid)); EditorExport::get_singleton()->add_export_platform(exporter); } diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 2ee0b34c48..3ba8468e0b 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -175,7 +175,7 @@ Error OS_Android::initialize(const VideoMode &p_desired, int p_video_driver, int input = memnew(InputDefault); input->set_fallback_mapping("Default Android Gamepad"); - //power_manager = memnew(power_android); + //power_manager = memnew(PowerAndroid); return OK; } diff --git a/platform/android/os_android.h b/platform/android/os_android.h index 3c591af4bb..1e5b89e24d 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -134,7 +134,7 @@ private: SetKeepScreenOnFunc set_keep_screen_on_func; AlertFunc alert_func; - //power_android *power_manager; + //PowerAndroid *power_manager; int video_driver_index; public: diff --git a/platform/android/power_android.cpp b/platform/android/power_android.cpp index 40b9d81189..4d2fbfbf1a 100644 --- a/platform/android/power_android.cpp +++ b/platform/android/power_android.cpp @@ -190,7 +190,7 @@ int Android_JNI_GetPowerInfo(int *plugged, int *charged, int *battery, int *seco return 0; } -bool power_android::GetPowerInfo_Android() { +bool PowerAndroid::GetPowerInfo_Android() { int battery; int plugged; int charged; @@ -218,7 +218,7 @@ bool power_android::GetPowerInfo_Android() { return true; } -OS::PowerState power_android::get_power_state() { +OS::PowerState PowerAndroid::get_power_state() { if (GetPowerInfo_Android()) { return power_state; } else { @@ -227,7 +227,7 @@ OS::PowerState power_android::get_power_state() { } } -int power_android::get_power_seconds_left() { +int PowerAndroid::get_power_seconds_left() { if (GetPowerInfo_Android()) { return nsecs_left; } else { @@ -236,7 +236,7 @@ int power_android::get_power_seconds_left() { } } -int power_android::get_power_percent_left() { +int PowerAndroid::get_power_percent_left() { if (GetPowerInfo_Android()) { return percent_left; } else { @@ -245,11 +245,11 @@ int power_android::get_power_percent_left() { } } -power_android::power_android() : +PowerAndroid::PowerAndroid() : nsecs_left(-1), percent_left(-1), power_state(OS::POWERSTATE_UNKNOWN) { } -power_android::~power_android() { +PowerAndroid::~PowerAndroid() { } diff --git a/platform/android/power_android.h b/platform/android/power_android.h index 9730c53674..6cb745b6c0 100644 --- a/platform/android/power_android.h +++ b/platform/android/power_android.h @@ -28,13 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PLATFORM_ANDROID_POWER_ANDROID_H_ -#define PLATFORM_ANDROID_POWER_ANDROID_H_ +#ifndef POWER_ANDROID_H +#define POWER_ANDROID_H #include "core/os/os.h" + #include -class power_android { +class PowerAndroid { struct LocalReferenceHolder { JNIEnv *m_env; @@ -65,8 +66,8 @@ private: public: static int s_active; - power_android(); - virtual ~power_android(); + PowerAndroid(); + virtual ~PowerAndroid(); static bool LocalReferenceHolder_Init(struct LocalReferenceHolder *refholder, JNIEnv *env); static struct LocalReferenceHolder LocalReferenceHolder_Setup(const char *func); static void LocalReferenceHolder_Cleanup(struct LocalReferenceHolder *refholder); @@ -76,4 +77,4 @@ public: int get_power_percent_left(); }; -#endif /* PLATFORM_ANDROID_POWER_ANDROID_H_ */ +#endif // POWER_ANDROID_H diff --git a/platform/iphone/SCsub b/platform/iphone/SCsub index d5540fe8db..41991bce86 100644 --- a/platform/iphone/SCsub +++ b/platform/iphone/SCsub @@ -7,7 +7,7 @@ import os iphone_lib = [ 'godot_iphone.cpp', 'os_iphone.cpp', - 'sem_iphone.cpp', + 'semaphore_iphone.cpp', 'gl_view.mm', 'main.m', 'app_delegate.mm', diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp index 16634c3b30..c939e234b9 100644 --- a/platform/iphone/os_iphone.cpp +++ b/platform/iphone/os_iphone.cpp @@ -45,9 +45,10 @@ #include "core/project_settings.h" #include "drivers/unix/syslog_logger.h" -#include "sem_iphone.h" +#include "semaphore_iphone.h" #include "ios.h" + #include int OSIPhone::get_video_driver_count() const { diff --git a/platform/iphone/power_iphone.h b/platform/iphone/power_iphone.h index eb930b99c5..d7d4bf4a69 100644 --- a/platform/iphone/power_iphone.h +++ b/platform/iphone/power_iphone.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PLATFORM_IPHONE_POWER_IPHONE_H_ -#define PLATFORM_IPHONE_POWER_IPHONE_H_ +#ifndef POWER_IPHONE_H +#define POWER_IPHONE_H #include @@ -50,4 +50,4 @@ public: int get_power_percent_left(); }; -#endif /* PLATFORM_IPHONE_POWER_IPHONE_H_ */ +#endif // POWER_IPHONE_H diff --git a/platform/iphone/sem_iphone.cpp b/platform/iphone/sem_iphone.cpp deleted file mode 100644 index 05cdb6a2f7..0000000000 --- a/platform/iphone/sem_iphone.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************/ -/* sem_iphone.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 "sem_iphone.h" - -#include -#include - -void cgsem_init(cgsem_t *); -void cgsem_post(cgsem_t *); -void cgsem_wait(cgsem_t *); -void cgsem_destroy(cgsem_t *); - -void cgsem_init(cgsem_t *cgsem) { - int flags, fd, i; - - pipe(cgsem->pipefd); - - /* Make the pipes FD_CLOEXEC to allow them to close should we call - * execv on restart. */ - for (i = 0; i < 2; i++) { - fd = cgsem->pipefd[i]; - flags = fcntl(fd, F_GETFD, 0); - flags |= FD_CLOEXEC; - fcntl(fd, F_SETFD, flags); - } -} - -void cgsem_post(cgsem_t *cgsem) { - const char buf = 1; - - write(cgsem->pipefd[1], &buf, 1); -} - -void cgsem_wait(cgsem_t *cgsem) { - char buf; - - read(cgsem->pipefd[0], &buf, 1); -} - -void cgsem_destroy(cgsem_t *cgsem) { - close(cgsem->pipefd[1]); - close(cgsem->pipefd[0]); -} - -#include "core/os/memory.h" -#include - -Error SemaphoreIphone::wait() { - - cgsem_wait(&sem); - return OK; -} - -Error SemaphoreIphone::post() { - - cgsem_post(&sem); - - return OK; -} -int SemaphoreIphone::get() const { - - return 0; -} - -Semaphore *SemaphoreIphone::create_semaphore_iphone() { - - return memnew(SemaphoreIphone); -} - -void SemaphoreIphone::make_default() { - - create_func = create_semaphore_iphone; -} - -SemaphoreIphone::SemaphoreIphone() { - - cgsem_init(&sem); -} - -SemaphoreIphone::~SemaphoreIphone() { - - cgsem_destroy(&sem); -} diff --git a/platform/iphone/sem_iphone.h b/platform/iphone/sem_iphone.h deleted file mode 100644 index 134bc723d9..0000000000 --- a/platform/iphone/sem_iphone.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************/ -/* sem_iphone.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 SEM_IPHONE_H -#define SEM_IPHONE_H - -struct cgsem { - int pipefd[2]; -}; - -typedef struct cgsem cgsem_t; - -#include "core/os/semaphore.h" - -class SemaphoreIphone : public Semaphore { - - mutable cgsem_t sem; - - static Semaphore *create_semaphore_iphone(); - -public: - virtual Error wait(); - virtual Error post(); - virtual int get() const; - - static void make_default(); - SemaphoreIphone(); - - ~SemaphoreIphone(); -}; - -#endif diff --git a/platform/iphone/semaphore_iphone.cpp b/platform/iphone/semaphore_iphone.cpp new file mode 100644 index 0000000000..cc7dde72f7 --- /dev/null +++ b/platform/iphone/semaphore_iphone.cpp @@ -0,0 +1,112 @@ +/*************************************************************************/ +/* semaphore_iphone.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 "semaphore_iphone.h" + +#include +#include + +void cgsem_init(cgsem_t *); +void cgsem_post(cgsem_t *); +void cgsem_wait(cgsem_t *); +void cgsem_destroy(cgsem_t *); + +void cgsem_init(cgsem_t *cgsem) { + int flags, fd, i; + + pipe(cgsem->pipefd); + + /* Make the pipes FD_CLOEXEC to allow them to close should we call + * execv on restart. */ + for (i = 0; i < 2; i++) { + fd = cgsem->pipefd[i]; + flags = fcntl(fd, F_GETFD, 0); + flags |= FD_CLOEXEC; + fcntl(fd, F_SETFD, flags); + } +} + +void cgsem_post(cgsem_t *cgsem) { + const char buf = 1; + + write(cgsem->pipefd[1], &buf, 1); +} + +void cgsem_wait(cgsem_t *cgsem) { + char buf; + + read(cgsem->pipefd[0], &buf, 1); +} + +void cgsem_destroy(cgsem_t *cgsem) { + close(cgsem->pipefd[1]); + close(cgsem->pipefd[0]); +} + +#include "core/os/memory.h" + +#include + +Error SemaphoreIphone::wait() { + + cgsem_wait(&sem); + return OK; +} + +Error SemaphoreIphone::post() { + + cgsem_post(&sem); + + return OK; +} +int SemaphoreIphone::get() const { + + return 0; +} + +Semaphore *SemaphoreIphone::create_semaphore_iphone() { + + return memnew(SemaphoreIphone); +} + +void SemaphoreIphone::make_default() { + + create_func = create_semaphore_iphone; +} + +SemaphoreIphone::SemaphoreIphone() { + + cgsem_init(&sem); +} + +SemaphoreIphone::~SemaphoreIphone() { + + cgsem_destroy(&sem); +} diff --git a/platform/iphone/semaphore_iphone.h b/platform/iphone/semaphore_iphone.h new file mode 100644 index 0000000000..16658384e6 --- /dev/null +++ b/platform/iphone/semaphore_iphone.h @@ -0,0 +1,59 @@ +/*************************************************************************/ +/* semaphore_iphone.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 SEMAPHORE_IPHONE_H +#define SEMAPHORE_IPHONE_H + +struct cgsem { + int pipefd[2]; +}; + +typedef struct cgsem cgsem_t; + +#include "core/os/semaphore.h" + +class SemaphoreIphone : public Semaphore { + + mutable cgsem_t sem; + + static Semaphore *create_semaphore_iphone(); + +public: + virtual Error wait(); + virtual Error post(); + virtual int get() const; + + static void make_default(); + SemaphoreIphone(); + + ~SemaphoreIphone(); +}; + +#endif // SEMAPHORE_IPHONE_H diff --git a/platform/osx/SCsub b/platform/osx/SCsub index dc407eee9e..d2952ebdc0 100644 --- a/platform/osx/SCsub +++ b/platform/osx/SCsub @@ -10,7 +10,7 @@ files = [ 'crash_handler_osx.mm', 'os_osx.mm', 'godot_main_osx.mm', - 'sem_osx.cpp', + 'semaphore_osx.cpp', 'dir_access_osx.mm', 'joypad_osx.cpp', 'power_osx.cpp', diff --git a/platform/osx/crash_handler_osx.h b/platform/osx/crash_handler_osx.h index dead90ca90..6a72ce8ae9 100644 --- a/platform/osx/crash_handler_osx.h +++ b/platform/osx/crash_handler_osx.h @@ -45,4 +45,4 @@ public: ~CrashHandler(); }; -#endif +#endif // CRASH_HANDLER_OSX_H diff --git a/platform/osx/crash_handler_osx.mm b/platform/osx/crash_handler_osx.mm index 6684898085..ed8a955ae5 100644 --- a/platform/osx/crash_handler_osx.mm +++ b/platform/osx/crash_handler_osx.mm @@ -28,9 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include "crash_handler_osx.h" + +#include "core/os/os.h" #include "core/project_settings.h" #include "main/main.h" -#include "os_osx.h" #include #include diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h index 32199e0adb..dfe7b27bd0 100644 --- a/platform/osx/os_osx.h +++ b/platform/osx/os_osx.h @@ -43,6 +43,7 @@ #include "servers/visual/rasterizer.h" #include "servers/visual/visual_server_wrap_mt.h" #include "servers/visual_server.h" + #include #include #include @@ -132,7 +133,7 @@ public: String im_text; Point2 im_selection; - power_osx *power_manager; + PowerOSX *power_manager; CrashHandler crash_handler; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 6b65c1a529..225e0aee06 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -37,7 +37,7 @@ #include "drivers/gles2/rasterizer_gles2.h" #include "drivers/gles3/rasterizer_gles3.h" #include "main/main.h" -#include "sem_osx.h" +#include "semaphore_osx.h" #include "servers/visual/visual_server_raster.h" #include @@ -1461,7 +1461,7 @@ Error OS_OSX::initialize(const VideoMode &p_desired, int p_video_driver, int p_a input = memnew(InputDefault); joypad_osx = memnew(JoypadOSX); - power_manager = memnew(power_osx); + power_manager = memnew(PowerOSX); _ensure_user_data_dir(); diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp index a7cf9d831f..04d423d8c5 100644 --- a/platform/osx/power_osx.cpp +++ b/platform/osx/power_osx.cpp @@ -67,7 +67,7 @@ Adapted from corresponding SDL 2.0 code. CFDictionaryGetValueIfPresent(dict, CFSTR(k), (const void **)v) /* Note that AC power sources also include a laptop battery it is charging. */ -void power_osx::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging) { +void PowerOSX::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, bool *charging) { CFStringRef strval; /* don't CFRelease() this. */ CFBooleanRef bval; CFNumberRef numval; @@ -169,7 +169,7 @@ void power_osx::checkps(CFDictionaryRef dict, bool *have_ac, bool *have_battery, #undef STRMATCH // CODE CHUNK IMPORTED FROM SDL 2.0 -bool power_osx::GetPowerInfo_MacOSX() { +bool PowerOSX::GetPowerInfo_MacOSX() { CFTypeRef blob = IOPSCopyPowerSourcesInfo(); nsecs_left = -1; @@ -211,14 +211,14 @@ bool power_osx::GetPowerInfo_MacOSX() { return true; /* always the definitive answer on Mac OS X. */ } -bool power_osx::UpdatePowerInfo() { +bool PowerOSX::UpdatePowerInfo() { if (GetPowerInfo_MacOSX()) { return true; } return false; } -OS::PowerState power_osx::get_power_state() { +OS::PowerState PowerOSX::get_power_state() { if (UpdatePowerInfo()) { return power_state; } else { @@ -226,7 +226,7 @@ OS::PowerState power_osx::get_power_state() { } } -int power_osx::get_power_seconds_left() { +int PowerOSX::get_power_seconds_left() { if (UpdatePowerInfo()) { return nsecs_left; } else { @@ -234,7 +234,7 @@ int power_osx::get_power_seconds_left() { } } -int power_osx::get_power_percent_left() { +int PowerOSX::get_power_percent_left() { if (UpdatePowerInfo()) { return percent_left; } else { @@ -242,11 +242,11 @@ int power_osx::get_power_percent_left() { } } -power_osx::power_osx() : +PowerOSX::PowerOSX() : nsecs_left(-1), percent_left(-1), power_state(OS::POWERSTATE_UNKNOWN) { } -power_osx::~power_osx() { +PowerOSX::~PowerOSX() { } diff --git a/platform/osx/power_osx.h b/platform/osx/power_osx.h index 0f18f9f691..40d0d40fd4 100644 --- a/platform/osx/power_osx.h +++ b/platform/osx/power_osx.h @@ -28,15 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PLATFORM_OSX_POWER_OSX_H_ -#define PLATFORM_OSX_POWER_OSX_H_ +#ifndef POWER_OSX_H +#define POWER_OSX_H #include "core/os/file_access.h" #include "core/os/os.h" #include "dir_access_osx.h" + #include -class power_osx { +class PowerOSX { private: int nsecs_left; @@ -47,12 +48,12 @@ private: bool UpdatePowerInfo(); public: - power_osx(); - virtual ~power_osx(); + PowerOSX(); + virtual ~PowerOSX(); OS::PowerState get_power_state(); int get_power_seconds_left(); int get_power_percent_left(); }; -#endif /* PLATFORM_OSX_POWER_OSX_H_ */ +#endif // POWER_OSX_H diff --git a/platform/osx/sem_osx.cpp b/platform/osx/sem_osx.cpp deleted file mode 100644 index 4c3bad4379..0000000000 --- a/platform/osx/sem_osx.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************/ -/* sem_osx.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 "sem_osx.h" - -#include -#include - -void cgsem_init(cgsem_t *cgsem) { - int flags, fd, i; - - pipe(cgsem->pipefd); - - /* Make the pipes FD_CLOEXEC to allow them to close should we call - * execv on restart. */ - for (i = 0; i < 2; i++) { - fd = cgsem->pipefd[i]; - flags = fcntl(fd, F_GETFD, 0); - flags |= FD_CLOEXEC; - fcntl(fd, F_SETFD, flags); - } -} - -void cgsem_post(cgsem_t *cgsem) { - const char buf = 1; - - write(cgsem->pipefd[1], &buf, 1); -} - -void cgsem_wait(cgsem_t *cgsem) { - char buf; - - read(cgsem->pipefd[0], &buf, 1); -} - -void cgsem_destroy(cgsem_t *cgsem) { - close(cgsem->pipefd[1]); - close(cgsem->pipefd[0]); -} - -#include "core/os/memory.h" -#include - -Error SemaphoreOSX::wait() { - - cgsem_wait(&sem); - return OK; -} - -Error SemaphoreOSX::post() { - - cgsem_post(&sem); - - return OK; -} -int SemaphoreOSX::get() const { - - return 0; -} - -Semaphore *SemaphoreOSX::create_semaphore_osx() { - - return memnew(SemaphoreOSX); -} - -void SemaphoreOSX::make_default() { - - create_func = create_semaphore_osx; -} - -SemaphoreOSX::SemaphoreOSX() { - - cgsem_init(&sem); -} - -SemaphoreOSX::~SemaphoreOSX() { - - cgsem_destroy(&sem); -} diff --git a/platform/osx/sem_osx.h b/platform/osx/sem_osx.h deleted file mode 100644 index 563bdfdcb1..0000000000 --- a/platform/osx/sem_osx.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************/ -/* sem_osx.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 SEM_OSX_H -#define SEM_OSX_H - -struct cgsem { - int pipefd[2]; -}; - -typedef struct cgsem cgsem_t; - -#include "core/os/semaphore.h" - -class SemaphoreOSX : public Semaphore { - - mutable cgsem_t sem; - - static Semaphore *create_semaphore_osx(); - -public: - virtual Error wait(); - virtual Error post(); - virtual int get() const; - - static void make_default(); - SemaphoreOSX(); - - ~SemaphoreOSX(); -}; - -#endif diff --git a/platform/osx/semaphore_osx.cpp b/platform/osx/semaphore_osx.cpp new file mode 100644 index 0000000000..fe7d19bd9e --- /dev/null +++ b/platform/osx/semaphore_osx.cpp @@ -0,0 +1,107 @@ +/*************************************************************************/ +/* semaphore_osx.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 "semaphore_osx.h" + +#include +#include + +void cgsem_init(cgsem_t *cgsem) { + int flags, fd, i; + + pipe(cgsem->pipefd); + + /* Make the pipes FD_CLOEXEC to allow them to close should we call + * execv on restart. */ + for (i = 0; i < 2; i++) { + fd = cgsem->pipefd[i]; + flags = fcntl(fd, F_GETFD, 0); + flags |= FD_CLOEXEC; + fcntl(fd, F_SETFD, flags); + } +} + +void cgsem_post(cgsem_t *cgsem) { + const char buf = 1; + + write(cgsem->pipefd[1], &buf, 1); +} + +void cgsem_wait(cgsem_t *cgsem) { + char buf; + + read(cgsem->pipefd[0], &buf, 1); +} + +void cgsem_destroy(cgsem_t *cgsem) { + close(cgsem->pipefd[1]); + close(cgsem->pipefd[0]); +} + +#include "core/os/memory.h" + +#include + +Error SemaphoreOSX::wait() { + + cgsem_wait(&sem); + return OK; +} + +Error SemaphoreOSX::post() { + + cgsem_post(&sem); + + return OK; +} +int SemaphoreOSX::get() const { + + return 0; +} + +Semaphore *SemaphoreOSX::create_semaphore_osx() { + + return memnew(SemaphoreOSX); +} + +void SemaphoreOSX::make_default() { + + create_func = create_semaphore_osx; +} + +SemaphoreOSX::SemaphoreOSX() { + + cgsem_init(&sem); +} + +SemaphoreOSX::~SemaphoreOSX() { + + cgsem_destroy(&sem); +} diff --git a/platform/osx/semaphore_osx.h b/platform/osx/semaphore_osx.h new file mode 100644 index 0000000000..c8e7c45227 --- /dev/null +++ b/platform/osx/semaphore_osx.h @@ -0,0 +1,59 @@ +/*************************************************************************/ +/* semaphore_osx.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 SEMAPHORE_OSX_H +#define SEMAPHORE_OSX_H + +struct cgsem { + int pipefd[2]; +}; + +typedef struct cgsem cgsem_t; + +#include "core/os/semaphore.h" + +class SemaphoreOSX : public Semaphore { + + mutable cgsem_t sem; + + static Semaphore *create_semaphore_osx(); + +public: + virtual Error wait(); + virtual Error post(); + virtual int get() const; + + static void make_default(); + SemaphoreOSX(); + + ~SemaphoreOSX(); +}; + +#endif // SEMAPHORE_OSX_H diff --git a/platform/server/SCsub b/platform/server/SCsub index 51fd05a87e..62d45efbc0 100644 --- a/platform/server/SCsub +++ b/platform/server/SCsub @@ -13,7 +13,7 @@ common_server = [\ if sys.platform == "darwin": common_server.append("#platform/osx/crash_handler_osx.mm") common_server.append("#platform/osx/power_osx.cpp") - common_server.append("#platform/osx/sem_osx.cpp") + common_server.append("#platform/osx/semaphore_osx.cpp") else: common_server.append("#platform/x11/crash_handler_x11.cpp") common_server.append("#platform/x11/power_x11.cpp") diff --git a/platform/server/os_server.cpp b/platform/server/os_server.cpp index 9b6e7864e1..e643d3e8bb 100644 --- a/platform/server/os_server.cpp +++ b/platform/server/os_server.cpp @@ -93,7 +93,7 @@ Error OS_Server::initialize(const VideoMode &p_desired, int p_video_driver, int input = memnew(InputDefault); #ifdef __APPLE__ - power_manager = memnew(power_osx); + power_manager = memnew(PowerOSX); #else power_manager = memnew(PowerX11); #endif diff --git a/platform/server/os_server.h b/platform/server/os_server.h index 7273a690ca..312b5811d1 100644 --- a/platform/server/os_server.h +++ b/platform/server/os_server.h @@ -38,7 +38,7 @@ #ifdef __APPLE__ #include "platform/osx/crash_handler_osx.h" #include "platform/osx/power_osx.h" -#include "platform/osx/sem_osx.h" +#include "platform/osx/semaphore_osx.h" #else #include "platform/x11/crash_handler_x11.h" #include "platform/x11/power_x11.h" @@ -69,7 +69,7 @@ class OS_Server : public OS_Unix { InputDefault *input; #ifdef __APPLE__ - power_osx *power_manager; + PowerOSX *power_manager; #else PowerX11 *power_manager; #endif diff --git a/platform/uwp/SCsub b/platform/uwp/SCsub index fb0c4a92ae..c14290f0c4 100644 --- a/platform/uwp/SCsub +++ b/platform/uwp/SCsub @@ -4,11 +4,11 @@ Import('env') files = [ 'thread_uwp.cpp', - '#platform/windows/key_mapping_win.cpp', + '#platform/windows/key_mapping_windows.cpp', '#platform/windows/windows_terminal_logger.cpp', 'joypad_uwp.cpp', 'power_uwp.cpp', - 'gl_context_egl.cpp', + 'context_egl_uwp.cpp', 'app.cpp', 'os_uwp.cpp', ] diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp index 1b8f9f3f9e..4f2ee0237a 100644 --- a/platform/uwp/app.cpp +++ b/platform/uwp/app.cpp @@ -39,7 +39,7 @@ #include "core/os/keyboard.h" #include "main/main.h" -#include "platform/windows/key_mapping_win.h" +#include "platform/windows/key_mapping_windows.h" #include @@ -99,7 +99,7 @@ void App::Initialize(CoreApplicationView ^ applicationView) { // Information about the Suspending and Resuming event handlers can be found here: // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh994930.aspx - os = new OSUWP; + os = new OS_UWP; } // Called when the CoreWindow object is created (or re-created). @@ -398,7 +398,7 @@ void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) { void App::key_event(Windows::UI::Core::CoreWindow ^ sender, bool p_pressed, Windows::UI::Core::KeyEventArgs ^ key_args, Windows::UI::Core::CharacterReceivedEventArgs ^ char_args) { - OSUWP::KeyEvent ke; + OS_UWP::KeyEvent ke; ke.control = sender->GetAsyncKeyState(VirtualKey::Control) == CoreVirtualKeyStates::Down; ke.alt = sender->GetAsyncKeyState(VirtualKey::Menu) == CoreVirtualKeyStates::Down; @@ -408,14 +408,14 @@ void App::key_event(Windows::UI::Core::CoreWindow ^ sender, bool p_pressed, Wind if (key_args != nullptr) { - ke.type = OSUWP::KeyEvent::MessageType::KEY_EVENT_MESSAGE; + ke.type = OS_UWP::KeyEvent::MessageType::KEY_EVENT_MESSAGE; ke.unicode = 0; ke.scancode = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey); ke.echo = (!p_pressed && !key_args->KeyStatus.IsKeyReleased) || (p_pressed && key_args->KeyStatus.WasKeyDown); } else { - ke.type = OSUWP::KeyEvent::MessageType::CHAR_EVENT_MESSAGE; + ke.type = OS_UWP::KeyEvent::MessageType::CHAR_EVENT_MESSAGE; ke.unicode = char_args->KeyCode; ke.scancode = 0; ke.echo = (!p_pressed && !char_args->KeyStatus.IsKeyReleased) || (p_pressed && char_args->KeyStatus.WasKeyDown); diff --git a/platform/uwp/app.h b/platform/uwp/app.h index d403dace9d..0bd996d483 100644 --- a/platform/uwp/app.h +++ b/platform/uwp/app.h @@ -103,7 +103,7 @@ namespace GodotUWP EGLSurface mEglSurface; CoreWindow^ window; - OSUWP* os; + OS_UWP* os; int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse int last_touch_y[32]; diff --git a/platform/uwp/context_egl_uwp.cpp b/platform/uwp/context_egl_uwp.cpp new file mode 100644 index 0000000000..061c54687c --- /dev/null +++ b/platform/uwp/context_egl_uwp.cpp @@ -0,0 +1,221 @@ +/*************************************************************************/ +/* context_egl_uwp.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 "context_egl_uwp.h" + +#include "EGL/eglext.h" + +using Platform::Exception; + +void ContextEGL_UWP::release_current() { + + eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, mEglContext); +}; + +void ContextEGL_UWP::make_current() { + + eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext); +}; + +int ContextEGL_UWP::get_window_width() { + + return width; +}; + +int ContextEGL_UWP::get_window_height() { + + return height; +}; + +void ContextEGL_UWP::reset() { + + cleanup(); + + window = CoreWindow::GetForCurrentThread(); + initialize(); +}; + +void ContextEGL_UWP::swap_buffers() { + + if (eglSwapBuffers(mEglDisplay, mEglSurface) != EGL_TRUE) { + cleanup(); + + window = CoreWindow::GetForCurrentThread(); + initialize(); + + // tell rasterizer to reload textures and stuff? + } +}; + +Error ContextEGL_UWP::initialize() { + + EGLint configAttribList[] = { + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 8, + EGL_STENCIL_SIZE, 8, + EGL_SAMPLE_BUFFERS, 0, + EGL_NONE + }; + + EGLint surfaceAttribList[] = { + EGL_NONE, EGL_NONE + }; + + EGLint numConfigs = 0; + EGLint majorVersion = 1; + EGLint minorVersion; + if (driver == GLES_2_0) { + minorVersion = 0; + } else { + minorVersion = 5; + } + EGLDisplay display = EGL_NO_DISPLAY; + EGLContext context = EGL_NO_CONTEXT; + EGLSurface surface = EGL_NO_SURFACE; + EGLConfig config = nullptr; + EGLint contextAttribs[3]; + if (driver == GLES_2_0) { + contextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION; + contextAttribs[1] = 2; + contextAttribs[2] = EGL_NONE; + } else { + contextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION; + contextAttribs[1] = 3; + contextAttribs[2] = EGL_NONE; + } + + try { + + const EGLint displayAttributes[] = { + /*EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9, + EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3, + EGL_NONE,*/ + // These are the default display attributes, used to request ANGLE's D3D11 renderer. + // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+. + EGL_PLATFORM_ANGLE_TYPE_ANGLE, + EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, + + // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices. + // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it. + EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, + EGL_TRUE, + + // EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call + // the IDXGIDevice3::Trim method on behalf of the application when it gets suspended. + // Calling IDXGIDevice3::Trim when an application is suspended is a Windows Store application certification requirement. + EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, + EGL_TRUE, + EGL_NONE, + }; + + PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast(eglGetProcAddress("eglGetPlatformDisplayEXT")); + + if (!eglGetPlatformDisplayEXT) { + throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT"); + } + + display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes); + + if (display == EGL_NO_DISPLAY) { + throw Exception::CreateException(E_FAIL, L"Failed to get default EGL display"); + } + + if (eglInitialize(display, &majorVersion, &minorVersion) == EGL_FALSE) { + throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL"); + } + + if (eglGetConfigs(display, NULL, 0, &numConfigs) == EGL_FALSE) { + throw Exception::CreateException(E_FAIL, L"Failed to get EGLConfig count"); + } + + if (eglChooseConfig(display, configAttribList, &config, 1, &numConfigs) == EGL_FALSE) { + throw Exception::CreateException(E_FAIL, L"Failed to choose first EGLConfig count"); + } + + surface = eglCreateWindowSurface(display, config, reinterpret_cast(window), surfaceAttribList); + if (surface == EGL_NO_SURFACE) { + throw Exception::CreateException(E_FAIL, L"Failed to create EGL fullscreen surface"); + } + + context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs); + if (context == EGL_NO_CONTEXT) { + throw Exception::CreateException(E_FAIL, L"Failed to create EGL context"); + } + + if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { + throw Exception::CreateException(E_FAIL, L"Failed to make fullscreen EGLSurface current"); + } + } catch (...) { + return FAILED; + }; + + mEglDisplay = display; + mEglSurface = surface; + mEglContext = context; + + eglQuerySurface(display, surface, EGL_WIDTH, &width); + eglQuerySurface(display, surface, EGL_HEIGHT, &height); + + return OK; +}; + +void ContextEGL_UWP::cleanup() { + + if (mEglDisplay != EGL_NO_DISPLAY && mEglSurface != EGL_NO_SURFACE) { + eglDestroySurface(mEglDisplay, mEglSurface); + mEglSurface = EGL_NO_SURFACE; + } + + if (mEglDisplay != EGL_NO_DISPLAY && mEglContext != EGL_NO_CONTEXT) { + eglDestroyContext(mEglDisplay, mEglContext); + mEglContext = EGL_NO_CONTEXT; + } + + if (mEglDisplay != EGL_NO_DISPLAY) { + eglTerminate(mEglDisplay); + mEglDisplay = EGL_NO_DISPLAY; + } +}; + +ContextEGL_UWP::ContextEGL_UWP(CoreWindow ^ p_window, Driver p_driver) : + mEglDisplay(EGL_NO_DISPLAY), + mEglContext(EGL_NO_CONTEXT), + mEglSurface(EGL_NO_SURFACE), + driver(p_driver), + window(p_window) {} + +ContextEGL_UWP::~ContextEGL_UWP() { + + cleanup(); +}; diff --git a/platform/uwp/context_egl_uwp.h b/platform/uwp/context_egl_uwp.h new file mode 100644 index 0000000000..812bdfb688 --- /dev/null +++ b/platform/uwp/context_egl_uwp.h @@ -0,0 +1,87 @@ +/*************************************************************************/ +/* context_egl_uwp.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 CONTEXT_EGL_UWP_H +#define CONTEXT_EGL_UWP_H + +#include + +#include + +#include "core/error_list.h" +#include "core/os/os.h" +#include "drivers/gl_context/context_gl.h" + +using namespace Windows::UI::Core; + +class ContextEGL_UWP : public ContextGL { + +public: + enum Driver { + GLES_2_0, + GLES_3_0, + }; + +private: + CoreWindow ^ window; + + EGLDisplay mEglDisplay; + EGLContext mEglContext; + EGLSurface mEglSurface; + + EGLint width; + EGLint height; + + bool vsync; + + Driver driver; + +public: + virtual void release_current(); + + virtual void make_current(); + + virtual int get_window_width(); + virtual int get_window_height(); + virtual void swap_buffers(); + + virtual void set_use_vsync(bool use) { vsync = use; } + virtual bool is_using_vsync() const { return vsync; } + + virtual Error initialize(); + void reset(); + + void cleanup(); + + ContextEGL_UWP(CoreWindow ^ p_window, Driver p_driver); + virtual ~ContextEGL_UWP(); +}; + +#endif // CONTEXT_EGL_UWP_H diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index 6808016f13..a4655117a7 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -646,9 +646,9 @@ AppxPackager::~AppxPackager() {} //////////////////////////////////////////////////////////////////// -class EditorExportUWP : public EditorExportPlatform { +class EditorExportPlatformUWP : public EditorExportPlatform { - GDCLASS(EditorExportUWP, EditorExportPlatform); + GDCLASS(EditorExportPlatformUWP, EditorExportPlatform); Ref logo; @@ -1035,13 +1035,13 @@ public: r_features->push_back("s3tc"); r_features->push_back("etc"); switch ((int)p_preset->get("architecture/target")) { - case EditorExportUWP::ARM: { + case EditorExportPlatformUWP::ARM: { r_features->push_back("arm"); } break; - case EditorExportUWP::X86: { + case EditorExportPlatformUWP::X86: { r_features->push_back("32"); } break; - case EditorExportUWP::X64: { + case EditorExportPlatformUWP::X64: { r_features->push_back("64"); } break; } @@ -1123,13 +1123,13 @@ public: String platform_infix; switch (arch) { - case EditorExportUWP::ARM: { + case EditorExportPlatformUWP::ARM: { platform_infix = "arm"; } break; - case EditorExportUWP::X86: { + case EditorExportPlatformUWP::X86: { platform_infix = "x86"; } break; - case EditorExportUWP::X64: { + case EditorExportPlatformUWP::X64: { platform_infix = "x64"; } break; } @@ -1459,7 +1459,7 @@ public: virtual void resolve_platform_feature_priorities(const Ref &p_preset, Set &p_features) { } - EditorExportUWP() { + EditorExportPlatformUWP() { Ref img = memnew(Image(_uwp_logo)); logo.instance(); logo->create_from_image(img); @@ -1478,7 +1478,7 @@ void register_uwp_exporter() { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "export/uwp/debug_algorithm", PROPERTY_HINT_ENUM, "MD5,SHA1,SHA256")); #endif // WINDOWS_ENABLED - Ref exporter; + Ref exporter; exporter.instance(); EditorExport::get_singleton()->add_export_platform(exporter); } diff --git a/platform/uwp/gl_context_egl.cpp b/platform/uwp/gl_context_egl.cpp deleted file mode 100644 index db15be3e06..0000000000 --- a/platform/uwp/gl_context_egl.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/*************************************************************************/ -/* gl_context_egl.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 "gl_context_egl.h" - -#include "EGL/eglext.h" - -using Platform::Exception; - -void ContextEGL::release_current() { - - eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, mEglContext); -}; - -void ContextEGL::make_current() { - - eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext); -}; - -int ContextEGL::get_window_width() { - - return width; -}; - -int ContextEGL::get_window_height() { - - return height; -}; - -void ContextEGL::reset() { - - cleanup(); - - window = CoreWindow::GetForCurrentThread(); - initialize(); -}; - -void ContextEGL::swap_buffers() { - - if (eglSwapBuffers(mEglDisplay, mEglSurface) != EGL_TRUE) { - cleanup(); - - window = CoreWindow::GetForCurrentThread(); - initialize(); - - // tell rasterizer to reload textures and stuff? - } -}; - -Error ContextEGL::initialize() { - - EGLint configAttribList[] = { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 8, - EGL_STENCIL_SIZE, 8, - EGL_SAMPLE_BUFFERS, 0, - EGL_NONE - }; - - EGLint surfaceAttribList[] = { - EGL_NONE, EGL_NONE - }; - - EGLint numConfigs = 0; - EGLint majorVersion = 1; - EGLint minorVersion; - if (driver == GLES_2_0) { - minorVersion = 0; - } else { - minorVersion = 5; - } - EGLDisplay display = EGL_NO_DISPLAY; - EGLContext context = EGL_NO_CONTEXT; - EGLSurface surface = EGL_NO_SURFACE; - EGLConfig config = nullptr; - EGLint contextAttribs[3]; - if (driver == GLES_2_0) { - contextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION; - contextAttribs[1] = 2; - contextAttribs[2] = EGL_NONE; - } else { - contextAttribs[0] = EGL_CONTEXT_CLIENT_VERSION; - contextAttribs[1] = 3; - contextAttribs[2] = EGL_NONE; - } - - try { - - const EGLint displayAttributes[] = { - /*EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, - EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE, 9, - EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE, 3, - EGL_NONE,*/ - // These are the default display attributes, used to request ANGLE's D3D11 renderer. - // eglInitialize will only succeed with these attributes if the hardware supports D3D11 Feature Level 10_0+. - EGL_PLATFORM_ANGLE_TYPE_ANGLE, - EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, - - // EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER is an optimization that can have large performance benefits on mobile devices. - // Its syntax is subject to change, though. Please update your Visual Studio templates if you experience compilation issues with it. - EGL_ANGLE_DISPLAY_ALLOW_RENDER_TO_BACK_BUFFER, - EGL_TRUE, - - // EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE is an option that enables ANGLE to automatically call - // the IDXGIDevice3::Trim method on behalf of the application when it gets suspended. - // Calling IDXGIDevice3::Trim when an application is suspended is a Windows Store application certification requirement. - EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, - EGL_TRUE, - EGL_NONE, - }; - - PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT = reinterpret_cast(eglGetProcAddress("eglGetPlatformDisplayEXT")); - - if (!eglGetPlatformDisplayEXT) { - throw Exception::CreateException(E_FAIL, L"Failed to get function eglGetPlatformDisplayEXT"); - } - - display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes); - - if (display == EGL_NO_DISPLAY) { - throw Exception::CreateException(E_FAIL, L"Failed to get default EGL display"); - } - - if (eglInitialize(display, &majorVersion, &minorVersion) == EGL_FALSE) { - throw Exception::CreateException(E_FAIL, L"Failed to initialize EGL"); - } - - if (eglGetConfigs(display, NULL, 0, &numConfigs) == EGL_FALSE) { - throw Exception::CreateException(E_FAIL, L"Failed to get EGLConfig count"); - } - - if (eglChooseConfig(display, configAttribList, &config, 1, &numConfigs) == EGL_FALSE) { - throw Exception::CreateException(E_FAIL, L"Failed to choose first EGLConfig count"); - } - - surface = eglCreateWindowSurface(display, config, reinterpret_cast(window), surfaceAttribList); - if (surface == EGL_NO_SURFACE) { - throw Exception::CreateException(E_FAIL, L"Failed to create EGL fullscreen surface"); - } - - context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs); - if (context == EGL_NO_CONTEXT) { - throw Exception::CreateException(E_FAIL, L"Failed to create EGL context"); - } - - if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { - throw Exception::CreateException(E_FAIL, L"Failed to make fullscreen EGLSurface current"); - } - } catch (...) { - return FAILED; - }; - - mEglDisplay = display; - mEglSurface = surface; - mEglContext = context; - - eglQuerySurface(display, surface, EGL_WIDTH, &width); - eglQuerySurface(display, surface, EGL_HEIGHT, &height); - - return OK; -}; - -void ContextEGL::cleanup() { - - if (mEglDisplay != EGL_NO_DISPLAY && mEglSurface != EGL_NO_SURFACE) { - eglDestroySurface(mEglDisplay, mEglSurface); - mEglSurface = EGL_NO_SURFACE; - } - - if (mEglDisplay != EGL_NO_DISPLAY && mEglContext != EGL_NO_CONTEXT) { - eglDestroyContext(mEglDisplay, mEglContext); - mEglContext = EGL_NO_CONTEXT; - } - - if (mEglDisplay != EGL_NO_DISPLAY) { - eglTerminate(mEglDisplay); - mEglDisplay = EGL_NO_DISPLAY; - } -}; - -ContextEGL::ContextEGL(CoreWindow ^ p_window, Driver p_driver) : - mEglDisplay(EGL_NO_DISPLAY), - mEglContext(EGL_NO_CONTEXT), - mEglSurface(EGL_NO_SURFACE), - driver(p_driver), - window(p_window) {} - -ContextEGL::~ContextEGL() { - - cleanup(); -}; diff --git a/platform/uwp/gl_context_egl.h b/platform/uwp/gl_context_egl.h deleted file mode 100644 index 60feed2e24..0000000000 --- a/platform/uwp/gl_context_egl.h +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************/ -/* gl_context_egl.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 CONTEXT_EGL_H -#define CONTEXT_EGL_H - -#include - -#include "EGL/egl.h" -#include "core/error_list.h" -#include "core/os/os.h" -#include "drivers/gl_context/context_gl.h" - -using namespace Windows::UI::Core; - -class ContextEGL : public ContextGL { - -public: - enum Driver { - GLES_2_0, - GLES_3_0, - }; - -private: - CoreWindow ^ window; - - EGLDisplay mEglDisplay; - EGLContext mEglContext; - EGLSurface mEglSurface; - - EGLint width; - EGLint height; - - bool vsync; - - Driver driver; - -public: - virtual void release_current(); - - virtual void make_current(); - - virtual int get_window_width(); - virtual int get_window_height(); - virtual void swap_buffers(); - - virtual void set_use_vsync(bool use) { vsync = use; } - virtual bool is_using_vsync() const { return vsync; } - - virtual Error initialize(); - void reset(); - - void cleanup(); - - ContextEGL(CoreWindow ^ p_window, Driver p_driver); - virtual ~ContextEGL(); -}; - -#endif diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index ea4f63b49c..9c9280ac7e 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -67,22 +67,22 @@ using namespace Windows::Devices::Sensors; using namespace Windows::ApplicationModel::DataTransfer; using namespace concurrency; -int OSUWP::get_video_driver_count() const { +int OS_UWP::get_video_driver_count() const { return 2; } -Size2 OSUWP::get_window_size() const { +Size2 OS_UWP::get_window_size() const { Size2 size; size.width = video_mode.width; size.height = video_mode.height; return size; } -int OSUWP::get_current_video_driver() const { +int OS_UWP::get_current_video_driver() const { return video_driver_index; } -void OSUWP::set_window_size(const Size2 p_size) { +void OS_UWP::set_window_size(const Size2 p_size) { Windows::Foundation::Size new_size; new_size.Width = p_size.width; @@ -97,7 +97,7 @@ void OSUWP::set_window_size(const Size2 p_size) { } } -void OSUWP::set_window_fullscreen(bool p_enabled) { +void OS_UWP::set_window_fullscreen(bool p_enabled) { ApplicationView ^ view = ApplicationView::GetForCurrentView(); @@ -117,12 +117,12 @@ void OSUWP::set_window_fullscreen(bool p_enabled) { } } -bool OSUWP::is_window_fullscreen() const { +bool OS_UWP::is_window_fullscreen() const { return ApplicationView::GetForCurrentView()->IsFullScreenMode; } -void OSUWP::set_keep_screen_on(bool p_enabled) { +void OS_UWP::set_keep_screen_on(bool p_enabled) { if (is_keep_screen_on() == p_enabled) return; @@ -134,7 +134,7 @@ void OSUWP::set_keep_screen_on(bool p_enabled) { OS::set_keep_screen_on(p_enabled); } -void OSUWP::initialize_core() { +void OS_UWP::initialize_core() { last_button_state = 0; @@ -167,36 +167,36 @@ void OSUWP::initialize_core() { cursor_shape = CURSOR_ARROW; } -bool OSUWP::can_draw() const { +bool OS_UWP::can_draw() const { return !minimized; }; -void OSUWP::set_window(Windows::UI::Core::CoreWindow ^ p_window) { +void OS_UWP::set_window(Windows::UI::Core::CoreWindow ^ p_window) { window = p_window; } -void OSUWP::screen_size_changed() { +void OS_UWP::screen_size_changed() { gl_context->reset(); }; -Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { +Error OS_UWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { main_loop = NULL; outside = true; - ContextEGL::Driver opengl_api_type = ContextEGL::GLES_2_0; + ContextEGL_UWP::Driver opengl_api_type = ContextEGL_UWP::GLES_2_0; if (p_video_driver == VIDEO_DRIVER_GLES2) { - opengl_api_type = ContextEGL::GLES_2_0; + opengl_api_type = ContextEGL_UWP::GLES_2_0; } bool gl_initialization_error = false; gl_context = NULL; while (!gl_context) { - gl_context = memnew(ContextEGL(window, opengl_api_type)); + gl_context = memnew(ContextEGL_UWP(window, opengl_api_type)); if (gl_context->initialize() != OK) { memdelete(gl_context); @@ -209,7 +209,7 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au } p_video_driver = VIDEO_DRIVER_GLES2; - opengl_api_type = ContextEGL::GLES_2_0; + opengl_api_type = ContextEGL_UWP::GLES_2_0; } else { gl_initialization_error = true; break; @@ -218,7 +218,7 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au } while (true) { - if (opengl_api_type == ContextEGL::GLES_3_0) { + if (opengl_api_type == ContextEGL_UWP::GLES_3_0) { if (RasterizerGLES3::is_viable() == OK) { RasterizerGLES3::register_config(); RasterizerGLES3::make_current(); @@ -226,7 +226,7 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au } else { if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best") { p_video_driver = VIDEO_DRIVER_GLES2; - opengl_api_type = ContextEGL::GLES_2_0; + opengl_api_type = ContextEGL_UWP::GLES_2_0; continue; } else { gl_initialization_error = true; @@ -235,7 +235,7 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au } } - if (opengl_api_type == ContextEGL::GLES_2_0) { + if (opengl_api_type == ContextEGL_UWP::GLES_2_0) { if (RasterizerGLES2::is_viable() == OK) { RasterizerGLES2::register_config(); RasterizerGLES2::make_current(); @@ -349,7 +349,7 @@ Error OSUWP::initialize(const VideoMode &p_desired, int p_video_driver, int p_au return OK; } -void OSUWP::set_clipboard(const String &p_text) { +void OS_UWP::set_clipboard(const String &p_text) { DataPackage ^ clip = ref new DataPackage(); clip->RequestedOperation = DataPackageOperation::Copy; @@ -358,7 +358,7 @@ void OSUWP::set_clipboard(const String &p_text) { Clipboard::SetContent(clip); }; -String OSUWP::get_clipboard() const { +String OS_UWP::get_clipboard() const { if (managed_object->clipboard != nullptr) return managed_object->clipboard->Data(); @@ -366,25 +366,25 @@ String OSUWP::get_clipboard() const { return ""; }; -void OSUWP::input_event(const Ref &p_event) { +void OS_UWP::input_event(const Ref &p_event) { input->parse_input_event(p_event); }; -void OSUWP::delete_main_loop() { +void OS_UWP::delete_main_loop() { if (main_loop) memdelete(main_loop); main_loop = NULL; } -void OSUWP::set_main_loop(MainLoop *p_main_loop) { +void OS_UWP::set_main_loop(MainLoop *p_main_loop) { input->set_main_loop(p_main_loop); main_loop = p_main_loop; } -void OSUWP::finalize() { +void OS_UWP::finalize() { if (main_loop) memdelete(main_loop); @@ -403,19 +403,19 @@ void OSUWP::finalize() { joypad = nullptr; } -void OSUWP::finalize_core() { +void OS_UWP::finalize_core() { NetSocketPosix::cleanup(); } -void OSUWP::alert(const String &p_alert, const String &p_title) { +void OS_UWP::alert(const String &p_alert, const String &p_title) { Platform::String ^ alert = ref new Platform::String(p_alert.c_str()); Platform::String ^ title = ref new Platform::String(p_title.c_str()); MessageDialog ^ msg = ref new MessageDialog(alert, title); - UICommand ^ close = ref new UICommand("Close", ref new UICommandInvokedHandler(managed_object, &OSUWP::ManagedType::alert_close)); + UICommand ^ close = ref new UICommand("Close", ref new UICommandInvokedHandler(managed_object, &OS_UWP::ManagedType::alert_close)); msg->Commands->Append(close); msg->DefaultCommandIndex = 0; @@ -424,17 +424,17 @@ void OSUWP::alert(const String &p_alert, const String &p_title) { msg->ShowAsync(); } -void OSUWP::ManagedType::alert_close(IUICommand ^ command) { +void OS_UWP::ManagedType::alert_close(IUICommand ^ command) { alert_close_handle = false; } -void OSUWP::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) { +void OS_UWP::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) { update_clipboard(); } -void OSUWP::ManagedType::update_clipboard() { +void OS_UWP::ManagedType::update_clipboard() { DataPackageView ^ data = Clipboard::GetContent(); @@ -446,7 +446,7 @@ void OSUWP::ManagedType::update_clipboard() { } } -void OSUWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) { +void OS_UWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) { AccelerometerReading ^ reading = args->Reading; @@ -456,7 +456,7 @@ void OSUWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender reading->AccelerationZ)); } -void OSUWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) { +void OS_UWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) { MagnetometerReading ^ reading = args->Reading; @@ -466,7 +466,7 @@ void OSUWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, reading->MagneticFieldZ)); } -void OSUWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) { +void OS_UWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) { GyrometerReading ^ reading = args->Reading; @@ -476,7 +476,7 @@ void OSUWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, Gyrome reading->AngularVelocityZ)); } -void OSUWP::set_mouse_mode(MouseMode p_mode) { +void OS_UWP::set_mouse_mode(MouseMode p_mode) { if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) { @@ -501,41 +501,41 @@ void OSUWP::set_mouse_mode(MouseMode p_mode) { SetEvent(mouse_mode_changed); } -OSUWP::MouseMode OSUWP::get_mouse_mode() const { +OS_UWP::MouseMode OS_UWP::get_mouse_mode() const { return mouse_mode; } -Point2 OSUWP::get_mouse_position() const { +Point2 OS_UWP::get_mouse_position() const { return Point2(old_x, old_y); } -int OSUWP::get_mouse_button_state() const { +int OS_UWP::get_mouse_button_state() const { return last_button_state; } -void OSUWP::set_window_title(const String &p_title) { +void OS_UWP::set_window_title(const String &p_title) { } -void OSUWP::set_video_mode(const VideoMode &p_video_mode, int p_screen) { +void OS_UWP::set_video_mode(const VideoMode &p_video_mode, int p_screen) { video_mode = p_video_mode; } -OS::VideoMode OSUWP::get_video_mode(int p_screen) const { +OS::VideoMode OS_UWP::get_video_mode(int p_screen) const { return video_mode; } -void OSUWP::get_fullscreen_mode_list(List *p_list, int p_screen) const { +void OS_UWP::get_fullscreen_mode_list(List *p_list, int p_screen) const { } -String OSUWP::get_name() { +String OS_UWP::get_name() { return "UWP"; } -OS::Date OSUWP::get_date(bool utc) const { +OS::Date OS_UWP::get_date(bool utc) const { SYSTEMTIME systemtime; if (utc) @@ -551,7 +551,7 @@ OS::Date OSUWP::get_date(bool utc) const { date.dst = false; return date; } -OS::Time OSUWP::get_time(bool utc) const { +OS::Time OS_UWP::get_time(bool utc) const { SYSTEMTIME systemtime; if (utc) @@ -566,7 +566,7 @@ OS::Time OSUWP::get_time(bool utc) const { return time; } -OS::TimeZoneInfo OSUWP::get_time_zone_info() const { +OS::TimeZoneInfo OS_UWP::get_time_zone_info() const { TIME_ZONE_INFORMATION info; bool daylight = false; if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) @@ -583,7 +583,7 @@ OS::TimeZoneInfo OSUWP::get_time_zone_info() const { return ret; } -uint64_t OSUWP::get_unix_time() const { +uint64_t OS_UWP::get_unix_time() const { FILETIME ft; SYSTEMTIME st; @@ -605,14 +605,14 @@ uint64_t OSUWP::get_unix_time() const { return (*(uint64_t *)&ft - *(uint64_t *)&fep) / 10000000; }; -void OSUWP::delay_usec(uint32_t p_usec) const { +void OS_UWP::delay_usec(uint32_t p_usec) const { int msec = p_usec < 1000 ? 1 : p_usec / 1000; // no Sleep() WaitForSingleObjectEx(GetCurrentThread(), msec, false); } -uint64_t OSUWP::get_ticks_usec() const { +uint64_t OS_UWP::get_ticks_usec() const { uint64_t ticks; uint64_t time; @@ -626,13 +626,13 @@ uint64_t OSUWP::get_ticks_usec() const { return time; } -void OSUWP::process_events() { +void OS_UWP::process_events() { joypad->process_controllers(); process_key_events(); } -void OSUWP::process_key_events() { +void OS_UWP::process_key_events() { for (int i = 0; i < key_event_pos; i++) { @@ -653,7 +653,7 @@ void OSUWP::process_key_events() { key_event_pos = 0; } -void OSUWP::queue_key_event(KeyEvent &p_event) { +void OS_UWP::queue_key_event(KeyEvent &p_event) { // This merges Char events with the previous Key event, so // the unicode can be retrieved without sending duplicate events. if (p_event.type == KeyEvent::MessageType::CHAR_EVENT_MESSAGE && key_event_pos > 0) { @@ -670,7 +670,7 @@ void OSUWP::queue_key_event(KeyEvent &p_event) { key_event_buffer[key_event_pos++] = p_event; } -void OSUWP::set_cursor_shape(CursorShape p_shape) { +void OS_UWP::set_cursor_shape(CursorShape p_shape) { ERR_FAIL_INDEX(p_shape, CURSOR_MAX); @@ -702,62 +702,62 @@ void OSUWP::set_cursor_shape(CursorShape p_shape) { cursor_shape = p_shape; } -void OSUWP::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { +void OS_UWP::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) { // TODO } -Error OSUWP::execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr) { +Error OS_UWP::execute(const String &p_path, const List &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr) { return FAILED; }; -Error OSUWP::kill(const ProcessID &p_pid) { +Error OS_UWP::kill(const ProcessID &p_pid) { return FAILED; }; -Error OSUWP::set_cwd(const String &p_cwd) { +Error OS_UWP::set_cwd(const String &p_cwd) { return FAILED; } -String OSUWP::get_executable_path() const { +String OS_UWP::get_executable_path() const { return ""; } -void OSUWP::set_icon(const Ref &p_icon) { +void OS_UWP::set_icon(const Ref &p_icon) { } -bool OSUWP::has_environment(const String &p_var) const { +bool OS_UWP::has_environment(const String &p_var) const { return false; }; -String OSUWP::get_environment(const String &p_var) const { +String OS_UWP::get_environment(const String &p_var) const { return ""; }; -bool OSUWP::set_environment(const String &p_var, const String &p_value) const { +bool OS_UWP::set_environment(const String &p_var, const String &p_value) const { return false; } -String OSUWP::get_stdin_string(bool p_block) { +String OS_UWP::get_stdin_string(bool p_block) { return String(); } -void OSUWP::move_window_to_foreground() { +void OS_UWP::move_window_to_foreground() { } -Error OSUWP::shell_open(String p_uri) { +Error OS_UWP::shell_open(String p_uri) { return FAILED; } -String OSUWP::get_locale() const { +String OS_UWP::get_locale() const { #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // this should work on phone 8.1, but it doesn't return "en"; @@ -767,39 +767,39 @@ String OSUWP::get_locale() const { #endif } -void OSUWP::release_rendering_thread() { +void OS_UWP::release_rendering_thread() { gl_context->release_current(); } -void OSUWP::make_rendering_thread() { +void OS_UWP::make_rendering_thread() { gl_context->make_current(); } -void OSUWP::swap_buffers() { +void OS_UWP::swap_buffers() { gl_context->swap_buffers(); } -bool OSUWP::has_touchscreen_ui_hint() const { +bool OS_UWP::has_touchscreen_ui_hint() const { TouchCapabilities ^ tc = ref new TouchCapabilities(); return tc->TouchPresent != 0 || UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; } -bool OSUWP::has_virtual_keyboard() const { +bool OS_UWP::has_virtual_keyboard() const { return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; } -void OSUWP::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) { +void OS_UWP::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) { InputPane ^ pane = InputPane::GetForCurrentView(); pane->TryShow(); } -void OSUWP::hide_virtual_keyboard() { +void OS_UWP::hide_virtual_keyboard() { InputPane ^ pane = InputPane::GetForCurrentView(); pane->TryHide(); @@ -818,7 +818,7 @@ static String format_error_message(DWORD id) { return msg; } -Error OSUWP::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { +Error OS_UWP::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { String full_path = "game/" + p_path; p_library_handle = (void *)LoadPackagedLibrary(full_path.c_str(), 0); @@ -830,14 +830,14 @@ Error OSUWP::open_dynamic_library(const String p_path, void *&p_library_handle, return OK; } -Error OSUWP::close_dynamic_library(void *p_library_handle) { +Error OS_UWP::close_dynamic_library(void *p_library_handle) { if (!FreeLibrary((HMODULE)p_library_handle)) { return FAILED; } return OK; } -Error OSUWP::get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional) { +Error OS_UWP::get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional) { p_symbol_handle = (void *)GetProcAddress((HMODULE)p_library_handle, p_name.utf8().get_data()); if (!p_symbol_handle) { if (!p_optional) { @@ -850,7 +850,7 @@ Error OSUWP::get_dynamic_library_symbol_handle(void *p_library_handle, const Str return OK; } -void OSUWP::run() { +void OS_UWP::run() { if (!main_loop) return; @@ -874,35 +874,35 @@ void OSUWP::run() { main_loop->finish(); } -MainLoop *OSUWP::get_main_loop() const { +MainLoop *OS_UWP::get_main_loop() const { return main_loop; } -String OSUWP::get_user_data_dir() const { +String OS_UWP::get_user_data_dir() const { Windows::Storage::StorageFolder ^ data_folder = Windows::Storage::ApplicationData::Current->LocalFolder; return String(data_folder->Path->Data()).replace("\\", "/"); } -bool OSUWP::_check_internal_feature_support(const String &p_feature) { +bool OS_UWP::_check_internal_feature_support(const String &p_feature) { return p_feature == "pc" || p_feature == "s3tc"; } -OS::PowerState OSUWP::get_power_state() { +OS::PowerState OS_UWP::get_power_state() { return power_manager->get_power_state(); } -int OSUWP::get_power_seconds_left() { +int OS_UWP::get_power_seconds_left() { return power_manager->get_power_seconds_left(); } -int OSUWP::get_power_percent_left() { +int OS_UWP::get_power_percent_left() { return power_manager->get_power_percent_left(); } -OSUWP::OSUWP() { +OS_UWP::OS_UWP() { key_event_pos = 0; force_quit = false; @@ -936,7 +936,7 @@ OSUWP::OSUWP() { _set_logger(memnew(CompositeLogger(loggers))); } -OSUWP::~OSUWP() { +OS_UWP::~OS_UWP() { #ifdef STDOUT_FILE fclose(stdo); #endif diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 5475c4e60a..fd78b3cdf7 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef OSUWP_H -#define OSUWP_H +#ifndef OS_UWP_H +#define OS_UWP_H +#include "context_egl_uwp.h" #include "core/math/transform_2d.h" #include "core/os/input.h" #include "core/os/os.h" #include "core/ustring.h" #include "drivers/xaudio2/audio_driver_xaudio2.h" -#include "gl_context_egl.h" #include "joypad_uwp.h" #include "main/input_default.h" #include "power_uwp.h" @@ -52,7 +52,7 @@ /** @author Juan Linietsky */ -class OSUWP : public OS { +class OS_UWP : public OS { public: struct KeyEvent { @@ -95,7 +95,7 @@ private: VisualServer *visual_server; int pressrc; - ContextEGL *gl_context; + ContextEGL_UWP *gl_context; Windows::UI::Core::CoreWindow ^ window; VideoMode video_mode; @@ -144,7 +144,7 @@ private: /* clang-format off */ internal: ManagedType() { alert_close_handle = false; } - property OSUWP* os; + property OS_UWP* os; /* clang-format on */ }; ManagedType ^ managed_object; @@ -262,8 +262,8 @@ public: void queue_key_event(KeyEvent &p_event); - OSUWP(); - ~OSUWP(); + OS_UWP(); + ~OS_UWP(); }; #endif diff --git a/platform/uwp/power_uwp.h b/platform/uwp/power_uwp.h index d6623f9340..cc19904a62 100644 --- a/platform/uwp/power_uwp.h +++ b/platform/uwp/power_uwp.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PLATFORM_UWP_POWER_UWP_H_ -#define PLATFORM_UWP_POWER_UWP_H_ +#ifndef POWER_UWP_H +#define POWER_UWP_H #include "core/os/dir_access.h" #include "core/os/file_access.h" @@ -53,4 +53,4 @@ public: int get_power_percent_left(); }; -#endif /* PLATFORM_UWP_POWER_UWP_H_ */ +#endif // POWER_UWP_H 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 diff --git a/platform/x11/crash_handler_x11.cpp b/platform/x11/crash_handler_x11.cpp index 8737a2b92b..1e7f393bdd 100644 --- a/platform/x11/crash_handler_x11.cpp +++ b/platform/x11/crash_handler_x11.cpp @@ -28,15 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifdef DEBUG_ENABLED -#define CRASH_HANDLER_ENABLED 1 -#endif - #include "crash_handler_x11.h" + #include "core/os/os.h" #include "core/project_settings.h" #include "main/main.h" +#ifdef DEBUG_ENABLED +#define CRASH_HANDLER_ENABLED 1 +#endif + #ifdef CRASH_HANDLER_ENABLED #include #include diff --git a/platform/x11/crash_handler_x11.h b/platform/x11/crash_handler_x11.h index 6efdd33d9d..d0664aef85 100644 --- a/platform/x11/crash_handler_x11.h +++ b/platform/x11/crash_handler_x11.h @@ -45,4 +45,4 @@ public: ~CrashHandler(); }; -#endif +#endif // CRASH_HANDLER_X11_H diff --git a/platform/x11/power_x11.h b/platform/x11/power_x11.h index 56fbd602f4..469e3910f4 100644 --- a/platform/x11/power_x11.h +++ b/platform/x11/power_x11.h @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef X11_POWER_H_ -#define X11_POWER_H_ +#ifndef POWER_X11_H +#define POWER_X11_H #include "core/os/dir_access.h" #include "core/os/file_access.h" @@ -63,4 +63,4 @@ public: int get_power_percent_left(); }; -#endif /* X11_POWER_H_ */ +#endif // POWER_X11_H -- cgit v1.2.3