From fb5a73a39fb7e6e5924db362062cba628525028a Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 2 Nov 2016 18:26:42 -0200 Subject: Rename WinRT files to UWP --- modules/freetype/SCsub | 4 +- modules/freetype/uwpdef.h | 32 + modules/freetype/winrtdef.h | 32 - modules/openssl/SCsub | 6 +- modules/webm/libvpx/SCsub | 8 +- platform/uwp/SCsub | 23 + platform/uwp/app.cpp | 647 ++++++++++ platform/uwp/app.h | 108 ++ platform/uwp/detect.py | 166 +++ platform/uwp/export/export.cpp | 2391 ++++++++++++++++++++++++++++++++++++ platform/uwp/export/export.h | 29 + platform/uwp/gl_context_egl.cpp | 218 ++++ platform/uwp/gl_context_egl.h | 78 ++ platform/uwp/joystick_uwp.cpp | 147 +++ platform/uwp/joystick_uwp.h | 81 ++ platform/uwp/logo.png | Bin 0 -> 1882 bytes platform/uwp/os_uwp.cpp | 983 +++++++++++++++ platform/uwp/os_uwp.h | 281 +++++ platform/uwp/platform_config.h | 29 + platform/uwp/thread_uwp.cpp | 74 ++ platform/uwp/thread_uwp.h | 63 + platform/winrt/SCsub | 23 - platform/winrt/app.cpp | 647 ---------- platform/winrt/app.h | 108 -- platform/winrt/detect.py | 166 --- platform/winrt/export/export.cpp | 2391 ------------------------------------ platform/winrt/export/export.h | 29 - platform/winrt/gl_context_egl.cpp | 218 ---- platform/winrt/gl_context_egl.h | 78 -- platform/winrt/joystick_winrt.cpp | 147 --- platform/winrt/joystick_winrt.h | 81 -- platform/winrt/logo.png | Bin 1882 -> 0 bytes platform/winrt/os_winrt.cpp | 983 --------------- platform/winrt/os_winrt.h | 281 ----- platform/winrt/platform_config.h | 29 - platform/winrt/thread_winrt.cpp | 74 -- platform/winrt/thread_winrt.h | 63 - thirdparty/openssl/uwp.cpp | 155 +++ thirdparty/openssl/uwp_fix.patch | 64 + thirdparty/openssl/winrt.cpp | 155 --- thirdparty/openssl/winrt_fix.patch | 64 - 41 files changed, 5578 insertions(+), 5578 deletions(-) create mode 100644 modules/freetype/uwpdef.h delete mode 100644 modules/freetype/winrtdef.h create mode 100644 platform/uwp/SCsub create mode 100644 platform/uwp/app.cpp create mode 100644 platform/uwp/app.h create mode 100644 platform/uwp/detect.py create mode 100644 platform/uwp/export/export.cpp create mode 100644 platform/uwp/export/export.h create mode 100644 platform/uwp/gl_context_egl.cpp create mode 100644 platform/uwp/gl_context_egl.h create mode 100644 platform/uwp/joystick_uwp.cpp create mode 100644 platform/uwp/joystick_uwp.h create mode 100644 platform/uwp/logo.png create mode 100644 platform/uwp/os_uwp.cpp create mode 100644 platform/uwp/os_uwp.h create mode 100644 platform/uwp/platform_config.h create mode 100644 platform/uwp/thread_uwp.cpp create mode 100644 platform/uwp/thread_uwp.h delete mode 100644 platform/winrt/SCsub delete mode 100644 platform/winrt/app.cpp delete mode 100644 platform/winrt/app.h delete mode 100644 platform/winrt/detect.py delete mode 100644 platform/winrt/export/export.cpp delete mode 100644 platform/winrt/export/export.h delete mode 100644 platform/winrt/gl_context_egl.cpp delete mode 100644 platform/winrt/gl_context_egl.h delete mode 100644 platform/winrt/joystick_winrt.cpp delete mode 100644 platform/winrt/joystick_winrt.h delete mode 100644 platform/winrt/logo.png delete mode 100644 platform/winrt/os_winrt.cpp delete mode 100644 platform/winrt/os_winrt.h delete mode 100644 platform/winrt/platform_config.h delete mode 100644 platform/winrt/thread_winrt.cpp delete mode 100644 platform/winrt/thread_winrt.h create mode 100644 thirdparty/openssl/uwp.cpp create mode 100644 thirdparty/openssl/uwp_fix.patch delete mode 100644 thirdparty/openssl/winrt.cpp delete mode 100644 thirdparty/openssl/winrt_fix.patch diff --git a/modules/freetype/SCsub b/modules/freetype/SCsub index 87652a3ddf..5a5b87df50 100644 --- a/modules/freetype/SCsub +++ b/modules/freetype/SCsub @@ -55,8 +55,8 @@ if (env['builtin_freetype'] != 'no'): thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] # Include header for WinRT to fix build issues - if "platform" in env and env["platform"] == "winrt": - env.Append(CCFLAGS=['/FI', '"modules/freetype/winrtdef.h"']) + if "platform" in env and env["platform"] == "uwp": + env.Append(CCFLAGS=['/FI', '"modules/freetype/uwpdef.h"']) env.Append(CPPPATH=[thirdparty_dir, thirdparty_dir + "/include"]) diff --git a/modules/freetype/uwpdef.h b/modules/freetype/uwpdef.h new file mode 100644 index 0000000000..c7dce80461 --- /dev/null +++ b/modules/freetype/uwpdef.h @@ -0,0 +1,32 @@ +/*************************************************************************/ +/* uwpdef.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ + +// "generic" is a reserved keyword in C++/CX code +// this avoids the errors in the variable name from Freetype code +#define generic freetype_generic diff --git a/modules/freetype/winrtdef.h b/modules/freetype/winrtdef.h deleted file mode 100644 index 69c6baf532..0000000000 --- a/modules/freetype/winrtdef.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************/ -/* winrtdef.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ - -// "generic" is a reserved keyword in C++/CX code -// this avoids the errors in the variable name from Freetype code -#define generic freetype_generic diff --git a/modules/openssl/SCsub b/modules/openssl/SCsub index ccd90d1534..e379570c72 100644 --- a/modules/openssl/SCsub +++ b/modules/openssl/SCsub @@ -648,8 +648,8 @@ if (env['builtin_openssl'] != 'no'): "crypto/bn/bn_asm.c", ] - if "platform" in env and env["platform"] == "winrt": - thirdparty_sources += ['winrt.cpp'] + if "platform" in env and env["platform"] == "uwp": + thirdparty_sources += ['uwp.cpp'] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] @@ -680,7 +680,7 @@ env_openssl.add_source_files(env.modules_sources, "*.cpp") env_openssl.add_source_files(env.modules_sources, "*.c") # platform/winrt need to know openssl is available, pass to main env -if "platform" in env and env["platform"] == "winrt": +if "platform" in env and env["platform"] == "uwp": env.Append(CPPPATH=[thirdparty_dir]) env.Append(CPPFLAGS=['-DOPENSSL_ENABLED']) diff --git a/modules/webm/libvpx/SCsub b/modules/webm/libvpx/SCsub index a7eca29c05..365cabd072 100644 --- a/modules/webm/libvpx/SCsub +++ b/modules/webm/libvpx/SCsub @@ -257,7 +257,7 @@ cpu_bits = env["bits"] osx_fat = (env["platform"] == 'osx' and cpu_bits == 'fat') webm_cpu_x86 = False webm_cpu_arm = False -if env["platform"] == 'winrt': +if env["platform"] == 'uwp': if 'arm' in env["PROGSUFFIX"]: webm_cpu_arm = True else: @@ -306,7 +306,7 @@ if webm_cpu_x86: env_libvpx["ASFLAGS"] = '-I' + libvpx_dir[1:] env_libvpx["ASCOM"] = '$AS $ASFLAGS $TARGET $SOURCES' else: - if env["platform"] == 'windows' or env["platform"] == 'winrt': + if env["platform"] == 'windows' or env["platform"] == 'uwp': env_libvpx["ASFORMAT"] = 'win' elif env["platform"] == 'osx': env_libvpx["ASFORMAT"] = 'macho' @@ -332,7 +332,7 @@ if webm_cpu_arm: env_libvpx["ASFLAGS"] = '-arch armv7' elif env["platform"] == 'android': env_libvpx["ASFLAGS"] = '-mfpu=neon' - elif env["platform"] == 'winrt': + elif env["platform"] == 'uwp': env_libvpx["AS"] = 'armasm' env_libvpx["ASFLAGS"] = '' env_libvpx["ASCOM"] = '$AS $ASFLAGS -o $TARGET $SOURCES' @@ -382,7 +382,7 @@ elif webm_cpu_arm: env_libvpx_neon.Append(CCFLAGS=['-mfpu=neon']) env_libvpx_neon.add_source_files(env.modules_sources, libvpx_sources_arm_neon) - if env["platform"] == 'winrt': + if env["platform"] == 'uwp': env_libvpx.add_source_files(env.modules_sources, libvpx_sources_arm_neon_armasm_ms) elif env["platform"] == 'iphone': env_libvpx.add_source_files(env.modules_sources, libvpx_sources_arm_neon_gas_apple) diff --git a/platform/uwp/SCsub b/platform/uwp/SCsub new file mode 100644 index 0000000000..430d4ef9e7 --- /dev/null +++ b/platform/uwp/SCsub @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +Import('env') + +files = [ + 'thread_uwp.cpp', + '#platform/windows/tcp_server_winsock.cpp', + '#platform/windows/packet_peer_udp_winsock.cpp', + '#platform/windows/stream_peer_winsock.cpp', + '#platform/windows/key_mapping_win.cpp', + 'joystick_uwp.cpp', + 'gl_context_egl.cpp', + 'app.cpp', + 'os_uwp.cpp', +] + +if "build_angle" in env and env["build_angle"]: + cmd = env.AlwaysBuild(env.ANGLE('libANGLE.lib', None)) + +prog = env.Program('#bin/godot', files) + +if "build_angle" in env and env["build_angle"]: + env.Depends(prog, [cmd]) diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp new file mode 100644 index 0000000000..c2b7ba0641 --- /dev/null +++ b/platform/uwp/app.cpp @@ -0,0 +1,647 @@ +/*************************************************************************/ +/* app.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ +// +// This file demonstrates how to initialize EGL in a Windows Store app, using ICoreWindow. +// + +#include "app.h" + +#include "main/main.h" +#include "core/os/dir_access.h" +#include "core/os/file_access.h" +#include "core/os/keyboard.h" + +#include "platform/windows/key_mapping_win.h" + +#include + +using namespace Windows::ApplicationModel::Core; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::UI::Core; +using namespace Windows::UI::Input; +using namespace Windows::Devices::Input; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::Foundation; +using namespace Windows::Graphics::Display; +using namespace Windows::System; +using namespace Windows::System::Threading::Core; +using namespace Microsoft::WRL; + +using namespace GodotWinRT; + +// Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels. +inline float ConvertDipsToPixels(float dips, float dpi) +{ + static const float dipsPerInch = 96.0f; + return floor(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer. +} + +// Implementation of the IFrameworkViewSource interface, necessary to run our app. +ref class GodotWinrtViewSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +{ +public: + virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() + { + return ref new App(); + } +}; + +// The main function creates an IFrameworkViewSource for our app, and runs the app. +[Platform::MTAThread] +int main(Platform::Array^) +{ + auto godotApplicationSource = ref new GodotWinrtViewSource(); + CoreApplication::Run(godotApplicationSource); + return 0; +} + +App::App() : + mWindowClosed(false), + mWindowVisible(true), + mWindowWidth(0), + mWindowHeight(0), + mEglDisplay(EGL_NO_DISPLAY), + mEglContext(EGL_NO_CONTEXT), + mEglSurface(EGL_NO_SURFACE), + number_of_contacts(0) +{ +} + +// The first method called when the IFrameworkView is being created. +void App::Initialize(CoreApplicationView^ applicationView) +{ + // Register event handlers for app lifecycle. This example includes Activated, so that we + // can make the CoreWindow active and start rendering on the window. + applicationView->Activated += + ref new TypedEventHandler(this, &App::OnActivated); + + // Logic for other event handlers could go here. + // 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 OSWinrt; + +} + +// Called when the CoreWindow object is created (or re-created). +void App::SetWindow(CoreWindow^ p_window) +{ + window = p_window; + window->VisibilityChanged += + ref new TypedEventHandler(this, &App::OnVisibilityChanged); + + window->Closed += + ref new TypedEventHandler(this, &App::OnWindowClosed); + + window->SizeChanged += + ref new TypedEventHandler(this, &App::OnWindowSizeChanged); + +#if !(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) + // Disable all pointer visual feedback for better performance when touching. + // This is not supported on Windows Phone applications. + auto pointerVisualizationSettings = PointerVisualizationSettings::GetForCurrentView(); + pointerVisualizationSettings->IsContactFeedbackEnabled = false; + pointerVisualizationSettings->IsBarrelButtonFeedbackEnabled = false; +#endif + + + window->PointerPressed += + ref new TypedEventHandler(this, &App::OnPointerPressed); + window->PointerMoved += + ref new TypedEventHandler(this, &App::OnPointerMoved); + window->PointerReleased += + ref new TypedEventHandler(this, &App::OnPointerReleased); + window->PointerWheelChanged += + ref new TypedEventHandler(this, &App::OnPointerWheelChanged); + + mouseChangedNotifier = SignalNotifier::AttachToEvent(L"os_mouse_mode_changed", ref new SignalHandler( + this, &App::OnMouseModeChanged + )); + + mouseChangedNotifier->Enable(); + + window->CharacterReceived += + ref new TypedEventHandler(this, &App::OnCharacterReceived); + window->KeyDown += + ref new TypedEventHandler(this, &App::OnKeyDown); + window->KeyUp += + ref new TypedEventHandler(this, &App::OnKeyUp); + + + unsigned int argc; + char** argv = get_command_line(&argc); + + Main::setup("winrt", argc, argv, false); + + // The CoreWindow has been created, so EGL can be initialized. + ContextEGL* context = memnew(ContextEGL(window)); + os->set_gl_context(context); + UpdateWindowSize(Size(window->Bounds.Width, window->Bounds.Height)); + + Main::setup2(); +} + +static int _get_button(Windows::UI::Input::PointerPoint ^pt) { + + using namespace Windows::UI::Input; + +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP + return BUTTON_LEFT; +#else + switch (pt->Properties->PointerUpdateKind) + { + case PointerUpdateKind::LeftButtonPressed: + case PointerUpdateKind::LeftButtonReleased: + return BUTTON_LEFT; + + case PointerUpdateKind::RightButtonPressed: + case PointerUpdateKind::RightButtonReleased: + return BUTTON_RIGHT; + + case PointerUpdateKind::MiddleButtonPressed: + case PointerUpdateKind::MiddleButtonReleased: + return BUTTON_MIDDLE; + + case PointerUpdateKind::XButton1Pressed: + case PointerUpdateKind::XButton1Released: + return BUTTON_WHEEL_UP; + + case PointerUpdateKind::XButton2Pressed: + case PointerUpdateKind::XButton2Released: + return BUTTON_WHEEL_DOWN; + + default: + break; + } +#endif + + return 0; +}; + +static bool _is_touch(Windows::UI::Input::PointerPoint ^pointerPoint) { +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP + return true; +#else + using namespace Windows::Devices::Input; + switch (pointerPoint->PointerDevice->PointerDeviceType) { + case PointerDeviceType::Touch: + case PointerDeviceType::Pen: + return true; + default: + return false; + } +#endif +} + + +static Windows::Foundation::Point _get_pixel_position(CoreWindow^ window, Windows::Foundation::Point rawPosition, OS* os) { + + Windows::Foundation::Point outputPosition; + + // Compute coordinates normalized from 0..1. + // If the coordinates need to be sized to the SDL window, + // we'll do that after. + #if 1 || WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP + outputPosition.X = rawPosition.X / window->Bounds.Width; + outputPosition.Y = rawPosition.Y / window->Bounds.Height; + #else + switch (DisplayProperties::CurrentOrientation) + { + case DisplayOrientations::Portrait: + outputPosition.X = rawPosition.X / window->Bounds.Width; + outputPosition.Y = rawPosition.Y / window->Bounds.Height; + break; + case DisplayOrientations::PortraitFlipped: + outputPosition.X = 1.0f - (rawPosition.X / window->Bounds.Width); + outputPosition.Y = 1.0f - (rawPosition.Y / window->Bounds.Height); + break; + case DisplayOrientations::Landscape: + outputPosition.X = rawPosition.Y / window->Bounds.Height; + outputPosition.Y = 1.0f - (rawPosition.X / window->Bounds.Width); + break; + case DisplayOrientations::LandscapeFlipped: + outputPosition.X = 1.0f - (rawPosition.Y / window->Bounds.Height); + outputPosition.Y = rawPosition.X / window->Bounds.Width; + break; + default: + break; + } + #endif + + OS::VideoMode vm = os->get_video_mode(); + outputPosition.X *= vm.width; + outputPosition.Y *= vm.height; + + return outputPosition; +}; + +static int _get_finger(uint32_t p_touch_id) { + + return p_touch_id % 31; // for now +}; + +void App::pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel) { + + Windows::UI::Input::PointerPoint ^point = args->CurrentPoint; + Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os); + int but = _get_button(point); + if (_is_touch(point)) { + + InputEvent event; + event.type = InputEvent::SCREEN_TOUCH; + event.device = 0; + event.screen_touch.pressed = p_pressed; + event.screen_touch.x = pos.X; + event.screen_touch.y = pos.Y; + event.screen_touch.index = _get_finger(point->PointerId); + + last_touch_x[event.screen_touch.index] = pos.X; + last_touch_y[event.screen_touch.index] = pos.Y; + + os->input_event(event); + if (number_of_contacts > 1) + return; + + }; // fallthrought of sorts + + InputEvent event; + event.type = InputEvent::MOUSE_BUTTON; + event.device = 0; + event.mouse_button.pressed = p_pressed; + event.mouse_button.button_index = but; + event.mouse_button.x = pos.X; + event.mouse_button.y = pos.Y; + event.mouse_button.global_x = pos.X; + event.mouse_button.global_y = pos.Y; + + if (p_is_wheel) { + if (point->Properties->MouseWheelDelta > 0) { + event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_UP; + } else if (point->Properties->MouseWheelDelta < 0) { + event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_LEFT : BUTTON_WHEEL_DOWN; + } + } + + last_touch_x[31] = pos.X; + last_touch_y[31] = pos.Y; + + os->input_event(event); +}; + + +void App::OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { + + number_of_contacts++; + pointer_event(sender, args, true); +}; + + +void App::OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { + + number_of_contacts--; + pointer_event(sender, args, false); +}; + +void App::OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { + + pointer_event(sender, args, true, true); +} + +void App::OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier^ signalNotifier, bool timedOut) { + + OS::MouseMode mode = os->get_mouse_mode(); + SignalNotifier^ notifier = mouseChangedNotifier; + + window->Dispatcher->RunAsync( + CoreDispatcherPriority::High, + ref new DispatchedHandler( + [mode, notifier, this]() { + if (mode == OS::MOUSE_MODE_CAPTURED) { + + this->MouseMovedToken = MouseDevice::GetForCurrentView()->MouseMoved += + ref new TypedEventHandler(this, &App::OnMouseMoved); + + } else { + + MouseDevice::GetForCurrentView()->MouseMoved -= MouseMovedToken; + + } + + notifier->Enable(); + })); + + ResetEvent(os->mouse_mode_changed); + + +} + +void App::OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { + + Windows::UI::Input::PointerPoint ^point = args->CurrentPoint; + Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os); + + if (point->IsInContact && _is_touch(point)) { + + InputEvent event; + event.type = InputEvent::SCREEN_DRAG; + event.device = 0; + event.screen_drag.x = pos.X; + event.screen_drag.y = pos.Y; + event.screen_drag.index = _get_finger(point->PointerId); + event.screen_drag.relative_x = event.screen_drag.x - last_touch_x[event.screen_drag.index]; + event.screen_drag.relative_y = event.screen_drag.y - last_touch_y[event.screen_drag.index]; + + os->input_event(event); + if (number_of_contacts > 1) + return; + + }; // fallthrought of sorts + + // In case the mouse grabbed, MouseMoved will handle this + if (os->get_mouse_mode() == OS::MouseMode::MOUSE_MODE_CAPTURED) + return; + + InputEvent event; + event.type = InputEvent::MOUSE_MOTION; + event.device = 0; + event.mouse_motion.x = pos.X; + event.mouse_motion.y = pos.Y; + event.mouse_motion.global_x = pos.X; + event.mouse_motion.global_y = pos.Y; + event.mouse_motion.relative_x = pos.X - last_touch_x[31]; + event.mouse_motion.relative_y = pos.Y - last_touch_y[31]; + + last_mouse_pos = pos; + + os->input_event(event); + +} + +void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) { + + // In case the mouse isn't grabbed, PointerMoved will handle this + if (os->get_mouse_mode() != OS::MouseMode::MOUSE_MODE_CAPTURED) + return; + + Windows::Foundation::Point pos; + pos.X = last_mouse_pos.X + args->MouseDelta.X; + pos.Y = last_mouse_pos.Y + args->MouseDelta.Y; + + InputEvent event; + event.type = InputEvent::MOUSE_MOTION; + event.device = 0; + event.mouse_motion.x = pos.X; + event.mouse_motion.y = pos.Y; + event.mouse_motion.global_x = pos.X; + event.mouse_motion.global_y = pos.Y; + event.mouse_motion.relative_x = args->MouseDelta.X; + event.mouse_motion.relative_y = args->MouseDelta.Y; + + last_mouse_pos = pos; + + os->input_event(event); +} + +void App::key_event(Windows::UI::Core::CoreWindow^ sender, bool p_pressed, Windows::UI::Core::KeyEventArgs^ key_args, Windows::UI::Core::CharacterReceivedEventArgs^ char_args) +{ + + OSWinrt::KeyEvent ke; + + InputModifierState mod; + mod.meta = false; + mod.command = false; + mod.control = sender->GetAsyncKeyState(VirtualKey::Control) == CoreVirtualKeyStates::Down; + mod.alt = sender->GetAsyncKeyState(VirtualKey::Menu) == CoreVirtualKeyStates::Down; + mod.shift = sender->GetAsyncKeyState(VirtualKey::Shift) == CoreVirtualKeyStates::Down; + ke.mod_state = mod; + + ke.pressed = p_pressed; + + if (key_args != nullptr) { + + ke.type = OSWinrt::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 = OSWinrt::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); + } + + os->queue_key_event(ke); + +} +void App::OnKeyDown(CoreWindow^ sender, KeyEventArgs^ args) +{ + key_event(sender, true, args); +} + +void App::OnKeyUp(CoreWindow^ sender, KeyEventArgs^ args) +{ + key_event(sender, false, args); +} + +void App::OnCharacterReceived(CoreWindow^ sender, CharacterReceivedEventArgs^ args) +{ + key_event(sender, true, nullptr, args); +} + + +// Initializes scene resources +void App::Load(Platform::String^ entryPoint) +{ + +} + +// This method is called after the window becomes active. +void App::Run() +{ + if (Main::start()) + os->run(); +} + +// Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView +// class is torn down while the app is in the foreground. +void App::Uninitialize() +{ + Main::cleanup(); + delete os; +} + +// Application lifecycle event handler. +void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) +{ + // Run() won't start until the CoreWindow is activated. + CoreWindow::GetForCurrentThread()->Activate(); +} + +// Window event handlers. +void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) +{ + mWindowVisible = args->Visible; +} + +void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) +{ + mWindowClosed = true; +} + +void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) +{ +#if (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) + // On Windows 8.1, apps are resized when they are snapped alongside other apps, or when the device is rotated. + // The default framebuffer will be automatically resized when either of these occur. + // In particular, on a 90 degree rotation, the default framebuffer's width and height will switch. + UpdateWindowSize(args->Size); +#else if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) + // On Windows Phone 8.1, the window size changes when the device is rotated. + // The default framebuffer will not be automatically resized when this occurs. + // It is therefore up to the app to handle rotation-specific logic in its rendering code. + //os->screen_size_changed(); + UpdateWindowSize(args->Size); +#endif +} + +void App::UpdateWindowSize(Size size) +{ + float dpi; +#if (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) + DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); + dpi = currentDisplayInformation->LogicalDpi; +#else if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) + dpi = DisplayProperties::LogicalDpi; +#endif + Size pixelSize(ConvertDipsToPixels(size.Width, dpi), ConvertDipsToPixels(size.Height, dpi)); + + mWindowWidth = static_cast(pixelSize.Width); + mWindowHeight = static_cast(pixelSize.Height); + + OS::VideoMode vm; + vm.width = mWindowWidth; + vm.height = mWindowHeight; + vm.fullscreen = true; + vm.resizable = false; + os->set_video_mode(vm); +} + +char** App::get_command_line(unsigned int* out_argc) { + + static char* fail_cl[] = { "-path", "game", NULL }; + *out_argc = 2; + + FILE* f = _wfopen(L"__cl__.cl", L"rb"); + + if (f == NULL) { + + wprintf(L"Couldn't open command line file."); + return fail_cl; + } + +#define READ_LE_4(v) ((int)(##v[3] & 0xFF) << 24) | ((int)(##v[2] & 0xFF) << 16) | ((int)(##v[1] & 0xFF) << 8) | ((int)(##v[0] & 0xFF)) +#define CMD_MAX_LEN 65535 + + uint8_t len[4]; + int r = fread(len, sizeof(uint8_t), 4, f); + + Platform::Collections::Vector cl; + + if (r < 4) { + fclose(f); + wprintf(L"Wrong cmdline length."); + return(fail_cl); + } + + int argc = READ_LE_4(len); + + for (int i = 0; i < argc; i++) { + + r = fread(len, sizeof(uint8_t), 4, f); + + if (r < 4) { + fclose(f); + wprintf(L"Wrong cmdline param length."); + return(fail_cl); + } + + int strlen = READ_LE_4(len); + + if (strlen > CMD_MAX_LEN) { + fclose(f); + wprintf(L"Wrong command length."); + return(fail_cl); + } + + char* arg = new char[strlen + 1]; + r = fread(arg, sizeof(char), strlen, f); + arg[strlen] = '\0'; + + if (r == strlen) { + + int warg_size = MultiByteToWideChar(CP_UTF8, 0, arg, -1, NULL, 0); + wchar_t* warg = new wchar_t[warg_size]; + + MultiByteToWideChar(CP_UTF8, 0, arg, -1, warg, warg_size); + + cl.Append(ref new Platform::String(warg, warg_size)); + + } else { + + delete[] arg; + fclose(f); + wprintf(L"Error reading command."); + return(fail_cl); + } + } + +#undef READ_LE_4 +#undef CMD_MAX_LEN + + fclose(f); + + char** ret = new char*[cl.Size + 1]; + + for (int i = 0; i < cl.Size; i++) { + + int arg_size = WideCharToMultiByte(CP_UTF8, 0, cl.GetAt(i)->Data(), -1, NULL, 0, NULL, NULL); + char* arg = new char[arg_size]; + + WideCharToMultiByte(CP_UTF8, 0, cl.GetAt(i)->Data(), -1, arg, arg_size, NULL, NULL); + + ret[i] = arg; + + } + ret[cl.Size] = NULL; + *out_argc = cl.Size; + + return ret; +} diff --git a/platform/uwp/app.h b/platform/uwp/app.h new file mode 100644 index 0000000000..91cac37985 --- /dev/null +++ b/platform/uwp/app.h @@ -0,0 +1,108 @@ +/*************************************************************************/ +/* app.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ +#pragma once + +#include + +#include + +#include "os_uwp.h" +#include "GLES2/gl2.h" + +namespace GodotWinRT +{ + ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView + { + public: + App(); + + // IFrameworkView Methods. + virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); + virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); + virtual void Load(Platform::String^ entryPoint); + virtual void Run(); + virtual void Uninitialize(); + + property Windows::Foundation::EventRegistrationToken MouseMovedToken { + Windows::Foundation::EventRegistrationToken get() { return this->mouseMovedToken; } + void set(Windows::Foundation::EventRegistrationToken p_token) { this->mouseMovedToken = p_token; } + }; + + private: + void RecreateRenderer(); + + // Application lifecycle event handlers. + void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); + + // Window event handlers. + void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); + void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); + void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); + + void pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel = false); + void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouse_device, Windows::Devices::Input::MouseEventArgs^ args); + void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); + + Windows::System::Threading::Core::SignalNotifier^ mouseChangedNotifier; + Windows::Foundation::EventRegistrationToken mouseMovedToken; + void OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier^ signalNotifier, bool timedOut); + + void key_event(Windows::UI::Core::CoreWindow^ sender, bool p_pressed, Windows::UI::Core::KeyEventArgs^ key_args = nullptr, Windows::UI::Core::CharacterReceivedEventArgs^ char_args = nullptr); + void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); + void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); + void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); + + void UpdateWindowSize(Windows::Foundation::Size size); + void InitializeEGL(Windows::UI::Core::CoreWindow^ window); + void CleanupEGL(); + + char** get_command_line(unsigned int* out_argc); + + bool mWindowClosed; + bool mWindowVisible; + GLsizei mWindowWidth; + GLsizei mWindowHeight; + + EGLDisplay mEglDisplay; + EGLContext mEglContext; + EGLSurface mEglSurface; + + CoreWindow^ window; + OSWinrt* os; + + int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse + int last_touch_y[32]; + int number_of_contacts; + Windows::Foundation::Point last_mouse_pos; + }; + +} diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py new file mode 100644 index 0000000000..85d6d54a70 --- /dev/null +++ b/platform/uwp/detect.py @@ -0,0 +1,166 @@ +import os + +import sys +import string +import methods + + +def is_active(): + return True + + +def get_name(): + return "WinRT" + + +def can_build(): + if (os.name == "nt"): + # building natively on windows! + if (os.getenv("VSINSTALLDIR")): + + if (os.getenv("ANGLE_SRC_PATH") == None): + return False + + return True + return False + + +def get_opts(): + return [] + + +def get_flags(): + + return [ + ('tools', 'no'), + ('xaudio2', 'yes'), + ] + + +def configure(env): + + if(env["bits"] != "default"): + print "Error: bits argument is disabled for MSVC" + print ("Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console (or Visual Studio settings)" + + " that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits argument (example: scons p=uwp) and SCons will attempt to detect what MSVC compiler" + + " will be executed and inform you.") + sys.exit() + + arch = "" + env['ENV'] = os.environ + + # ANGLE + angle_root = os.getenv("ANGLE_SRC_PATH") + env.Append(CPPPATH=[angle_root + '/include']) + jobs = str(env.GetOption("num_jobs")) + angle_build_cmd = "msbuild.exe " + angle_root + "/winrt/10/src/angle.sln /nologo /v:m /m:" + jobs + " /p:Configuration=Release /p:Platform=" + + if os.path.isfile(str(os.getenv("ANGLE_SRC_PATH")) + "/winrt/10/src/angle.sln"): + env["build_angle"] = True + + if os.getenv('Platform') == "ARM": + + print "Compiled program architecture will be an ARM executable. (forcing bits=32)." + + arch = "arm" + env["bits"] = "32" + env.Append(LINKFLAGS=['/MACHINE:ARM']) + env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store/arm']) + + angle_build_cmd += "ARM" + + env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_ARM/lib']) + + else: + + compiler_version_str = methods.detect_visual_c_compiler_version(env['ENV']) + + if(compiler_version_str == "amd64" or compiler_version_str == "x86_amd64"): + env["bits"] = "64" + print "Compiled program architecture will be a x64 executable (forcing bits=64)." + elif (compiler_version_str == "x86" or compiler_version_str == "amd64_x86"): + env["bits"] = "32" + print "Compiled program architecture will be a x86 executable. (forcing bits=32)." + else: + print "Failed to detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup." + env["bits"] = "32" + + if (env["bits"] == "32"): + arch = "x86" + + angle_build_cmd += "Win32" + + env.Append(CPPFLAGS=['/DPNG_ABORT=abort']) + env.Append(LINKFLAGS=['/MACHINE:X86']) + env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store']) + env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_Win32/lib']) + + else: + arch = "x64" + + angle_build_cmd += "x64" + + env.Append(LINKFLAGS=['/MACHINE:X64']) + env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store/amd64']) + env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_x64/lib']) + + env.Append(CPPPATH=['#platform/uwp', '#drivers/windows']) + env.Append(LINKFLAGS=['/MANIFEST:NO', '/NXCOMPAT', '/DYNAMICBASE', '/WINMD', '/APPCONTAINER', '/ERRORREPORT:PROMPT', '/NOLOGO', '/TLBID:1', '/NODEFAULTLIB:"kernel32.lib"', '/NODEFAULTLIB:"ole32.lib"']) + env.Append(CPPFLAGS=['/D', '__WRL_NO_DEFAULT_LIB__', '/D', 'WIN32']) + env.Append(CPPFLAGS=['/FU', os.environ['VCINSTALLDIR'] + 'lib/store/references/platform.winmd']) + env.Append(CPPFLAGS=['/AI', os.environ['VCINSTALLDIR'] + 'lib/store/references']) + + env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store/references']) + + if (env["target"] == "release"): + + env.Append(CPPFLAGS=['/O2', '/GL']) + env.Append(CPPFLAGS=['/MD']) + env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS', '/LTCG']) + + elif (env["target"] == "release_debug"): + + env.Append(CCFLAGS=['/O2', '/Zi', '/DDEBUG_ENABLED']) + env.Append(CPPFLAGS=['/MD']) + env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) + + elif (env["target"] == "debug"): + + env.Append(CCFLAGS=['/Zi', '/DDEBUG_ENABLED', '/DDEBUG_MEMORY_ENABLED']) + env.Append(CPPFLAGS=['/MDd']) + env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) + env.Append(LINKFLAGS=['/DEBUG']) + + env.Append(CCFLAGS=string.split('/FS /MP /GS /wd"4453" /wd"28204" /wd"4291" /Zc:wchar_t /Gm- /fp:precise /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP" /errorReport:prompt /WX- /Zc:forScope /Gd /EHsc /nologo')) + env.Append(CXXFLAGS=string.split('/ZW /FS')) + env.Append(CCFLAGS=['/AI', os.environ['VCINSTALLDIR'] + '\\vcpackages', '/AI', os.environ['WINDOWSSDKDIR'] + '\\References\\CommonConfiguration\\Neutral']) + + env["PROGSUFFIX"] = "." + arch + env["PROGSUFFIX"] + env["OBJSUFFIX"] = "." + arch + env["OBJSUFFIX"] + env["LIBSUFFIX"] = "." + arch + env["LIBSUFFIX"] + + env.Append(CCFLAGS=['/DWINRT_ENABLED']) + env.Append(CCFLAGS=['/DWINDOWS_ENABLED']) + env.Append(CCFLAGS=['/DTYPED_METHOD_BIND']) + + env.Append(CCFLAGS=['/DGLES2_ENABLED', '/DGL_GLEXT_PROTOTYPES', '/DEGL_EGLEXT_PROTOTYPES', '/DANGLE_ENABLED']) + + LIBS = [ + 'WindowsApp', + 'mincore', + 'libANGLE', + 'libEGL', + 'libGLESv2', + ] + env.Append(LINKFLAGS=[p + ".lib" for p in LIBS]) + + # Incremental linking fix + env['BUILDERS']['ProgramOriginal'] = env['BUILDERS']['Program'] + env['BUILDERS']['Program'] = methods.precious_program + + env.Append(BUILDERS={'ANGLE': env.Builder(action=angle_build_cmd)}) + + env.Append(BUILDERS={'GLSL120': env.Builder(action=methods.build_legacygl_headers, suffix='glsl.h', src_suffix='.glsl')}) + env.Append(BUILDERS={'GLSL': env.Builder(action=methods.build_glsl_headers, suffix='glsl.h', src_suffix='.glsl')}) + env.Append(BUILDERS={'HLSL9': env.Builder(action=methods.build_hlsl_dx9_headers, suffix='hlsl.h', src_suffix='.hlsl')}) + env.Append(BUILDERS={'GLSL120GLES': env.Builder(action=methods.build_gles2_headers, suffix='glsl.h', src_suffix='.glsl')}) diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp new file mode 100644 index 0000000000..6a35c1cebc --- /dev/null +++ b/platform/uwp/export/export.cpp @@ -0,0 +1,2391 @@ +/*************************************************************************/ +/* export.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ + +/************************************************************************* + * The code for signing the package was ported from fb-util-for-appx + * available at https://github.com/facebook/fb-util-for-appx + * and distributed also under the following license: + +BSD License + +For fb-util-for-appx software + +Copyright (c) 2016, Facebook, Inc. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name Facebook nor the names of its contributors may be used to + endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*************************************************************************/ + + +#include "version.h" +#include "export.h" +#include "object.h" +#include "tools/editor/editor_import_export.h" +#include "tools/editor/editor_node.h" +#include "platform/uwp/logo.h" +#include "os/file_access.h" +#include "io/zip.h" +#include "io/unzip.h" +#include "io/zip_io.h" +#include "io/sha256.h" +#include "io/base64.h" +#include "bind/core_bind.h" +#include "globals.h" +#include "io/marshalls.h" + +#include + +// Capabilities +static const char* uwp_capabilities[] = { + "allJoyn", + "codeGeneration", + "internetClient", + "internetClientServer", + "privateNetworkClientServer", + NULL +}; +static const char* uwp_uap_capabilities[] = { + "appointments", + "blockedChatMessages", + "chat", + "contacts", + "enterpriseAuthentication", + "musicLibrary", + "objects3D", + "picturesLibrary", + "phoneCall", + "removableStorage", + "sharedUserCertificates", + "userAccountInformation", + "videosLibrary", + "voipCall", + NULL +}; +static const char* uwp_device_capabilites[] = { + "bluetooth", + "location", + "microphone", + "proximity", + "webcam", + NULL +}; + +#ifdef OPENSSL_ENABLED +#include +#include +#include +#include +#include +#include +#include +#include + +namespace asn1 { + // https://msdn.microsoft.com/en-us/gg463180.aspx + + struct SPCStatementType { + ASN1_OBJECT *type; + }; + DECLARE_ASN1_FUNCTIONS(SPCStatementType) + + struct SPCSpOpusInfo { + ASN1_TYPE *programName; + ASN1_TYPE *moreInfo; + }; + DECLARE_ASN1_FUNCTIONS(SPCSpOpusInfo) + + struct DigestInfo { + X509_ALGOR *digestAlgorithm; + ASN1_OCTET_STRING *digest; + }; + DECLARE_ASN1_FUNCTIONS(DigestInfo) + + struct SPCAttributeTypeAndOptionalValue { + ASN1_OBJECT *type; + ASN1_TYPE *value; // SPCInfoValue + }; + DECLARE_ASN1_FUNCTIONS(SPCAttributeTypeAndOptionalValue) + + // Undocumented. + struct SPCInfoValue { + ASN1_INTEGER *i1; + ASN1_OCTET_STRING *s1; + ASN1_INTEGER *i2; + ASN1_INTEGER *i3; + ASN1_INTEGER *i4; + ASN1_INTEGER *i5; + ASN1_INTEGER *i6; + }; + DECLARE_ASN1_FUNCTIONS(SPCInfoValue) + + struct SPCIndirectDataContent { + SPCAttributeTypeAndOptionalValue *data; + DigestInfo *messageDigest; + }; + DECLARE_ASN1_FUNCTIONS(SPCIndirectDataContent) + + IMPLEMENT_ASN1_FUNCTIONS(SPCIndirectDataContent) + ASN1_SEQUENCE(SPCIndirectDataContent) = { + ASN1_SIMPLE(SPCIndirectDataContent, data, + SPCAttributeTypeAndOptionalValue), + ASN1_SIMPLE(SPCIndirectDataContent, messageDigest, DigestInfo), + } ASN1_SEQUENCE_END(SPCIndirectDataContent) + + IMPLEMENT_ASN1_FUNCTIONS(SPCAttributeTypeAndOptionalValue) + ASN1_SEQUENCE(SPCAttributeTypeAndOptionalValue) = { + ASN1_SIMPLE(SPCAttributeTypeAndOptionalValue, type, + ASN1_OBJECT), + ASN1_OPT(SPCAttributeTypeAndOptionalValue, value, ASN1_ANY), + } ASN1_SEQUENCE_END(SPCAttributeTypeAndOptionalValue) + + IMPLEMENT_ASN1_FUNCTIONS(SPCInfoValue) + ASN1_SEQUENCE(SPCInfoValue) = { + ASN1_SIMPLE(SPCInfoValue, i1, ASN1_INTEGER), + ASN1_SIMPLE(SPCInfoValue, s1, ASN1_OCTET_STRING), + ASN1_SIMPLE(SPCInfoValue, i2, ASN1_INTEGER), + ASN1_SIMPLE(SPCInfoValue, i3, ASN1_INTEGER), + ASN1_SIMPLE(SPCInfoValue, i4, ASN1_INTEGER), + ASN1_SIMPLE(SPCInfoValue, i5, ASN1_INTEGER), + ASN1_SIMPLE(SPCInfoValue, i6, ASN1_INTEGER), + } ASN1_SEQUENCE_END(SPCInfoValue) + + IMPLEMENT_ASN1_FUNCTIONS(DigestInfo) + ASN1_SEQUENCE(DigestInfo) = { + ASN1_SIMPLE(DigestInfo, digestAlgorithm, X509_ALGOR), + ASN1_SIMPLE(DigestInfo, digest, ASN1_OCTET_STRING), + } ASN1_SEQUENCE_END(DigestInfo) + + ASN1_SEQUENCE(SPCSpOpusInfo) = { + ASN1_OPT(SPCSpOpusInfo, programName, ASN1_ANY), + ASN1_OPT(SPCSpOpusInfo, moreInfo, ASN1_ANY), + } ASN1_SEQUENCE_END(SPCSpOpusInfo) + IMPLEMENT_ASN1_FUNCTIONS(SPCSpOpusInfo) + + ASN1_SEQUENCE(SPCStatementType) = { + ASN1_SIMPLE(SPCStatementType, type, ASN1_OBJECT), + } ASN1_SEQUENCE_END(SPCStatementType) + IMPLEMENT_ASN1_FUNCTIONS(SPCStatementType) +} + +class EncodedASN1 { + + uint8_t* i_data; + size_t i_size; + + EncodedASN1(uint8_t** p_data, size_t p_size) { + + i_data = *p_data; + i_size = p_size; + } + +public: + + template + static EncodedASN1 FromItem(T *item) { + uint8_t *dataRaw = NULL; + int size = TEncode(item, &dataRaw); + + return EncodedASN1(&dataRaw, size); + } + + const uint8_t *data() const { + return i_data; + } + + size_t size() const { + return i_size; + } + + // Assumes the encoded ASN.1 represents a SEQUENCE and puts it into + // an ASN1_STRING. + // + // The returned object holds a copy of this object's data. + ASN1_STRING* ToSequenceString() { + ASN1_STRING* string = ASN1_STRING_new(); + if (!string) { + return NULL; + } + if (!ASN1_STRING_set(string, i_data, i_size)) { + return NULL; + } + return string; + } + + // Assumes the encoded ASN.1 represents a SEQUENCE and puts it into + // an ASN1_TYPE. + // + // The returned object holds a copy of this object's data. + ASN1_TYPE* ToSequenceType() { + ASN1_STRING* string = ToSequenceString(); + ASN1_TYPE* type = ASN1_TYPE_new(); + if (!type) { + return NULL; + } + type->type = V_ASN1_SEQUENCE; + type->value.sequence = string; + return type; + } + +}; + +#endif // OPENSSL_ENABLED + +class AppxPackager { + + enum { + FILE_HEADER_MAGIC = 0x04034b50, + DATA_DESCRIPTOR_MAGIC = 0x08074b50, + CENTRAL_DIR_MAGIC = 0x02014b50, + END_OF_CENTRAL_DIR_MAGIC = 0x06054b50, + ZIP64_END_OF_CENTRAL_DIR_MAGIC = 0x06064b50, + ZIP64_END_DIR_LOCATOR_MAGIC = 0x07064b50, + P7X_SIGNATURE = 0x58434b50, + ZIP64_HEADER_ID = 0x0001, + ZIP_VERSION = 20, + ZIP_ARCHIVE_VERSION = 45, + GENERAL_PURPOSE = 0x00, + BASE_FILE_HEADER_SIZE = 30, + DATA_DESCRIPTOR_SIZE = 24, + BASE_CENTRAL_DIR_SIZE = 46, + EXTRA_FIELD_LENGTH = 28, + ZIP64_HEADER_SIZE = 24, + ZIP64_END_OF_CENTRAL_DIR_SIZE = (56 - 12), + END_OF_CENTRAL_DIR_SIZE = 42, + BLOCK_SIZE = 65536, + }; + + struct BlockHash { + + String base64_hash; + size_t compressed_size; + }; + + struct FileMeta { + + String name; + int lfh_size; + bool compressed; + size_t compressed_size; + size_t uncompressed_size; + Vector hashes; + uLong file_crc32; + ZPOS64_T zip_offset; + }; + + String progress_task; + FileAccess *package; + String tmp_blockmap_file_path; + String tmp_content_types_file_path; + + Set mime_types; + + Vector file_metadata; + + ZPOS64_T central_dir_offset; + ZPOS64_T end_of_central_dir_offset; + Vector central_dir_data; + + String hash_block(uint8_t* p_block_data, size_t p_block_len); + + void make_block_map(); + void make_content_types(); + + + _FORCE_INLINE_ unsigned int buf_put_int16(uint16_t p_val, uint8_t * p_buf) { + for (int i = 0; i < 2; i++) { + *p_buf++ = (p_val >> (i * 8)) & 0xFF; + } + return 2; + } + + _FORCE_INLINE_ unsigned int buf_put_int32(uint32_t p_val, uint8_t * p_buf) { + for (int i = 0; i < 4; i++) { + *p_buf++ = (p_val >> (i * 8)) & 0xFF; + } + return 4; + } + + _FORCE_INLINE_ unsigned int buf_put_int64(uint64_t p_val, uint8_t * p_buf) { + for (int i = 0; i < 8; i++) { + *p_buf++ = (p_val >> (i * 8)) & 0xFF; + } + return 8; + } + + _FORCE_INLINE_ unsigned int buf_put_string(String p_val, uint8_t * p_buf) { + for (int i = 0; i < p_val.length(); i++) { + *p_buf++ = p_val.utf8().get(i); + } + return p_val.length(); + } + + Vector make_file_header(FileMeta p_file_meta); + void store_central_dir_header(const FileMeta p_file, bool p_do_hash = true); + Vector make_end_of_central_record(); + + String content_type(String p_extension); + +#ifdef OPENSSL_ENABLED + + // Signing methods and structs: + + String certificate_path; + String certificate_pass; + bool sign_package; + + struct CertFile { + + EVP_PKEY* private_key; + X509* certificate; + }; + + SHA256_CTX axpc_context; // SHA256 context for ZIP file entries + SHA256_CTX axcd_context; // SHA256 context for ZIP directory entries + + struct AppxDigests { + + uint8_t axpc[SHA256_DIGEST_LENGTH]; // ZIP file entries + uint8_t axcd[SHA256_DIGEST_LENGTH]; // ZIP directory entry + uint8_t axct[SHA256_DIGEST_LENGTH]; // Content types XML + uint8_t axbm[SHA256_DIGEST_LENGTH]; // Block map XML + uint8_t axci[SHA256_DIGEST_LENGTH]; // Code Integrity file (optional) + }; + + CertFile cert_file; + AppxDigests digests; + + void MakeSPCInfoValue(asn1::SPCInfoValue &info); + Error MakeIndirectDataContent(asn1::SPCIndirectDataContent &idc); + Error add_attributes(PKCS7_SIGNER_INFO *signerInfo); + void make_digests(); + void write_digest(Vector &p_out_buffer); + + Error openssl_error(unsigned long p_err); + Error read_cert_file(const String &p_path, const String &p_password, CertFile* p_out_cf); + Error sign(const CertFile &p_cert, const AppxDigests &digests, PKCS7* p_out_signature); + +#endif // OPENSSL_ENABLED + +public: + + enum SignOption { + + SIGN, + DONT_SIGN, + }; + + void set_progress_task(String p_task) { progress_task = p_task; } + void init(FileAccess* p_fa, SignOption p_sign, String &p_certificate_path, String &p_certificate_password); + void add_file(String p_file_name, const uint8_t* p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress = false); + void finish(); + + AppxPackager(); + ~AppxPackager(); +}; + +class EditorExportPlatformWinrt : public EditorExportPlatform { + + OBJ_TYPE(EditorExportPlatformWinrt, EditorExportPlatform); + + Ref logo; + + enum Platform { + ARM, + X86, + X64 + } arch; + + bool is_debug; + + String custom_release_package; + String custom_debug_package; + + String cmdline; + + String display_name; + String short_name; + String unique_name; + String description; + String publisher; + String publisher_display_name; + + String product_guid; + String publisher_guid; + + int version_major; + int version_minor; + int version_build; + int version_revision; + + bool orientation_landscape; + bool orientation_portrait; + bool orientation_landscape_flipped; + bool orientation_portrait_flipped; + + String background_color; + Ref store_logo; + Ref square44; + Ref square71; + Ref square150; + Ref square310; + Ref wide310; + Ref splash; + + bool name_on_square150; + bool name_on_square310; + bool name_on_wide; + + Set capabilities; + Set uap_capabilities; + Set device_capabilities; + + bool sign_package; + String certificate_path; + String certificate_pass; + + _FORCE_INLINE_ bool array_has(const char** p_array, const char* p_value) const { + while (*p_array) { + if (String(*p_array) == String(p_value)) return true; + p_array++; + } + return false; + } + + bool _valid_resource_name(const String &p_name) const; + bool _valid_guid(const String &p_guid) const; + bool _valid_bgcolor(const String &p_color) const; + bool _valid_image(const Ref p_image, int p_width, int p_height) const; + + Vector _fix_manifest(const Vector &p_template, bool p_give_internet) const; + Vector _get_image_data(const String &p_path); + + static Error save_appx_file(void *p_userdata, const String& p_path, const Vector& p_data, int p_file, int p_total); + static bool _should_compress_asset(const String& p_path, const Vector& p_data); + +protected: + + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; + +public: + + virtual String get_name() const { return "Windows Universal"; } + virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_ETC1; } + virtual Ref get_logo() const { return logo; } + + virtual bool can_export(String *r_error = NULL) const; + virtual String get_binary_extension() const { return "appx"; } + + virtual Error export_project(const String& p_path, bool p_debug, int p_flags = 0); + + EditorExportPlatformWinrt(); + ~EditorExportPlatformWinrt(); +}; + + +/////////////////////////////////////////////////////////////////////////// + +String AppxPackager::hash_block(uint8_t * p_block_data, size_t p_block_len) { + + char hash[32]; + char base64[45]; + + sha256_context ctx; + sha256_init(&ctx); + sha256_hash(&ctx, p_block_data, p_block_len); + sha256_done(&ctx, (uint8_t*)hash); + + base64_encode(base64, hash, 32); + base64[44] = '\0'; + + return String(base64); +} + +void AppxPackager::make_block_map() { + + FileAccess* tmp_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::WRITE); + + tmp_file->store_string(""); + tmp_file->store_string(""); + + for (int i = 0; i < file_metadata.size(); i++) { + + FileMeta file = file_metadata[i]; + + tmp_file->store_string( + ""); + + + for (int j = 0; j < file.hashes.size(); j++) { + + tmp_file->store_string("store_string("Size=\"" + itos(file.hashes[j].compressed_size) + "\" "); + tmp_file->store_string("/>"); + } + + tmp_file->store_string(""); + } + + tmp_file->store_string(""); + + tmp_file->close(); + memdelete(tmp_file); + tmp_file = NULL; +} + +String AppxPackager::content_type(String p_extension) { + + if (p_extension == "png") + return "image/png"; + else if (p_extension == "jpg") + return "image/jpg"; + else if (p_extension == "xml") + return "application/xml"; + else if (p_extension == "exe" || p_extension == "dll") + return "application/x-msdownload"; + else + return "application/octet-stream"; +} + +void AppxPackager::make_content_types() { + + FileAccess* tmp_file = FileAccess::open(tmp_content_types_file_path, FileAccess::WRITE); + + tmp_file->store_string(""); + tmp_file->store_string(""); + + Map types; + + for (int i = 0; i < file_metadata.size(); i++) { + + String ext = file_metadata[i].name.extension(); + + if (types.has(ext)) continue; + + types[ext] = content_type(ext); + + tmp_file->store_string(""); + } + + // Appx signature file + tmp_file->store_string(""); + + // Override for package files + tmp_file->store_string(""); + tmp_file->store_string(""); + tmp_file->store_string(""); + tmp_file->store_string(""); + + tmp_file->store_string(""); + + tmp_file->close(); + memdelete(tmp_file); + tmp_file = NULL; +} + +Vector AppxPackager::make_file_header(FileMeta p_file_meta) { + + Vector buf; + buf.resize(BASE_FILE_HEADER_SIZE + p_file_meta.name.length()); + + int offs = 0; + // Write magic + offs += buf_put_int32(FILE_HEADER_MAGIC, &buf[offs]); + + // Version + offs += buf_put_int16(ZIP_VERSION, &buf[offs]); + + // Special flag + offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]); + + // Compression + offs += buf_put_int16(p_file_meta.compressed ? Z_DEFLATED : 0, &buf[offs]); + + // File date and time + offs += buf_put_int32(0, &buf[offs]); + + // CRC-32 + offs += buf_put_int32(p_file_meta.file_crc32, &buf[offs]); + + // Compressed size + offs += buf_put_int32(p_file_meta.compressed_size, &buf[offs]); + + // Uncompressed size + offs += buf_put_int32(p_file_meta.uncompressed_size, &buf[offs]); + + // File name length + offs += buf_put_int16(p_file_meta.name.length(), &buf[offs]); + + // Extra data length + offs += buf_put_int16(0, &buf[offs]); + + // File name + offs += buf_put_string(p_file_meta.name, &buf[offs]); + + // Done! + return buf; +} + +void AppxPackager::store_central_dir_header(const FileMeta p_file, bool p_do_hash) { + + Vector &buf = central_dir_data; + int offs = buf.size(); + buf.resize(buf.size() + BASE_CENTRAL_DIR_SIZE + p_file.name.length()); + + + // Write magic + offs += buf_put_int32(CENTRAL_DIR_MAGIC, &buf[offs]); + + // ZIP versions + offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]); + offs += buf_put_int16(ZIP_VERSION, &buf[offs]); + + // General purpose flag + offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]); + + // Compression + offs += buf_put_int16(p_file.compressed ? Z_DEFLATED : 0, &buf[offs]); + + // Modification date/time + offs += buf_put_int32(0, &buf[offs]); + + // Crc-32 + offs += buf_put_int32(p_file.file_crc32, &buf[offs]); + + // File sizes + offs += buf_put_int32(p_file.compressed_size, &buf[offs]); + offs += buf_put_int32(p_file.uncompressed_size, &buf[offs]); + + // File name length + offs += buf_put_int16(p_file.name.length(), &buf[offs]); + + // Extra field length + offs += buf_put_int16(0, &buf[offs]); + + // Comment length + offs += buf_put_int16(0, &buf[offs]); + + // Disk number start, internal/external file attributes + for (int i = 0; i < 8; i++) { + buf[offs++] = 0; + } + + // Relative offset + offs += buf_put_int32(p_file.zip_offset, &buf[offs]); + + // File name + offs += buf_put_string(p_file.name, &buf[offs]); + +#ifdef OPENSSL_ENABLED + // Calculate the hash for signing + if (p_do_hash) + SHA256_Update(&axcd_context, buf.ptr(), buf.size()); +#endif // OPENSSL_ENABLED + + // Done! +} + +Vector AppxPackager::make_end_of_central_record() { + + Vector buf; + buf.resize(ZIP64_END_OF_CENTRAL_DIR_SIZE + 12 + END_OF_CENTRAL_DIR_SIZE); // Size plus magic + + int offs = 0; + + // Write magic + offs += buf_put_int32(ZIP64_END_OF_CENTRAL_DIR_MAGIC, &buf[offs]); + + // Size of this record + offs += buf_put_int64(ZIP64_END_OF_CENTRAL_DIR_SIZE, &buf[offs]); + + // Version (yes, twice) + offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]); + offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]); + + // Disk number + for (int i = 0; i < 8; i++) { + buf[offs++] = 0; + } + + // Number of entries (total and per disk) + offs += buf_put_int64(file_metadata.size(), &buf[offs]); + offs += buf_put_int64(file_metadata.size(), &buf[offs]); + + // Size of central dir + offs += buf_put_int64(central_dir_data.size(), &buf[offs]); + + // Central dir offset + offs += buf_put_int64(central_dir_offset, &buf[offs]); + + ////// ZIP64 locator + + // Write magic for zip64 central dir locator + offs += buf_put_int32(ZIP64_END_DIR_LOCATOR_MAGIC, &buf[offs]); + + // Disk number + for (int i = 0; i < 4; i++) { + buf[offs++] = 0; + } + + // Relative offset + offs += buf_put_int64(end_of_central_dir_offset, &buf[offs]); + + // Number of disks + offs += buf_put_int32(1, &buf[offs]); + + /////// End of zip directory + + // Write magic for end central dir + offs += buf_put_int32(END_OF_CENTRAL_DIR_MAGIC, &buf[offs]); + + // Dummy stuff for Zip64 + for (int i = 0; i < 4; i++) { + buf[offs++] = 0x0; + } + for (int i = 0; i < 12; i++) { + buf[offs++] = 0xFF; + } + + // Size of comments + for (int i = 0; i < 2; i++) { + buf[offs++] = 0; + } + + // Done! + return buf; +} + +void AppxPackager::init(FileAccess * p_fa, SignOption p_sign, String &p_certificate_path, String &p_certificate_password) { + + package = p_fa; + central_dir_offset = 0; + end_of_central_dir_offset = 0; + tmp_blockmap_file_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpblockmap.xml"; + tmp_content_types_file_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpcontenttypes.xml"; +#ifdef OPENSSL_ENABLED + certificate_path = p_certificate_path; + certificate_pass = p_certificate_password; + sign_package = p_sign == SIGN; + SHA256_Init(&axpc_context); + SHA256_Init(&axcd_context); +#endif // OPENSSL_ENABLED +} + +void AppxPackager::add_file(String p_file_name, const uint8_t * p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) { + + if (p_file_no >= 1 && p_total_files >= 1) { + EditorNode::progress_task_step(progress_task, "File: " + p_file_name, (p_file_no * 100) / p_total_files); + } + + bool do_hash = p_file_name != "AppxSignature.p7x"; + + FileMeta meta; + meta.name = p_file_name; + meta.uncompressed_size = p_len; + meta.compressed_size = p_len; + meta.compressed = p_compress; + meta.zip_offset = package->get_pos(); + + Vector file_buffer; + + // Data for compression + z_stream strm; + FileAccess* strm_f = NULL; + Vector strm_in; + strm_in.resize(BLOCK_SIZE); + Vector strm_out; + + if (p_compress) { + + strm.zalloc = zipio_alloc; + strm.zfree = zipio_free; + strm.opaque = &strm_f; + + strm_out.resize(BLOCK_SIZE + 8); + + deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); + } + + int step = 0; + + while (p_len - step > 0) { + + size_t block_size = (p_len - step) > BLOCK_SIZE ? BLOCK_SIZE : (p_len - step); + + for (int i = 0; i < block_size; i++) { + strm_in[i] = p_buffer[step + i]; + } + + BlockHash bh; + bh.base64_hash = hash_block(strm_in.ptr(), block_size); + + if (p_compress) { + + strm.avail_in = block_size; + strm.avail_out = strm_out.size(); + strm.next_in = strm_in.ptr(); + strm.next_out = strm_out.ptr(); + + int total_out_before = strm.total_out; + + deflate(&strm, Z_FULL_FLUSH); + bh.compressed_size = strm.total_out - total_out_before; + + //package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before); + int start = file_buffer.size(); + file_buffer.resize(file_buffer.size() + bh.compressed_size); + for (int i = 0; i < bh.compressed_size; i++) + file_buffer[start + i] = strm_out[i]; +#ifdef OPENSSL_ENABLED + if (do_hash) + SHA256_Update(&axpc_context, strm_out.ptr(), strm.total_out - total_out_before); +#endif // OPENSSL_ENABLED + + } else { + bh.compressed_size = block_size; + //package->store_buffer(strm_in.ptr(), block_size); + int start = file_buffer.size(); + file_buffer.resize(file_buffer.size() + block_size); + for (int i = 0; i < bh.compressed_size; i++) + file_buffer[start + i] = strm_in[i]; +#ifdef OPENSSL_ENABLED + if (do_hash) + SHA256_Update(&axpc_context, strm_in.ptr(), block_size); +#endif // OPENSSL_ENABLED + } + + meta.hashes.push_back(bh); + + step += block_size; + } + + if (p_compress) { + + strm.avail_in = 0; + strm.avail_out = strm_out.size(); + strm.next_in = strm_in.ptr(); + strm.next_out = strm_out.ptr(); + + int total_out_before = strm.total_out; + + deflate(&strm, Z_FINISH); + + //package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before); + int start = file_buffer.size(); + file_buffer.resize(file_buffer.size() + (strm.total_out - total_out_before)); + for (int i = 0; i < (strm.total_out - total_out_before); i++) + file_buffer[start + i] = strm_out[i]; +#ifdef OPENSSL_ENABLED + if (do_hash) + SHA256_Update(&axpc_context, strm_out.ptr(), strm.total_out - total_out_before); +#endif // OPENSSL_ENABLED + + deflateEnd(&strm); + meta.compressed_size = strm.total_out; + + } else { + + meta.compressed_size = p_len; + } + + // Calculate file CRC-32 + uLong crc = crc32(0L, Z_NULL, 0); + crc = crc32(crc, p_buffer, p_len); + meta.file_crc32 = crc; + + // Create file header + Vector file_header = make_file_header(meta); + meta.lfh_size = file_header.size(); + +#ifdef OPENSSL_ENABLED + // Hash the data for signing + if (do_hash) { + SHA256_Update(&axpc_context, file_header.ptr(), file_header.size()); + SHA256_Update(&axpc_context, file_buffer.ptr(), file_buffer.size()); + } +#endif // OPENSSL_ENABLED + + // Store the header and file; + package->store_buffer(file_header.ptr(), file_header.size()); + package->store_buffer(file_buffer.ptr(), file_buffer.size()); + + file_metadata.push_back(meta); +} + +void AppxPackager::finish() { + + // Create and add block map file + EditorNode::progress_task_step("export", "Creating block map...", 4); + + make_block_map(); + FileAccess* blockmap_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::READ); + Vector blockmap_buffer; + blockmap_buffer.resize(blockmap_file->get_len()); + + blockmap_file->get_buffer(blockmap_buffer.ptr(), blockmap_buffer.size()); + +#ifdef OPENSSL_ENABLED + // Hash the file for signing + if (sign_package) { + SHA256_CTX axbm_context; + SHA256_Init(&axbm_context); + SHA256_Update(&axbm_context, blockmap_buffer.ptr(), blockmap_buffer.size()); + SHA256_Final(digests.axbm, &axbm_context); + } +#endif // OPENSSL_ENABLED + + add_file("AppxBlockMap.xml", blockmap_buffer.ptr(), blockmap_buffer.size(), -1, -1, true); + + blockmap_file->close(); + memdelete(blockmap_file); + blockmap_file = NULL; + + // Add content types + EditorNode::progress_task_step("export", "Setting content types...", 5); + make_content_types(); + + FileAccess* types_file = FileAccess::open(tmp_content_types_file_path, FileAccess::READ); + Vector types_buffer; + types_buffer.resize(types_file->get_len()); + + types_file->get_buffer(types_buffer.ptr(), types_buffer.size()); + +#ifdef OPENSSL_ENABLED + if (sign_package) { + // Hash the file for signing + SHA256_CTX axct_context; + SHA256_Init(&axct_context); + SHA256_Update(&axct_context, types_buffer.ptr(), types_buffer.size()); + SHA256_Final(digests.axct, &axct_context); + } +#endif // OPENSSL_ENABLED + + add_file("[Content_Types].xml", types_buffer.ptr(), types_buffer.size(), -1, -1, true); + + types_file->close(); + memdelete(types_file); + types_file = NULL; + + // Pre-process central directory before signing + for (int i = 0; i < file_metadata.size(); i++) { + store_central_dir_header(file_metadata[i]); + } + +#ifdef OPENSSL_ENABLED + // Create the signature file + if (sign_package) { + + Error err = read_cert_file(certificate_path, certificate_pass, &cert_file); + + if (err != OK) { + EditorNode::add_io_error(TTR("Couldn't read the certficate file. Are the path and password both correct?")); + package->close(); + memdelete(package); + package = NULL; + return; + } + + + // Make a temp end of the zip for hashing + central_dir_offset = package->get_pos(); + end_of_central_dir_offset = central_dir_offset + central_dir_data.size(); + Vector zip_end_dir = make_end_of_central_record(); + + // Hash the end directory + SHA256_Update(&axcd_context, zip_end_dir.ptr(), zip_end_dir.size()); + + // Finish the hashes + make_digests(); + + PKCS7* signature = PKCS7_new(); + if (!signature) { + EditorNode::add_io_error(TTR("Error creating the signature object.")); + package->close(); + memdelete(package); + package = NULL; + return; + } + + err = sign(cert_file, digests, signature); + + if (err != OK) { + EditorNode::add_io_error(TTR("Error creating the package signature.")); + package->close(); + memdelete(package); + package = NULL; + return; + } + + // Read the signature as bytes + BIO* bio_out = BIO_new(BIO_s_mem()); + i2d_PKCS7_bio(bio_out, signature); + + BIO_flush(bio_out); + + uint8_t* bio_ptr; + size_t bio_size = BIO_get_mem_data(bio_out, &bio_ptr); + + // Create the signature buffer with magic number + Vector signature_file; + signature_file.resize(4 + bio_size); + buf_put_int32(P7X_SIGNATURE, signature_file.ptr()); + for (int i = 0; i < bio_size; i++) + signature_file[i + 4] = bio_ptr[i]; + + // Add the signature to the package + add_file("AppxSignature.p7x", signature_file.ptr(), signature_file.size(), -1, -1, true); + + // Add central directory entry + store_central_dir_header(file_metadata[file_metadata.size() - 1], false); + } +#endif // OPENSSL_ENABLED + + + // Write central directory + EditorNode::progress_task_step("export", "Finishing package...", 6); + central_dir_offset = package->get_pos(); + package->store_buffer(central_dir_data.ptr(), central_dir_data.size()); + + // End record + end_of_central_dir_offset = package->get_pos(); + Vector end_record = make_end_of_central_record(); + package->store_buffer(end_record.ptr(), end_record.size()); + + package->close(); + memdelete(package); + package = NULL; +} + +#ifdef OPENSSL_ENABLED +// https://support.microsoft.com/en-us/kb/287547 +const char SPC_INDIRECT_DATA_OBJID[] = "1.3.6.1.4.1.311.2.1.4"; +const char SPC_STATEMENT_TYPE_OBJID[] = "1.3.6.1.4.1.311.2.1.11"; +const char SPC_SP_OPUS_INFO_OBJID[] = "1.3.6.1.4.1.311.2.1.12"; +const char SPC_SIPINFO_OBJID[] = "1.3.6.1.4.1.311.2.1.30"; +#endif // OPENSSL_ENABLED + +AppxPackager::AppxPackager() {} + +AppxPackager::~AppxPackager() {} + + +//////////////////////////////////////////////////////////////////// + +#ifdef OPENSSL_ENABLED +Error AppxPackager::openssl_error(unsigned long p_err) { + + ERR_load_crypto_strings(); + + char buffer[256]; + ERR_error_string_n(p_err, buffer, sizeof(buffer)); + + String err(buffer); + + ERR_EXPLAIN(err); + ERR_FAIL_V(FAILED); +} + +void AppxPackager::MakeSPCInfoValue(asn1::SPCInfoValue &info) { + + // I have no idea what these numbers mean. + static uint8_t s1Magic[] = { + 0x4B, 0xDF, 0xC5, 0x0A, 0x07, 0xCE, 0xE2, 0x4D, + 0xB7, 0x6E, 0x23, 0xC8, 0x39, 0xA0, 0x9F, 0xD1, + }; + ASN1_INTEGER_set(info.i1, 0x01010000); + ASN1_OCTET_STRING_set(info.s1, s1Magic, sizeof(s1Magic)); + ASN1_INTEGER_set(info.i2, 0x00000000); + ASN1_INTEGER_set(info.i3, 0x00000000); + ASN1_INTEGER_set(info.i4, 0x00000000); + ASN1_INTEGER_set(info.i5, 0x00000000); + ASN1_INTEGER_set(info.i6, 0x00000000); +} + +Error AppxPackager::MakeIndirectDataContent(asn1::SPCIndirectDataContent &idc) { + + using namespace asn1; + + ASN1_TYPE* algorithmParameter = ASN1_TYPE_new(); + if (!algorithmParameter) { + return openssl_error(ERR_peek_last_error()); + } + algorithmParameter->type = V_ASN1_NULL; + + SPCInfoValue* infoValue = SPCInfoValue_new(); + if (!infoValue) { + return openssl_error(ERR_peek_last_error()); + } + MakeSPCInfoValue(*infoValue); + + ASN1_TYPE* value = + EncodedASN1::FromItem(infoValue) + .ToSequenceType(); + + { + Vector digest; + write_digest(digest); + if (!ASN1_OCTET_STRING_set(idc.messageDigest->digest, + digest.ptr(), digest.size())) { + + return openssl_error(ERR_peek_last_error()); + } + } + + idc.data->type = OBJ_txt2obj(SPC_SIPINFO_OBJID, 1); + idc.data->value = value; + idc.messageDigest->digestAlgorithm->algorithm = OBJ_nid2obj(NID_sha256); + idc.messageDigest->digestAlgorithm->parameter = algorithmParameter; + + return OK; +} + +Error AppxPackager::add_attributes(PKCS7_SIGNER_INFO * p_signer_info) { + + // Add opus attribute + asn1::SPCSpOpusInfo* opus = asn1::SPCSpOpusInfo_new(); + if (!opus) return openssl_error(ERR_peek_last_error()); + + ASN1_STRING* opus_value = EncodedASN1::FromItem(opus) + .ToSequenceString(); + + if (!PKCS7_add_signed_attribute( + p_signer_info, + OBJ_txt2nid(SPC_SP_OPUS_INFO_OBJID), + V_ASN1_SEQUENCE, + opus_value + )) { + + asn1::SPCSpOpusInfo_free(opus); + + ASN1_STRING_free(opus_value); + return openssl_error(ERR_peek_last_error()); + } + + // Add content type attribute + if (!PKCS7_add_signed_attribute( + p_signer_info, + NID_pkcs9_contentType, + V_ASN1_OBJECT, + OBJ_txt2obj(SPC_INDIRECT_DATA_OBJID, 1) + )) { + + asn1::SPCSpOpusInfo_free(opus); + ASN1_STRING_free(opus_value); + return openssl_error(ERR_peek_last_error()); + } + + // Add statement type attribute + asn1::SPCStatementType* statement_type = asn1::SPCStatementType_new(); + if (!statement_type) return openssl_error(ERR_peek_last_error()); + + statement_type->type = OBJ_nid2obj(NID_ms_code_ind); + ASN1_STRING* statement_type_value = + EncodedASN1::FromItem(statement_type) + .ToSequenceString(); + + if (!PKCS7_add_signed_attribute( + p_signer_info, + OBJ_txt2nid(SPC_STATEMENT_TYPE_OBJID), + V_ASN1_SEQUENCE, + statement_type_value + )) { + + ASN1_STRING_free(opus_value); + asn1::SPCStatementType_free(statement_type); + ASN1_STRING_free(statement_type_value); + + return openssl_error(ERR_peek_last_error()); + } + + return OK; + +} + +void AppxPackager::make_digests() { + + // AXPC + SHA256_Final(digests.axpc, &axpc_context); + + // AXCD + SHA256_Final(digests.axcd, &axcd_context); + + // AXCI + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) + digests.axci[i] = 0; + +} + +void AppxPackager::write_digest(Vector& p_out_buffer) { + + // Size of digests plus 6 32-bit magic numbers + p_out_buffer.resize((SHA256_DIGEST_LENGTH * 5) + (6 * 4)); + + int offs = 0; + + // APPX + uint32_t sig = 0x58505041; + offs += buf_put_int32(sig, &p_out_buffer[offs]); + + // AXPC + uint32_t axpc_sig = 0x43505841; + offs += buf_put_int32(axpc_sig, &p_out_buffer[offs]); + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + p_out_buffer[offs++] = digests.axpc[i]; + } + + // AXCD + uint32_t axcd_sig = 0x44435841; + offs += buf_put_int32(axcd_sig, &p_out_buffer[offs]); + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + p_out_buffer[offs++] = digests.axcd[i]; + } + + // AXCT + uint32_t axct_sig = 0x54435841; + offs += buf_put_int32(axct_sig, &p_out_buffer[offs]); + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + p_out_buffer[offs++] = digests.axct[i]; + } + + // AXBM + uint32_t axbm_sig = 0x4D425841; + offs += buf_put_int32(axbm_sig, &p_out_buffer[offs]); + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + p_out_buffer[offs++] = digests.axbm[i]; + } + + // AXCI + uint32_t axci_sig = 0x49435841; + offs += buf_put_int32(axci_sig, &p_out_buffer[offs]); + for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { + p_out_buffer[offs++] = digests.axci[i]; + } + + // Done! +} + +Error AppxPackager::read_cert_file(const String & p_path, const String &p_password, CertFile* p_out_cf) { + + ERR_FAIL_COND_V(!p_out_cf, ERR_INVALID_PARAMETER); + + BIO* bio = BIO_new_file(p_path.utf8().get_data(), "rb"); + if (!bio) { + return openssl_error(ERR_peek_last_error()); + } + + PKCS12* data = d2i_PKCS12_bio(bio, NULL); + if (!data) { + BIO_free(bio); + return openssl_error(ERR_peek_last_error()); + } + + /* Fails to link with GCC, need to solve when implement signing + if (!PKCS12_parse(data, p_password.utf8().get_data(), &p_out_cf->private_key, &p_out_cf->certificate, NULL)) { + PKCS12_free(data); + BIO_free(bio); + return openssl_error(ERR_peek_last_error()); + }*/ + + if (!p_out_cf->private_key) { + PKCS12_free(data); + BIO_free(bio); + return openssl_error(ERR_peek_last_error()); + } + + if (!p_out_cf->certificate) { + PKCS12_free(data); + BIO_free(bio); + return openssl_error(ERR_peek_last_error()); + } + + PKCS12_free(data); + BIO_free(bio); + + return OK; +} + +Error AppxPackager::sign(const CertFile & p_cert, const AppxDigests & digests, PKCS7 * p_out_signature) { + + OpenSSL_add_all_algorithms(); + + // Register object IDs + OBJ_create_and_add_object(SPC_INDIRECT_DATA_OBJID, NULL, NULL); + OBJ_create_and_add_object(SPC_SIPINFO_OBJID, NULL, NULL); + OBJ_create_and_add_object(SPC_SP_OPUS_INFO_OBJID, NULL, NULL); + OBJ_create_and_add_object(SPC_STATEMENT_TYPE_OBJID, NULL, NULL); + + if (!PKCS7_set_type(p_out_signature, NID_pkcs7_signed)) { + + return openssl_error(ERR_peek_last_error()); + } + + PKCS7_SIGNER_INFO *signer_info = PKCS7_add_signature(p_out_signature, p_cert.certificate, p_cert.private_key, EVP_sha256()); + if (!signer_info) return openssl_error(ERR_peek_last_error()); + + add_attributes(signer_info); + + if (!PKCS7_content_new(p_out_signature, NID_pkcs7_data)) { + + return openssl_error(ERR_peek_last_error()); + } + + if (!PKCS7_add_certificate(p_out_signature, p_cert.certificate)) { + + return openssl_error(ERR_peek_last_error()); + } + + asn1::SPCIndirectDataContent* idc = asn1::SPCIndirectDataContent_new(); + + MakeIndirectDataContent(*idc); + EncodedASN1 idc_encoded = + EncodedASN1::FromItem(idc); + + BIO* signed_data = PKCS7_dataInit(p_out_signature, NULL); + + if (idc_encoded.size() < 2) { + + ERR_EXPLAIN("Invalid encoded size"); + ERR_FAIL_V(FAILED); + } + + if ((idc_encoded.data()[1] & 0x80) == 0x00) { + + ERR_EXPLAIN("Invalid encoded data"); + ERR_FAIL_V(FAILED); + } + + size_t skip = 4; + + if (BIO_write(signed_data, idc_encoded.data() + skip, idc_encoded.size() - skip) + != idc_encoded.size() - skip) { + + return openssl_error(ERR_peek_last_error()); + } + if (BIO_flush(signed_data) != 1) { + + return openssl_error(ERR_peek_last_error()); + } + + if (!PKCS7_dataFinal(p_out_signature, signed_data)) { + + return openssl_error(ERR_peek_last_error()); + } + + PKCS7* content = PKCS7_new(); + if (!content) { + + return openssl_error(ERR_peek_last_error()); + } + + content->type = OBJ_txt2obj(SPC_INDIRECT_DATA_OBJID, 1); + + ASN1_TYPE* idc_sequence = idc_encoded.ToSequenceType(); + content->d.other = idc_sequence; + + if (!PKCS7_set_content(p_out_signature, content)) { + + return openssl_error(ERR_peek_last_error()); + } + + return OK; +} + +#endif // OPENSSL_ENABLED + +//////////////////////////////////////////////////////////////////// + + +bool EditorExportPlatformWinrt::_valid_resource_name(const String &p_name) const { + + if (p_name.empty()) return false; + if (p_name.ends_with(".")) return false; + + static const char* invalid_names[] = { + "CON","PRN","AUX","NUL","COM1","COM2","COM3","COM4","COM5","COM6","COM7", + "COM8","COM9","LPT1","LPT2","LPT3","LPT4","LPT5","LPT6","LPT7","LPT8","LPT9", + NULL + }; + + const char** t = invalid_names; + while (*t) { + if (p_name == *t) return false; + t++; + } + + return true; +} + +bool EditorExportPlatformWinrt::_valid_guid(const String & p_guid) const { + + Vector parts = p_guid.split("-"); + + if (parts.size() != 5) return false; + if (parts[0].length() != 8) return false; + for (int i = 1; i < 4; i++) + if (parts[i].length() != 4) return false; + if (parts[4].length() != 12) return false; + + return true; +} + +bool EditorExportPlatformWinrt::_valid_bgcolor(const String & p_color) const { + + if (p_color.empty()) return true; + if (p_color.begins_with("#") && p_color.is_valid_html_color()) return true; + + // Colors from https://msdn.microsoft.com/en-us/library/windows/apps/dn934817.aspx + static const char* valid_colors[] = { + "aliceBlue","antiqueWhite","aqua","aquamarine","azure","beige", + "bisque","black","blanchedAlmond","blue","blueViolet","brown", + "burlyWood","cadetBlue","chartreuse","chocolate","coral","cornflowerBlue", + "cornsilk","crimson","cyan","darkBlue","darkCyan","darkGoldenrod", + "darkGray","darkGreen","darkKhaki","darkMagenta","darkOliveGreen","darkOrange", + "darkOrchid","darkRed","darkSalmon","darkSeaGreen","darkSlateBlue","darkSlateGray", + "darkTurquoise","darkViolet","deepPink","deepSkyBlue","dimGray","dodgerBlue", + "firebrick","floralWhite","forestGreen","fuchsia","gainsboro","ghostWhite", + "gold","goldenrod","gray","green","greenYellow","honeydew", + "hotPink","indianRed","indigo","ivory","khaki","lavender", + "lavenderBlush","lawnGreen","lemonChiffon","lightBlue","lightCoral","lightCyan", + "lightGoldenrodYellow","lightGreen","lightGray","lightPink","lightSalmon","lightSeaGreen", + "lightSkyBlue","lightSlateGray","lightSteelBlue","lightYellow","lime","limeGreen", + "linen","magenta","maroon","mediumAquamarine","mediumBlue","mediumOrchid", + "mediumPurple","mediumSeaGreen","mediumSlateBlue","mediumSpringGreen","mediumTurquoise","mediumVioletRed", + "midnightBlue","mintCream","mistyRose","moccasin","navajoWhite","navy", + "oldLace","olive","oliveDrab","orange","orangeRed","orchid", + "paleGoldenrod","paleGreen","paleTurquoise","paleVioletRed","papayaWhip","peachPuff", + "peru","pink","plum","powderBlue","purple","red", + "rosyBrown","royalBlue","saddleBrown","salmon","sandyBrown","seaGreen", + "seaShell","sienna","silver","skyBlue","slateBlue","slateGray", + "snow","springGreen","steelBlue","tan","teal","thistle", + "tomato","transparent","turquoise","violet","wheat","white", + "whiteSmoke","yellow","yellowGreen", + NULL + }; + + const char** color = valid_colors; + + while(*color) { + if (p_color == *color) return true; + color++; + } + + return false; +} + +bool EditorExportPlatformWinrt::_valid_image(const Ref p_image, int p_width, int p_height) const { + + if (!p_image.is_valid()) return false; + + // TODO: Add resource creation or image rescaling to enable other scales: + // 1.25, 1.5, 2.0 + real_t scales[] = { 1.0 }; + bool valid_w = false; + bool valid_h = false; + + for (int i = 0; i < 1; i++) { + + int w = ceil(p_width * scales[i]); + int h = ceil(p_height * scales[i]); + + if (w == p_image->get_width()) + valid_w = true; + if (h == p_image->get_height()) + valid_h = true; + } + + return valid_w && valid_h; +} + +Vector EditorExportPlatformWinrt::_fix_manifest(const Vector &p_template, bool p_give_internet) const { + + String result = String::utf8((const char*)p_template.ptr(), p_template.size()); + + result = result.replace("$godot_version$", VERSION_FULL_NAME); + + result = result.replace("$identity_name$", unique_name); + result = result.replace("$publisher$", publisher); + + result = result.replace("$product_guid$", product_guid); + result = result.replace("$publisher_guid$", publisher_guid); + + String version = itos(version_major) + "." + itos(version_minor) + "." + itos(version_build) + "." + itos(version_revision); + result = result.replace("$version_string$", version); + + String architecture = arch == ARM ? "ARM" : arch == X86 ? "x86" : "x64"; + result = result.replace("$architecture$", architecture); + + result = result.replace("$display_name$", display_name.empty() ? (String)Globals::get_singleton()->get("application/name") : display_name); + result = result.replace("$publisher_display_name$", publisher_display_name); + result = result.replace("$app_description$", description); + result = result.replace("$bg_color$", background_color); + result = result.replace("$short_name$", short_name); + + String name_on_tiles = ""; + if (name_on_square150) { + name_on_tiles += " \n"; + } + if (name_on_wide) { + name_on_tiles += " \n"; + } + if (name_on_square310) { + name_on_tiles += " \n"; + } + + String show_name_on_tiles = ""; + if (!name_on_tiles.empty()) { + show_name_on_tiles = "\n" + name_on_tiles + " "; + } + + result = result.replace("$name_on_tiles$", name_on_tiles); + + String rotations = ""; + if (orientation_landscape) { + rotations += " \n"; + } + if (orientation_portrait) { + rotations += " \n"; + } + if (orientation_landscape_flipped) { + rotations += " \n"; + } + if (orientation_portrait_flipped) { + rotations += " \n"; + } + + String rotation_preference = ""; + if (!rotations.empty()) { + rotation_preference = "\n" + rotations + " "; + } + + result = result.replace("$rotation_preference$", rotation_preference); + + String capabilities_elements = ""; + const char **basic = uwp_capabilities; + while (*basic) { + if (capabilities.has(*basic)) { + capabilities_elements += " \n"; + } + basic++; + } + const char **uap = uwp_uap_capabilities; + while (*uap) { + if (uap_capabilities.has(*uap)) { + capabilities_elements += " \n"; + } + uap++; + } + const char **device = uwp_device_capabilites; + while (*device) { + if (uap_capabilities.has(*device)) { + capabilities_elements += " \n"; + } + device++; + } + + if (!capabilities.has("internetClient") && p_give_internet) { + capabilities_elements += " \n"; + } + + String capabilities_string = ""; + if (!capabilities_elements.empty()) { + capabilities_string = "\n" + capabilities_elements + " "; + } + + result = result.replace("$capabilities_place$", capabilities_string); + + Vector r_ret; + r_ret.resize(result.length()); + + for (int i = 0; i < result.length(); i++) + r_ret[i] = result.utf8().get(i); + + return r_ret; +} + +Vector EditorExportPlatformWinrt::_get_image_data(const String & p_path) { + + Vector data; + Ref ref; + + if (p_path.find("StoreLogo") != -1) { + ref = store_logo; + } else if (p_path.find("Square44x44Logo") != -1) { + ref = square44; + } else if (p_path.find("Square71x71Logo") != -1) { + ref = square71; + } else if (p_path.find("Square150x150Logo") != -1) { + ref = square150; + } else if (p_path.find("Square310x310Logo") != -1) { + ref = square310; + } else if (p_path.find("Wide310x150Logo") != -1) { + ref = wide310; + } else if (p_path.find("SplashScreen") != -1) { + ref = splash; + } + + if (!ref.is_valid()) return data; + + + String tmp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/uwp_tmp_logo.png"); + + Error err = ref->get_data().save_png(tmp_path); + + if (err != OK) { + + String err_string = "Couldn't save temp logo file."; + + EditorNode::add_io_error(err_string); + ERR_EXPLAIN(err_string); + ERR_FAIL_V(data); + } + + FileAccess* f = FileAccess::open(tmp_path, FileAccess::READ, &err); + + if (err != OK) { + + String err_string = "Couldn't open temp logo file."; + + EditorNode::add_io_error(err_string); + ERR_EXPLAIN(err_string); + ERR_FAIL_V(data); + } + + data.resize(f->get_len()); + f->get_buffer(data.ptr(), data.size()); + + f->close(); + memdelete(f); + + // Delete temp file + DirAccess* dir = DirAccess::open(tmp_path.get_base_dir(), &err); + + if (err != OK) { + + String err_string = "Couldn't open temp path to remove temp logo file."; + + EditorNode::add_io_error(err_string); + ERR_EXPLAIN(err_string); + ERR_FAIL_V(data); + } + + err = dir->remove(tmp_path); + + memdelete(dir); + + if (err != OK) { + + String err_string = "Couldn't remove temp logo file."; + + EditorNode::add_io_error(err_string); + ERR_EXPLAIN(err_string); + ERR_FAIL_V(data); + } + + return data; +} + +Error EditorExportPlatformWinrt::save_appx_file(void * p_userdata, const String & p_path, const Vector& p_data, int p_file, int p_total) { + + AppxPackager *packager = (AppxPackager*)p_userdata; + String dst_path = p_path.replace_first("res://", "game/"); + + packager->add_file(dst_path, p_data.ptr(), p_data.size(), p_file, p_total, _should_compress_asset(p_path, p_data)); + + return OK; +} + +bool EditorExportPlatformWinrt::_should_compress_asset(const String & p_path, const Vector& p_data) { + + /* TODO: This was copied verbatim from Android export. It should be + * refactored to the parent class and also be used for .zip export. + */ + + /* + * By not compressing files with little or not benefit in doing so, + * a performance gain is expected at runtime. Moreover, if the APK is + * zip-aligned, assets stored as they are can be efficiently read by + * Android by memory-mapping them. + */ + + // -- Unconditional uncompress to mimic AAPT plus some other + + static const char* unconditional_compress_ext[] = { + // From https://github.com/android/platform_frameworks_base/blob/master/tools/aapt/Package.cpp + // These formats are already compressed, or don't compress well: + ".jpg", ".jpeg", ".png", ".gif", + ".wav", ".mp2", ".mp3", ".ogg", ".aac", + ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet", + ".rtttl", ".imy", ".xmf", ".mp4", ".m4a", + ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2", + ".amr", ".awb", ".wma", ".wmv", + // Godot-specific: + ".webp", // Same reasoning as .png + ".cfb", // Don't let small config files slow-down startup + // Trailer for easier processing + NULL + }; + + for (const char** ext = unconditional_compress_ext; *ext; ++ext) { + if (p_path.to_lower().ends_with(String(*ext))) { + return false; + } + } + + // -- Compressed resource? + + if (p_data.size() >= 4 && p_data[0] == 'R' && p_data[1] == 'S' && p_data[2] == 'C' && p_data[3] == 'C') { + // Already compressed + return false; + } + + // --- TODO: Decide on texture resources according to their image compression setting + + return true; +} + +bool EditorExportPlatformWinrt::_set(const StringName& p_name, const Variant& p_value) { + + String n = p_name; + + if (n == "architecture/target") + arch = (Platform)((int)p_value); + else if (n == "custom_package/debug") + custom_debug_package = p_value; + else if (n == "custom_package/release") + custom_release_package = p_value; + else if (n == "command_line/extra_args") + cmdline = p_value; + else if (n == "package/display_name") + display_name = p_value; + else if (n == "package/short_name") + short_name = p_value; + else if (n == "package/unique_name") + unique_name = p_value; + else if (n == "package/description") + description = p_value; + else if (n == "package/publisher") + publisher = p_value; + else if (n == "package/publisher_display_name") + publisher_display_name = p_value; + else if (n == "identity/product_guid") + product_guid = p_value; + else if (n == "identity/publisher_guid") + publisher_guid = p_value; + else if (n == "version/major") + version_major = p_value; + else if (n == "version/minor") + version_minor = p_value; + else if (n == "version/build") + version_build = p_value; + else if (n == "version/revision") + version_revision = p_value; + else if (n == "orientation/landscape") + orientation_landscape = p_value; + else if (n == "orientation/portrait") + orientation_portrait = p_value; + else if (n == "orientation/landscape_flipped") + orientation_landscape_flipped = p_value; + else if (n == "orientation/portrait_flipped") + orientation_portrait_flipped = p_value; + else if (n == "images/background_color") + background_color = p_value; + else if (n == "images/store_logo") + store_logo = p_value; + else if (n == "images/square44x44_logo") + square44 = p_value; + else if (n == "images/square71x71_logo") + square71 = p_value; + else if (n == "images/square150x150_logo") + square150 = p_value; + else if (n == "images/square310x310_logo") + square310 = p_value; + else if (n == "images/wide310x150_logo") + wide310 = p_value; + else if (n == "images/splash_screen") + splash = p_value; + else if (n == "tiles/show_name_on_square150x150") + name_on_square150 = p_value; + else if (n == "tiles/show_name_on_wide310x150") + name_on_wide = p_value; + else if (n == "tiles/show_name_on_square310x310") + name_on_square310 = p_value; + +#if 0 // Signing disabled + else if (n == "signing/sign") + sign_package = p_value; + else if (n == "signing/certificate_file") + certificate_path = p_value; + else if (n == "signing/certificate_password") + certificate_pass = p_value; +#endif + else if (n.begins_with("capabilities/")) { + + String what = n.get_slice("/", 1).replace("_", ""); + bool enable = p_value; + + if (array_has(uwp_capabilities, what.utf8().get_data())) { + + if (enable) + capabilities.insert(what); + else + capabilities.erase(what); + + } else if (array_has(uwp_uap_capabilities, what.utf8().get_data())) { + + if (enable) + uap_capabilities.insert(what); + else + uap_capabilities.erase(what); + + } else if (array_has(uwp_device_capabilites, what.utf8().get_data())) { + + if (enable) + device_capabilities.insert(what); + else + device_capabilities.erase(what); + } + } else return false; + + return true; +} + +bool EditorExportPlatformWinrt::_get(const StringName& p_name, Variant &r_ret) const { + + String n = p_name; + + if (n == "architecture/target") + r_ret = (int)arch; + else if (n == "custom_package/debug") + r_ret = custom_debug_package; + else if (n == "custom_package/release") + r_ret = custom_release_package; + else if (n == "command_line/extra_args") + r_ret = cmdline; + else if (n == "package/display_name") + r_ret = display_name; + else if (n == "package/short_name") + r_ret = short_name; + else if (n == "package/unique_name") + r_ret = unique_name; + else if (n == "package/description") + r_ret = description; + else if (n == "package/publisher") + r_ret = publisher; + else if (n == "package/publisher_display_name") + r_ret = publisher_display_name; + else if (n == "identity/product_guid") + r_ret = product_guid; + else if (n == "identity/publisher_guid") + r_ret = publisher_guid; + else if (n == "version/major") + r_ret = version_major; + else if (n == "version/minor") + r_ret = version_minor; + else if (n == "version/build") + r_ret = version_build; + else if (n == "version/revision") + r_ret = version_revision; + else if (n == "orientation/landscape") + r_ret = orientation_landscape; + else if (n == "orientation/portrait") + r_ret = orientation_portrait; + else if (n == "orientation/landscape_flipped") + r_ret = orientation_landscape_flipped; + else if (n == "orientation/portrait_flipped") + r_ret = orientation_portrait_flipped; + else if (n == "images/background_color") + r_ret = background_color; + else if (n == "images/store_logo") + r_ret = store_logo; + else if (n == "images/square44x44_logo") + r_ret = square44; + else if (n == "images/square71x71_logo") + r_ret = square71; + else if (n == "images/square150x150_logo") + r_ret = square150; + else if (n == "images/square310x310_logo") + r_ret = square310; + else if (n == "images/wide310x150_logo") + r_ret = wide310; + else if (n == "images/splash_screen") + r_ret = splash; + else if (n == "tiles/show_name_on_square150x150") + r_ret = name_on_square150; + else if (n == "tiles/show_name_on_wide310x150") + r_ret = name_on_wide; + else if (n == "tiles/show_name_on_square310x310") + r_ret = name_on_square310; + +#if 0 // Signing disabled + else if (n == "signing/sign") + r_ret = sign_package; + else if (n == "signing/certificate_file") + r_ret = certificate_path; + else if (n == "signing/certificate_password") + r_ret = certificate_pass; +#endif + else if (n.begins_with("capabilities/")) { + + String what = n.get_slice("/", 1).replace("_", ""); + + if (array_has(uwp_capabilities, what.utf8().get_data())) { + + r_ret = capabilities.has(what); + + } else if (array_has(uwp_uap_capabilities, what.utf8().get_data())) { + + r_ret = uap_capabilities.has(what); + + } else if (array_has(uwp_device_capabilites, what.utf8().get_data())) { + + r_ret = device_capabilities.has(what); + } + } else return false; + + return true; +} + +void EditorExportPlatformWinrt::_get_property_list(List* p_list) const { + + p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "appx")); + p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "appx")); + + p_list->push_back(PropertyInfo(Variant::INT, "architecture/target", PROPERTY_HINT_ENUM, "ARM,x86,x64")); + + p_list->push_back(PropertyInfo(Variant::STRING, "command_line/extra_args")); + + p_list->push_back(PropertyInfo(Variant::STRING, "package/display_name")); + p_list->push_back(PropertyInfo(Variant::STRING, "package/short_name")); + p_list->push_back(PropertyInfo(Variant::STRING, "package/unique_name")); + p_list->push_back(PropertyInfo(Variant::STRING, "package/description")); + p_list->push_back(PropertyInfo(Variant::STRING, "package/publisher")); + p_list->push_back(PropertyInfo(Variant::STRING, "package/publisher_display_name")); + + p_list->push_back(PropertyInfo(Variant::STRING, "identity/product_guid")); + p_list->push_back(PropertyInfo(Variant::STRING, "identity/publisher_guid")); + + p_list->push_back(PropertyInfo(Variant::INT, "version/major")); + p_list->push_back(PropertyInfo(Variant::INT, "version/minor")); + p_list->push_back(PropertyInfo(Variant::INT, "version/build")); + p_list->push_back(PropertyInfo(Variant::INT, "version/revision")); + + p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/landscape")); + p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/portrait")); + p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/landscape_flipped")); + p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/portrait_flipped")); + + p_list->push_back(PropertyInfo(Variant::STRING, "images/background_color")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "images/store_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square44x44_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square71x71_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square150x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square310x310_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "images/wide310x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); + p_list->push_back(PropertyInfo(Variant::OBJECT, "images/splash_screen", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); + + p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square150x150")); + p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_wide310x150")); + p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square310x310")); + +#if 0 // Signing does not work :( disabling for now + p_list->push_back(PropertyInfo(Variant::BOOL, "signing/sign")); + p_list->push_back(PropertyInfo(Variant::STRING, "signing/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "pfx")); + p_list->push_back(PropertyInfo(Variant::STRING, "signing/certificate_password")); +#endif + + // Capabilites + const char **basic = uwp_capabilities; + while (*basic) { + p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*basic).camelcase_to_underscore(false))); + basic++; + } + + const char **uap = uwp_uap_capabilities; + while (*uap) { + p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*uap).camelcase_to_underscore(false))); + uap++; + } + + const char **device = uwp_device_capabilites; + while (*device) { + p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*device).camelcase_to_underscore(false))); + device++; + } + +} + +bool EditorExportPlatformWinrt::can_export(String * r_error) const { + + String err; + bool valid = true; + + if (!exists_export_template("winrt_x86_debug.zip") || !exists_export_template("winrt_x86_release.zip") + || !exists_export_template("winrt_arm_debug.zip") || !exists_export_template("winrt_arm_release.zip") + || !exists_export_template("winrt_x64_debug.zip") || !exists_export_template("winrt_x64_release.zip")) { + valid = false; + err += TTR("No export templates found.\nDownload and install export templates.") + "\n"; + } + + if (custom_debug_package != "" && !FileAccess::exists(custom_debug_package)) { + valid = false; + err += TTR("Custom debug package not found.") + "\n"; + } + + if (custom_release_package != "" && !FileAccess::exists(custom_release_package)) { + valid = false; + err += TTR("Custom release package not found.") + "\n"; + } + + if (!_valid_resource_name(unique_name)) { + valid = false; + err += TTR("Invalid unique name.") + "\n"; + } + + if (!_valid_guid(product_guid)) { + valid = false; + err += TTR("Invalid product GUID.") + "\n"; + } + + if (!_valid_guid(publisher_guid)) { + valid = false; + err += TTR("Invalid publisher GUID.") + "\n"; + } + + if (!_valid_bgcolor(background_color)) { + valid = false; + err += TTR("Invalid background color.") + "\n"; + } + + if (store_logo.is_valid() && !_valid_image(store_logo, 50, 50)) { + valid = false; + err += TTR("Invalid Store Logo image dimensions (should be 50x50).") + "\n"; + } + + if (square44.is_valid() && !_valid_image(square44, 44, 44)) { + valid = false; + err += TTR("Invalid square 44x44 logo image dimensions (should be 44x44).") + "\n"; + } + + if (square71.is_valid() && !_valid_image(square71, 71, 71)) { + valid = false; + err += TTR("Invalid square 71x71 logo image dimensions (should be 71x71).") + "\n"; + } + + if (square150.is_valid() && !_valid_image(square150, 150, 150)) { + valid = false; + err += TTR("Invalid square 150x150 logo image dimensions (should be 150x150).") + "\n"; + } + + if (square310.is_valid() && !_valid_image(square310, 310, 310)) { + valid = false; + err += TTR("Invalid square 310x310 logo image dimensions (should be 310x310).") + "\n"; + } + + if (wide310.is_valid() && !_valid_image(wide310, 310, 150)) { + valid = false; + err += TTR("Invalid wide 310x150 logo image dimensions (should be 310x150).") + "\n"; + } + + if (splash.is_valid() && !_valid_image(splash, 620, 300)) { + valid = false; + err += TTR("Invalid splash screen image dimensions (should be 620x300).") + "\n"; + } + + if (r_error) + *r_error = err; + + return valid; +} + +Error EditorExportPlatformWinrt::export_project(const String & p_path, bool p_debug, int p_flags) { + + String src_appx; + + EditorProgress ep("export", "Exporting for Windows Universal", 7); + + if (is_debug) + src_appx = custom_debug_package; + else + src_appx = custom_release_package; + + if (src_appx == "") { + String err; + if (p_debug) { + switch (arch) { + case X86: { + src_appx = find_export_template("winrt_x86_debug.zip", &err); + break; + } + case X64: { + src_appx = find_export_template("winrt_x64_debug.zip", &err); + break; + } + case ARM: { + src_appx = find_export_template("winrt_arm_debug.zip", &err); + break; + } + } + } else { + switch (arch) { + case X86: { + src_appx = find_export_template("winrt_x86_release.zip", &err); + break; + } + case X64: { + src_appx = find_export_template("winrt_x64_release.zip", &err); + break; + } + case ARM: { + src_appx = find_export_template("winrt_arm_release.zip", &err); + break; + } + } + } + if (src_appx == "") { + EditorNode::add_io_error(err); + return ERR_FILE_NOT_FOUND; + } + } + + Error err = OK; + + FileAccess *fa_pack = FileAccess::open(p_path, FileAccess::WRITE, &err); + ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); + + AppxPackager packager; + packager.init(fa_pack, sign_package ? AppxPackager::SIGN : AppxPackager::DONT_SIGN, certificate_path, certificate_pass); + + FileAccess *src_f = NULL; + zlib_filefunc_def io = zipio_create_io_from_file(&src_f); + + ep.step("Creating package...", 0); + + unzFile pkg = unzOpen2(src_appx.utf8().get_data(), &io); + + if (!pkg) { + + EditorNode::add_io_error("Could not find template appx to export:\n" + src_appx); + return ERR_FILE_NOT_FOUND; + } + + int ret = unzGoToFirstFile(pkg); + + ep.step("Copying template files...", 1); + + EditorNode::progress_add_task("template_files", "Template files", 100); + packager.set_progress_task("template_files"); + + int template_files_amount = 9; + int template_file_no = 1; + + while (ret == UNZ_OK) { + + // get file name + unz_file_info info; + char fname[16834]; + ret = unzGetCurrentFileInfo(pkg, &info, fname, 16834, NULL, 0, NULL, 0); + + String path = fname; + + if (path.ends_with("/")) { + // Ignore directories + ret = unzGoToNextFile(pkg); + continue; + } + + Vector data; + bool do_read = true; + + if (path.begins_with("Assets/")) { + + path = path.replace(".scale-100", ""); + + data = _get_image_data(path); + if (data.size() > 0) do_read = false; + } + + //read + if (do_read) { + data.resize(info.uncompressed_size); + unzOpenCurrentFile(pkg); + unzReadCurrentFile(pkg, data.ptr(), data.size()); + unzCloseCurrentFile(pkg); + } + + if (path == "AppxManifest.xml") { + + data = _fix_manifest(data, p_flags&(EXPORT_DUMB_CLIENT | EXPORT_REMOTE_DEBUG)); + } + + print_line("ADDING: " + path); + + packager.add_file(path, data.ptr(), data.size(), template_file_no++, template_files_amount, _should_compress_asset(path, data)); + + ret = unzGoToNextFile(pkg); + } + + EditorNode::progress_end_task("template_files"); + + ep.step("Creating command line...", 2); + + Vector cl = cmdline.strip_edges().split(" "); + for (int i = 0;i clf; + + // Argc + clf.resize(4); + encode_uint32(cl.size(), clf.ptr()); + + for (int i = 0; i < cl.size(); i++) { + + CharString txt = cl[i].utf8(); + int base = clf.size(); + clf.resize(base + 4 + txt.length()); + encode_uint32(txt.length(), &clf[base]); + copymem(&clf[base + 4], txt.ptr(), txt.length()); + print_line(itos(i) + " param: " + cl[i]); + } + + packager.add_file("__cl__.cl", clf.ptr(), clf.size(), -1, -1, false); + + ep.step("Adding project files...", 3); + + EditorNode::progress_add_task("project_files", "Project Files", 100); + packager.set_progress_task("project_files"); + + err = export_project_files(save_appx_file, &packager, false); + + EditorNode::progress_end_task("project_files"); + + ep.step("Closing package...", 7); + + unzClose(pkg); + + packager.finish(); + + return OK; +} + +EditorExportPlatformWinrt::EditorExportPlatformWinrt() { + + Image img(_uwp_logo); + logo = Ref(memnew(ImageTexture)); + logo->create_from_image(img); + + is_debug = true; + + custom_release_package = ""; + custom_debug_package = ""; + + arch = X86; + + display_name = ""; + short_name = "Godot"; + unique_name = "Godot.Engine"; + description = "Godot Engine"; + publisher = "CN=GodotEngine"; + publisher_display_name = "Godot Engine"; + + product_guid = "00000000-0000-0000-0000-000000000000"; + publisher_guid = "00000000-0000-0000-0000-000000000000"; + + version_major = 1; + version_minor = 0; + version_build = 0; + version_revision = 0; + + orientation_landscape = true; + orientation_portrait = true; + orientation_landscape_flipped = true; + orientation_portrait_flipped = true; + + background_color = "transparent"; + + name_on_square150 = false; + name_on_square310 = false; + name_on_wide = false; + + sign_package = false; + certificate_path = ""; + certificate_pass = ""; +} + +EditorExportPlatformWinrt::~EditorExportPlatformWinrt() {} + + +void register_uwp_exporter() { + + Ref exporter = Ref(memnew(EditorExportPlatformWinrt)); + EditorImportExport::get_singleton()->add_export_platform(exporter); +} diff --git a/platform/uwp/export/export.h b/platform/uwp/export/export.h new file mode 100644 index 0000000000..f25065341d --- /dev/null +++ b/platform/uwp/export/export.h @@ -0,0 +1,29 @@ +/*************************************************************************/ +/* export.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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. */ +/*************************************************************************/ +void register_uwp_exporter(); diff --git a/platform/uwp/gl_context_egl.cpp b/platform/uwp/gl_context_egl.cpp new file mode 100644 index 0000000000..f7b514b3c0 --- /dev/null +++ b/platform/uwp/gl_context_egl.cpp @@ -0,0 +1,218 @@ +/*************************************************************************/ +/* gl_context_egl.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 namespace Platform; + +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 = 0; + EGLDisplay display = EGL_NO_DISPLAY; + EGLContext context = EGL_NO_CONTEXT; + EGLSurface surface = EGL_NO_SURFACE; + EGLConfig config = nullptr; + EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, 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) : + mEglDisplay(EGL_NO_DISPLAY), + mEglContext(EGL_NO_CONTEXT), + mEglSurface(EGL_NO_SURFACE) + { + + window = p_window; +}; + +ContextEGL::~ContextEGL() { + + cleanup(); +}; + diff --git a/platform/uwp/gl_context_egl.h b/platform/uwp/gl_context_egl.h new file mode 100644 index 0000000000..8124c2903d --- /dev/null +++ b/platform/uwp/gl_context_egl.h @@ -0,0 +1,78 @@ +/*************************************************************************/ +/* gl_context_egl.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "os/os.h" +#include "EGL/egl.h" +#include "error_list.h" +#include "drivers/gl_context/context_gl.h" + +using namespace Windows::UI::Core; + +class ContextEGL : public ContextGL { + + CoreWindow^ window; + + EGLDisplay mEglDisplay; + EGLContext mEglContext; + EGLSurface mEglSurface; + + EGLint width; + EGLint height; + + bool vsync; + +public: + + virtual void release_current(); + + virtual void make_current(); + + virtual int get_window_width(); + virtual int get_window_height(); + virtual void swap_buffers(); + + void set_use_vsync(bool use) { vsync = use; } + bool is_using_vsync() const { return vsync; } + + virtual Error initialize(); + void reset(); + + void cleanup(); + + ContextEGL(CoreWindow^ p_window); + ~ContextEGL(); + +}; + +#endif + diff --git a/platform/uwp/joystick_uwp.cpp b/platform/uwp/joystick_uwp.cpp new file mode 100644 index 0000000000..bcd867b14c --- /dev/null +++ b/platform/uwp/joystick_uwp.cpp @@ -0,0 +1,147 @@ +/*************************************************************************/ +/* joystick_uwp.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "joystick_uwp.h" + +using namespace Windows::Gaming::Input; +using namespace Windows::Foundation; + +void JoystickWinrt::register_events() { + + Gamepad::GamepadAdded += + ref new EventHandler(this, &JoystickWinrt::OnGamepadAdded); + Gamepad::GamepadRemoved += + ref new EventHandler(this, &JoystickWinrt::OnGamepadRemoved); +} + +uint32_t JoystickWinrt::process_controllers(uint32_t p_last_id) { + + for (int i = 0; i < MAX_CONTROLLERS; i++) { + + if (!controllers[i].connected) break; + + switch (controllers[i].type) { + + case ControllerType::GAMEPAD_CONTROLLER: { + + GamepadReading reading = ((Gamepad^)controllers[i].controller_reference)->GetCurrentReading(); + + int button_mask = (int)GamepadButtons::Menu; + for (int j = 0; j < 14; j++) { + + p_last_id = input->joy_button(p_last_id, controllers[i].id, j,(int)reading.Buttons & button_mask); + button_mask *= 2; + } + + p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX)); + p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true)); + p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX)); + p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true)); + p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true)); + p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true)); + + break; + } + } + } + + return p_last_id; +} + +JoystickWinrt::JoystickWinrt() { + + for (int i = 0; i < MAX_CONTROLLERS; i++) + controllers[i].id = i; +} + +JoystickWinrt::JoystickWinrt(InputDefault * p_input) { + + input = p_input; + + JoystickWinrt(); +} + +void JoystickWinrt::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { + + short idx = -1; + + for (int i = 0; i < MAX_CONTROLLERS; i++) { + + if (!controllers[i].connected) { + idx = i; + break; + } + } + + ERR_FAIL_COND(idx == -1); + + controllers[idx].connected = true; + controllers[idx].controller_reference = value; + controllers[idx].id = idx; + controllers[idx].type = ControllerType::GAMEPAD_CONTROLLER; + + input->joy_connection_changed(controllers[idx].id, true, "Xbox Controller", "__WINRT_GAMEPAD__"); +} + +void JoystickWinrt::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { + + short idx = -1; + + for (int i = 0; i < MAX_CONTROLLERS; i++) { + + if (controllers[i].controller_reference == value) { + idx = i; + break; + } + } + + ERR_FAIL_COND(idx == -1); + + for (int i = idx + 1; i < MAX_CONTROLLERS - 1; i++) { + + if (!controllers[i].connected) { + break; + } + + controllers[i - 1] = controllers[i]; + } + controllers[MAX_CONTROLLERS - 1] = ControllerDevice(); + + input->joy_connection_changed(idx, false, "Xbox Controller"); +} + +InputDefault::JoyAxis JoystickWinrt::axis_correct(double p_val, bool p_negate, bool p_trigger) const { + + InputDefault::JoyAxis jx; + + jx.min = p_trigger ? 0 : -1; + jx.value = (float)(p_negate ? -p_val : p_val); + + return jx; +} diff --git a/platform/uwp/joystick_uwp.h b/platform/uwp/joystick_uwp.h new file mode 100644 index 0000000000..0ae8b35b02 --- /dev/null +++ b/platform/uwp/joystick_uwp.h @@ -0,0 +1,81 @@ +/*************************************************************************/ +/* joystick_uwp.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 JOYSTICK_WINRT_H +#define JOYSTICK_WINRT_H + +#include "main/input_default.h" + +ref class JoystickWinrt sealed { + +internal: + + void register_events(); + uint32_t process_controllers(uint32_t p_last_id); + + JoystickWinrt(); + JoystickWinrt(InputDefault* p_input); + +private: + + enum { + MAX_CONTROLLERS = 4, + }; + + enum ControllerType { + GAMEPAD_CONTROLLER, + ARCADE_STICK_CONTROLLER, + RACING_WHEEL_CONTROLLER, + }; + + struct ControllerDevice { + + Windows::Gaming::Input::IGameController^ controller_reference; + + int id; + bool connected; + ControllerType type; + + ControllerDevice() { + id = -1; + connected = false; + type = ControllerType::GAMEPAD_CONTROLLER; + } + }; + + ControllerDevice controllers[MAX_CONTROLLERS]; + + InputDefault* input; + + void OnGamepadAdded(Platform::Object^ sender, Windows::Gaming::Input::Gamepad^ value); + void OnGamepadRemoved(Platform::Object^ sender, Windows::Gaming::Input::Gamepad^ value); + + InputDefault::JoyAxis axis_correct(double p_val, bool p_negate = false, bool p_trigger = false) const; +}; + +#endif diff --git a/platform/uwp/logo.png b/platform/uwp/logo.png new file mode 100644 index 0000000000..4376abd563 Binary files /dev/null and b/platform/uwp/logo.png differ diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp new file mode 100644 index 0000000000..23d0a6aa9b --- /dev/null +++ b/platform/uwp/os_uwp.cpp @@ -0,0 +1,983 @@ +/*************************************************************************/ +/* os_uwp.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "drivers/gles2/rasterizer_gles2.h" +#include "os_uwp.h" +#include "drivers/unix/memory_pool_static_malloc.h" +#include "os/memory_pool_dynamic_static.h" +#include "thread_uwp.h" +#include "drivers/windows/semaphore_windows.h" +#include "drivers/windows/mutex_windows.h" +#include "main/main.h" +#include "drivers/windows/file_access_windows.h" +#include "drivers/windows/dir_access_windows.h" + + +#include "servers/visual/visual_server_raster.h" +#include "servers/audio/audio_server_sw.h" +#include "servers/visual/visual_server_wrap_mt.h" + +#include "os/memory_pool_dynamic_prealloc.h" +#include "globals.h" +#include "io/marshalls.h" + +#include "platform/windows/packet_peer_udp_winsock.h" +#include "platform/windows/stream_peer_winsock.h" +#include "platform/windows/tcp_server_winsock.h" +#include "drivers/unix/ip_unix.h" + +#include +#include + +using namespace Windows::ApplicationModel::Core; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::UI::Core; +using namespace Windows::UI::Input; +using namespace Windows::UI::Popups; +using namespace Windows::Foundation; +using namespace Windows::Graphics::Display; +using namespace Microsoft::WRL; +using namespace Windows::UI::ViewManagement; +using namespace Windows::Devices::Input; +using namespace Windows::Devices::Sensors; +using namespace Windows::ApplicationModel::DataTransfer; +using namespace concurrency; + + +int OSWinrt::get_video_driver_count() const { + + return 1; +} +const char * OSWinrt::get_video_driver_name(int p_driver) const { + + return "GLES2"; +} + +OS::VideoMode OSWinrt::get_default_video_mode() const { + + return video_mode; +} + +Size2 OSWinrt::get_window_size() const { + Size2 size; + size.width = video_mode.width; + size.height = video_mode.height; + return size; +} + +void OSWinrt::set_window_size(const Size2 p_size) { + + Windows::Foundation::Size new_size; + new_size.Width = p_size.width; + new_size.Height = p_size.height; + + ApplicationView^ view = ApplicationView::GetForCurrentView(); + + if (view->TryResizeView(new_size)) { + + video_mode.width = p_size.width; + video_mode.height = p_size.height; + } +} + +void OSWinrt::set_window_fullscreen(bool p_enabled) { + + ApplicationView^ view = ApplicationView::GetForCurrentView(); + + video_mode.fullscreen = view->IsFullScreenMode; + + if (video_mode.fullscreen == p_enabled) + return; + + if (p_enabled) { + + video_mode.fullscreen = view->TryEnterFullScreenMode(); + + } else { + + view->ExitFullScreenMode(); + video_mode.fullscreen = false; + + } +} + +bool OSWinrt::is_window_fullscreen() const { + + return ApplicationView::GetForCurrentView()->IsFullScreenMode; +} + +void OSWinrt::set_keep_screen_on(bool p_enabled) { + + if (is_keep_screen_on() == p_enabled) return; + + if (p_enabled) + display_request->RequestActive(); + else + display_request->RequestRelease(); + + OS::set_keep_screen_on(p_enabled); +} + +int OSWinrt::get_audio_driver_count() const { + + return AudioDriverManagerSW::get_driver_count(); +} +const char * OSWinrt::get_audio_driver_name(int p_driver) const { + + AudioDriverSW* driver = AudioDriverManagerSW::get_driver(p_driver); + ERR_FAIL_COND_V( !driver, "" ); + return AudioDriverManagerSW::get_driver(p_driver)->get_name(); +} + +static MemoryPoolStatic *mempool_static=NULL; +static MemoryPoolDynamic *mempool_dynamic=NULL; + +void OSWinrt::initialize_core() { + + + last_button_state=0; + + //RedirectIOToConsole(); + + ThreadWinrt::make_default(); + SemaphoreWindows::make_default(); + MutexWindows::make_default(); + + FileAccess::make_default(FileAccess::ACCESS_RESOURCES); + FileAccess::make_default(FileAccess::ACCESS_USERDATA); + FileAccess::make_default(FileAccess::ACCESS_FILESYSTEM); + //FileAccessBufferedFA::make_default(); + DirAccess::make_default(DirAccess::ACCESS_RESOURCES); + DirAccess::make_default(DirAccess::ACCESS_USERDATA); + DirAccess::make_default(DirAccess::ACCESS_FILESYSTEM); + + //TCPServerWinsock::make_default(); + //StreamPeerWinsock::make_default(); + + TCPServerWinsock::make_default(); + StreamPeerWinsock::make_default(); + PacketPeerUDPWinsock::make_default(); + + mempool_static = new MemoryPoolStaticMalloc; +#if 1 + mempool_dynamic = memnew( MemoryPoolDynamicStatic ); +#else +#define DYNPOOL_SIZE 4*1024*1024 + void * buffer = malloc( DYNPOOL_SIZE ); + mempool_dynamic = memnew( MemoryPoolDynamicPrealloc(buffer,DYNPOOL_SIZE) ); + +#endif + + // We need to know how often the clock is updated + if( !QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second) ) + ticks_per_second = 1000; + // If timeAtGameStart is 0 then we get the time since + // the start of the computer when we call GetGameTime() + ticks_start = 0; + ticks_start = get_ticks_usec(); + + IP_Unix::make_default(); + + cursor_shape=CURSOR_ARROW; +} + +bool OSWinrt::can_draw() const { + + return !minimized; +}; + + +void OSWinrt::set_gl_context(ContextEGL* p_context) { + + gl_context = p_context; +}; + +void OSWinrt::screen_size_changed() { + + gl_context->reset(); +}; + +void OSWinrt::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { + + main_loop=NULL; + outside=true; + + gl_context->initialize(); + VideoMode vm; + vm.width = gl_context->get_window_width(); + vm.height = gl_context->get_window_height(); + vm.resizable = false; + + ApplicationView^ view = ApplicationView::GetForCurrentView(); + vm.fullscreen = view->IsFullScreenMode; + + view->SetDesiredBoundsMode(ApplicationViewBoundsMode::UseVisible); + view->PreferredLaunchWindowingMode = ApplicationViewWindowingMode::PreferredLaunchViewSize; + + if (p_desired.fullscreen != view->IsFullScreenMode) { + if (p_desired.fullscreen) { + + vm.fullscreen = view->TryEnterFullScreenMode(); + + } else { + + view->ExitFullScreenMode(); + vm.fullscreen = false; + } + } + + Windows::Foundation::Size desired; + desired.Width = p_desired.width; + desired.Height = p_desired.height; + + view->PreferredLaunchViewSize = desired; + + if (view->TryResizeView(desired)) { + + vm.width = view->VisibleBounds.Width; + vm.height = view->VisibleBounds.Height; + } + + set_video_mode(vm); + + gl_context->make_current(); + rasterizer = memnew( RasterizerGLES2 ); + + visual_server = memnew( VisualServerRaster(rasterizer) ); + if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { + + visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); + } + + // + physics_server = memnew( PhysicsServerSW ); + physics_server->init(); + + physics_2d_server = memnew( Physics2DServerSW ); + physics_2d_server->init(); + + visual_server->init(); + + input = memnew( InputDefault ); + + joystick = ref new JoystickWinrt(input); + joystick->register_events(); + + AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); + + if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { + + ERR_PRINT("Initializing audio failed."); + } + + sample_manager = memnew( SampleManagerMallocSW ); + audio_server = memnew( AudioServerSW(sample_manager) ); + + audio_server->init(); + + spatial_sound_server = memnew( SpatialSoundServerSW ); + spatial_sound_server->init(); + spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); + spatial_sound_2d_server->init(); + + managed_object->update_clipboard(); + + Clipboard::ContentChanged += ref new EventHandler(managed_object, &ManagedType::on_clipboard_changed); + + accelerometer = Accelerometer::GetDefault(); + if (accelerometer != nullptr) { + // 60 FPS + accelerometer->ReportInterval = (1.0f / 60.0f) * 1000; + accelerometer->ReadingChanged += + ref new TypedEventHandler + (managed_object, &ManagedType::on_accelerometer_reading_changed); + } + + magnetometer = Magnetometer::GetDefault(); + if (magnetometer != nullptr) { + // 60 FPS + magnetometer->ReportInterval = (1.0f / 60.0f) * 1000; + magnetometer->ReadingChanged += + ref new TypedEventHandler + (managed_object, &ManagedType::on_magnetometer_reading_changed); + } + + gyrometer = Gyrometer::GetDefault(); + if (gyrometer != nullptr) { + // 60 FPS + gyrometer->ReportInterval = (1.0f / 60.0f) * 1000; + gyrometer->ReadingChanged += + ref new TypedEventHandler + (managed_object, &ManagedType::on_gyroscope_reading_changed); + } + + _ensure_data_dir(); + + if (is_keep_screen_on()) + display_request->RequestActive(); + + set_keep_screen_on(GLOBAL_DEF("display/keep_screen_on", true)); + +} + +void OSWinrt::set_clipboard(const String& p_text) { + + DataPackage^ clip = ref new DataPackage(); + clip->RequestedOperation = DataPackageOperation::Copy; + clip->SetText(ref new Platform::String((const wchar_t*)p_text.c_str())); + + Clipboard::SetContent(clip); +}; + +String OSWinrt::get_clipboard() const { + + if (managed_object->clipboard != nullptr) + return managed_object->clipboard->Data(); + else + return ""; +}; + + +void OSWinrt::input_event(InputEvent &p_event) { + + p_event.ID = ++last_id; + + input->parse_input_event(p_event); + + if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index>3) { + + //send release for mouse wheel + p_event.mouse_button.pressed = false; + p_event.ID = ++last_id; + input->parse_input_event(p_event); + } +}; + +void OSWinrt::delete_main_loop() { + + if (main_loop) + memdelete(main_loop); + main_loop=NULL; +} + +void OSWinrt::set_main_loop( MainLoop * p_main_loop ) { + + input->set_main_loop(p_main_loop); + main_loop=p_main_loop; +} + +void OSWinrt::finalize() { + + if(main_loop) + memdelete(main_loop); + + main_loop=NULL; + + visual_server->finish(); + memdelete(visual_server); +#ifdef OPENGL_ENABLED + if (gl_context) + memdelete(gl_context); +#endif + if (rasterizer) + memdelete(rasterizer); + + spatial_sound_server->finish(); + memdelete(spatial_sound_server); + spatial_sound_2d_server->finish(); + memdelete(spatial_sound_2d_server); + + //if (debugger_connection_console) { +// memdelete(debugger_connection_console); +//} + + memdelete(sample_manager); + + audio_server->finish(); + memdelete(audio_server); + + memdelete(input); + + physics_server->finish(); + memdelete(physics_server); + + physics_2d_server->finish(); + memdelete(physics_2d_server); + + joystick = nullptr; + +} +void OSWinrt::finalize_core() { + + if (mempool_dynamic) + memdelete( mempool_dynamic ); + delete mempool_static; + +} + +void OSWinrt::vprint(const char* p_format, va_list p_list, bool p_stderr) { + + char buf[16384+1]; + int len = vsnprintf(buf,16384,p_format,p_list); + if (len<=0) + return; + buf[len]=0; + + + int wlen = MultiByteToWideChar(CP_UTF8,0,buf,len,NULL,0); + if (wlen<0) + return; + + wchar_t *wbuf = (wchar_t*)malloc((len+1)*sizeof(wchar_t)); + MultiByteToWideChar(CP_UTF8,0,buf,len,wbuf,wlen); + wbuf[wlen]=0; + + if (p_stderr) + fwprintf(stderr,L"%s",wbuf); + else + wprintf(L"%s",wbuf); + + free(wbuf); + + fflush(stdout); +}; + +void OSWinrt::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, &OSWinrt::ManagedType::alert_close)); + msg->Commands->Append(close); + msg->DefaultCommandIndex = 0; + + managed_object->alert_close_handle = true; + + msg->ShowAsync(); +} + +void OSWinrt::ManagedType::alert_close(IUICommand^ command) { + + alert_close_handle = false; +} + +void OSWinrt::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) { + + update_clipboard(); +} + +void OSWinrt::ManagedType::update_clipboard() { + + DataPackageView^ data = Clipboard::GetContent(); + + if (data->Contains(StandardDataFormats::Text)) { + + create_task(data->GetTextAsync()).then( + [this](Platform::String^ clipboard_content) { + + this->clipboard = clipboard_content; + }); + } +} + +void OSWinrt::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) { + + AccelerometerReading^ reading = args->Reading; + + os->input->set_accelerometer(Vector3( + reading->AccelerationX, + reading->AccelerationY, + reading->AccelerationZ + )); +} + +void OSWinrt::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) { + + MagnetometerReading^ reading = args->Reading; + + os->input->set_magnetometer(Vector3( + reading->MagneticFieldX, + reading->MagneticFieldY, + reading->MagneticFieldZ + )); +} + +void OSWinrt::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) { + + GyrometerReading^ reading = args->Reading; + + os->input->set_magnetometer(Vector3( + reading->AngularVelocityX, + reading->AngularVelocityY, + reading->AngularVelocityZ + )); +} + +void OSWinrt::set_mouse_mode(MouseMode p_mode) { + + if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) { + + CoreWindow::GetForCurrentThread()->SetPointerCapture(); + + } else { + + CoreWindow::GetForCurrentThread()->ReleasePointerCapture(); + + } + + if (p_mode == MouseMode::MOUSE_MODE_CAPTURED || p_mode == MouseMode::MOUSE_MODE_HIDDEN) { + + CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; + + } else { + + CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); + } + + mouse_mode = p_mode; + + SetEvent(mouse_mode_changed); +} + +OSWinrt::MouseMode OSWinrt::get_mouse_mode() const{ + + return mouse_mode; +} + + + +Point2 OSWinrt::get_mouse_pos() const { + + return Point2(old_x, old_y); +} + +int OSWinrt::get_mouse_button_state() const { + + return last_button_state; +} + +void OSWinrt::set_window_title(const String& p_title) { + +} + +void OSWinrt::set_video_mode(const VideoMode& p_video_mode,int p_screen) { + + video_mode = p_video_mode; +} +OS::VideoMode OSWinrt::get_video_mode(int p_screen) const { + + return video_mode; +} +void OSWinrt::get_fullscreen_mode_list(List *p_list,int p_screen) const { + + +} + +void OSWinrt::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) { + + const char* err_details; + if (p_rationale && p_rationale[0]) + err_details = p_rationale; + else + err_details = p_code; + + switch(p_type) { + case ERR_ERROR: + print("ERROR: %s: %s\n", p_function, err_details); + print(" At: %s:%i\n", p_file, p_line); + break; + case ERR_WARNING: + print("WARNING: %s: %s\n", p_function, err_details); + print(" At: %s:%i\n", p_file, p_line); + break; + case ERR_SCRIPT: + print("SCRIPT ERROR: %s: %s\n", p_function, err_details); + print(" At: %s:%i\n", p_file, p_line); + break; + } +} + + +String OSWinrt::get_name() { + + return "WinRT"; +} + +OS::Date OSWinrt::get_date(bool utc) const { + + SYSTEMTIME systemtime; + if (utc) + GetSystemTime(&systemtime); + else + GetLocalTime(&systemtime); + + Date date; + date.day=systemtime.wDay; + date.month=Month(systemtime.wMonth); + date.weekday=Weekday(systemtime.wDayOfWeek); + date.year=systemtime.wYear; + date.dst=false; + return date; +} +OS::Time OSWinrt::get_time(bool utc) const { + + SYSTEMTIME systemtime; + if (utc) + GetSystemTime(&systemtime); + else + GetLocalTime(&systemtime); + + Time time; + time.hour=systemtime.wHour; + time.min=systemtime.wMinute; + time.sec=systemtime.wSecond; + return time; +} + +OS::TimeZoneInfo OSWinrt::get_time_zone_info() const { + TIME_ZONE_INFORMATION info; + bool daylight = false; + if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) + daylight = true; + + TimeZoneInfo ret; + if (daylight) { + ret.name = info.DaylightName; + } else { + ret.name = info.StandardName; + } + + ret.bias = info.Bias; + return ret; +} + +uint64_t OSWinrt::get_unix_time() const { + + FILETIME ft; + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, &ft); + + SYSTEMTIME ep; + ep.wYear = 1970; + ep.wMonth = 1; + ep.wDayOfWeek = 4; + ep.wDay = 1; + ep.wHour = 0; + ep.wMinute = 0; + ep.wSecond = 0; + ep.wMilliseconds = 0; + FILETIME fep; + SystemTimeToFileTime(&ep, &fep); + + return (*(uint64_t*)&ft - *(uint64_t*)&fep) / 10000000; +}; + +void OSWinrt::delay_usec(uint32_t p_usec) const { + + int msec = p_usec < 1000 ? 1 : p_usec / 1000; + + // no Sleep() + WaitForSingleObjectEx(GetCurrentThread(), msec, false); + +} +uint64_t OSWinrt::get_ticks_usec() const { + + uint64_t ticks; + uint64_t time; + // This is the number of clock ticks since start + QueryPerformanceCounter((LARGE_INTEGER *)&ticks); + // Divide by frequency to get the time in seconds + time = ticks * 1000000L / ticks_per_second; + // Subtract the time at game start to get + // the time since the game started + time -= ticks_start; + return time; +} + + +void OSWinrt::process_events() { + + last_id = joystick->process_controllers(last_id); + process_key_events(); +} + +void OSWinrt::process_key_events() +{ + + for (int i = 0; i < key_event_pos; i++) { + + KeyEvent &kev = key_event_buffer[i]; + InputEvent iev; + + iev.type = InputEvent::KEY; + iev.key.mod = kev.mod_state; + iev.key.echo = kev.echo; + iev.key.scancode = kev.scancode; + iev.key.unicode = kev.unicode; + iev.key.pressed = kev.pressed; + + input_event(iev); + + } + key_event_pos = 0; +} + +void OSWinrt::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) { + + KeyEvent &old = key_event_buffer[key_event_pos - 1]; + ERR_FAIL_COND(old.type != KeyEvent::MessageType::KEY_EVENT_MESSAGE); + + key_event_buffer[key_event_pos - 1].unicode = p_event.unicode; + return; + } + + ERR_FAIL_COND(key_event_pos >= KEY_EVENT_BUFFER_SIZE); + + key_event_buffer[key_event_pos++] = p_event; +} + +void OSWinrt::set_cursor_shape(CursorShape p_shape) { + + ERR_FAIL_INDEX(p_shape, CURSOR_MAX); + + if (cursor_shape == p_shape) + return; + + static const CoreCursorType uwp_cursors[CURSOR_MAX] = { + CoreCursorType::Arrow, + CoreCursorType::IBeam, + CoreCursorType::Hand, + CoreCursorType::Cross, + CoreCursorType::Wait, + CoreCursorType::Wait, + CoreCursorType::Arrow, + CoreCursorType::Arrow, + CoreCursorType::UniversalNo, + CoreCursorType::SizeNorthSouth, + CoreCursorType::SizeWestEast, + CoreCursorType::SizeNortheastSouthwest, + CoreCursorType::SizeNorthwestSoutheast, + CoreCursorType::SizeAll, + CoreCursorType::SizeNorthSouth, + CoreCursorType::SizeWestEast, + CoreCursorType::Help + }; + + CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(uwp_cursors[p_shape], 0); + + cursor_shape = p_shape; +} + +Error OSWinrt::execute(const String& p_path, const List& p_arguments,bool p_blocking,ProcessID *r_child_id,String* r_pipe,int *r_exitcode) { + + return FAILED; +}; + +Error OSWinrt::kill(const ProcessID& p_pid) { + + return FAILED; +}; + +Error OSWinrt::set_cwd(const String& p_cwd) { + + return FAILED; +} + +String OSWinrt::get_executable_path() const { + + return ""; +} + +void OSWinrt::set_icon(const Image& p_icon) { + +} + + +bool OSWinrt::has_environment(const String& p_var) const { + + return false; +}; + +String OSWinrt::get_environment(const String& p_var) const { + + return ""; +}; + +String OSWinrt::get_stdin_string(bool p_block) { + + return String(); +} + + +void OSWinrt::move_window_to_foreground() { + +} + +Error OSWinrt::shell_open(String p_uri) { + + return FAILED; +} + + +String OSWinrt::get_locale() const { + +#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // this should work on phone 8.1, but it doesn't + return "en"; +#else + Platform::String ^language = Windows::Globalization::Language::CurrentInputMethodLanguageTag; + return String(language->Data()).replace("-", "_"); +#endif +} + +void OSWinrt::release_rendering_thread() { + + gl_context->release_current(); +} + +void OSWinrt::make_rendering_thread() { + + gl_context->make_current(); +} + +void OSWinrt::swap_buffers() { + + gl_context->swap_buffers(); +} + +bool OSWinrt::has_touchscreen_ui_hint() const { + + TouchCapabilities^ tc = ref new TouchCapabilities(); + return tc->TouchPresent != 0 || UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; +} + +bool OSWinrt::has_virtual_keyboard() const { + + return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; +} + +void OSWinrt::show_virtual_keyboard(const String & p_existing_text, const Rect2 & p_screen_rect) { + + InputPane^ pane = InputPane::GetForCurrentView(); + pane->TryShow(); +} + +void OSWinrt::hide_virtual_keyboard() { + + InputPane^ pane = InputPane::GetForCurrentView(); + pane->TryHide(); +} + + +void OSWinrt::run() { + + if (!main_loop) + return; + + main_loop->init(); + + uint64_t last_ticks=get_ticks_usec(); + + int frames=0; + uint64_t frame=0; + + while (!force_quit) { + + CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); + if (managed_object->alert_close_handle) continue; + process_events(); // get rid of pending events + if (Main::iteration()==true) + break; + }; + + main_loop->finish(); + +} + + + +MainLoop *OSWinrt::get_main_loop() const { + + return main_loop; +} + + +String OSWinrt::get_data_dir() const { + + Windows::Storage::StorageFolder ^data_folder = Windows::Storage::ApplicationData::Current->LocalFolder; + + return String(data_folder->Path->Data()).replace("\\", "/"); +} + + +OSWinrt::OSWinrt() { + + key_event_pos=0; + force_quit=false; + alt_mem=false; + gr_mem=false; + shift_mem=false; + control_mem=false; + meta_mem=false; + minimized = false; + + pressrc=0; + old_invalid=true; + last_id=0; + mouse_mode=MOUSE_MODE_VISIBLE; +#ifdef STDOUT_FILE + stdo=fopen("stdout.txt","wb"); +#endif + + gl_context = NULL; + + display_request = ref new Windows::System::Display::DisplayRequest(); + + managed_object = ref new ManagedType; + managed_object->os = this; + + mouse_mode_changed = CreateEvent(NULL, TRUE, FALSE, L"os_mouse_mode_changed"); + + AudioDriverManagerSW::add_driver(&audio_driver); +} + + +OSWinrt::~OSWinrt() +{ +#ifdef STDOUT_FILE + fclose(stdo); +#endif +} + + diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h new file mode 100644 index 0000000000..98a3cc54cc --- /dev/null +++ b/platform/uwp/os_uwp.h @@ -0,0 +1,281 @@ +/*************************************************************************/ +/* os_uwp.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 OSWinrt_H +#define OSWinrt_H + +#include "os/input.h" +#include "os/os.h" +#include "servers/visual_server.h" +#include "servers/visual/rasterizer.h" +#include "servers/physics/physics_server_sw.h" + +#include "servers/audio/audio_server_sw.h" +#include "servers/audio/sample_manager_sw.h" +#include "servers/spatial_sound/spatial_sound_server_sw.h" +#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" +#include "servers/physics_2d/physics_2d_server_sw.h" +#include "drivers/xaudio2/audio_driver_xaudio2.h" + +#include "gl_context_egl.h" + +#include "core/math/math_2d.h" +#include "core/ustring.h" + +#include + +#include + +#include +#include +#include "main/input_default.h" + +#include "joystick_uwp.h" + +/** + @author Juan Linietsky +*/ +class OSWinrt : public OS { + +public: + + struct KeyEvent { + + enum MessageType + { + KEY_EVENT_MESSAGE, + CHAR_EVENT_MESSAGE + }; + + InputModifierState mod_state; + MessageType type; + bool pressed; + unsigned int scancode; + unsigned int unicode; + bool echo; + CorePhysicalKeyStatus status; + + }; + +private: + + enum { + JOYSTICKS_MAX = 8, + JOY_AXIS_COUNT = 6, + MAX_JOY_AXIS = 32768, // I've no idea + KEY_EVENT_BUFFER_SIZE=512 + }; + + FILE *stdo; + + KeyEvent key_event_buffer[KEY_EVENT_BUFFER_SIZE]; + int key_event_pos; + + + uint64_t ticks_start; + uint64_t ticks_per_second; + + bool minimized; + bool old_invalid; + bool outside; + int old_x,old_y; + Point2i center; + unsigned int last_id; + VisualServer *visual_server; + Rasterizer *rasterizer; + PhysicsServer *physics_server; + Physics2DServer *physics_2d_server; + int pressrc; + + ContextEGL* gl_context; + + VideoMode video_mode; + + MainLoop *main_loop; + + AudioDriverXAudio2 audio_driver; + AudioServerSW *audio_server; + SampleManagerMallocSW *sample_manager; + SpatialSoundServerSW *spatial_sound_server; + SpatialSound2DServerSW *spatial_sound_2d_server; + + MouseMode mouse_mode; + bool alt_mem; + bool gr_mem; + bool shift_mem; + bool control_mem; + bool meta_mem; + bool force_quit; + uint32_t last_button_state; + + CursorShape cursor_shape; + + InputDefault *input; + + JoystickWinrt^ joystick; + + Windows::System::Display::DisplayRequest^ display_request; + + void _post_dpad(DWORD p_dpad, int p_device, bool p_pressed); + + void _drag_event(int idx,UINT uMsg, WPARAM wParam, LPARAM lParam); + void _touch_event(int idx, UINT uMsg, WPARAM wParam, LPARAM lParam); + + ref class ManagedType { + public: + property bool alert_close_handle; + property Platform::String^ clipboard; + void alert_close(Windows::UI::Popups::IUICommand^ command); + void on_clipboard_changed(Platform::Object^ sender, Platform::Object^ ev); + void update_clipboard(); + void on_accelerometer_reading_changed(Windows::Devices::Sensors::Accelerometer^ sender, Windows::Devices::Sensors::AccelerometerReadingChangedEventArgs^ args); + void on_magnetometer_reading_changed(Windows::Devices::Sensors::Magnetometer^ sender, Windows::Devices::Sensors::MagnetometerReadingChangedEventArgs^ args); + void on_gyroscope_reading_changed(Windows::Devices::Sensors::Gyrometer^ sender, Windows::Devices::Sensors::GyrometerReadingChangedEventArgs^ args); + + internal: + ManagedType() { alert_close_handle = false; } + property OSWinrt* os; + }; + ManagedType^ managed_object; + Windows::Devices::Sensors::Accelerometer^ accelerometer; + Windows::Devices::Sensors::Magnetometer^ magnetometer; + Windows::Devices::Sensors::Gyrometer^ gyrometer; + + // functions used by main to initialize/deintialize the OS +protected: + virtual int get_video_driver_count() const; + virtual const char * get_video_driver_name(int p_driver) const; + + virtual VideoMode get_default_video_mode() const; + + virtual int get_audio_driver_count() const; + virtual const char * get_audio_driver_name(int p_driver) const; + + virtual void initialize_core(); + virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); + + virtual void set_main_loop( MainLoop * p_main_loop ); + virtual void delete_main_loop(); + + virtual void finalize(); + virtual void finalize_core(); + + void process_events(); + + void process_key_events(); + +public: + + // Event to send to the app wrapper + HANDLE mouse_mode_changed; + + void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type); + + virtual void vprint(const char *p_format, va_list p_list, bool p_stderr=false); + virtual void alert(const String& p_alert,const String& p_title="ALERT!"); + String get_stdin_string(bool p_block); + + void set_mouse_mode(MouseMode p_mode); + MouseMode get_mouse_mode() const; + + virtual Point2 get_mouse_pos() const; + virtual int get_mouse_button_state() const; + virtual void set_window_title(const String& p_title); + + virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); + virtual VideoMode get_video_mode(int p_screen=0) const; + virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; + virtual Size2 get_window_size() const; + virtual void set_window_size(const Size2 p_size); + virtual void set_window_fullscreen(bool p_enabled); + virtual bool is_window_fullscreen() const; + virtual void set_keep_screen_on(bool p_enabled); + + virtual MainLoop *get_main_loop() const; + + virtual String get_name(); + + virtual Date get_date(bool utc) const; + virtual Time get_time(bool utc) const; + virtual TimeZoneInfo get_time_zone_info() const; + virtual uint64_t get_unix_time() const; + + virtual bool can_draw() const; + virtual Error set_cwd(const String& p_cwd); + + virtual void delay_usec(uint32_t p_usec) const; + virtual uint64_t get_ticks_usec() const; + + virtual Error execute(const String& p_path, const List& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL); + virtual Error kill(const ProcessID& p_pid); + + virtual bool has_environment(const String& p_var) const; + virtual String get_environment(const String& p_var) const; + + virtual void set_clipboard(const String& p_text); + virtual String get_clipboard() const; + + void set_cursor_shape(CursorShape p_shape); + void set_icon(const Image& p_icon); + + virtual String get_executable_path() const; + + virtual String get_locale() const; + + virtual void move_window_to_foreground(); + virtual String get_data_dir() const; + + void set_gl_context(ContextEGL* p_context); + void screen_size_changed(); + + virtual void release_rendering_thread(); + virtual void make_rendering_thread(); + virtual void swap_buffers(); + + virtual bool has_touchscreen_ui_hint() const; + + virtual bool has_virtual_keyboard() const; + virtual void show_virtual_keyboard(const String& p_existing_text, const Rect2& p_screen_rect = Rect2()); + virtual void hide_virtual_keyboard(); + + virtual Error shell_open(String p_uri); + + void run(); + + virtual bool get_swap_ok_cancel() { return true; } + + void input_event(InputEvent &p_event); + + void queue_key_event(KeyEvent &p_event); + + OSWinrt(); + ~OSWinrt(); + +}; + +#endif diff --git a/platform/uwp/platform_config.h b/platform/uwp/platform_config.h new file mode 100644 index 0000000000..88b1fefed8 --- /dev/null +++ b/platform/uwp/platform_config.h @@ -0,0 +1,29 @@ +/*************************************************************************/ +/* platform_config.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 diff --git a/platform/uwp/thread_uwp.cpp b/platform/uwp/thread_uwp.cpp new file mode 100644 index 0000000000..5f7d1ca24b --- /dev/null +++ b/platform/uwp/thread_uwp.cpp @@ -0,0 +1,74 @@ +/*************************************************************************/ +/* thread_uwp.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "thread_uwp.h" + +#include "os/memory.h" + +Thread* ThreadWinrt::create_func_winrt(ThreadCreateCallback p_callback,void *p_user,const Settings&) { + + ThreadWinrt* thread = memnew(ThreadWinrt); + + + std::thread new_thread(p_callback, p_user); + std::swap(thread->thread, new_thread); + + return thread; +}; + +Thread::ID ThreadWinrt::get_thread_ID_func_winrt() { + + return std::hash()(std::this_thread::get_id()); +}; + +void ThreadWinrt::wait_to_finish_func_winrt(Thread* p_thread) { + + ThreadWinrt *tp=static_cast(p_thread); + tp->thread.join(); +}; + + +Thread::ID ThreadWinrt::get_ID() const { + + return std::hash()(thread.get_id()); +}; + +void ThreadWinrt::make_default() { + create_func = create_func_winrt; + get_thread_ID_func = get_thread_ID_func_winrt; + wait_to_finish_func = wait_to_finish_func_winrt; +}; + +ThreadWinrt::ThreadWinrt() { + +}; + +ThreadWinrt::~ThreadWinrt() { + +}; + diff --git a/platform/uwp/thread_uwp.h b/platform/uwp/thread_uwp.h new file mode 100644 index 0000000000..e0d386a317 --- /dev/null +++ b/platform/uwp/thread_uwp.h @@ -0,0 +1,63 @@ +/*************************************************************************/ +/* thread_uwp.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 THREAD_WINRT_H +#define THREAD_WINRT_H + +#ifdef WINRT_ENABLED + +#include "os/thread.h" + +#include + +class ThreadWinrt : public Thread { + + std::thread thread; + + static Thread* create_func_winrt(ThreadCreateCallback p_callback,void *,const Settings&); + static ID get_thread_ID_func_winrt(); + static void wait_to_finish_func_winrt(Thread* p_thread); + + ThreadWinrt(); +public: + + + virtual ID get_ID() const; + + static void make_default(); + + + ~ThreadWinrt(); + +}; + + +#endif + +#endif + diff --git a/platform/winrt/SCsub b/platform/winrt/SCsub deleted file mode 100644 index 5259e7dc22..0000000000 --- a/platform/winrt/SCsub +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python - -Import('env') - -files = [ - 'thread_winrt.cpp', - '#platform/windows/tcp_server_winsock.cpp', - '#platform/windows/packet_peer_udp_winsock.cpp', - '#platform/windows/stream_peer_winsock.cpp', - '#platform/windows/key_mapping_win.cpp', - 'joystick_winrt.cpp', - 'gl_context_egl.cpp', - 'app.cpp', - 'os_winrt.cpp', -] - -if "build_angle" in env and env["build_angle"]: - cmd = env.AlwaysBuild(env.ANGLE('libANGLE.lib', None)) - -prog = env.Program('#bin/godot', files) - -if "build_angle" in env and env["build_angle"]: - env.Depends(prog, [cmd]) diff --git a/platform/winrt/app.cpp b/platform/winrt/app.cpp deleted file mode 100644 index c2b7ba0641..0000000000 --- a/platform/winrt/app.cpp +++ /dev/null @@ -1,647 +0,0 @@ -/*************************************************************************/ -/* app.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -// -// This file demonstrates how to initialize EGL in a Windows Store app, using ICoreWindow. -// - -#include "app.h" - -#include "main/main.h" -#include "core/os/dir_access.h" -#include "core/os/file_access.h" -#include "core/os/keyboard.h" - -#include "platform/windows/key_mapping_win.h" - -#include - -using namespace Windows::ApplicationModel::Core; -using namespace Windows::ApplicationModel::Activation; -using namespace Windows::UI::Core; -using namespace Windows::UI::Input; -using namespace Windows::Devices::Input; -using namespace Windows::UI::Xaml::Input; -using namespace Windows::Foundation; -using namespace Windows::Graphics::Display; -using namespace Windows::System; -using namespace Windows::System::Threading::Core; -using namespace Microsoft::WRL; - -using namespace GodotWinRT; - -// Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels. -inline float ConvertDipsToPixels(float dips, float dpi) -{ - static const float dipsPerInch = 96.0f; - return floor(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer. -} - -// Implementation of the IFrameworkViewSource interface, necessary to run our app. -ref class GodotWinrtViewSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource -{ -public: - virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() - { - return ref new App(); - } -}; - -// The main function creates an IFrameworkViewSource for our app, and runs the app. -[Platform::MTAThread] -int main(Platform::Array^) -{ - auto godotApplicationSource = ref new GodotWinrtViewSource(); - CoreApplication::Run(godotApplicationSource); - return 0; -} - -App::App() : - mWindowClosed(false), - mWindowVisible(true), - mWindowWidth(0), - mWindowHeight(0), - mEglDisplay(EGL_NO_DISPLAY), - mEglContext(EGL_NO_CONTEXT), - mEglSurface(EGL_NO_SURFACE), - number_of_contacts(0) -{ -} - -// The first method called when the IFrameworkView is being created. -void App::Initialize(CoreApplicationView^ applicationView) -{ - // Register event handlers for app lifecycle. This example includes Activated, so that we - // can make the CoreWindow active and start rendering on the window. - applicationView->Activated += - ref new TypedEventHandler(this, &App::OnActivated); - - // Logic for other event handlers could go here. - // 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 OSWinrt; - -} - -// Called when the CoreWindow object is created (or re-created). -void App::SetWindow(CoreWindow^ p_window) -{ - window = p_window; - window->VisibilityChanged += - ref new TypedEventHandler(this, &App::OnVisibilityChanged); - - window->Closed += - ref new TypedEventHandler(this, &App::OnWindowClosed); - - window->SizeChanged += - ref new TypedEventHandler(this, &App::OnWindowSizeChanged); - -#if !(WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) - // Disable all pointer visual feedback for better performance when touching. - // This is not supported on Windows Phone applications. - auto pointerVisualizationSettings = PointerVisualizationSettings::GetForCurrentView(); - pointerVisualizationSettings->IsContactFeedbackEnabled = false; - pointerVisualizationSettings->IsBarrelButtonFeedbackEnabled = false; -#endif - - - window->PointerPressed += - ref new TypedEventHandler(this, &App::OnPointerPressed); - window->PointerMoved += - ref new TypedEventHandler(this, &App::OnPointerMoved); - window->PointerReleased += - ref new TypedEventHandler(this, &App::OnPointerReleased); - window->PointerWheelChanged += - ref new TypedEventHandler(this, &App::OnPointerWheelChanged); - - mouseChangedNotifier = SignalNotifier::AttachToEvent(L"os_mouse_mode_changed", ref new SignalHandler( - this, &App::OnMouseModeChanged - )); - - mouseChangedNotifier->Enable(); - - window->CharacterReceived += - ref new TypedEventHandler(this, &App::OnCharacterReceived); - window->KeyDown += - ref new TypedEventHandler(this, &App::OnKeyDown); - window->KeyUp += - ref new TypedEventHandler(this, &App::OnKeyUp); - - - unsigned int argc; - char** argv = get_command_line(&argc); - - Main::setup("winrt", argc, argv, false); - - // The CoreWindow has been created, so EGL can be initialized. - ContextEGL* context = memnew(ContextEGL(window)); - os->set_gl_context(context); - UpdateWindowSize(Size(window->Bounds.Width, window->Bounds.Height)); - - Main::setup2(); -} - -static int _get_button(Windows::UI::Input::PointerPoint ^pt) { - - using namespace Windows::UI::Input; - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - return BUTTON_LEFT; -#else - switch (pt->Properties->PointerUpdateKind) - { - case PointerUpdateKind::LeftButtonPressed: - case PointerUpdateKind::LeftButtonReleased: - return BUTTON_LEFT; - - case PointerUpdateKind::RightButtonPressed: - case PointerUpdateKind::RightButtonReleased: - return BUTTON_RIGHT; - - case PointerUpdateKind::MiddleButtonPressed: - case PointerUpdateKind::MiddleButtonReleased: - return BUTTON_MIDDLE; - - case PointerUpdateKind::XButton1Pressed: - case PointerUpdateKind::XButton1Released: - return BUTTON_WHEEL_UP; - - case PointerUpdateKind::XButton2Pressed: - case PointerUpdateKind::XButton2Released: - return BUTTON_WHEEL_DOWN; - - default: - break; - } -#endif - - return 0; -}; - -static bool _is_touch(Windows::UI::Input::PointerPoint ^pointerPoint) { -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP - return true; -#else - using namespace Windows::Devices::Input; - switch (pointerPoint->PointerDevice->PointerDeviceType) { - case PointerDeviceType::Touch: - case PointerDeviceType::Pen: - return true; - default: - return false; - } -#endif -} - - -static Windows::Foundation::Point _get_pixel_position(CoreWindow^ window, Windows::Foundation::Point rawPosition, OS* os) { - - Windows::Foundation::Point outputPosition; - - // Compute coordinates normalized from 0..1. - // If the coordinates need to be sized to the SDL window, - // we'll do that after. - #if 1 || WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP - outputPosition.X = rawPosition.X / window->Bounds.Width; - outputPosition.Y = rawPosition.Y / window->Bounds.Height; - #else - switch (DisplayProperties::CurrentOrientation) - { - case DisplayOrientations::Portrait: - outputPosition.X = rawPosition.X / window->Bounds.Width; - outputPosition.Y = rawPosition.Y / window->Bounds.Height; - break; - case DisplayOrientations::PortraitFlipped: - outputPosition.X = 1.0f - (rawPosition.X / window->Bounds.Width); - outputPosition.Y = 1.0f - (rawPosition.Y / window->Bounds.Height); - break; - case DisplayOrientations::Landscape: - outputPosition.X = rawPosition.Y / window->Bounds.Height; - outputPosition.Y = 1.0f - (rawPosition.X / window->Bounds.Width); - break; - case DisplayOrientations::LandscapeFlipped: - outputPosition.X = 1.0f - (rawPosition.Y / window->Bounds.Height); - outputPosition.Y = rawPosition.X / window->Bounds.Width; - break; - default: - break; - } - #endif - - OS::VideoMode vm = os->get_video_mode(); - outputPosition.X *= vm.width; - outputPosition.Y *= vm.height; - - return outputPosition; -}; - -static int _get_finger(uint32_t p_touch_id) { - - return p_touch_id % 31; // for now -}; - -void App::pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel) { - - Windows::UI::Input::PointerPoint ^point = args->CurrentPoint; - Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os); - int but = _get_button(point); - if (_is_touch(point)) { - - InputEvent event; - event.type = InputEvent::SCREEN_TOUCH; - event.device = 0; - event.screen_touch.pressed = p_pressed; - event.screen_touch.x = pos.X; - event.screen_touch.y = pos.Y; - event.screen_touch.index = _get_finger(point->PointerId); - - last_touch_x[event.screen_touch.index] = pos.X; - last_touch_y[event.screen_touch.index] = pos.Y; - - os->input_event(event); - if (number_of_contacts > 1) - return; - - }; // fallthrought of sorts - - InputEvent event; - event.type = InputEvent::MOUSE_BUTTON; - event.device = 0; - event.mouse_button.pressed = p_pressed; - event.mouse_button.button_index = but; - event.mouse_button.x = pos.X; - event.mouse_button.y = pos.Y; - event.mouse_button.global_x = pos.X; - event.mouse_button.global_y = pos.Y; - - if (p_is_wheel) { - if (point->Properties->MouseWheelDelta > 0) { - event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_UP; - } else if (point->Properties->MouseWheelDelta < 0) { - event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_LEFT : BUTTON_WHEEL_DOWN; - } - } - - last_touch_x[31] = pos.X; - last_touch_y[31] = pos.Y; - - os->input_event(event); -}; - - -void App::OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - - number_of_contacts++; - pointer_event(sender, args, true); -}; - - -void App::OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - - number_of_contacts--; - pointer_event(sender, args, false); -}; - -void App::OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - - pointer_event(sender, args, true, true); -} - -void App::OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier^ signalNotifier, bool timedOut) { - - OS::MouseMode mode = os->get_mouse_mode(); - SignalNotifier^ notifier = mouseChangedNotifier; - - window->Dispatcher->RunAsync( - CoreDispatcherPriority::High, - ref new DispatchedHandler( - [mode, notifier, this]() { - if (mode == OS::MOUSE_MODE_CAPTURED) { - - this->MouseMovedToken = MouseDevice::GetForCurrentView()->MouseMoved += - ref new TypedEventHandler(this, &App::OnMouseMoved); - - } else { - - MouseDevice::GetForCurrentView()->MouseMoved -= MouseMovedToken; - - } - - notifier->Enable(); - })); - - ResetEvent(os->mouse_mode_changed); - - -} - -void App::OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args) { - - Windows::UI::Input::PointerPoint ^point = args->CurrentPoint; - Windows::Foundation::Point pos = _get_pixel_position(window, point->Position, os); - - if (point->IsInContact && _is_touch(point)) { - - InputEvent event; - event.type = InputEvent::SCREEN_DRAG; - event.device = 0; - event.screen_drag.x = pos.X; - event.screen_drag.y = pos.Y; - event.screen_drag.index = _get_finger(point->PointerId); - event.screen_drag.relative_x = event.screen_drag.x - last_touch_x[event.screen_drag.index]; - event.screen_drag.relative_y = event.screen_drag.y - last_touch_y[event.screen_drag.index]; - - os->input_event(event); - if (number_of_contacts > 1) - return; - - }; // fallthrought of sorts - - // In case the mouse grabbed, MouseMoved will handle this - if (os->get_mouse_mode() == OS::MouseMode::MOUSE_MODE_CAPTURED) - return; - - InputEvent event; - event.type = InputEvent::MOUSE_MOTION; - event.device = 0; - event.mouse_motion.x = pos.X; - event.mouse_motion.y = pos.Y; - event.mouse_motion.global_x = pos.X; - event.mouse_motion.global_y = pos.Y; - event.mouse_motion.relative_x = pos.X - last_touch_x[31]; - event.mouse_motion.relative_y = pos.Y - last_touch_y[31]; - - last_mouse_pos = pos; - - os->input_event(event); - -} - -void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) { - - // In case the mouse isn't grabbed, PointerMoved will handle this - if (os->get_mouse_mode() != OS::MouseMode::MOUSE_MODE_CAPTURED) - return; - - Windows::Foundation::Point pos; - pos.X = last_mouse_pos.X + args->MouseDelta.X; - pos.Y = last_mouse_pos.Y + args->MouseDelta.Y; - - InputEvent event; - event.type = InputEvent::MOUSE_MOTION; - event.device = 0; - event.mouse_motion.x = pos.X; - event.mouse_motion.y = pos.Y; - event.mouse_motion.global_x = pos.X; - event.mouse_motion.global_y = pos.Y; - event.mouse_motion.relative_x = args->MouseDelta.X; - event.mouse_motion.relative_y = args->MouseDelta.Y; - - last_mouse_pos = pos; - - os->input_event(event); -} - -void App::key_event(Windows::UI::Core::CoreWindow^ sender, bool p_pressed, Windows::UI::Core::KeyEventArgs^ key_args, Windows::UI::Core::CharacterReceivedEventArgs^ char_args) -{ - - OSWinrt::KeyEvent ke; - - InputModifierState mod; - mod.meta = false; - mod.command = false; - mod.control = sender->GetAsyncKeyState(VirtualKey::Control) == CoreVirtualKeyStates::Down; - mod.alt = sender->GetAsyncKeyState(VirtualKey::Menu) == CoreVirtualKeyStates::Down; - mod.shift = sender->GetAsyncKeyState(VirtualKey::Shift) == CoreVirtualKeyStates::Down; - ke.mod_state = mod; - - ke.pressed = p_pressed; - - if (key_args != nullptr) { - - ke.type = OSWinrt::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 = OSWinrt::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); - } - - os->queue_key_event(ke); - -} -void App::OnKeyDown(CoreWindow^ sender, KeyEventArgs^ args) -{ - key_event(sender, true, args); -} - -void App::OnKeyUp(CoreWindow^ sender, KeyEventArgs^ args) -{ - key_event(sender, false, args); -} - -void App::OnCharacterReceived(CoreWindow^ sender, CharacterReceivedEventArgs^ args) -{ - key_event(sender, true, nullptr, args); -} - - -// Initializes scene resources -void App::Load(Platform::String^ entryPoint) -{ - -} - -// This method is called after the window becomes active. -void App::Run() -{ - if (Main::start()) - os->run(); -} - -// Terminate events do not cause Uninitialize to be called. It will be called if your IFrameworkView -// class is torn down while the app is in the foreground. -void App::Uninitialize() -{ - Main::cleanup(); - delete os; -} - -// Application lifecycle event handler. -void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) -{ - // Run() won't start until the CoreWindow is activated. - CoreWindow::GetForCurrentThread()->Activate(); -} - -// Window event handlers. -void App::OnVisibilityChanged(CoreWindow^ sender, VisibilityChangedEventArgs^ args) -{ - mWindowVisible = args->Visible; -} - -void App::OnWindowClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) -{ - mWindowClosed = true; -} - -void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) -{ -#if (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) - // On Windows 8.1, apps are resized when they are snapped alongside other apps, or when the device is rotated. - // The default framebuffer will be automatically resized when either of these occur. - // In particular, on a 90 degree rotation, the default framebuffer's width and height will switch. - UpdateWindowSize(args->Size); -#else if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) - // On Windows Phone 8.1, the window size changes when the device is rotated. - // The default framebuffer will not be automatically resized when this occurs. - // It is therefore up to the app to handle rotation-specific logic in its rendering code. - //os->screen_size_changed(); - UpdateWindowSize(args->Size); -#endif -} - -void App::UpdateWindowSize(Size size) -{ - float dpi; -#if (WINAPI_FAMILY == WINAPI_FAMILY_PC_APP) - DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView(); - dpi = currentDisplayInformation->LogicalDpi; -#else if (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) - dpi = DisplayProperties::LogicalDpi; -#endif - Size pixelSize(ConvertDipsToPixels(size.Width, dpi), ConvertDipsToPixels(size.Height, dpi)); - - mWindowWidth = static_cast(pixelSize.Width); - mWindowHeight = static_cast(pixelSize.Height); - - OS::VideoMode vm; - vm.width = mWindowWidth; - vm.height = mWindowHeight; - vm.fullscreen = true; - vm.resizable = false; - os->set_video_mode(vm); -} - -char** App::get_command_line(unsigned int* out_argc) { - - static char* fail_cl[] = { "-path", "game", NULL }; - *out_argc = 2; - - FILE* f = _wfopen(L"__cl__.cl", L"rb"); - - if (f == NULL) { - - wprintf(L"Couldn't open command line file."); - return fail_cl; - } - -#define READ_LE_4(v) ((int)(##v[3] & 0xFF) << 24) | ((int)(##v[2] & 0xFF) << 16) | ((int)(##v[1] & 0xFF) << 8) | ((int)(##v[0] & 0xFF)) -#define CMD_MAX_LEN 65535 - - uint8_t len[4]; - int r = fread(len, sizeof(uint8_t), 4, f); - - Platform::Collections::Vector cl; - - if (r < 4) { - fclose(f); - wprintf(L"Wrong cmdline length."); - return(fail_cl); - } - - int argc = READ_LE_4(len); - - for (int i = 0; i < argc; i++) { - - r = fread(len, sizeof(uint8_t), 4, f); - - if (r < 4) { - fclose(f); - wprintf(L"Wrong cmdline param length."); - return(fail_cl); - } - - int strlen = READ_LE_4(len); - - if (strlen > CMD_MAX_LEN) { - fclose(f); - wprintf(L"Wrong command length."); - return(fail_cl); - } - - char* arg = new char[strlen + 1]; - r = fread(arg, sizeof(char), strlen, f); - arg[strlen] = '\0'; - - if (r == strlen) { - - int warg_size = MultiByteToWideChar(CP_UTF8, 0, arg, -1, NULL, 0); - wchar_t* warg = new wchar_t[warg_size]; - - MultiByteToWideChar(CP_UTF8, 0, arg, -1, warg, warg_size); - - cl.Append(ref new Platform::String(warg, warg_size)); - - } else { - - delete[] arg; - fclose(f); - wprintf(L"Error reading command."); - return(fail_cl); - } - } - -#undef READ_LE_4 -#undef CMD_MAX_LEN - - fclose(f); - - char** ret = new char*[cl.Size + 1]; - - for (int i = 0; i < cl.Size; i++) { - - int arg_size = WideCharToMultiByte(CP_UTF8, 0, cl.GetAt(i)->Data(), -1, NULL, 0, NULL, NULL); - char* arg = new char[arg_size]; - - WideCharToMultiByte(CP_UTF8, 0, cl.GetAt(i)->Data(), -1, arg, arg_size, NULL, NULL); - - ret[i] = arg; - - } - ret[cl.Size] = NULL; - *out_argc = cl.Size; - - return ret; -} diff --git a/platform/winrt/app.h b/platform/winrt/app.h deleted file mode 100644 index 652ec86e1f..0000000000 --- a/platform/winrt/app.h +++ /dev/null @@ -1,108 +0,0 @@ -/*************************************************************************/ -/* app.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -#pragma once - -#include - -#include - -#include "os_winrt.h" -#include "GLES2/gl2.h" - -namespace GodotWinRT -{ - ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView - { - public: - App(); - - // IFrameworkView Methods. - virtual void Initialize(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView); - virtual void SetWindow(Windows::UI::Core::CoreWindow^ window); - virtual void Load(Platform::String^ entryPoint); - virtual void Run(); - virtual void Uninitialize(); - - property Windows::Foundation::EventRegistrationToken MouseMovedToken { - Windows::Foundation::EventRegistrationToken get() { return this->mouseMovedToken; } - void set(Windows::Foundation::EventRegistrationToken p_token) { this->mouseMovedToken = p_token; } - }; - - private: - void RecreateRenderer(); - - // Application lifecycle event handlers. - void OnActivated(Windows::ApplicationModel::Core::CoreApplicationView^ applicationView, Windows::ApplicationModel::Activation::IActivatedEventArgs^ args); - - // Window event handlers. - void OnWindowSizeChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::WindowSizeChangedEventArgs^ args); - void OnVisibilityChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::VisibilityChangedEventArgs^ args); - void OnWindowClosed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CoreWindowEventArgs^ args); - - void pointer_event(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args, bool p_pressed, bool p_is_wheel = false); - void OnPointerPressed(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); - void OnPointerReleased(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); - void OnPointerMoved(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); - void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouse_device, Windows::Devices::Input::MouseEventArgs^ args); - void OnPointerWheelChanged(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::PointerEventArgs^ args); - - Windows::System::Threading::Core::SignalNotifier^ mouseChangedNotifier; - Windows::Foundation::EventRegistrationToken mouseMovedToken; - void OnMouseModeChanged(Windows::System::Threading::Core::SignalNotifier^ signalNotifier, bool timedOut); - - void key_event(Windows::UI::Core::CoreWindow^ sender, bool p_pressed, Windows::UI::Core::KeyEventArgs^ key_args = nullptr, Windows::UI::Core::CharacterReceivedEventArgs^ char_args = nullptr); - void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); - void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); - void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); - - void UpdateWindowSize(Windows::Foundation::Size size); - void InitializeEGL(Windows::UI::Core::CoreWindow^ window); - void CleanupEGL(); - - char** get_command_line(unsigned int* out_argc); - - bool mWindowClosed; - bool mWindowVisible; - GLsizei mWindowWidth; - GLsizei mWindowHeight; - - EGLDisplay mEglDisplay; - EGLContext mEglContext; - EGLSurface mEglSurface; - - CoreWindow^ window; - OSWinrt* os; - - int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse - int last_touch_y[32]; - int number_of_contacts; - Windows::Foundation::Point last_mouse_pos; - }; - -} diff --git a/platform/winrt/detect.py b/platform/winrt/detect.py deleted file mode 100644 index 6a1a06d8ab..0000000000 --- a/platform/winrt/detect.py +++ /dev/null @@ -1,166 +0,0 @@ -import os - -import sys -import string -import methods - - -def is_active(): - return True - - -def get_name(): - return "WinRT" - - -def can_build(): - if (os.name == "nt"): - # building natively on windows! - if (os.getenv("VSINSTALLDIR")): - - if (os.getenv("ANGLE_SRC_PATH") == None): - return False - - return True - return False - - -def get_opts(): - return [] - - -def get_flags(): - - return [ - ('tools', 'no'), - ('xaudio2', 'yes'), - ] - - -def configure(env): - - if(env["bits"] != "default"): - print "Error: bits argument is disabled for MSVC" - print ("Bits argument is not supported for MSVC compilation. Architecture depends on the Native/Cross Compile Tools Prompt/Developer Console (or Visual Studio settings)" - + " that is being used to run SCons. As a consequence, bits argument is disabled. Run scons again without bits argument (example: scons p=winrt) and SCons will attempt to detect what MSVC compiler" - + " will be executed and inform you.") - sys.exit() - - arch = "" - env['ENV'] = os.environ - - # ANGLE - angle_root = os.getenv("ANGLE_SRC_PATH") - env.Append(CPPPATH=[angle_root + '/include']) - jobs = str(env.GetOption("num_jobs")) - angle_build_cmd = "msbuild.exe " + angle_root + "/winrt/10/src/angle.sln /nologo /v:m /m:" + jobs + " /p:Configuration=Release /p:Platform=" - - if os.path.isfile(str(os.getenv("ANGLE_SRC_PATH")) + "/winrt/10/src/angle.sln"): - env["build_angle"] = True - - if os.getenv('Platform') == "ARM": - - print "Compiled program architecture will be an ARM executable. (forcing bits=32)." - - arch = "arm" - env["bits"] = "32" - env.Append(LINKFLAGS=['/MACHINE:ARM']) - env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store/arm']) - - angle_build_cmd += "ARM" - - env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_ARM/lib']) - - else: - - compiler_version_str = methods.detect_visual_c_compiler_version(env['ENV']) - - if(compiler_version_str == "amd64" or compiler_version_str == "x86_amd64"): - env["bits"] = "64" - print "Compiled program architecture will be a x64 executable (forcing bits=64)." - elif (compiler_version_str == "x86" or compiler_version_str == "amd64_x86"): - env["bits"] = "32" - print "Compiled program architecture will be a x86 executable. (forcing bits=32)." - else: - print "Failed to detect MSVC compiler architecture version... Defaulting to 32bit executable settings (forcing bits=32). Compilation attempt will continue, but SCons can not detect for what architecture this build is compiled for. You should check your settings/compilation setup." - env["bits"] = "32" - - if (env["bits"] == "32"): - arch = "x86" - - angle_build_cmd += "Win32" - - env.Append(CPPFLAGS=['/DPNG_ABORT=abort']) - env.Append(LINKFLAGS=['/MACHINE:X86']) - env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store']) - env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_Win32/lib']) - - else: - arch = "x64" - - angle_build_cmd += "x64" - - env.Append(LINKFLAGS=['/MACHINE:X64']) - env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store/amd64']) - env.Append(LIBPATH=[angle_root + '/winrt/10/src/Release_x64/lib']) - - env.Append(CPPPATH=['#platform/winrt', '#drivers/windows']) - env.Append(LINKFLAGS=['/MANIFEST:NO', '/NXCOMPAT', '/DYNAMICBASE', '/WINMD', '/APPCONTAINER', '/ERRORREPORT:PROMPT', '/NOLOGO', '/TLBID:1', '/NODEFAULTLIB:"kernel32.lib"', '/NODEFAULTLIB:"ole32.lib"']) - env.Append(CPPFLAGS=['/D', '__WRL_NO_DEFAULT_LIB__', '/D', 'WIN32']) - env.Append(CPPFLAGS=['/FU', os.environ['VCINSTALLDIR'] + 'lib/store/references/platform.winmd']) - env.Append(CPPFLAGS=['/AI', os.environ['VCINSTALLDIR'] + 'lib/store/references']) - - env.Append(LIBPATH=[os.environ['VCINSTALLDIR'] + 'lib/store/references']) - - if (env["target"] == "release"): - - env.Append(CPPFLAGS=['/O2', '/GL']) - env.Append(CPPFLAGS=['/MD']) - env.Append(LINKFLAGS=['/SUBSYSTEM:WINDOWS', '/LTCG']) - - elif (env["target"] == "release_debug"): - - env.Append(CCFLAGS=['/O2', '/Zi', '/DDEBUG_ENABLED']) - env.Append(CPPFLAGS=['/MD']) - env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) - - elif (env["target"] == "debug"): - - env.Append(CCFLAGS=['/Zi', '/DDEBUG_ENABLED', '/DDEBUG_MEMORY_ENABLED']) - env.Append(CPPFLAGS=['/MDd']) - env.Append(LINKFLAGS=['/SUBSYSTEM:CONSOLE']) - env.Append(LINKFLAGS=['/DEBUG']) - - env.Append(CCFLAGS=string.split('/FS /MP /GS /wd"4453" /wd"28204" /wd"4291" /Zc:wchar_t /Gm- /fp:precise /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP" /errorReport:prompt /WX- /Zc:forScope /Gd /EHsc /nologo')) - env.Append(CXXFLAGS=string.split('/ZW /FS')) - env.Append(CCFLAGS=['/AI', os.environ['VCINSTALLDIR'] + '\\vcpackages', '/AI', os.environ['WINDOWSSDKDIR'] + '\\References\\CommonConfiguration\\Neutral']) - - env["PROGSUFFIX"] = "." + arch + env["PROGSUFFIX"] - env["OBJSUFFIX"] = "." + arch + env["OBJSUFFIX"] - env["LIBSUFFIX"] = "." + arch + env["LIBSUFFIX"] - - env.Append(CCFLAGS=['/DWINRT_ENABLED']) - env.Append(CCFLAGS=['/DWINDOWS_ENABLED']) - env.Append(CCFLAGS=['/DTYPED_METHOD_BIND']) - - env.Append(CCFLAGS=['/DGLES2_ENABLED', '/DGL_GLEXT_PROTOTYPES', '/DEGL_EGLEXT_PROTOTYPES', '/DANGLE_ENABLED']) - - LIBS = [ - 'WindowsApp', - 'mincore', - 'libANGLE', - 'libEGL', - 'libGLESv2', - ] - env.Append(LINKFLAGS=[p + ".lib" for p in LIBS]) - - # Incremental linking fix - env['BUILDERS']['ProgramOriginal'] = env['BUILDERS']['Program'] - env['BUILDERS']['Program'] = methods.precious_program - - env.Append(BUILDERS={'ANGLE': env.Builder(action=angle_build_cmd)}) - - env.Append(BUILDERS={'GLSL120': env.Builder(action=methods.build_legacygl_headers, suffix='glsl.h', src_suffix='.glsl')}) - env.Append(BUILDERS={'GLSL': env.Builder(action=methods.build_glsl_headers, suffix='glsl.h', src_suffix='.glsl')}) - env.Append(BUILDERS={'HLSL9': env.Builder(action=methods.build_hlsl_dx9_headers, suffix='hlsl.h', src_suffix='.hlsl')}) - env.Append(BUILDERS={'GLSL120GLES': env.Builder(action=methods.build_gles2_headers, suffix='glsl.h', src_suffix='.glsl')}) diff --git a/platform/winrt/export/export.cpp b/platform/winrt/export/export.cpp deleted file mode 100644 index eca9f09de6..0000000000 --- a/platform/winrt/export/export.cpp +++ /dev/null @@ -1,2391 +0,0 @@ -/*************************************************************************/ -/* export.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ - -/************************************************************************* - * The code for signing the package was ported from fb-util-for-appx - * available at https://github.com/facebook/fb-util-for-appx - * and distributed also under the following license: - -BSD License - -For fb-util-for-appx software - -Copyright (c) 2016, Facebook, Inc. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name Facebook nor the names of its contributors may be used to - endorse or promote products derived from this software without specific - prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*************************************************************************/ - - -#include "version.h" -#include "export.h" -#include "object.h" -#include "tools/editor/editor_import_export.h" -#include "tools/editor/editor_node.h" -#include "platform/winrt/logo.h" -#include "os/file_access.h" -#include "io/zip.h" -#include "io/unzip.h" -#include "io/zip_io.h" -#include "io/sha256.h" -#include "io/base64.h" -#include "bind/core_bind.h" -#include "globals.h" -#include "io/marshalls.h" - -#include - -// Capabilities -static const char* uwp_capabilities[] = { - "allJoyn", - "codeGeneration", - "internetClient", - "internetClientServer", - "privateNetworkClientServer", - NULL -}; -static const char* uwp_uap_capabilities[] = { - "appointments", - "blockedChatMessages", - "chat", - "contacts", - "enterpriseAuthentication", - "musicLibrary", - "objects3D", - "picturesLibrary", - "phoneCall", - "removableStorage", - "sharedUserCertificates", - "userAccountInformation", - "videosLibrary", - "voipCall", - NULL -}; -static const char* uwp_device_capabilites[] = { - "bluetooth", - "location", - "microphone", - "proximity", - "webcam", - NULL -}; - -#ifdef OPENSSL_ENABLED -#include -#include -#include -#include -#include -#include -#include -#include - -namespace asn1 { - // https://msdn.microsoft.com/en-us/gg463180.aspx - - struct SPCStatementType { - ASN1_OBJECT *type; - }; - DECLARE_ASN1_FUNCTIONS(SPCStatementType) - - struct SPCSpOpusInfo { - ASN1_TYPE *programName; - ASN1_TYPE *moreInfo; - }; - DECLARE_ASN1_FUNCTIONS(SPCSpOpusInfo) - - struct DigestInfo { - X509_ALGOR *digestAlgorithm; - ASN1_OCTET_STRING *digest; - }; - DECLARE_ASN1_FUNCTIONS(DigestInfo) - - struct SPCAttributeTypeAndOptionalValue { - ASN1_OBJECT *type; - ASN1_TYPE *value; // SPCInfoValue - }; - DECLARE_ASN1_FUNCTIONS(SPCAttributeTypeAndOptionalValue) - - // Undocumented. - struct SPCInfoValue { - ASN1_INTEGER *i1; - ASN1_OCTET_STRING *s1; - ASN1_INTEGER *i2; - ASN1_INTEGER *i3; - ASN1_INTEGER *i4; - ASN1_INTEGER *i5; - ASN1_INTEGER *i6; - }; - DECLARE_ASN1_FUNCTIONS(SPCInfoValue) - - struct SPCIndirectDataContent { - SPCAttributeTypeAndOptionalValue *data; - DigestInfo *messageDigest; - }; - DECLARE_ASN1_FUNCTIONS(SPCIndirectDataContent) - - IMPLEMENT_ASN1_FUNCTIONS(SPCIndirectDataContent) - ASN1_SEQUENCE(SPCIndirectDataContent) = { - ASN1_SIMPLE(SPCIndirectDataContent, data, - SPCAttributeTypeAndOptionalValue), - ASN1_SIMPLE(SPCIndirectDataContent, messageDigest, DigestInfo), - } ASN1_SEQUENCE_END(SPCIndirectDataContent) - - IMPLEMENT_ASN1_FUNCTIONS(SPCAttributeTypeAndOptionalValue) - ASN1_SEQUENCE(SPCAttributeTypeAndOptionalValue) = { - ASN1_SIMPLE(SPCAttributeTypeAndOptionalValue, type, - ASN1_OBJECT), - ASN1_OPT(SPCAttributeTypeAndOptionalValue, value, ASN1_ANY), - } ASN1_SEQUENCE_END(SPCAttributeTypeAndOptionalValue) - - IMPLEMENT_ASN1_FUNCTIONS(SPCInfoValue) - ASN1_SEQUENCE(SPCInfoValue) = { - ASN1_SIMPLE(SPCInfoValue, i1, ASN1_INTEGER), - ASN1_SIMPLE(SPCInfoValue, s1, ASN1_OCTET_STRING), - ASN1_SIMPLE(SPCInfoValue, i2, ASN1_INTEGER), - ASN1_SIMPLE(SPCInfoValue, i3, ASN1_INTEGER), - ASN1_SIMPLE(SPCInfoValue, i4, ASN1_INTEGER), - ASN1_SIMPLE(SPCInfoValue, i5, ASN1_INTEGER), - ASN1_SIMPLE(SPCInfoValue, i6, ASN1_INTEGER), - } ASN1_SEQUENCE_END(SPCInfoValue) - - IMPLEMENT_ASN1_FUNCTIONS(DigestInfo) - ASN1_SEQUENCE(DigestInfo) = { - ASN1_SIMPLE(DigestInfo, digestAlgorithm, X509_ALGOR), - ASN1_SIMPLE(DigestInfo, digest, ASN1_OCTET_STRING), - } ASN1_SEQUENCE_END(DigestInfo) - - ASN1_SEQUENCE(SPCSpOpusInfo) = { - ASN1_OPT(SPCSpOpusInfo, programName, ASN1_ANY), - ASN1_OPT(SPCSpOpusInfo, moreInfo, ASN1_ANY), - } ASN1_SEQUENCE_END(SPCSpOpusInfo) - IMPLEMENT_ASN1_FUNCTIONS(SPCSpOpusInfo) - - ASN1_SEQUENCE(SPCStatementType) = { - ASN1_SIMPLE(SPCStatementType, type, ASN1_OBJECT), - } ASN1_SEQUENCE_END(SPCStatementType) - IMPLEMENT_ASN1_FUNCTIONS(SPCStatementType) -} - -class EncodedASN1 { - - uint8_t* i_data; - size_t i_size; - - EncodedASN1(uint8_t** p_data, size_t p_size) { - - i_data = *p_data; - i_size = p_size; - } - -public: - - template - static EncodedASN1 FromItem(T *item) { - uint8_t *dataRaw = NULL; - int size = TEncode(item, &dataRaw); - - return EncodedASN1(&dataRaw, size); - } - - const uint8_t *data() const { - return i_data; - } - - size_t size() const { - return i_size; - } - - // Assumes the encoded ASN.1 represents a SEQUENCE and puts it into - // an ASN1_STRING. - // - // The returned object holds a copy of this object's data. - ASN1_STRING* ToSequenceString() { - ASN1_STRING* string = ASN1_STRING_new(); - if (!string) { - return NULL; - } - if (!ASN1_STRING_set(string, i_data, i_size)) { - return NULL; - } - return string; - } - - // Assumes the encoded ASN.1 represents a SEQUENCE and puts it into - // an ASN1_TYPE. - // - // The returned object holds a copy of this object's data. - ASN1_TYPE* ToSequenceType() { - ASN1_STRING* string = ToSequenceString(); - ASN1_TYPE* type = ASN1_TYPE_new(); - if (!type) { - return NULL; - } - type->type = V_ASN1_SEQUENCE; - type->value.sequence = string; - return type; - } - -}; - -#endif // OPENSSL_ENABLED - -class AppxPackager { - - enum { - FILE_HEADER_MAGIC = 0x04034b50, - DATA_DESCRIPTOR_MAGIC = 0x08074b50, - CENTRAL_DIR_MAGIC = 0x02014b50, - END_OF_CENTRAL_DIR_MAGIC = 0x06054b50, - ZIP64_END_OF_CENTRAL_DIR_MAGIC = 0x06064b50, - ZIP64_END_DIR_LOCATOR_MAGIC = 0x07064b50, - P7X_SIGNATURE = 0x58434b50, - ZIP64_HEADER_ID = 0x0001, - ZIP_VERSION = 20, - ZIP_ARCHIVE_VERSION = 45, - GENERAL_PURPOSE = 0x00, - BASE_FILE_HEADER_SIZE = 30, - DATA_DESCRIPTOR_SIZE = 24, - BASE_CENTRAL_DIR_SIZE = 46, - EXTRA_FIELD_LENGTH = 28, - ZIP64_HEADER_SIZE = 24, - ZIP64_END_OF_CENTRAL_DIR_SIZE = (56 - 12), - END_OF_CENTRAL_DIR_SIZE = 42, - BLOCK_SIZE = 65536, - }; - - struct BlockHash { - - String base64_hash; - size_t compressed_size; - }; - - struct FileMeta { - - String name; - int lfh_size; - bool compressed; - size_t compressed_size; - size_t uncompressed_size; - Vector hashes; - uLong file_crc32; - ZPOS64_T zip_offset; - }; - - String progress_task; - FileAccess *package; - String tmp_blockmap_file_path; - String tmp_content_types_file_path; - - Set mime_types; - - Vector file_metadata; - - ZPOS64_T central_dir_offset; - ZPOS64_T end_of_central_dir_offset; - Vector central_dir_data; - - String hash_block(uint8_t* p_block_data, size_t p_block_len); - - void make_block_map(); - void make_content_types(); - - - _FORCE_INLINE_ unsigned int buf_put_int16(uint16_t p_val, uint8_t * p_buf) { - for (int i = 0; i < 2; i++) { - *p_buf++ = (p_val >> (i * 8)) & 0xFF; - } - return 2; - } - - _FORCE_INLINE_ unsigned int buf_put_int32(uint32_t p_val, uint8_t * p_buf) { - for (int i = 0; i < 4; i++) { - *p_buf++ = (p_val >> (i * 8)) & 0xFF; - } - return 4; - } - - _FORCE_INLINE_ unsigned int buf_put_int64(uint64_t p_val, uint8_t * p_buf) { - for (int i = 0; i < 8; i++) { - *p_buf++ = (p_val >> (i * 8)) & 0xFF; - } - return 8; - } - - _FORCE_INLINE_ unsigned int buf_put_string(String p_val, uint8_t * p_buf) { - for (int i = 0; i < p_val.length(); i++) { - *p_buf++ = p_val.utf8().get(i); - } - return p_val.length(); - } - - Vector make_file_header(FileMeta p_file_meta); - void store_central_dir_header(const FileMeta p_file, bool p_do_hash = true); - Vector make_end_of_central_record(); - - String content_type(String p_extension); - -#ifdef OPENSSL_ENABLED - - // Signing methods and structs: - - String certificate_path; - String certificate_pass; - bool sign_package; - - struct CertFile { - - EVP_PKEY* private_key; - X509* certificate; - }; - - SHA256_CTX axpc_context; // SHA256 context for ZIP file entries - SHA256_CTX axcd_context; // SHA256 context for ZIP directory entries - - struct AppxDigests { - - uint8_t axpc[SHA256_DIGEST_LENGTH]; // ZIP file entries - uint8_t axcd[SHA256_DIGEST_LENGTH]; // ZIP directory entry - uint8_t axct[SHA256_DIGEST_LENGTH]; // Content types XML - uint8_t axbm[SHA256_DIGEST_LENGTH]; // Block map XML - uint8_t axci[SHA256_DIGEST_LENGTH]; // Code Integrity file (optional) - }; - - CertFile cert_file; - AppxDigests digests; - - void MakeSPCInfoValue(asn1::SPCInfoValue &info); - Error MakeIndirectDataContent(asn1::SPCIndirectDataContent &idc); - Error add_attributes(PKCS7_SIGNER_INFO *signerInfo); - void make_digests(); - void write_digest(Vector &p_out_buffer); - - Error openssl_error(unsigned long p_err); - Error read_cert_file(const String &p_path, const String &p_password, CertFile* p_out_cf); - Error sign(const CertFile &p_cert, const AppxDigests &digests, PKCS7* p_out_signature); - -#endif // OPENSSL_ENABLED - -public: - - enum SignOption { - - SIGN, - DONT_SIGN, - }; - - void set_progress_task(String p_task) { progress_task = p_task; } - void init(FileAccess* p_fa, SignOption p_sign, String &p_certificate_path, String &p_certificate_password); - void add_file(String p_file_name, const uint8_t* p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress = false); - void finish(); - - AppxPackager(); - ~AppxPackager(); -}; - -class EditorExportPlatformWinrt : public EditorExportPlatform { - - OBJ_TYPE(EditorExportPlatformWinrt, EditorExportPlatform); - - Ref logo; - - enum Platform { - ARM, - X86, - X64 - } arch; - - bool is_debug; - - String custom_release_package; - String custom_debug_package; - - String cmdline; - - String display_name; - String short_name; - String unique_name; - String description; - String publisher; - String publisher_display_name; - - String product_guid; - String publisher_guid; - - int version_major; - int version_minor; - int version_build; - int version_revision; - - bool orientation_landscape; - bool orientation_portrait; - bool orientation_landscape_flipped; - bool orientation_portrait_flipped; - - String background_color; - Ref store_logo; - Ref square44; - Ref square71; - Ref square150; - Ref square310; - Ref wide310; - Ref splash; - - bool name_on_square150; - bool name_on_square310; - bool name_on_wide; - - Set capabilities; - Set uap_capabilities; - Set device_capabilities; - - bool sign_package; - String certificate_path; - String certificate_pass; - - _FORCE_INLINE_ bool array_has(const char** p_array, const char* p_value) const { - while (*p_array) { - if (String(*p_array) == String(p_value)) return true; - p_array++; - } - return false; - } - - bool _valid_resource_name(const String &p_name) const; - bool _valid_guid(const String &p_guid) const; - bool _valid_bgcolor(const String &p_color) const; - bool _valid_image(const Ref p_image, int p_width, int p_height) const; - - Vector _fix_manifest(const Vector &p_template, bool p_give_internet) const; - Vector _get_image_data(const String &p_path); - - static Error save_appx_file(void *p_userdata, const String& p_path, const Vector& p_data, int p_file, int p_total); - static bool _should_compress_asset(const String& p_path, const Vector& p_data); - -protected: - - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - -public: - - virtual String get_name() const { return "Windows Universal"; } - virtual ImageCompression get_image_compression() const { return IMAGE_COMPRESSION_ETC1; } - virtual Ref get_logo() const { return logo; } - - virtual bool can_export(String *r_error = NULL) const; - virtual String get_binary_extension() const { return "appx"; } - - virtual Error export_project(const String& p_path, bool p_debug, int p_flags = 0); - - EditorExportPlatformWinrt(); - ~EditorExportPlatformWinrt(); -}; - - -/////////////////////////////////////////////////////////////////////////// - -String AppxPackager::hash_block(uint8_t * p_block_data, size_t p_block_len) { - - char hash[32]; - char base64[45]; - - sha256_context ctx; - sha256_init(&ctx); - sha256_hash(&ctx, p_block_data, p_block_len); - sha256_done(&ctx, (uint8_t*)hash); - - base64_encode(base64, hash, 32); - base64[44] = '\0'; - - return String(base64); -} - -void AppxPackager::make_block_map() { - - FileAccess* tmp_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::WRITE); - - tmp_file->store_string(""); - tmp_file->store_string(""); - - for (int i = 0; i < file_metadata.size(); i++) { - - FileMeta file = file_metadata[i]; - - tmp_file->store_string( - ""); - - - for (int j = 0; j < file.hashes.size(); j++) { - - tmp_file->store_string("store_string("Size=\"" + itos(file.hashes[j].compressed_size) + "\" "); - tmp_file->store_string("/>"); - } - - tmp_file->store_string(""); - } - - tmp_file->store_string(""); - - tmp_file->close(); - memdelete(tmp_file); - tmp_file = NULL; -} - -String AppxPackager::content_type(String p_extension) { - - if (p_extension == "png") - return "image/png"; - else if (p_extension == "jpg") - return "image/jpg"; - else if (p_extension == "xml") - return "application/xml"; - else if (p_extension == "exe" || p_extension == "dll") - return "application/x-msdownload"; - else - return "application/octet-stream"; -} - -void AppxPackager::make_content_types() { - - FileAccess* tmp_file = FileAccess::open(tmp_content_types_file_path, FileAccess::WRITE); - - tmp_file->store_string(""); - tmp_file->store_string(""); - - Map types; - - for (int i = 0; i < file_metadata.size(); i++) { - - String ext = file_metadata[i].name.extension(); - - if (types.has(ext)) continue; - - types[ext] = content_type(ext); - - tmp_file->store_string(""); - } - - // Appx signature file - tmp_file->store_string(""); - - // Override for package files - tmp_file->store_string(""); - tmp_file->store_string(""); - tmp_file->store_string(""); - tmp_file->store_string(""); - - tmp_file->store_string(""); - - tmp_file->close(); - memdelete(tmp_file); - tmp_file = NULL; -} - -Vector AppxPackager::make_file_header(FileMeta p_file_meta) { - - Vector buf; - buf.resize(BASE_FILE_HEADER_SIZE + p_file_meta.name.length()); - - int offs = 0; - // Write magic - offs += buf_put_int32(FILE_HEADER_MAGIC, &buf[offs]); - - // Version - offs += buf_put_int16(ZIP_VERSION, &buf[offs]); - - // Special flag - offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]); - - // Compression - offs += buf_put_int16(p_file_meta.compressed ? Z_DEFLATED : 0, &buf[offs]); - - // File date and time - offs += buf_put_int32(0, &buf[offs]); - - // CRC-32 - offs += buf_put_int32(p_file_meta.file_crc32, &buf[offs]); - - // Compressed size - offs += buf_put_int32(p_file_meta.compressed_size, &buf[offs]); - - // Uncompressed size - offs += buf_put_int32(p_file_meta.uncompressed_size, &buf[offs]); - - // File name length - offs += buf_put_int16(p_file_meta.name.length(), &buf[offs]); - - // Extra data length - offs += buf_put_int16(0, &buf[offs]); - - // File name - offs += buf_put_string(p_file_meta.name, &buf[offs]); - - // Done! - return buf; -} - -void AppxPackager::store_central_dir_header(const FileMeta p_file, bool p_do_hash) { - - Vector &buf = central_dir_data; - int offs = buf.size(); - buf.resize(buf.size() + BASE_CENTRAL_DIR_SIZE + p_file.name.length()); - - - // Write magic - offs += buf_put_int32(CENTRAL_DIR_MAGIC, &buf[offs]); - - // ZIP versions - offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]); - offs += buf_put_int16(ZIP_VERSION, &buf[offs]); - - // General purpose flag - offs += buf_put_int16(GENERAL_PURPOSE, &buf[offs]); - - // Compression - offs += buf_put_int16(p_file.compressed ? Z_DEFLATED : 0, &buf[offs]); - - // Modification date/time - offs += buf_put_int32(0, &buf[offs]); - - // Crc-32 - offs += buf_put_int32(p_file.file_crc32, &buf[offs]); - - // File sizes - offs += buf_put_int32(p_file.compressed_size, &buf[offs]); - offs += buf_put_int32(p_file.uncompressed_size, &buf[offs]); - - // File name length - offs += buf_put_int16(p_file.name.length(), &buf[offs]); - - // Extra field length - offs += buf_put_int16(0, &buf[offs]); - - // Comment length - offs += buf_put_int16(0, &buf[offs]); - - // Disk number start, internal/external file attributes - for (int i = 0; i < 8; i++) { - buf[offs++] = 0; - } - - // Relative offset - offs += buf_put_int32(p_file.zip_offset, &buf[offs]); - - // File name - offs += buf_put_string(p_file.name, &buf[offs]); - -#ifdef OPENSSL_ENABLED - // Calculate the hash for signing - if (p_do_hash) - SHA256_Update(&axcd_context, buf.ptr(), buf.size()); -#endif // OPENSSL_ENABLED - - // Done! -} - -Vector AppxPackager::make_end_of_central_record() { - - Vector buf; - buf.resize(ZIP64_END_OF_CENTRAL_DIR_SIZE + 12 + END_OF_CENTRAL_DIR_SIZE); // Size plus magic - - int offs = 0; - - // Write magic - offs += buf_put_int32(ZIP64_END_OF_CENTRAL_DIR_MAGIC, &buf[offs]); - - // Size of this record - offs += buf_put_int64(ZIP64_END_OF_CENTRAL_DIR_SIZE, &buf[offs]); - - // Version (yes, twice) - offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]); - offs += buf_put_int16(ZIP_ARCHIVE_VERSION, &buf[offs]); - - // Disk number - for (int i = 0; i < 8; i++) { - buf[offs++] = 0; - } - - // Number of entries (total and per disk) - offs += buf_put_int64(file_metadata.size(), &buf[offs]); - offs += buf_put_int64(file_metadata.size(), &buf[offs]); - - // Size of central dir - offs += buf_put_int64(central_dir_data.size(), &buf[offs]); - - // Central dir offset - offs += buf_put_int64(central_dir_offset, &buf[offs]); - - ////// ZIP64 locator - - // Write magic for zip64 central dir locator - offs += buf_put_int32(ZIP64_END_DIR_LOCATOR_MAGIC, &buf[offs]); - - // Disk number - for (int i = 0; i < 4; i++) { - buf[offs++] = 0; - } - - // Relative offset - offs += buf_put_int64(end_of_central_dir_offset, &buf[offs]); - - // Number of disks - offs += buf_put_int32(1, &buf[offs]); - - /////// End of zip directory - - // Write magic for end central dir - offs += buf_put_int32(END_OF_CENTRAL_DIR_MAGIC, &buf[offs]); - - // Dummy stuff for Zip64 - for (int i = 0; i < 4; i++) { - buf[offs++] = 0x0; - } - for (int i = 0; i < 12; i++) { - buf[offs++] = 0xFF; - } - - // Size of comments - for (int i = 0; i < 2; i++) { - buf[offs++] = 0; - } - - // Done! - return buf; -} - -void AppxPackager::init(FileAccess * p_fa, SignOption p_sign, String &p_certificate_path, String &p_certificate_password) { - - package = p_fa; - central_dir_offset = 0; - end_of_central_dir_offset = 0; - tmp_blockmap_file_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpblockmap.xml"; - tmp_content_types_file_path = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmpcontenttypes.xml"; -#ifdef OPENSSL_ENABLED - certificate_path = p_certificate_path; - certificate_pass = p_certificate_password; - sign_package = p_sign == SIGN; - SHA256_Init(&axpc_context); - SHA256_Init(&axcd_context); -#endif // OPENSSL_ENABLED -} - -void AppxPackager::add_file(String p_file_name, const uint8_t * p_buffer, size_t p_len, int p_file_no, int p_total_files, bool p_compress) { - - if (p_file_no >= 1 && p_total_files >= 1) { - EditorNode::progress_task_step(progress_task, "File: " + p_file_name, (p_file_no * 100) / p_total_files); - } - - bool do_hash = p_file_name != "AppxSignature.p7x"; - - FileMeta meta; - meta.name = p_file_name; - meta.uncompressed_size = p_len; - meta.compressed_size = p_len; - meta.compressed = p_compress; - meta.zip_offset = package->get_pos(); - - Vector file_buffer; - - // Data for compression - z_stream strm; - FileAccess* strm_f = NULL; - Vector strm_in; - strm_in.resize(BLOCK_SIZE); - Vector strm_out; - - if (p_compress) { - - strm.zalloc = zipio_alloc; - strm.zfree = zipio_free; - strm.opaque = &strm_f; - - strm_out.resize(BLOCK_SIZE + 8); - - deflateInit2(&strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY); - } - - int step = 0; - - while (p_len - step > 0) { - - size_t block_size = (p_len - step) > BLOCK_SIZE ? BLOCK_SIZE : (p_len - step); - - for (int i = 0; i < block_size; i++) { - strm_in[i] = p_buffer[step + i]; - } - - BlockHash bh; - bh.base64_hash = hash_block(strm_in.ptr(), block_size); - - if (p_compress) { - - strm.avail_in = block_size; - strm.avail_out = strm_out.size(); - strm.next_in = strm_in.ptr(); - strm.next_out = strm_out.ptr(); - - int total_out_before = strm.total_out; - - deflate(&strm, Z_FULL_FLUSH); - bh.compressed_size = strm.total_out - total_out_before; - - //package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before); - int start = file_buffer.size(); - file_buffer.resize(file_buffer.size() + bh.compressed_size); - for (int i = 0; i < bh.compressed_size; i++) - file_buffer[start + i] = strm_out[i]; -#ifdef OPENSSL_ENABLED - if (do_hash) - SHA256_Update(&axpc_context, strm_out.ptr(), strm.total_out - total_out_before); -#endif // OPENSSL_ENABLED - - } else { - bh.compressed_size = block_size; - //package->store_buffer(strm_in.ptr(), block_size); - int start = file_buffer.size(); - file_buffer.resize(file_buffer.size() + block_size); - for (int i = 0; i < bh.compressed_size; i++) - file_buffer[start + i] = strm_in[i]; -#ifdef OPENSSL_ENABLED - if (do_hash) - SHA256_Update(&axpc_context, strm_in.ptr(), block_size); -#endif // OPENSSL_ENABLED - } - - meta.hashes.push_back(bh); - - step += block_size; - } - - if (p_compress) { - - strm.avail_in = 0; - strm.avail_out = strm_out.size(); - strm.next_in = strm_in.ptr(); - strm.next_out = strm_out.ptr(); - - int total_out_before = strm.total_out; - - deflate(&strm, Z_FINISH); - - //package->store_buffer(strm_out.ptr(), strm.total_out - total_out_before); - int start = file_buffer.size(); - file_buffer.resize(file_buffer.size() + (strm.total_out - total_out_before)); - for (int i = 0; i < (strm.total_out - total_out_before); i++) - file_buffer[start + i] = strm_out[i]; -#ifdef OPENSSL_ENABLED - if (do_hash) - SHA256_Update(&axpc_context, strm_out.ptr(), strm.total_out - total_out_before); -#endif // OPENSSL_ENABLED - - deflateEnd(&strm); - meta.compressed_size = strm.total_out; - - } else { - - meta.compressed_size = p_len; - } - - // Calculate file CRC-32 - uLong crc = crc32(0L, Z_NULL, 0); - crc = crc32(crc, p_buffer, p_len); - meta.file_crc32 = crc; - - // Create file header - Vector file_header = make_file_header(meta); - meta.lfh_size = file_header.size(); - -#ifdef OPENSSL_ENABLED - // Hash the data for signing - if (do_hash) { - SHA256_Update(&axpc_context, file_header.ptr(), file_header.size()); - SHA256_Update(&axpc_context, file_buffer.ptr(), file_buffer.size()); - } -#endif // OPENSSL_ENABLED - - // Store the header and file; - package->store_buffer(file_header.ptr(), file_header.size()); - package->store_buffer(file_buffer.ptr(), file_buffer.size()); - - file_metadata.push_back(meta); -} - -void AppxPackager::finish() { - - // Create and add block map file - EditorNode::progress_task_step("export", "Creating block map...", 4); - - make_block_map(); - FileAccess* blockmap_file = FileAccess::open(tmp_blockmap_file_path, FileAccess::READ); - Vector blockmap_buffer; - blockmap_buffer.resize(blockmap_file->get_len()); - - blockmap_file->get_buffer(blockmap_buffer.ptr(), blockmap_buffer.size()); - -#ifdef OPENSSL_ENABLED - // Hash the file for signing - if (sign_package) { - SHA256_CTX axbm_context; - SHA256_Init(&axbm_context); - SHA256_Update(&axbm_context, blockmap_buffer.ptr(), blockmap_buffer.size()); - SHA256_Final(digests.axbm, &axbm_context); - } -#endif // OPENSSL_ENABLED - - add_file("AppxBlockMap.xml", blockmap_buffer.ptr(), blockmap_buffer.size(), -1, -1, true); - - blockmap_file->close(); - memdelete(blockmap_file); - blockmap_file = NULL; - - // Add content types - EditorNode::progress_task_step("export", "Setting content types...", 5); - make_content_types(); - - FileAccess* types_file = FileAccess::open(tmp_content_types_file_path, FileAccess::READ); - Vector types_buffer; - types_buffer.resize(types_file->get_len()); - - types_file->get_buffer(types_buffer.ptr(), types_buffer.size()); - -#ifdef OPENSSL_ENABLED - if (sign_package) { - // Hash the file for signing - SHA256_CTX axct_context; - SHA256_Init(&axct_context); - SHA256_Update(&axct_context, types_buffer.ptr(), types_buffer.size()); - SHA256_Final(digests.axct, &axct_context); - } -#endif // OPENSSL_ENABLED - - add_file("[Content_Types].xml", types_buffer.ptr(), types_buffer.size(), -1, -1, true); - - types_file->close(); - memdelete(types_file); - types_file = NULL; - - // Pre-process central directory before signing - for (int i = 0; i < file_metadata.size(); i++) { - store_central_dir_header(file_metadata[i]); - } - -#ifdef OPENSSL_ENABLED - // Create the signature file - if (sign_package) { - - Error err = read_cert_file(certificate_path, certificate_pass, &cert_file); - - if (err != OK) { - EditorNode::add_io_error(TTR("Couldn't read the certficate file. Are the path and password both correct?")); - package->close(); - memdelete(package); - package = NULL; - return; - } - - - // Make a temp end of the zip for hashing - central_dir_offset = package->get_pos(); - end_of_central_dir_offset = central_dir_offset + central_dir_data.size(); - Vector zip_end_dir = make_end_of_central_record(); - - // Hash the end directory - SHA256_Update(&axcd_context, zip_end_dir.ptr(), zip_end_dir.size()); - - // Finish the hashes - make_digests(); - - PKCS7* signature = PKCS7_new(); - if (!signature) { - EditorNode::add_io_error(TTR("Error creating the signature object.")); - package->close(); - memdelete(package); - package = NULL; - return; - } - - err = sign(cert_file, digests, signature); - - if (err != OK) { - EditorNode::add_io_error(TTR("Error creating the package signature.")); - package->close(); - memdelete(package); - package = NULL; - return; - } - - // Read the signature as bytes - BIO* bio_out = BIO_new(BIO_s_mem()); - i2d_PKCS7_bio(bio_out, signature); - - BIO_flush(bio_out); - - uint8_t* bio_ptr; - size_t bio_size = BIO_get_mem_data(bio_out, &bio_ptr); - - // Create the signature buffer with magic number - Vector signature_file; - signature_file.resize(4 + bio_size); - buf_put_int32(P7X_SIGNATURE, signature_file.ptr()); - for (int i = 0; i < bio_size; i++) - signature_file[i + 4] = bio_ptr[i]; - - // Add the signature to the package - add_file("AppxSignature.p7x", signature_file.ptr(), signature_file.size(), -1, -1, true); - - // Add central directory entry - store_central_dir_header(file_metadata[file_metadata.size() - 1], false); - } -#endif // OPENSSL_ENABLED - - - // Write central directory - EditorNode::progress_task_step("export", "Finishing package...", 6); - central_dir_offset = package->get_pos(); - package->store_buffer(central_dir_data.ptr(), central_dir_data.size()); - - // End record - end_of_central_dir_offset = package->get_pos(); - Vector end_record = make_end_of_central_record(); - package->store_buffer(end_record.ptr(), end_record.size()); - - package->close(); - memdelete(package); - package = NULL; -} - -#ifdef OPENSSL_ENABLED -// https://support.microsoft.com/en-us/kb/287547 -const char SPC_INDIRECT_DATA_OBJID[] = "1.3.6.1.4.1.311.2.1.4"; -const char SPC_STATEMENT_TYPE_OBJID[] = "1.3.6.1.4.1.311.2.1.11"; -const char SPC_SP_OPUS_INFO_OBJID[] = "1.3.6.1.4.1.311.2.1.12"; -const char SPC_SIPINFO_OBJID[] = "1.3.6.1.4.1.311.2.1.30"; -#endif // OPENSSL_ENABLED - -AppxPackager::AppxPackager() {} - -AppxPackager::~AppxPackager() {} - - -//////////////////////////////////////////////////////////////////// - -#ifdef OPENSSL_ENABLED -Error AppxPackager::openssl_error(unsigned long p_err) { - - ERR_load_crypto_strings(); - - char buffer[256]; - ERR_error_string_n(p_err, buffer, sizeof(buffer)); - - String err(buffer); - - ERR_EXPLAIN(err); - ERR_FAIL_V(FAILED); -} - -void AppxPackager::MakeSPCInfoValue(asn1::SPCInfoValue &info) { - - // I have no idea what these numbers mean. - static uint8_t s1Magic[] = { - 0x4B, 0xDF, 0xC5, 0x0A, 0x07, 0xCE, 0xE2, 0x4D, - 0xB7, 0x6E, 0x23, 0xC8, 0x39, 0xA0, 0x9F, 0xD1, - }; - ASN1_INTEGER_set(info.i1, 0x01010000); - ASN1_OCTET_STRING_set(info.s1, s1Magic, sizeof(s1Magic)); - ASN1_INTEGER_set(info.i2, 0x00000000); - ASN1_INTEGER_set(info.i3, 0x00000000); - ASN1_INTEGER_set(info.i4, 0x00000000); - ASN1_INTEGER_set(info.i5, 0x00000000); - ASN1_INTEGER_set(info.i6, 0x00000000); -} - -Error AppxPackager::MakeIndirectDataContent(asn1::SPCIndirectDataContent &idc) { - - using namespace asn1; - - ASN1_TYPE* algorithmParameter = ASN1_TYPE_new(); - if (!algorithmParameter) { - return openssl_error(ERR_peek_last_error()); - } - algorithmParameter->type = V_ASN1_NULL; - - SPCInfoValue* infoValue = SPCInfoValue_new(); - if (!infoValue) { - return openssl_error(ERR_peek_last_error()); - } - MakeSPCInfoValue(*infoValue); - - ASN1_TYPE* value = - EncodedASN1::FromItem(infoValue) - .ToSequenceType(); - - { - Vector digest; - write_digest(digest); - if (!ASN1_OCTET_STRING_set(idc.messageDigest->digest, - digest.ptr(), digest.size())) { - - return openssl_error(ERR_peek_last_error()); - } - } - - idc.data->type = OBJ_txt2obj(SPC_SIPINFO_OBJID, 1); - idc.data->value = value; - idc.messageDigest->digestAlgorithm->algorithm = OBJ_nid2obj(NID_sha256); - idc.messageDigest->digestAlgorithm->parameter = algorithmParameter; - - return OK; -} - -Error AppxPackager::add_attributes(PKCS7_SIGNER_INFO * p_signer_info) { - - // Add opus attribute - asn1::SPCSpOpusInfo* opus = asn1::SPCSpOpusInfo_new(); - if (!opus) return openssl_error(ERR_peek_last_error()); - - ASN1_STRING* opus_value = EncodedASN1::FromItem(opus) - .ToSequenceString(); - - if (!PKCS7_add_signed_attribute( - p_signer_info, - OBJ_txt2nid(SPC_SP_OPUS_INFO_OBJID), - V_ASN1_SEQUENCE, - opus_value - )) { - - asn1::SPCSpOpusInfo_free(opus); - - ASN1_STRING_free(opus_value); - return openssl_error(ERR_peek_last_error()); - } - - // Add content type attribute - if (!PKCS7_add_signed_attribute( - p_signer_info, - NID_pkcs9_contentType, - V_ASN1_OBJECT, - OBJ_txt2obj(SPC_INDIRECT_DATA_OBJID, 1) - )) { - - asn1::SPCSpOpusInfo_free(opus); - ASN1_STRING_free(opus_value); - return openssl_error(ERR_peek_last_error()); - } - - // Add statement type attribute - asn1::SPCStatementType* statement_type = asn1::SPCStatementType_new(); - if (!statement_type) return openssl_error(ERR_peek_last_error()); - - statement_type->type = OBJ_nid2obj(NID_ms_code_ind); - ASN1_STRING* statement_type_value = - EncodedASN1::FromItem(statement_type) - .ToSequenceString(); - - if (!PKCS7_add_signed_attribute( - p_signer_info, - OBJ_txt2nid(SPC_STATEMENT_TYPE_OBJID), - V_ASN1_SEQUENCE, - statement_type_value - )) { - - ASN1_STRING_free(opus_value); - asn1::SPCStatementType_free(statement_type); - ASN1_STRING_free(statement_type_value); - - return openssl_error(ERR_peek_last_error()); - } - - return OK; - -} - -void AppxPackager::make_digests() { - - // AXPC - SHA256_Final(digests.axpc, &axpc_context); - - // AXCD - SHA256_Final(digests.axcd, &axcd_context); - - // AXCI - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) - digests.axci[i] = 0; - -} - -void AppxPackager::write_digest(Vector& p_out_buffer) { - - // Size of digests plus 6 32-bit magic numbers - p_out_buffer.resize((SHA256_DIGEST_LENGTH * 5) + (6 * 4)); - - int offs = 0; - - // APPX - uint32_t sig = 0x58505041; - offs += buf_put_int32(sig, &p_out_buffer[offs]); - - // AXPC - uint32_t axpc_sig = 0x43505841; - offs += buf_put_int32(axpc_sig, &p_out_buffer[offs]); - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - p_out_buffer[offs++] = digests.axpc[i]; - } - - // AXCD - uint32_t axcd_sig = 0x44435841; - offs += buf_put_int32(axcd_sig, &p_out_buffer[offs]); - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - p_out_buffer[offs++] = digests.axcd[i]; - } - - // AXCT - uint32_t axct_sig = 0x54435841; - offs += buf_put_int32(axct_sig, &p_out_buffer[offs]); - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - p_out_buffer[offs++] = digests.axct[i]; - } - - // AXBM - uint32_t axbm_sig = 0x4D425841; - offs += buf_put_int32(axbm_sig, &p_out_buffer[offs]); - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - p_out_buffer[offs++] = digests.axbm[i]; - } - - // AXCI - uint32_t axci_sig = 0x49435841; - offs += buf_put_int32(axci_sig, &p_out_buffer[offs]); - for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) { - p_out_buffer[offs++] = digests.axci[i]; - } - - // Done! -} - -Error AppxPackager::read_cert_file(const String & p_path, const String &p_password, CertFile* p_out_cf) { - - ERR_FAIL_COND_V(!p_out_cf, ERR_INVALID_PARAMETER); - - BIO* bio = BIO_new_file(p_path.utf8().get_data(), "rb"); - if (!bio) { - return openssl_error(ERR_peek_last_error()); - } - - PKCS12* data = d2i_PKCS12_bio(bio, NULL); - if (!data) { - BIO_free(bio); - return openssl_error(ERR_peek_last_error()); - } - - /* Fails to link with GCC, need to solve when implement signing - if (!PKCS12_parse(data, p_password.utf8().get_data(), &p_out_cf->private_key, &p_out_cf->certificate, NULL)) { - PKCS12_free(data); - BIO_free(bio); - return openssl_error(ERR_peek_last_error()); - }*/ - - if (!p_out_cf->private_key) { - PKCS12_free(data); - BIO_free(bio); - return openssl_error(ERR_peek_last_error()); - } - - if (!p_out_cf->certificate) { - PKCS12_free(data); - BIO_free(bio); - return openssl_error(ERR_peek_last_error()); - } - - PKCS12_free(data); - BIO_free(bio); - - return OK; -} - -Error AppxPackager::sign(const CertFile & p_cert, const AppxDigests & digests, PKCS7 * p_out_signature) { - - OpenSSL_add_all_algorithms(); - - // Register object IDs - OBJ_create_and_add_object(SPC_INDIRECT_DATA_OBJID, NULL, NULL); - OBJ_create_and_add_object(SPC_SIPINFO_OBJID, NULL, NULL); - OBJ_create_and_add_object(SPC_SP_OPUS_INFO_OBJID, NULL, NULL); - OBJ_create_and_add_object(SPC_STATEMENT_TYPE_OBJID, NULL, NULL); - - if (!PKCS7_set_type(p_out_signature, NID_pkcs7_signed)) { - - return openssl_error(ERR_peek_last_error()); - } - - PKCS7_SIGNER_INFO *signer_info = PKCS7_add_signature(p_out_signature, p_cert.certificate, p_cert.private_key, EVP_sha256()); - if (!signer_info) return openssl_error(ERR_peek_last_error()); - - add_attributes(signer_info); - - if (!PKCS7_content_new(p_out_signature, NID_pkcs7_data)) { - - return openssl_error(ERR_peek_last_error()); - } - - if (!PKCS7_add_certificate(p_out_signature, p_cert.certificate)) { - - return openssl_error(ERR_peek_last_error()); - } - - asn1::SPCIndirectDataContent* idc = asn1::SPCIndirectDataContent_new(); - - MakeIndirectDataContent(*idc); - EncodedASN1 idc_encoded = - EncodedASN1::FromItem(idc); - - BIO* signed_data = PKCS7_dataInit(p_out_signature, NULL); - - if (idc_encoded.size() < 2) { - - ERR_EXPLAIN("Invalid encoded size"); - ERR_FAIL_V(FAILED); - } - - if ((idc_encoded.data()[1] & 0x80) == 0x00) { - - ERR_EXPLAIN("Invalid encoded data"); - ERR_FAIL_V(FAILED); - } - - size_t skip = 4; - - if (BIO_write(signed_data, idc_encoded.data() + skip, idc_encoded.size() - skip) - != idc_encoded.size() - skip) { - - return openssl_error(ERR_peek_last_error()); - } - if (BIO_flush(signed_data) != 1) { - - return openssl_error(ERR_peek_last_error()); - } - - if (!PKCS7_dataFinal(p_out_signature, signed_data)) { - - return openssl_error(ERR_peek_last_error()); - } - - PKCS7* content = PKCS7_new(); - if (!content) { - - return openssl_error(ERR_peek_last_error()); - } - - content->type = OBJ_txt2obj(SPC_INDIRECT_DATA_OBJID, 1); - - ASN1_TYPE* idc_sequence = idc_encoded.ToSequenceType(); - content->d.other = idc_sequence; - - if (!PKCS7_set_content(p_out_signature, content)) { - - return openssl_error(ERR_peek_last_error()); - } - - return OK; -} - -#endif // OPENSSL_ENABLED - -//////////////////////////////////////////////////////////////////// - - -bool EditorExportPlatformWinrt::_valid_resource_name(const String &p_name) const { - - if (p_name.empty()) return false; - if (p_name.ends_with(".")) return false; - - static const char* invalid_names[] = { - "CON","PRN","AUX","NUL","COM1","COM2","COM3","COM4","COM5","COM6","COM7", - "COM8","COM9","LPT1","LPT2","LPT3","LPT4","LPT5","LPT6","LPT7","LPT8","LPT9", - NULL - }; - - const char** t = invalid_names; - while (*t) { - if (p_name == *t) return false; - t++; - } - - return true; -} - -bool EditorExportPlatformWinrt::_valid_guid(const String & p_guid) const { - - Vector parts = p_guid.split("-"); - - if (parts.size() != 5) return false; - if (parts[0].length() != 8) return false; - for (int i = 1; i < 4; i++) - if (parts[i].length() != 4) return false; - if (parts[4].length() != 12) return false; - - return true; -} - -bool EditorExportPlatformWinrt::_valid_bgcolor(const String & p_color) const { - - if (p_color.empty()) return true; - if (p_color.begins_with("#") && p_color.is_valid_html_color()) return true; - - // Colors from https://msdn.microsoft.com/en-us/library/windows/apps/dn934817.aspx - static const char* valid_colors[] = { - "aliceBlue","antiqueWhite","aqua","aquamarine","azure","beige", - "bisque","black","blanchedAlmond","blue","blueViolet","brown", - "burlyWood","cadetBlue","chartreuse","chocolate","coral","cornflowerBlue", - "cornsilk","crimson","cyan","darkBlue","darkCyan","darkGoldenrod", - "darkGray","darkGreen","darkKhaki","darkMagenta","darkOliveGreen","darkOrange", - "darkOrchid","darkRed","darkSalmon","darkSeaGreen","darkSlateBlue","darkSlateGray", - "darkTurquoise","darkViolet","deepPink","deepSkyBlue","dimGray","dodgerBlue", - "firebrick","floralWhite","forestGreen","fuchsia","gainsboro","ghostWhite", - "gold","goldenrod","gray","green","greenYellow","honeydew", - "hotPink","indianRed","indigo","ivory","khaki","lavender", - "lavenderBlush","lawnGreen","lemonChiffon","lightBlue","lightCoral","lightCyan", - "lightGoldenrodYellow","lightGreen","lightGray","lightPink","lightSalmon","lightSeaGreen", - "lightSkyBlue","lightSlateGray","lightSteelBlue","lightYellow","lime","limeGreen", - "linen","magenta","maroon","mediumAquamarine","mediumBlue","mediumOrchid", - "mediumPurple","mediumSeaGreen","mediumSlateBlue","mediumSpringGreen","mediumTurquoise","mediumVioletRed", - "midnightBlue","mintCream","mistyRose","moccasin","navajoWhite","navy", - "oldLace","olive","oliveDrab","orange","orangeRed","orchid", - "paleGoldenrod","paleGreen","paleTurquoise","paleVioletRed","papayaWhip","peachPuff", - "peru","pink","plum","powderBlue","purple","red", - "rosyBrown","royalBlue","saddleBrown","salmon","sandyBrown","seaGreen", - "seaShell","sienna","silver","skyBlue","slateBlue","slateGray", - "snow","springGreen","steelBlue","tan","teal","thistle", - "tomato","transparent","turquoise","violet","wheat","white", - "whiteSmoke","yellow","yellowGreen", - NULL - }; - - const char** color = valid_colors; - - while(*color) { - if (p_color == *color) return true; - color++; - } - - return false; -} - -bool EditorExportPlatformWinrt::_valid_image(const Ref p_image, int p_width, int p_height) const { - - if (!p_image.is_valid()) return false; - - // TODO: Add resource creation or image rescaling to enable other scales: - // 1.25, 1.5, 2.0 - real_t scales[] = { 1.0 }; - bool valid_w = false; - bool valid_h = false; - - for (int i = 0; i < 1; i++) { - - int w = ceil(p_width * scales[i]); - int h = ceil(p_height * scales[i]); - - if (w == p_image->get_width()) - valid_w = true; - if (h == p_image->get_height()) - valid_h = true; - } - - return valid_w && valid_h; -} - -Vector EditorExportPlatformWinrt::_fix_manifest(const Vector &p_template, bool p_give_internet) const { - - String result = String::utf8((const char*)p_template.ptr(), p_template.size()); - - result = result.replace("$godot_version$", VERSION_FULL_NAME); - - result = result.replace("$identity_name$", unique_name); - result = result.replace("$publisher$", publisher); - - result = result.replace("$product_guid$", product_guid); - result = result.replace("$publisher_guid$", publisher_guid); - - String version = itos(version_major) + "." + itos(version_minor) + "." + itos(version_build) + "." + itos(version_revision); - result = result.replace("$version_string$", version); - - String architecture = arch == ARM ? "ARM" : arch == X86 ? "x86" : "x64"; - result = result.replace("$architecture$", architecture); - - result = result.replace("$display_name$", display_name.empty() ? (String)Globals::get_singleton()->get("application/name") : display_name); - result = result.replace("$publisher_display_name$", publisher_display_name); - result = result.replace("$app_description$", description); - result = result.replace("$bg_color$", background_color); - result = result.replace("$short_name$", short_name); - - String name_on_tiles = ""; - if (name_on_square150) { - name_on_tiles += " \n"; - } - if (name_on_wide) { - name_on_tiles += " \n"; - } - if (name_on_square310) { - name_on_tiles += " \n"; - } - - String show_name_on_tiles = ""; - if (!name_on_tiles.empty()) { - show_name_on_tiles = "\n" + name_on_tiles + " "; - } - - result = result.replace("$name_on_tiles$", name_on_tiles); - - String rotations = ""; - if (orientation_landscape) { - rotations += " \n"; - } - if (orientation_portrait) { - rotations += " \n"; - } - if (orientation_landscape_flipped) { - rotations += " \n"; - } - if (orientation_portrait_flipped) { - rotations += " \n"; - } - - String rotation_preference = ""; - if (!rotations.empty()) { - rotation_preference = "\n" + rotations + " "; - } - - result = result.replace("$rotation_preference$", rotation_preference); - - String capabilities_elements = ""; - const char **basic = uwp_capabilities; - while (*basic) { - if (capabilities.has(*basic)) { - capabilities_elements += " \n"; - } - basic++; - } - const char **uap = uwp_uap_capabilities; - while (*uap) { - if (uap_capabilities.has(*uap)) { - capabilities_elements += " \n"; - } - uap++; - } - const char **device = uwp_device_capabilites; - while (*device) { - if (uap_capabilities.has(*device)) { - capabilities_elements += " \n"; - } - device++; - } - - if (!capabilities.has("internetClient") && p_give_internet) { - capabilities_elements += " \n"; - } - - String capabilities_string = ""; - if (!capabilities_elements.empty()) { - capabilities_string = "\n" + capabilities_elements + " "; - } - - result = result.replace("$capabilities_place$", capabilities_string); - - Vector r_ret; - r_ret.resize(result.length()); - - for (int i = 0; i < result.length(); i++) - r_ret[i] = result.utf8().get(i); - - return r_ret; -} - -Vector EditorExportPlatformWinrt::_get_image_data(const String & p_path) { - - Vector data; - Ref ref; - - if (p_path.find("StoreLogo") != -1) { - ref = store_logo; - } else if (p_path.find("Square44x44Logo") != -1) { - ref = square44; - } else if (p_path.find("Square71x71Logo") != -1) { - ref = square71; - } else if (p_path.find("Square150x150Logo") != -1) { - ref = square150; - } else if (p_path.find("Square310x310Logo") != -1) { - ref = square310; - } else if (p_path.find("Wide310x150Logo") != -1) { - ref = wide310; - } else if (p_path.find("SplashScreen") != -1) { - ref = splash; - } - - if (!ref.is_valid()) return data; - - - String tmp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/uwp_tmp_logo.png"); - - Error err = ref->get_data().save_png(tmp_path); - - if (err != OK) { - - String err_string = "Couldn't save temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } - - FileAccess* f = FileAccess::open(tmp_path, FileAccess::READ, &err); - - if (err != OK) { - - String err_string = "Couldn't open temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } - - data.resize(f->get_len()); - f->get_buffer(data.ptr(), data.size()); - - f->close(); - memdelete(f); - - // Delete temp file - DirAccess* dir = DirAccess::open(tmp_path.get_base_dir(), &err); - - if (err != OK) { - - String err_string = "Couldn't open temp path to remove temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } - - err = dir->remove(tmp_path); - - memdelete(dir); - - if (err != OK) { - - String err_string = "Couldn't remove temp logo file."; - - EditorNode::add_io_error(err_string); - ERR_EXPLAIN(err_string); - ERR_FAIL_V(data); - } - - return data; -} - -Error EditorExportPlatformWinrt::save_appx_file(void * p_userdata, const String & p_path, const Vector& p_data, int p_file, int p_total) { - - AppxPackager *packager = (AppxPackager*)p_userdata; - String dst_path = p_path.replace_first("res://", "game/"); - - packager->add_file(dst_path, p_data.ptr(), p_data.size(), p_file, p_total, _should_compress_asset(p_path, p_data)); - - return OK; -} - -bool EditorExportPlatformWinrt::_should_compress_asset(const String & p_path, const Vector& p_data) { - - /* TODO: This was copied verbatim from Android export. It should be - * refactored to the parent class and also be used for .zip export. - */ - - /* - * By not compressing files with little or not benefit in doing so, - * a performance gain is expected at runtime. Moreover, if the APK is - * zip-aligned, assets stored as they are can be efficiently read by - * Android by memory-mapping them. - */ - - // -- Unconditional uncompress to mimic AAPT plus some other - - static const char* unconditional_compress_ext[] = { - // From https://github.com/android/platform_frameworks_base/blob/master/tools/aapt/Package.cpp - // These formats are already compressed, or don't compress well: - ".jpg", ".jpeg", ".png", ".gif", - ".wav", ".mp2", ".mp3", ".ogg", ".aac", - ".mpg", ".mpeg", ".mid", ".midi", ".smf", ".jet", - ".rtttl", ".imy", ".xmf", ".mp4", ".m4a", - ".m4v", ".3gp", ".3gpp", ".3g2", ".3gpp2", - ".amr", ".awb", ".wma", ".wmv", - // Godot-specific: - ".webp", // Same reasoning as .png - ".cfb", // Don't let small config files slow-down startup - // Trailer for easier processing - NULL - }; - - for (const char** ext = unconditional_compress_ext; *ext; ++ext) { - if (p_path.to_lower().ends_with(String(*ext))) { - return false; - } - } - - // -- Compressed resource? - - if (p_data.size() >= 4 && p_data[0] == 'R' && p_data[1] == 'S' && p_data[2] == 'C' && p_data[3] == 'C') { - // Already compressed - return false; - } - - // --- TODO: Decide on texture resources according to their image compression setting - - return true; -} - -bool EditorExportPlatformWinrt::_set(const StringName& p_name, const Variant& p_value) { - - String n = p_name; - - if (n == "architecture/target") - arch = (Platform)((int)p_value); - else if (n == "custom_package/debug") - custom_debug_package = p_value; - else if (n == "custom_package/release") - custom_release_package = p_value; - else if (n == "command_line/extra_args") - cmdline = p_value; - else if (n == "package/display_name") - display_name = p_value; - else if (n == "package/short_name") - short_name = p_value; - else if (n == "package/unique_name") - unique_name = p_value; - else if (n == "package/description") - description = p_value; - else if (n == "package/publisher") - publisher = p_value; - else if (n == "package/publisher_display_name") - publisher_display_name = p_value; - else if (n == "identity/product_guid") - product_guid = p_value; - else if (n == "identity/publisher_guid") - publisher_guid = p_value; - else if (n == "version/major") - version_major = p_value; - else if (n == "version/minor") - version_minor = p_value; - else if (n == "version/build") - version_build = p_value; - else if (n == "version/revision") - version_revision = p_value; - else if (n == "orientation/landscape") - orientation_landscape = p_value; - else if (n == "orientation/portrait") - orientation_portrait = p_value; - else if (n == "orientation/landscape_flipped") - orientation_landscape_flipped = p_value; - else if (n == "orientation/portrait_flipped") - orientation_portrait_flipped = p_value; - else if (n == "images/background_color") - background_color = p_value; - else if (n == "images/store_logo") - store_logo = p_value; - else if (n == "images/square44x44_logo") - square44 = p_value; - else if (n == "images/square71x71_logo") - square71 = p_value; - else if (n == "images/square150x150_logo") - square150 = p_value; - else if (n == "images/square310x310_logo") - square310 = p_value; - else if (n == "images/wide310x150_logo") - wide310 = p_value; - else if (n == "images/splash_screen") - splash = p_value; - else if (n == "tiles/show_name_on_square150x150") - name_on_square150 = p_value; - else if (n == "tiles/show_name_on_wide310x150") - name_on_wide = p_value; - else if (n == "tiles/show_name_on_square310x310") - name_on_square310 = p_value; - -#if 0 // Signing disabled - else if (n == "signing/sign") - sign_package = p_value; - else if (n == "signing/certificate_file") - certificate_path = p_value; - else if (n == "signing/certificate_password") - certificate_pass = p_value; -#endif - else if (n.begins_with("capabilities/")) { - - String what = n.get_slice("/", 1).replace("_", ""); - bool enable = p_value; - - if (array_has(uwp_capabilities, what.utf8().get_data())) { - - if (enable) - capabilities.insert(what); - else - capabilities.erase(what); - - } else if (array_has(uwp_uap_capabilities, what.utf8().get_data())) { - - if (enable) - uap_capabilities.insert(what); - else - uap_capabilities.erase(what); - - } else if (array_has(uwp_device_capabilites, what.utf8().get_data())) { - - if (enable) - device_capabilities.insert(what); - else - device_capabilities.erase(what); - } - } else return false; - - return true; -} - -bool EditorExportPlatformWinrt::_get(const StringName& p_name, Variant &r_ret) const { - - String n = p_name; - - if (n == "architecture/target") - r_ret = (int)arch; - else if (n == "custom_package/debug") - r_ret = custom_debug_package; - else if (n == "custom_package/release") - r_ret = custom_release_package; - else if (n == "command_line/extra_args") - r_ret = cmdline; - else if (n == "package/display_name") - r_ret = display_name; - else if (n == "package/short_name") - r_ret = short_name; - else if (n == "package/unique_name") - r_ret = unique_name; - else if (n == "package/description") - r_ret = description; - else if (n == "package/publisher") - r_ret = publisher; - else if (n == "package/publisher_display_name") - r_ret = publisher_display_name; - else if (n == "identity/product_guid") - r_ret = product_guid; - else if (n == "identity/publisher_guid") - r_ret = publisher_guid; - else if (n == "version/major") - r_ret = version_major; - else if (n == "version/minor") - r_ret = version_minor; - else if (n == "version/build") - r_ret = version_build; - else if (n == "version/revision") - r_ret = version_revision; - else if (n == "orientation/landscape") - r_ret = orientation_landscape; - else if (n == "orientation/portrait") - r_ret = orientation_portrait; - else if (n == "orientation/landscape_flipped") - r_ret = orientation_landscape_flipped; - else if (n == "orientation/portrait_flipped") - r_ret = orientation_portrait_flipped; - else if (n == "images/background_color") - r_ret = background_color; - else if (n == "images/store_logo") - r_ret = store_logo; - else if (n == "images/square44x44_logo") - r_ret = square44; - else if (n == "images/square71x71_logo") - r_ret = square71; - else if (n == "images/square150x150_logo") - r_ret = square150; - else if (n == "images/square310x310_logo") - r_ret = square310; - else if (n == "images/wide310x150_logo") - r_ret = wide310; - else if (n == "images/splash_screen") - r_ret = splash; - else if (n == "tiles/show_name_on_square150x150") - r_ret = name_on_square150; - else if (n == "tiles/show_name_on_wide310x150") - r_ret = name_on_wide; - else if (n == "tiles/show_name_on_square310x310") - r_ret = name_on_square310; - -#if 0 // Signing disabled - else if (n == "signing/sign") - r_ret = sign_package; - else if (n == "signing/certificate_file") - r_ret = certificate_path; - else if (n == "signing/certificate_password") - r_ret = certificate_pass; -#endif - else if (n.begins_with("capabilities/")) { - - String what = n.get_slice("/", 1).replace("_", ""); - - if (array_has(uwp_capabilities, what.utf8().get_data())) { - - r_ret = capabilities.has(what); - - } else if (array_has(uwp_uap_capabilities, what.utf8().get_data())) { - - r_ret = uap_capabilities.has(what); - - } else if (array_has(uwp_device_capabilites, what.utf8().get_data())) { - - r_ret = device_capabilities.has(what); - } - } else return false; - - return true; -} - -void EditorExportPlatformWinrt::_get_property_list(List* p_list) const { - - p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "appx")); - p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "appx")); - - p_list->push_back(PropertyInfo(Variant::INT, "architecture/target", PROPERTY_HINT_ENUM, "ARM,x86,x64")); - - p_list->push_back(PropertyInfo(Variant::STRING, "command_line/extra_args")); - - p_list->push_back(PropertyInfo(Variant::STRING, "package/display_name")); - p_list->push_back(PropertyInfo(Variant::STRING, "package/short_name")); - p_list->push_back(PropertyInfo(Variant::STRING, "package/unique_name")); - p_list->push_back(PropertyInfo(Variant::STRING, "package/description")); - p_list->push_back(PropertyInfo(Variant::STRING, "package/publisher")); - p_list->push_back(PropertyInfo(Variant::STRING, "package/publisher_display_name")); - - p_list->push_back(PropertyInfo(Variant::STRING, "identity/product_guid")); - p_list->push_back(PropertyInfo(Variant::STRING, "identity/publisher_guid")); - - p_list->push_back(PropertyInfo(Variant::INT, "version/major")); - p_list->push_back(PropertyInfo(Variant::INT, "version/minor")); - p_list->push_back(PropertyInfo(Variant::INT, "version/build")); - p_list->push_back(PropertyInfo(Variant::INT, "version/revision")); - - p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/landscape")); - p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/portrait")); - p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/landscape_flipped")); - p_list->push_back(PropertyInfo(Variant::BOOL, "orientation/portrait_flipped")); - - p_list->push_back(PropertyInfo(Variant::STRING, "images/background_color")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "images/store_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square44x44_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square71x71_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square150x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "images/square310x310_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "images/wide310x150_logo", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); - p_list->push_back(PropertyInfo(Variant::OBJECT, "images/splash_screen", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture")); - - p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square150x150")); - p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_wide310x150")); - p_list->push_back(PropertyInfo(Variant::BOOL, "tiles/show_name_on_square310x310")); - -#if 0 // Signing does not work :( disabling for now - p_list->push_back(PropertyInfo(Variant::BOOL, "signing/sign")); - p_list->push_back(PropertyInfo(Variant::STRING, "signing/certificate_file", PROPERTY_HINT_GLOBAL_FILE, "pfx")); - p_list->push_back(PropertyInfo(Variant::STRING, "signing/certificate_password")); -#endif - - // Capabilites - const char **basic = uwp_capabilities; - while (*basic) { - p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*basic).camelcase_to_underscore(false))); - basic++; - } - - const char **uap = uwp_uap_capabilities; - while (*uap) { - p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*uap).camelcase_to_underscore(false))); - uap++; - } - - const char **device = uwp_device_capabilites; - while (*device) { - p_list->push_back(PropertyInfo(Variant::BOOL, "capabilities/" + String(*device).camelcase_to_underscore(false))); - device++; - } - -} - -bool EditorExportPlatformWinrt::can_export(String * r_error) const { - - String err; - bool valid = true; - - if (!exists_export_template("winrt_x86_debug.zip") || !exists_export_template("winrt_x86_release.zip") - || !exists_export_template("winrt_arm_debug.zip") || !exists_export_template("winrt_arm_release.zip") - || !exists_export_template("winrt_x64_debug.zip") || !exists_export_template("winrt_x64_release.zip")) { - valid = false; - err += TTR("No export templates found.\nDownload and install export templates.") + "\n"; - } - - if (custom_debug_package != "" && !FileAccess::exists(custom_debug_package)) { - valid = false; - err += TTR("Custom debug package not found.") + "\n"; - } - - if (custom_release_package != "" && !FileAccess::exists(custom_release_package)) { - valid = false; - err += TTR("Custom release package not found.") + "\n"; - } - - if (!_valid_resource_name(unique_name)) { - valid = false; - err += TTR("Invalid unique name.") + "\n"; - } - - if (!_valid_guid(product_guid)) { - valid = false; - err += TTR("Invalid product GUID.") + "\n"; - } - - if (!_valid_guid(publisher_guid)) { - valid = false; - err += TTR("Invalid publisher GUID.") + "\n"; - } - - if (!_valid_bgcolor(background_color)) { - valid = false; - err += TTR("Invalid background color.") + "\n"; - } - - if (store_logo.is_valid() && !_valid_image(store_logo, 50, 50)) { - valid = false; - err += TTR("Invalid Store Logo image dimensions (should be 50x50).") + "\n"; - } - - if (square44.is_valid() && !_valid_image(square44, 44, 44)) { - valid = false; - err += TTR("Invalid square 44x44 logo image dimensions (should be 44x44).") + "\n"; - } - - if (square71.is_valid() && !_valid_image(square71, 71, 71)) { - valid = false; - err += TTR("Invalid square 71x71 logo image dimensions (should be 71x71).") + "\n"; - } - - if (square150.is_valid() && !_valid_image(square150, 150, 150)) { - valid = false; - err += TTR("Invalid square 150x150 logo image dimensions (should be 150x150).") + "\n"; - } - - if (square310.is_valid() && !_valid_image(square310, 310, 310)) { - valid = false; - err += TTR("Invalid square 310x310 logo image dimensions (should be 310x310).") + "\n"; - } - - if (wide310.is_valid() && !_valid_image(wide310, 310, 150)) { - valid = false; - err += TTR("Invalid wide 310x150 logo image dimensions (should be 310x150).") + "\n"; - } - - if (splash.is_valid() && !_valid_image(splash, 620, 300)) { - valid = false; - err += TTR("Invalid splash screen image dimensions (should be 620x300).") + "\n"; - } - - if (r_error) - *r_error = err; - - return valid; -} - -Error EditorExportPlatformWinrt::export_project(const String & p_path, bool p_debug, int p_flags) { - - String src_appx; - - EditorProgress ep("export", "Exporting for Windows Universal", 7); - - if (is_debug) - src_appx = custom_debug_package; - else - src_appx = custom_release_package; - - if (src_appx == "") { - String err; - if (p_debug) { - switch (arch) { - case X86: { - src_appx = find_export_template("winrt_x86_debug.zip", &err); - break; - } - case X64: { - src_appx = find_export_template("winrt_x64_debug.zip", &err); - break; - } - case ARM: { - src_appx = find_export_template("winrt_arm_debug.zip", &err); - break; - } - } - } else { - switch (arch) { - case X86: { - src_appx = find_export_template("winrt_x86_release.zip", &err); - break; - } - case X64: { - src_appx = find_export_template("winrt_x64_release.zip", &err); - break; - } - case ARM: { - src_appx = find_export_template("winrt_arm_release.zip", &err); - break; - } - } - } - if (src_appx == "") { - EditorNode::add_io_error(err); - return ERR_FILE_NOT_FOUND; - } - } - - Error err = OK; - - FileAccess *fa_pack = FileAccess::open(p_path, FileAccess::WRITE, &err); - ERR_FAIL_COND_V(err != OK, ERR_CANT_CREATE); - - AppxPackager packager; - packager.init(fa_pack, sign_package ? AppxPackager::SIGN : AppxPackager::DONT_SIGN, certificate_path, certificate_pass); - - FileAccess *src_f = NULL; - zlib_filefunc_def io = zipio_create_io_from_file(&src_f); - - ep.step("Creating package...", 0); - - unzFile pkg = unzOpen2(src_appx.utf8().get_data(), &io); - - if (!pkg) { - - EditorNode::add_io_error("Could not find template appx to export:\n" + src_appx); - return ERR_FILE_NOT_FOUND; - } - - int ret = unzGoToFirstFile(pkg); - - ep.step("Copying template files...", 1); - - EditorNode::progress_add_task("template_files", "Template files", 100); - packager.set_progress_task("template_files"); - - int template_files_amount = 9; - int template_file_no = 1; - - while (ret == UNZ_OK) { - - // get file name - unz_file_info info; - char fname[16834]; - ret = unzGetCurrentFileInfo(pkg, &info, fname, 16834, NULL, 0, NULL, 0); - - String path = fname; - - if (path.ends_with("/")) { - // Ignore directories - ret = unzGoToNextFile(pkg); - continue; - } - - Vector data; - bool do_read = true; - - if (path.begins_with("Assets/")) { - - path = path.replace(".scale-100", ""); - - data = _get_image_data(path); - if (data.size() > 0) do_read = false; - } - - //read - if (do_read) { - data.resize(info.uncompressed_size); - unzOpenCurrentFile(pkg); - unzReadCurrentFile(pkg, data.ptr(), data.size()); - unzCloseCurrentFile(pkg); - } - - if (path == "AppxManifest.xml") { - - data = _fix_manifest(data, p_flags&(EXPORT_DUMB_CLIENT | EXPORT_REMOTE_DEBUG)); - } - - print_line("ADDING: " + path); - - packager.add_file(path, data.ptr(), data.size(), template_file_no++, template_files_amount, _should_compress_asset(path, data)); - - ret = unzGoToNextFile(pkg); - } - - EditorNode::progress_end_task("template_files"); - - ep.step("Creating command line...", 2); - - Vector cl = cmdline.strip_edges().split(" "); - for (int i = 0;i clf; - - // Argc - clf.resize(4); - encode_uint32(cl.size(), clf.ptr()); - - for (int i = 0; i < cl.size(); i++) { - - CharString txt = cl[i].utf8(); - int base = clf.size(); - clf.resize(base + 4 + txt.length()); - encode_uint32(txt.length(), &clf[base]); - copymem(&clf[base + 4], txt.ptr(), txt.length()); - print_line(itos(i) + " param: " + cl[i]); - } - - packager.add_file("__cl__.cl", clf.ptr(), clf.size(), -1, -1, false); - - ep.step("Adding project files...", 3); - - EditorNode::progress_add_task("project_files", "Project Files", 100); - packager.set_progress_task("project_files"); - - err = export_project_files(save_appx_file, &packager, false); - - EditorNode::progress_end_task("project_files"); - - ep.step("Closing package...", 7); - - unzClose(pkg); - - packager.finish(); - - return OK; -} - -EditorExportPlatformWinrt::EditorExportPlatformWinrt() { - - Image img(_winrt_logo); - logo = Ref(memnew(ImageTexture)); - logo->create_from_image(img); - - is_debug = true; - - custom_release_package = ""; - custom_debug_package = ""; - - arch = X86; - - display_name = ""; - short_name = "Godot"; - unique_name = "Godot.Engine"; - description = "Godot Engine"; - publisher = "CN=GodotEngine"; - publisher_display_name = "Godot Engine"; - - product_guid = "00000000-0000-0000-0000-000000000000"; - publisher_guid = "00000000-0000-0000-0000-000000000000"; - - version_major = 1; - version_minor = 0; - version_build = 0; - version_revision = 0; - - orientation_landscape = true; - orientation_portrait = true; - orientation_landscape_flipped = true; - orientation_portrait_flipped = true; - - background_color = "transparent"; - - name_on_square150 = false; - name_on_square310 = false; - name_on_wide = false; - - sign_package = false; - certificate_path = ""; - certificate_pass = ""; -} - -EditorExportPlatformWinrt::~EditorExportPlatformWinrt() {} - - -void register_winrt_exporter() { - - Ref exporter = Ref(memnew(EditorExportPlatformWinrt)); - EditorImportExport::get_singleton()->add_export_platform(exporter); -} diff --git a/platform/winrt/export/export.h b/platform/winrt/export/export.h deleted file mode 100644 index 278d6d23cd..0000000000 --- a/platform/winrt/export/export.h +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************/ -/* export.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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. */ -/*************************************************************************/ -void register_winrt_exporter(); diff --git a/platform/winrt/gl_context_egl.cpp b/platform/winrt/gl_context_egl.cpp deleted file mode 100644 index f7b514b3c0..0000000000 --- a/platform/winrt/gl_context_egl.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/*************************************************************************/ -/* gl_context_egl.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 namespace Platform; - -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 = 0; - EGLDisplay display = EGL_NO_DISPLAY; - EGLContext context = EGL_NO_CONTEXT; - EGLSurface surface = EGL_NO_SURFACE; - EGLConfig config = nullptr; - EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, 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) : - mEglDisplay(EGL_NO_DISPLAY), - mEglContext(EGL_NO_CONTEXT), - mEglSurface(EGL_NO_SURFACE) - { - - window = p_window; -}; - -ContextEGL::~ContextEGL() { - - cleanup(); -}; - diff --git a/platform/winrt/gl_context_egl.h b/platform/winrt/gl_context_egl.h deleted file mode 100644 index 8124c2903d..0000000000 --- a/platform/winrt/gl_context_egl.h +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************/ -/* gl_context_egl.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 "os/os.h" -#include "EGL/egl.h" -#include "error_list.h" -#include "drivers/gl_context/context_gl.h" - -using namespace Windows::UI::Core; - -class ContextEGL : public ContextGL { - - CoreWindow^ window; - - EGLDisplay mEglDisplay; - EGLContext mEglContext; - EGLSurface mEglSurface; - - EGLint width; - EGLint height; - - bool vsync; - -public: - - virtual void release_current(); - - virtual void make_current(); - - virtual int get_window_width(); - virtual int get_window_height(); - virtual void swap_buffers(); - - void set_use_vsync(bool use) { vsync = use; } - bool is_using_vsync() const { return vsync; } - - virtual Error initialize(); - void reset(); - - void cleanup(); - - ContextEGL(CoreWindow^ p_window); - ~ContextEGL(); - -}; - -#endif - diff --git a/platform/winrt/joystick_winrt.cpp b/platform/winrt/joystick_winrt.cpp deleted file mode 100644 index 9f93c5a26b..0000000000 --- a/platform/winrt/joystick_winrt.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/*************************************************************************/ -/* joystick.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 "joystick_winrt.h" - -using namespace Windows::Gaming::Input; -using namespace Windows::Foundation; - -void JoystickWinrt::register_events() { - - Gamepad::GamepadAdded += - ref new EventHandler(this, &JoystickWinrt::OnGamepadAdded); - Gamepad::GamepadRemoved += - ref new EventHandler(this, &JoystickWinrt::OnGamepadRemoved); -} - -uint32_t JoystickWinrt::process_controllers(uint32_t p_last_id) { - - for (int i = 0; i < MAX_CONTROLLERS; i++) { - - if (!controllers[i].connected) break; - - switch (controllers[i].type) { - - case ControllerType::GAMEPAD_CONTROLLER: { - - GamepadReading reading = ((Gamepad^)controllers[i].controller_reference)->GetCurrentReading(); - - int button_mask = (int)GamepadButtons::Menu; - for (int j = 0; j < 14; j++) { - - p_last_id = input->joy_button(p_last_id, controllers[i].id, j,(int)reading.Buttons & button_mask); - button_mask *= 2; - } - - p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_0, axis_correct(reading.LeftThumbstickX)); - p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_1, axis_correct(reading.LeftThumbstickY, true)); - p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_2, axis_correct(reading.RightThumbstickX)); - p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_3, axis_correct(reading.RightThumbstickY, true)); - p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_4, axis_correct(reading.LeftTrigger, false, true)); - p_last_id = input->joy_axis(p_last_id, controllers[i].id, JOY_AXIS_5, axis_correct(reading.RightTrigger, false, true)); - - break; - } - } - } - - return p_last_id; -} - -JoystickWinrt::JoystickWinrt() { - - for (int i = 0; i < MAX_CONTROLLERS; i++) - controllers[i].id = i; -} - -JoystickWinrt::JoystickWinrt(InputDefault * p_input) { - - input = p_input; - - JoystickWinrt(); -} - -void JoystickWinrt::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { - - short idx = -1; - - for (int i = 0; i < MAX_CONTROLLERS; i++) { - - if (!controllers[i].connected) { - idx = i; - break; - } - } - - ERR_FAIL_COND(idx == -1); - - controllers[idx].connected = true; - controllers[idx].controller_reference = value; - controllers[idx].id = idx; - controllers[idx].type = ControllerType::GAMEPAD_CONTROLLER; - - input->joy_connection_changed(controllers[idx].id, true, "Xbox Controller", "__WINRT_GAMEPAD__"); -} - -void JoystickWinrt::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { - - short idx = -1; - - for (int i = 0; i < MAX_CONTROLLERS; i++) { - - if (controllers[i].controller_reference == value) { - idx = i; - break; - } - } - - ERR_FAIL_COND(idx == -1); - - for (int i = idx + 1; i < MAX_CONTROLLERS - 1; i++) { - - if (!controllers[i].connected) { - break; - } - - controllers[i - 1] = controllers[i]; - } - controllers[MAX_CONTROLLERS - 1] = ControllerDevice(); - - input->joy_connection_changed(idx, false, "Xbox Controller"); -} - -InputDefault::JoyAxis JoystickWinrt::axis_correct(double p_val, bool p_negate, bool p_trigger) const { - - InputDefault::JoyAxis jx; - - jx.min = p_trigger ? 0 : -1; - jx.value = (float)(p_negate ? -p_val : p_val); - - return jx; -} diff --git a/platform/winrt/joystick_winrt.h b/platform/winrt/joystick_winrt.h deleted file mode 100644 index 17f9565708..0000000000 --- a/platform/winrt/joystick_winrt.h +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************/ -/* joystick.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 JOYSTICK_WINRT_H -#define JOYSTICK_WINRT_H - -#include "main/input_default.h" - -ref class JoystickWinrt sealed { - -internal: - - void register_events(); - uint32_t process_controllers(uint32_t p_last_id); - - JoystickWinrt(); - JoystickWinrt(InputDefault* p_input); - -private: - - enum { - MAX_CONTROLLERS = 4, - }; - - enum ControllerType { - GAMEPAD_CONTROLLER, - ARCADE_STICK_CONTROLLER, - RACING_WHEEL_CONTROLLER, - }; - - struct ControllerDevice { - - Windows::Gaming::Input::IGameController^ controller_reference; - - int id; - bool connected; - ControllerType type; - - ControllerDevice() { - id = -1; - connected = false; - type = ControllerType::GAMEPAD_CONTROLLER; - } - }; - - ControllerDevice controllers[MAX_CONTROLLERS]; - - InputDefault* input; - - void OnGamepadAdded(Platform::Object^ sender, Windows::Gaming::Input::Gamepad^ value); - void OnGamepadRemoved(Platform::Object^ sender, Windows::Gaming::Input::Gamepad^ value); - - InputDefault::JoyAxis axis_correct(double p_val, bool p_negate = false, bool p_trigger = false) const; -}; - -#endif diff --git a/platform/winrt/logo.png b/platform/winrt/logo.png deleted file mode 100644 index 4376abd563..0000000000 Binary files a/platform/winrt/logo.png and /dev/null differ diff --git a/platform/winrt/os_winrt.cpp b/platform/winrt/os_winrt.cpp deleted file mode 100644 index 4b23f3960e..0000000000 --- a/platform/winrt/os_winrt.cpp +++ /dev/null @@ -1,983 +0,0 @@ -/*************************************************************************/ -/* os_winrt.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 "drivers/gles2/rasterizer_gles2.h" -#include "os_winrt.h" -#include "drivers/unix/memory_pool_static_malloc.h" -#include "os/memory_pool_dynamic_static.h" -#include "thread_winrt.h" -#include "drivers/windows/semaphore_windows.h" -#include "drivers/windows/mutex_windows.h" -#include "main/main.h" -#include "drivers/windows/file_access_windows.h" -#include "drivers/windows/dir_access_windows.h" - - -#include "servers/visual/visual_server_raster.h" -#include "servers/audio/audio_server_sw.h" -#include "servers/visual/visual_server_wrap_mt.h" - -#include "os/memory_pool_dynamic_prealloc.h" -#include "globals.h" -#include "io/marshalls.h" - -#include "platform/windows/packet_peer_udp_winsock.h" -#include "platform/windows/stream_peer_winsock.h" -#include "platform/windows/tcp_server_winsock.h" -#include "drivers/unix/ip_unix.h" - -#include -#include - -using namespace Windows::ApplicationModel::Core; -using namespace Windows::ApplicationModel::Activation; -using namespace Windows::UI::Core; -using namespace Windows::UI::Input; -using namespace Windows::UI::Popups; -using namespace Windows::Foundation; -using namespace Windows::Graphics::Display; -using namespace Microsoft::WRL; -using namespace Windows::UI::ViewManagement; -using namespace Windows::Devices::Input; -using namespace Windows::Devices::Sensors; -using namespace Windows::ApplicationModel::DataTransfer; -using namespace concurrency; - - -int OSWinrt::get_video_driver_count() const { - - return 1; -} -const char * OSWinrt::get_video_driver_name(int p_driver) const { - - return "GLES2"; -} - -OS::VideoMode OSWinrt::get_default_video_mode() const { - - return video_mode; -} - -Size2 OSWinrt::get_window_size() const { - Size2 size; - size.width = video_mode.width; - size.height = video_mode.height; - return size; -} - -void OSWinrt::set_window_size(const Size2 p_size) { - - Windows::Foundation::Size new_size; - new_size.Width = p_size.width; - new_size.Height = p_size.height; - - ApplicationView^ view = ApplicationView::GetForCurrentView(); - - if (view->TryResizeView(new_size)) { - - video_mode.width = p_size.width; - video_mode.height = p_size.height; - } -} - -void OSWinrt::set_window_fullscreen(bool p_enabled) { - - ApplicationView^ view = ApplicationView::GetForCurrentView(); - - video_mode.fullscreen = view->IsFullScreenMode; - - if (video_mode.fullscreen == p_enabled) - return; - - if (p_enabled) { - - video_mode.fullscreen = view->TryEnterFullScreenMode(); - - } else { - - view->ExitFullScreenMode(); - video_mode.fullscreen = false; - - } -} - -bool OSWinrt::is_window_fullscreen() const { - - return ApplicationView::GetForCurrentView()->IsFullScreenMode; -} - -void OSWinrt::set_keep_screen_on(bool p_enabled) { - - if (is_keep_screen_on() == p_enabled) return; - - if (p_enabled) - display_request->RequestActive(); - else - display_request->RequestRelease(); - - OS::set_keep_screen_on(p_enabled); -} - -int OSWinrt::get_audio_driver_count() const { - - return AudioDriverManagerSW::get_driver_count(); -} -const char * OSWinrt::get_audio_driver_name(int p_driver) const { - - AudioDriverSW* driver = AudioDriverManagerSW::get_driver(p_driver); - ERR_FAIL_COND_V( !driver, "" ); - return AudioDriverManagerSW::get_driver(p_driver)->get_name(); -} - -static MemoryPoolStatic *mempool_static=NULL; -static MemoryPoolDynamic *mempool_dynamic=NULL; - -void OSWinrt::initialize_core() { - - - last_button_state=0; - - //RedirectIOToConsole(); - - ThreadWinrt::make_default(); - SemaphoreWindows::make_default(); - MutexWindows::make_default(); - - FileAccess::make_default(FileAccess::ACCESS_RESOURCES); - FileAccess::make_default(FileAccess::ACCESS_USERDATA); - FileAccess::make_default(FileAccess::ACCESS_FILESYSTEM); - //FileAccessBufferedFA::make_default(); - DirAccess::make_default(DirAccess::ACCESS_RESOURCES); - DirAccess::make_default(DirAccess::ACCESS_USERDATA); - DirAccess::make_default(DirAccess::ACCESS_FILESYSTEM); - - //TCPServerWinsock::make_default(); - //StreamPeerWinsock::make_default(); - - TCPServerWinsock::make_default(); - StreamPeerWinsock::make_default(); - PacketPeerUDPWinsock::make_default(); - - mempool_static = new MemoryPoolStaticMalloc; -#if 1 - mempool_dynamic = memnew( MemoryPoolDynamicStatic ); -#else -#define DYNPOOL_SIZE 4*1024*1024 - void * buffer = malloc( DYNPOOL_SIZE ); - mempool_dynamic = memnew( MemoryPoolDynamicPrealloc(buffer,DYNPOOL_SIZE) ); - -#endif - - // We need to know how often the clock is updated - if( !QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_second) ) - ticks_per_second = 1000; - // If timeAtGameStart is 0 then we get the time since - // the start of the computer when we call GetGameTime() - ticks_start = 0; - ticks_start = get_ticks_usec(); - - IP_Unix::make_default(); - - cursor_shape=CURSOR_ARROW; -} - -bool OSWinrt::can_draw() const { - - return !minimized; -}; - - -void OSWinrt::set_gl_context(ContextEGL* p_context) { - - gl_context = p_context; -}; - -void OSWinrt::screen_size_changed() { - - gl_context->reset(); -}; - -void OSWinrt::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { - - main_loop=NULL; - outside=true; - - gl_context->initialize(); - VideoMode vm; - vm.width = gl_context->get_window_width(); - vm.height = gl_context->get_window_height(); - vm.resizable = false; - - ApplicationView^ view = ApplicationView::GetForCurrentView(); - vm.fullscreen = view->IsFullScreenMode; - - view->SetDesiredBoundsMode(ApplicationViewBoundsMode::UseVisible); - view->PreferredLaunchWindowingMode = ApplicationViewWindowingMode::PreferredLaunchViewSize; - - if (p_desired.fullscreen != view->IsFullScreenMode) { - if (p_desired.fullscreen) { - - vm.fullscreen = view->TryEnterFullScreenMode(); - - } else { - - view->ExitFullScreenMode(); - vm.fullscreen = false; - } - } - - Windows::Foundation::Size desired; - desired.Width = p_desired.width; - desired.Height = p_desired.height; - - view->PreferredLaunchViewSize = desired; - - if (view->TryResizeView(desired)) { - - vm.width = view->VisibleBounds.Width; - vm.height = view->VisibleBounds.Height; - } - - set_video_mode(vm); - - gl_context->make_current(); - rasterizer = memnew( RasterizerGLES2 ); - - visual_server = memnew( VisualServerRaster(rasterizer) ); - if (get_render_thread_mode()!=RENDER_THREAD_UNSAFE) { - - visual_server =memnew(VisualServerWrapMT(visual_server,get_render_thread_mode()==RENDER_SEPARATE_THREAD)); - } - - // - physics_server = memnew( PhysicsServerSW ); - physics_server->init(); - - physics_2d_server = memnew( Physics2DServerSW ); - physics_2d_server->init(); - - visual_server->init(); - - input = memnew( InputDefault ); - - joystick = ref new JoystickWinrt(input); - joystick->register_events(); - - AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); - - if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) { - - ERR_PRINT("Initializing audio failed."); - } - - sample_manager = memnew( SampleManagerMallocSW ); - audio_server = memnew( AudioServerSW(sample_manager) ); - - audio_server->init(); - - spatial_sound_server = memnew( SpatialSoundServerSW ); - spatial_sound_server->init(); - spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); - spatial_sound_2d_server->init(); - - managed_object->update_clipboard(); - - Clipboard::ContentChanged += ref new EventHandler(managed_object, &ManagedType::on_clipboard_changed); - - accelerometer = Accelerometer::GetDefault(); - if (accelerometer != nullptr) { - // 60 FPS - accelerometer->ReportInterval = (1.0f / 60.0f) * 1000; - accelerometer->ReadingChanged += - ref new TypedEventHandler - (managed_object, &ManagedType::on_accelerometer_reading_changed); - } - - magnetometer = Magnetometer::GetDefault(); - if (magnetometer != nullptr) { - // 60 FPS - magnetometer->ReportInterval = (1.0f / 60.0f) * 1000; - magnetometer->ReadingChanged += - ref new TypedEventHandler - (managed_object, &ManagedType::on_magnetometer_reading_changed); - } - - gyrometer = Gyrometer::GetDefault(); - if (gyrometer != nullptr) { - // 60 FPS - gyrometer->ReportInterval = (1.0f / 60.0f) * 1000; - gyrometer->ReadingChanged += - ref new TypedEventHandler - (managed_object, &ManagedType::on_gyroscope_reading_changed); - } - - _ensure_data_dir(); - - if (is_keep_screen_on()) - display_request->RequestActive(); - - set_keep_screen_on(GLOBAL_DEF("display/keep_screen_on", true)); - -} - -void OSWinrt::set_clipboard(const String& p_text) { - - DataPackage^ clip = ref new DataPackage(); - clip->RequestedOperation = DataPackageOperation::Copy; - clip->SetText(ref new Platform::String((const wchar_t*)p_text.c_str())); - - Clipboard::SetContent(clip); -}; - -String OSWinrt::get_clipboard() const { - - if (managed_object->clipboard != nullptr) - return managed_object->clipboard->Data(); - else - return ""; -}; - - -void OSWinrt::input_event(InputEvent &p_event) { - - p_event.ID = ++last_id; - - input->parse_input_event(p_event); - - if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index>3) { - - //send release for mouse wheel - p_event.mouse_button.pressed = false; - p_event.ID = ++last_id; - input->parse_input_event(p_event); - } -}; - -void OSWinrt::delete_main_loop() { - - if (main_loop) - memdelete(main_loop); - main_loop=NULL; -} - -void OSWinrt::set_main_loop( MainLoop * p_main_loop ) { - - input->set_main_loop(p_main_loop); - main_loop=p_main_loop; -} - -void OSWinrt::finalize() { - - if(main_loop) - memdelete(main_loop); - - main_loop=NULL; - - visual_server->finish(); - memdelete(visual_server); -#ifdef OPENGL_ENABLED - if (gl_context) - memdelete(gl_context); -#endif - if (rasterizer) - memdelete(rasterizer); - - spatial_sound_server->finish(); - memdelete(spatial_sound_server); - spatial_sound_2d_server->finish(); - memdelete(spatial_sound_2d_server); - - //if (debugger_connection_console) { -// memdelete(debugger_connection_console); -//} - - memdelete(sample_manager); - - audio_server->finish(); - memdelete(audio_server); - - memdelete(input); - - physics_server->finish(); - memdelete(physics_server); - - physics_2d_server->finish(); - memdelete(physics_2d_server); - - joystick = nullptr; - -} -void OSWinrt::finalize_core() { - - if (mempool_dynamic) - memdelete( mempool_dynamic ); - delete mempool_static; - -} - -void OSWinrt::vprint(const char* p_format, va_list p_list, bool p_stderr) { - - char buf[16384+1]; - int len = vsnprintf(buf,16384,p_format,p_list); - if (len<=0) - return; - buf[len]=0; - - - int wlen = MultiByteToWideChar(CP_UTF8,0,buf,len,NULL,0); - if (wlen<0) - return; - - wchar_t *wbuf = (wchar_t*)malloc((len+1)*sizeof(wchar_t)); - MultiByteToWideChar(CP_UTF8,0,buf,len,wbuf,wlen); - wbuf[wlen]=0; - - if (p_stderr) - fwprintf(stderr,L"%s",wbuf); - else - wprintf(L"%s",wbuf); - - free(wbuf); - - fflush(stdout); -}; - -void OSWinrt::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, &OSWinrt::ManagedType::alert_close)); - msg->Commands->Append(close); - msg->DefaultCommandIndex = 0; - - managed_object->alert_close_handle = true; - - msg->ShowAsync(); -} - -void OSWinrt::ManagedType::alert_close(IUICommand^ command) { - - alert_close_handle = false; -} - -void OSWinrt::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) { - - update_clipboard(); -} - -void OSWinrt::ManagedType::update_clipboard() { - - DataPackageView^ data = Clipboard::GetContent(); - - if (data->Contains(StandardDataFormats::Text)) { - - create_task(data->GetTextAsync()).then( - [this](Platform::String^ clipboard_content) { - - this->clipboard = clipboard_content; - }); - } -} - -void OSWinrt::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) { - - AccelerometerReading^ reading = args->Reading; - - os->input->set_accelerometer(Vector3( - reading->AccelerationX, - reading->AccelerationY, - reading->AccelerationZ - )); -} - -void OSWinrt::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) { - - MagnetometerReading^ reading = args->Reading; - - os->input->set_magnetometer(Vector3( - reading->MagneticFieldX, - reading->MagneticFieldY, - reading->MagneticFieldZ - )); -} - -void OSWinrt::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) { - - GyrometerReading^ reading = args->Reading; - - os->input->set_magnetometer(Vector3( - reading->AngularVelocityX, - reading->AngularVelocityY, - reading->AngularVelocityZ - )); -} - -void OSWinrt::set_mouse_mode(MouseMode p_mode) { - - if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) { - - CoreWindow::GetForCurrentThread()->SetPointerCapture(); - - } else { - - CoreWindow::GetForCurrentThread()->ReleasePointerCapture(); - - } - - if (p_mode == MouseMode::MOUSE_MODE_CAPTURED || p_mode == MouseMode::MOUSE_MODE_HIDDEN) { - - CoreWindow::GetForCurrentThread()->PointerCursor = nullptr; - - } else { - - CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(CoreCursorType::Arrow, 0); - } - - mouse_mode = p_mode; - - SetEvent(mouse_mode_changed); -} - -OSWinrt::MouseMode OSWinrt::get_mouse_mode() const{ - - return mouse_mode; -} - - - -Point2 OSWinrt::get_mouse_pos() const { - - return Point2(old_x, old_y); -} - -int OSWinrt::get_mouse_button_state() const { - - return last_button_state; -} - -void OSWinrt::set_window_title(const String& p_title) { - -} - -void OSWinrt::set_video_mode(const VideoMode& p_video_mode,int p_screen) { - - video_mode = p_video_mode; -} -OS::VideoMode OSWinrt::get_video_mode(int p_screen) const { - - return video_mode; -} -void OSWinrt::get_fullscreen_mode_list(List *p_list,int p_screen) const { - - -} - -void OSWinrt::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) { - - const char* err_details; - if (p_rationale && p_rationale[0]) - err_details = p_rationale; - else - err_details = p_code; - - switch(p_type) { - case ERR_ERROR: - print("ERROR: %s: %s\n", p_function, err_details); - print(" At: %s:%i\n", p_file, p_line); - break; - case ERR_WARNING: - print("WARNING: %s: %s\n", p_function, err_details); - print(" At: %s:%i\n", p_file, p_line); - break; - case ERR_SCRIPT: - print("SCRIPT ERROR: %s: %s\n", p_function, err_details); - print(" At: %s:%i\n", p_file, p_line); - break; - } -} - - -String OSWinrt::get_name() { - - return "WinRT"; -} - -OS::Date OSWinrt::get_date(bool utc) const { - - SYSTEMTIME systemtime; - if (utc) - GetSystemTime(&systemtime); - else - GetLocalTime(&systemtime); - - Date date; - date.day=systemtime.wDay; - date.month=Month(systemtime.wMonth); - date.weekday=Weekday(systemtime.wDayOfWeek); - date.year=systemtime.wYear; - date.dst=false; - return date; -} -OS::Time OSWinrt::get_time(bool utc) const { - - SYSTEMTIME systemtime; - if (utc) - GetSystemTime(&systemtime); - else - GetLocalTime(&systemtime); - - Time time; - time.hour=systemtime.wHour; - time.min=systemtime.wMinute; - time.sec=systemtime.wSecond; - return time; -} - -OS::TimeZoneInfo OSWinrt::get_time_zone_info() const { - TIME_ZONE_INFORMATION info; - bool daylight = false; - if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) - daylight = true; - - TimeZoneInfo ret; - if (daylight) { - ret.name = info.DaylightName; - } else { - ret.name = info.StandardName; - } - - ret.bias = info.Bias; - return ret; -} - -uint64_t OSWinrt::get_unix_time() const { - - FILETIME ft; - SYSTEMTIME st; - GetSystemTime(&st); - SystemTimeToFileTime(&st, &ft); - - SYSTEMTIME ep; - ep.wYear = 1970; - ep.wMonth = 1; - ep.wDayOfWeek = 4; - ep.wDay = 1; - ep.wHour = 0; - ep.wMinute = 0; - ep.wSecond = 0; - ep.wMilliseconds = 0; - FILETIME fep; - SystemTimeToFileTime(&ep, &fep); - - return (*(uint64_t*)&ft - *(uint64_t*)&fep) / 10000000; -}; - -void OSWinrt::delay_usec(uint32_t p_usec) const { - - int msec = p_usec < 1000 ? 1 : p_usec / 1000; - - // no Sleep() - WaitForSingleObjectEx(GetCurrentThread(), msec, false); - -} -uint64_t OSWinrt::get_ticks_usec() const { - - uint64_t ticks; - uint64_t time; - // This is the number of clock ticks since start - QueryPerformanceCounter((LARGE_INTEGER *)&ticks); - // Divide by frequency to get the time in seconds - time = ticks * 1000000L / ticks_per_second; - // Subtract the time at game start to get - // the time since the game started - time -= ticks_start; - return time; -} - - -void OSWinrt::process_events() { - - last_id = joystick->process_controllers(last_id); - process_key_events(); -} - -void OSWinrt::process_key_events() -{ - - for (int i = 0; i < key_event_pos; i++) { - - KeyEvent &kev = key_event_buffer[i]; - InputEvent iev; - - iev.type = InputEvent::KEY; - iev.key.mod = kev.mod_state; - iev.key.echo = kev.echo; - iev.key.scancode = kev.scancode; - iev.key.unicode = kev.unicode; - iev.key.pressed = kev.pressed; - - input_event(iev); - - } - key_event_pos = 0; -} - -void OSWinrt::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) { - - KeyEvent &old = key_event_buffer[key_event_pos - 1]; - ERR_FAIL_COND(old.type != KeyEvent::MessageType::KEY_EVENT_MESSAGE); - - key_event_buffer[key_event_pos - 1].unicode = p_event.unicode; - return; - } - - ERR_FAIL_COND(key_event_pos >= KEY_EVENT_BUFFER_SIZE); - - key_event_buffer[key_event_pos++] = p_event; -} - -void OSWinrt::set_cursor_shape(CursorShape p_shape) { - - ERR_FAIL_INDEX(p_shape, CURSOR_MAX); - - if (cursor_shape == p_shape) - return; - - static const CoreCursorType uwp_cursors[CURSOR_MAX] = { - CoreCursorType::Arrow, - CoreCursorType::IBeam, - CoreCursorType::Hand, - CoreCursorType::Cross, - CoreCursorType::Wait, - CoreCursorType::Wait, - CoreCursorType::Arrow, - CoreCursorType::Arrow, - CoreCursorType::UniversalNo, - CoreCursorType::SizeNorthSouth, - CoreCursorType::SizeWestEast, - CoreCursorType::SizeNortheastSouthwest, - CoreCursorType::SizeNorthwestSoutheast, - CoreCursorType::SizeAll, - CoreCursorType::SizeNorthSouth, - CoreCursorType::SizeWestEast, - CoreCursorType::Help - }; - - CoreWindow::GetForCurrentThread()->PointerCursor = ref new CoreCursor(uwp_cursors[p_shape], 0); - - cursor_shape = p_shape; -} - -Error OSWinrt::execute(const String& p_path, const List& p_arguments,bool p_blocking,ProcessID *r_child_id,String* r_pipe,int *r_exitcode) { - - return FAILED; -}; - -Error OSWinrt::kill(const ProcessID& p_pid) { - - return FAILED; -}; - -Error OSWinrt::set_cwd(const String& p_cwd) { - - return FAILED; -} - -String OSWinrt::get_executable_path() const { - - return ""; -} - -void OSWinrt::set_icon(const Image& p_icon) { - -} - - -bool OSWinrt::has_environment(const String& p_var) const { - - return false; -}; - -String OSWinrt::get_environment(const String& p_var) const { - - return ""; -}; - -String OSWinrt::get_stdin_string(bool p_block) { - - return String(); -} - - -void OSWinrt::move_window_to_foreground() { - -} - -Error OSWinrt::shell_open(String p_uri) { - - return FAILED; -} - - -String OSWinrt::get_locale() const { - -#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // this should work on phone 8.1, but it doesn't - return "en"; -#else - Platform::String ^language = Windows::Globalization::Language::CurrentInputMethodLanguageTag; - return String(language->Data()).replace("-", "_"); -#endif -} - -void OSWinrt::release_rendering_thread() { - - gl_context->release_current(); -} - -void OSWinrt::make_rendering_thread() { - - gl_context->make_current(); -} - -void OSWinrt::swap_buffers() { - - gl_context->swap_buffers(); -} - -bool OSWinrt::has_touchscreen_ui_hint() const { - - TouchCapabilities^ tc = ref new TouchCapabilities(); - return tc->TouchPresent != 0 || UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; -} - -bool OSWinrt::has_virtual_keyboard() const { - - return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; -} - -void OSWinrt::show_virtual_keyboard(const String & p_existing_text, const Rect2 & p_screen_rect) { - - InputPane^ pane = InputPane::GetForCurrentView(); - pane->TryShow(); -} - -void OSWinrt::hide_virtual_keyboard() { - - InputPane^ pane = InputPane::GetForCurrentView(); - pane->TryHide(); -} - - -void OSWinrt::run() { - - if (!main_loop) - return; - - main_loop->init(); - - uint64_t last_ticks=get_ticks_usec(); - - int frames=0; - uint64_t frame=0; - - while (!force_quit) { - - CoreWindow::GetForCurrentThread()->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessAllIfPresent); - if (managed_object->alert_close_handle) continue; - process_events(); // get rid of pending events - if (Main::iteration()==true) - break; - }; - - main_loop->finish(); - -} - - - -MainLoop *OSWinrt::get_main_loop() const { - - return main_loop; -} - - -String OSWinrt::get_data_dir() const { - - Windows::Storage::StorageFolder ^data_folder = Windows::Storage::ApplicationData::Current->LocalFolder; - - return String(data_folder->Path->Data()).replace("\\", "/"); -} - - -OSWinrt::OSWinrt() { - - key_event_pos=0; - force_quit=false; - alt_mem=false; - gr_mem=false; - shift_mem=false; - control_mem=false; - meta_mem=false; - minimized = false; - - pressrc=0; - old_invalid=true; - last_id=0; - mouse_mode=MOUSE_MODE_VISIBLE; -#ifdef STDOUT_FILE - stdo=fopen("stdout.txt","wb"); -#endif - - gl_context = NULL; - - display_request = ref new Windows::System::Display::DisplayRequest(); - - managed_object = ref new ManagedType; - managed_object->os = this; - - mouse_mode_changed = CreateEvent(NULL, TRUE, FALSE, L"os_mouse_mode_changed"); - - AudioDriverManagerSW::add_driver(&audio_driver); -} - - -OSWinrt::~OSWinrt() -{ -#ifdef STDOUT_FILE - fclose(stdo); -#endif -} - - diff --git a/platform/winrt/os_winrt.h b/platform/winrt/os_winrt.h deleted file mode 100644 index a4667f213d..0000000000 --- a/platform/winrt/os_winrt.h +++ /dev/null @@ -1,281 +0,0 @@ -/*************************************************************************/ -/* os_winrt.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 OSWinrt_H -#define OSWinrt_H - -#include "os/input.h" -#include "os/os.h" -#include "servers/visual_server.h" -#include "servers/visual/rasterizer.h" -#include "servers/physics/physics_server_sw.h" - -#include "servers/audio/audio_server_sw.h" -#include "servers/audio/sample_manager_sw.h" -#include "servers/spatial_sound/spatial_sound_server_sw.h" -#include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h" -#include "servers/physics_2d/physics_2d_server_sw.h" -#include "drivers/xaudio2/audio_driver_xaudio2.h" - -#include "gl_context_egl.h" - -#include "core/math/math_2d.h" -#include "core/ustring.h" - -#include - -#include - -#include -#include -#include "main/input_default.h" - -#include "joystick_winrt.h" - -/** - @author Juan Linietsky -*/ -class OSWinrt : public OS { - -public: - - struct KeyEvent { - - enum MessageType - { - KEY_EVENT_MESSAGE, - CHAR_EVENT_MESSAGE - }; - - InputModifierState mod_state; - MessageType type; - bool pressed; - unsigned int scancode; - unsigned int unicode; - bool echo; - CorePhysicalKeyStatus status; - - }; - -private: - - enum { - JOYSTICKS_MAX = 8, - JOY_AXIS_COUNT = 6, - MAX_JOY_AXIS = 32768, // I've no idea - KEY_EVENT_BUFFER_SIZE=512 - }; - - FILE *stdo; - - KeyEvent key_event_buffer[KEY_EVENT_BUFFER_SIZE]; - int key_event_pos; - - - uint64_t ticks_start; - uint64_t ticks_per_second; - - bool minimized; - bool old_invalid; - bool outside; - int old_x,old_y; - Point2i center; - unsigned int last_id; - VisualServer *visual_server; - Rasterizer *rasterizer; - PhysicsServer *physics_server; - Physics2DServer *physics_2d_server; - int pressrc; - - ContextEGL* gl_context; - - VideoMode video_mode; - - MainLoop *main_loop; - - AudioDriverXAudio2 audio_driver; - AudioServerSW *audio_server; - SampleManagerMallocSW *sample_manager; - SpatialSoundServerSW *spatial_sound_server; - SpatialSound2DServerSW *spatial_sound_2d_server; - - MouseMode mouse_mode; - bool alt_mem; - bool gr_mem; - bool shift_mem; - bool control_mem; - bool meta_mem; - bool force_quit; - uint32_t last_button_state; - - CursorShape cursor_shape; - - InputDefault *input; - - JoystickWinrt^ joystick; - - Windows::System::Display::DisplayRequest^ display_request; - - void _post_dpad(DWORD p_dpad, int p_device, bool p_pressed); - - void _drag_event(int idx,UINT uMsg, WPARAM wParam, LPARAM lParam); - void _touch_event(int idx, UINT uMsg, WPARAM wParam, LPARAM lParam); - - ref class ManagedType { - public: - property bool alert_close_handle; - property Platform::String^ clipboard; - void alert_close(Windows::UI::Popups::IUICommand^ command); - void on_clipboard_changed(Platform::Object^ sender, Platform::Object^ ev); - void update_clipboard(); - void on_accelerometer_reading_changed(Windows::Devices::Sensors::Accelerometer^ sender, Windows::Devices::Sensors::AccelerometerReadingChangedEventArgs^ args); - void on_magnetometer_reading_changed(Windows::Devices::Sensors::Magnetometer^ sender, Windows::Devices::Sensors::MagnetometerReadingChangedEventArgs^ args); - void on_gyroscope_reading_changed(Windows::Devices::Sensors::Gyrometer^ sender, Windows::Devices::Sensors::GyrometerReadingChangedEventArgs^ args); - - internal: - ManagedType() { alert_close_handle = false; } - property OSWinrt* os; - }; - ManagedType^ managed_object; - Windows::Devices::Sensors::Accelerometer^ accelerometer; - Windows::Devices::Sensors::Magnetometer^ magnetometer; - Windows::Devices::Sensors::Gyrometer^ gyrometer; - - // functions used by main to initialize/deintialize the OS -protected: - virtual int get_video_driver_count() const; - virtual const char * get_video_driver_name(int p_driver) const; - - virtual VideoMode get_default_video_mode() const; - - virtual int get_audio_driver_count() const; - virtual const char * get_audio_driver_name(int p_driver) const; - - virtual void initialize_core(); - virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver); - - virtual void set_main_loop( MainLoop * p_main_loop ); - virtual void delete_main_loop(); - - virtual void finalize(); - virtual void finalize_core(); - - void process_events(); - - void process_key_events(); - -public: - - // Event to send to the app wrapper - HANDLE mouse_mode_changed; - - void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type); - - virtual void vprint(const char *p_format, va_list p_list, bool p_stderr=false); - virtual void alert(const String& p_alert,const String& p_title="ALERT!"); - String get_stdin_string(bool p_block); - - void set_mouse_mode(MouseMode p_mode); - MouseMode get_mouse_mode() const; - - virtual Point2 get_mouse_pos() const; - virtual int get_mouse_button_state() const; - virtual void set_window_title(const String& p_title); - - virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0); - virtual VideoMode get_video_mode(int p_screen=0) const; - virtual void get_fullscreen_mode_list(List *p_list,int p_screen=0) const; - virtual Size2 get_window_size() const; - virtual void set_window_size(const Size2 p_size); - virtual void set_window_fullscreen(bool p_enabled); - virtual bool is_window_fullscreen() const; - virtual void set_keep_screen_on(bool p_enabled); - - virtual MainLoop *get_main_loop() const; - - virtual String get_name(); - - virtual Date get_date(bool utc) const; - virtual Time get_time(bool utc) const; - virtual TimeZoneInfo get_time_zone_info() const; - virtual uint64_t get_unix_time() const; - - virtual bool can_draw() const; - virtual Error set_cwd(const String& p_cwd); - - virtual void delay_usec(uint32_t p_usec) const; - virtual uint64_t get_ticks_usec() const; - - virtual Error execute(const String& p_path, const List& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL); - virtual Error kill(const ProcessID& p_pid); - - virtual bool has_environment(const String& p_var) const; - virtual String get_environment(const String& p_var) const; - - virtual void set_clipboard(const String& p_text); - virtual String get_clipboard() const; - - void set_cursor_shape(CursorShape p_shape); - void set_icon(const Image& p_icon); - - virtual String get_executable_path() const; - - virtual String get_locale() const; - - virtual void move_window_to_foreground(); - virtual String get_data_dir() const; - - void set_gl_context(ContextEGL* p_context); - void screen_size_changed(); - - virtual void release_rendering_thread(); - virtual void make_rendering_thread(); - virtual void swap_buffers(); - - virtual bool has_touchscreen_ui_hint() const; - - virtual bool has_virtual_keyboard() const; - virtual void show_virtual_keyboard(const String& p_existing_text, const Rect2& p_screen_rect = Rect2()); - virtual void hide_virtual_keyboard(); - - virtual Error shell_open(String p_uri); - - void run(); - - virtual bool get_swap_ok_cancel() { return true; } - - void input_event(InputEvent &p_event); - - void queue_key_event(KeyEvent &p_event); - - OSWinrt(); - ~OSWinrt(); - -}; - -#endif diff --git a/platform/winrt/platform_config.h b/platform/winrt/platform_config.h deleted file mode 100644 index 88b1fefed8..0000000000 --- a/platform/winrt/platform_config.h +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************/ -/* platform_config.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 diff --git a/platform/winrt/thread_winrt.cpp b/platform/winrt/thread_winrt.cpp deleted file mode 100644 index 8e3e0d5bef..0000000000 --- a/platform/winrt/thread_winrt.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/*************************************************************************/ -/* thread_winrt.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 "thread_winrt.h" - -#include "os/memory.h" - -Thread* ThreadWinrt::create_func_winrt(ThreadCreateCallback p_callback,void *p_user,const Settings&) { - - ThreadWinrt* thread = memnew(ThreadWinrt); - - - std::thread new_thread(p_callback, p_user); - std::swap(thread->thread, new_thread); - - return thread; -}; - -Thread::ID ThreadWinrt::get_thread_ID_func_winrt() { - - return std::hash()(std::this_thread::get_id()); -}; - -void ThreadWinrt::wait_to_finish_func_winrt(Thread* p_thread) { - - ThreadWinrt *tp=static_cast(p_thread); - tp->thread.join(); -}; - - -Thread::ID ThreadWinrt::get_ID() const { - - return std::hash()(thread.get_id()); -}; - -void ThreadWinrt::make_default() { - create_func = create_func_winrt; - get_thread_ID_func = get_thread_ID_func_winrt; - wait_to_finish_func = wait_to_finish_func_winrt; -}; - -ThreadWinrt::ThreadWinrt() { - -}; - -ThreadWinrt::~ThreadWinrt() { - -}; - diff --git a/platform/winrt/thread_winrt.h b/platform/winrt/thread_winrt.h deleted file mode 100644 index df275d560a..0000000000 --- a/platform/winrt/thread_winrt.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************/ -/* thread_winrt.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* http://www.godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */ -/* */ -/* 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 THREAD_WINRT_H -#define THREAD_WINRT_H - -#ifdef WINRT_ENABLED - -#include "os/thread.h" - -#include - -class ThreadWinrt : public Thread { - - std::thread thread; - - static Thread* create_func_winrt(ThreadCreateCallback p_callback,void *,const Settings&); - static ID get_thread_ID_func_winrt(); - static void wait_to_finish_func_winrt(Thread* p_thread); - - ThreadWinrt(); -public: - - - virtual ID get_ID() const; - - static void make_default(); - - - ~ThreadWinrt(); - -}; - - -#endif - -#endif - diff --git a/thirdparty/openssl/uwp.cpp b/thirdparty/openssl/uwp.cpp new file mode 100644 index 0000000000..c3a6f8bfcc --- /dev/null +++ b/thirdparty/openssl/uwp.cpp @@ -0,0 +1,155 @@ +/* Snippets extracted from https://github.com/Microsoft/openssl/blob/ec7e430e06e4e3ac87c183dee33cb216814cf980/ms/winrt.cpp + * Adapted for Godot definitions + */ +/* winrt.cpp + * Copyright 2014 Microsoft Corporation + * C++/CX Entropy/shims for Windows Phone/Windows Store platform + * written by Alejandro Jimenez Martinez + * (aljim@microsoft.com) for the OpenSSL project 2014. + */ + +#include +#if defined(WINAPI_FAMILY) +extern "C" +{ + unsigned entropyRT(BYTE *buffer, unsigned len); + void RAND_add(const void *buf,int num,double entropy); + int RAND_poll(void); +} +#endif + +unsigned entropyRT(BYTE *buffer, unsigned len) + { + using namespace Platform; + using namespace Windows::Foundation; + using namespace Windows::Foundation::Collections; + using namespace Windows::Security::Cryptography; + using namespace Windows::Storage::Streams; + IBuffer ^buf = CryptographicBuffer::GenerateRandom(len); + Array ^arr; + CryptographicBuffer::CopyToByteArray(buf, &arr); + unsigned arrayLen = arr->Length; + + // Make sure not to overflow the copy + arrayLen = (arrayLen > len) ? len : arrayLen; + memcpy(buffer, arr->Data, arrayLen); + return arrayLen; + } + +int RAND_poll(void) + { + BYTE buf[60]; + unsigned collected = entropyRT(buf , sizeof(buf)); + RAND_add(buf, collected, collected); + return 1; + } + +#if defined(WINRT_ENABLED) +extern "C" +{ +#include +#include +#include + + void* GetModuleHandle( + _In_opt_ LPCTSTR lpModuleName + ) + { + return NULL; + } + //no log for phone + int RegisterEventSource( + _In_ LPCTSTR lpUNCServerName, + _In_ LPCTSTR lpSourceName + ) + { + return NULL; + } + + int ReportEvent( + _In_ HANDLE hEventLog, + _In_ WORD wType, + _In_ WORD wCategory, + _In_ DWORD dwEventID, + _In_ PSID lpUserSid, + _In_ WORD wNumStrings, + _In_ DWORD dwDataSize, + _In_ LPCTSTR *lpStrings, + _In_ LPVOID lpRawData + ) + { + return 0; + } + int MessageBox( + _In_opt_ HWND hWnd, + _In_opt_ LPCTSTR lpText, + _In_opt_ LPCTSTR lpCaption, + _In_ UINT uType + ) + { + return 0; + } + int __cdecl GetProcessWindowStation(void) + { + return NULL; + } + BOOL __cdecl GetUserObjectInformationW( + _In_ HANDLE hObj, + _In_ int nIndex, + _Out_opt_ PVOID pvInfo, + _In_ DWORD nLength, + _Out_opt_ LPDWORD lpnLengthNeeded + ) + { + return 0; + } + int __cdecl GetStdHandle( + _In_ DWORD nStdHandle + ) + { + return 0; + } + BOOL DeregisterEventSource( + _Inout_ HANDLE hEventLog + ) + { + return 0; + } + char *getenv( + const char *varname + ) + { + //hardcoded environmental variables used for the appx testing application for store/phone + if (!strcmp(varname, "OPENSSL_CONF")) + { + return "./openssl.cnf"; + } + return 0; + } + int setenv(const char *envname, const char *envval, int overwrite) + { + return -1; + } + int _getch(void) + { + return 0; + } + int _kbhit() + { + return 0; + } + BOOL __cdecl FlushConsoleInputBuffer( + _In_ HANDLE hConsoleInput + ) + { + return 0; + } + int winrt_GetTickCount(void) + { + LARGE_INTEGER t; + return(int) (QueryPerformanceCounter(&t) ? t.QuadPart : 0); + } + void *OPENSSL_UplinkTable [26]= {0}; +} //extern C + +#endif /*defined(WINRT_ENABLED)*/ diff --git a/thirdparty/openssl/uwp_fix.patch b/thirdparty/openssl/uwp_fix.patch new file mode 100644 index 0000000000..caf180a75b --- /dev/null +++ b/thirdparty/openssl/uwp_fix.patch @@ -0,0 +1,64 @@ +diff --git a/drivers/builtin_openssl2/crypto/rand/rand_win.c b/drivers/builtin_openssl2/crypto/rand/rand_win.c +index 06670ae..70fd52a 100644 +--- a/drivers/builtin_openssl2/crypto/rand/rand_win.c ++++ b/drivers/builtin_openssl2/crypto/rand/rand_win.c +@@ -118,8 +118,10 @@ + # ifndef _WIN32_WINNT + # define _WIN32_WINNT 0x0400 + # endif ++#ifndef WINRT_ENABLED + # include + # include ++#endif + + /* + * Limit the time spent walking through the heap, processes, threads and +@@ -161,7 +163,7 @@ typedef struct tagCURSORINFO { + # define CURSOR_SHOWING 0x00000001 + # endif /* CURSOR_SHOWING */ + +-# if !defined(OPENSSL_SYS_WINCE) ++# if !defined(OPENSSL_SYS_WINCE) && !defined(WINRT_ENABLED) + typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTW) (HCRYPTPROV *, LPCWSTR, LPCWSTR, + DWORD, DWORD); + typedef BOOL(WINAPI *CRYPTGENRANDOM) (HCRYPTPROV, DWORD, BYTE *); +@@ -196,6 +198,7 @@ typedef NET_API_STATUS(NET_API_FUNCTION *NETFREE) (LPBYTE); + # endif /* 1 */ + # endif /* !OPENSSL_SYS_WINCE */ + ++#if !defined(WINRT_ENABLED) + int RAND_poll(void) + { + MEMORYSTATUS m; +@@ -580,6 +583,8 @@ int RAND_poll(void) + return (1); + } + ++#endif // WINRT_ENABLED ++ + int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam) + { + double add_entropy = 0; +@@ -682,7 +687,7 @@ static void readtimer(void) + + static void readscreen(void) + { +-# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) ++# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(WINRT_ENABLED) + HDC hScrDC; /* screen DC */ + HBITMAP hBitmap; /* handle for our bitmap */ + BITMAP bm; /* bitmap properties */ +diff --git a/drivers/builtin_openssl2/openssl/dtls1.h b/drivers/builtin_openssl2/openssl/dtls1.h +index 64ad3c8..a58aca2 100644 +--- a/drivers/builtin_openssl2/openssl/dtls1.h ++++ b/drivers/builtin_openssl2/openssl/dtls1.h +@@ -81,6 +81,9 @@ + # include + # endif + # endif ++#ifdef WINRT_ENABLED ++#include ++#endif + + #ifdef __cplusplus + extern "C" { diff --git a/thirdparty/openssl/winrt.cpp b/thirdparty/openssl/winrt.cpp deleted file mode 100644 index c3a6f8bfcc..0000000000 --- a/thirdparty/openssl/winrt.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* Snippets extracted from https://github.com/Microsoft/openssl/blob/ec7e430e06e4e3ac87c183dee33cb216814cf980/ms/winrt.cpp - * Adapted for Godot definitions - */ -/* winrt.cpp - * Copyright 2014 Microsoft Corporation - * C++/CX Entropy/shims for Windows Phone/Windows Store platform - * written by Alejandro Jimenez Martinez - * (aljim@microsoft.com) for the OpenSSL project 2014. - */ - -#include -#if defined(WINAPI_FAMILY) -extern "C" -{ - unsigned entropyRT(BYTE *buffer, unsigned len); - void RAND_add(const void *buf,int num,double entropy); - int RAND_poll(void); -} -#endif - -unsigned entropyRT(BYTE *buffer, unsigned len) - { - using namespace Platform; - using namespace Windows::Foundation; - using namespace Windows::Foundation::Collections; - using namespace Windows::Security::Cryptography; - using namespace Windows::Storage::Streams; - IBuffer ^buf = CryptographicBuffer::GenerateRandom(len); - Array ^arr; - CryptographicBuffer::CopyToByteArray(buf, &arr); - unsigned arrayLen = arr->Length; - - // Make sure not to overflow the copy - arrayLen = (arrayLen > len) ? len : arrayLen; - memcpy(buffer, arr->Data, arrayLen); - return arrayLen; - } - -int RAND_poll(void) - { - BYTE buf[60]; - unsigned collected = entropyRT(buf , sizeof(buf)); - RAND_add(buf, collected, collected); - return 1; - } - -#if defined(WINRT_ENABLED) -extern "C" -{ -#include -#include -#include - - void* GetModuleHandle( - _In_opt_ LPCTSTR lpModuleName - ) - { - return NULL; - } - //no log for phone - int RegisterEventSource( - _In_ LPCTSTR lpUNCServerName, - _In_ LPCTSTR lpSourceName - ) - { - return NULL; - } - - int ReportEvent( - _In_ HANDLE hEventLog, - _In_ WORD wType, - _In_ WORD wCategory, - _In_ DWORD dwEventID, - _In_ PSID lpUserSid, - _In_ WORD wNumStrings, - _In_ DWORD dwDataSize, - _In_ LPCTSTR *lpStrings, - _In_ LPVOID lpRawData - ) - { - return 0; - } - int MessageBox( - _In_opt_ HWND hWnd, - _In_opt_ LPCTSTR lpText, - _In_opt_ LPCTSTR lpCaption, - _In_ UINT uType - ) - { - return 0; - } - int __cdecl GetProcessWindowStation(void) - { - return NULL; - } - BOOL __cdecl GetUserObjectInformationW( - _In_ HANDLE hObj, - _In_ int nIndex, - _Out_opt_ PVOID pvInfo, - _In_ DWORD nLength, - _Out_opt_ LPDWORD lpnLengthNeeded - ) - { - return 0; - } - int __cdecl GetStdHandle( - _In_ DWORD nStdHandle - ) - { - return 0; - } - BOOL DeregisterEventSource( - _Inout_ HANDLE hEventLog - ) - { - return 0; - } - char *getenv( - const char *varname - ) - { - //hardcoded environmental variables used for the appx testing application for store/phone - if (!strcmp(varname, "OPENSSL_CONF")) - { - return "./openssl.cnf"; - } - return 0; - } - int setenv(const char *envname, const char *envval, int overwrite) - { - return -1; - } - int _getch(void) - { - return 0; - } - int _kbhit() - { - return 0; - } - BOOL __cdecl FlushConsoleInputBuffer( - _In_ HANDLE hConsoleInput - ) - { - return 0; - } - int winrt_GetTickCount(void) - { - LARGE_INTEGER t; - return(int) (QueryPerformanceCounter(&t) ? t.QuadPart : 0); - } - void *OPENSSL_UplinkTable [26]= {0}; -} //extern C - -#endif /*defined(WINRT_ENABLED)*/ diff --git a/thirdparty/openssl/winrt_fix.patch b/thirdparty/openssl/winrt_fix.patch deleted file mode 100644 index caf180a75b..0000000000 --- a/thirdparty/openssl/winrt_fix.patch +++ /dev/null @@ -1,64 +0,0 @@ -diff --git a/drivers/builtin_openssl2/crypto/rand/rand_win.c b/drivers/builtin_openssl2/crypto/rand/rand_win.c -index 06670ae..70fd52a 100644 ---- a/drivers/builtin_openssl2/crypto/rand/rand_win.c -+++ b/drivers/builtin_openssl2/crypto/rand/rand_win.c -@@ -118,8 +118,10 @@ - # ifndef _WIN32_WINNT - # define _WIN32_WINNT 0x0400 - # endif -+#ifndef WINRT_ENABLED - # include - # include -+#endif - - /* - * Limit the time spent walking through the heap, processes, threads and -@@ -161,7 +163,7 @@ typedef struct tagCURSORINFO { - # define CURSOR_SHOWING 0x00000001 - # endif /* CURSOR_SHOWING */ - --# if !defined(OPENSSL_SYS_WINCE) -+# if !defined(OPENSSL_SYS_WINCE) && !defined(WINRT_ENABLED) - typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTW) (HCRYPTPROV *, LPCWSTR, LPCWSTR, - DWORD, DWORD); - typedef BOOL(WINAPI *CRYPTGENRANDOM) (HCRYPTPROV, DWORD, BYTE *); -@@ -196,6 +198,7 @@ typedef NET_API_STATUS(NET_API_FUNCTION *NETFREE) (LPBYTE); - # endif /* 1 */ - # endif /* !OPENSSL_SYS_WINCE */ - -+#if !defined(WINRT_ENABLED) - int RAND_poll(void) - { - MEMORYSTATUS m; -@@ -580,6 +583,8 @@ int RAND_poll(void) - return (1); - } - -+#endif // WINRT_ENABLED -+ - int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam) - { - double add_entropy = 0; -@@ -682,7 +687,7 @@ static void readtimer(void) - - static void readscreen(void) - { --# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) -+# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(WINRT_ENABLED) - HDC hScrDC; /* screen DC */ - HBITMAP hBitmap; /* handle for our bitmap */ - BITMAP bm; /* bitmap properties */ -diff --git a/drivers/builtin_openssl2/openssl/dtls1.h b/drivers/builtin_openssl2/openssl/dtls1.h -index 64ad3c8..a58aca2 100644 ---- a/drivers/builtin_openssl2/openssl/dtls1.h -+++ b/drivers/builtin_openssl2/openssl/dtls1.h -@@ -81,6 +81,9 @@ - # include - # endif - # endif -+#ifdef WINRT_ENABLED -+#include -+#endif - - #ifdef __cplusplus - extern "C" { -- cgit v1.2.3 From b113c7b7a3e63581ae268b0ae7f827d55e381b82 Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 2 Nov 2016 18:57:35 -0200 Subject: Rename WINRT_ENABLED to UWP_ENABLED --- drivers/unix/ip_unix.cpp | 4 ++-- drivers/unix/socket_helpers.h | 2 +- drivers/windows/dir_access_windows.cpp | 2 +- drivers/windows/file_access_windows.cpp | 2 +- drivers/windows/mutex_windows.cpp | 2 +- drivers/windows/semaphore_windows.cpp | 2 +- drivers/windows/shell_windows.cpp | 2 +- drivers/windows/thread_windows.cpp | 2 +- main/input_default.cpp | 2 +- platform/uwp/detect.py | 2 +- platform/uwp/thread_uwp.h | 2 +- thirdparty/enet/win32.c | 6 +++--- thirdparty/openssl/crypto/rand/rand_win.c | 10 +++++----- thirdparty/openssl/openssl/dtls1.h | 2 +- thirdparty/openssl/uwp.cpp | 4 ++-- thirdparty/openssl/uwp_fix.patch | 12 ++++++------ thirdparty/rtaudio/RtAudio.h | 2 +- 17 files changed, 30 insertions(+), 30 deletions(-) diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index e3d32618ee..d998c63dfa 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -40,7 +40,7 @@ #ifndef AI_V4MAPPED #define AI_V4MAPPED 0x00000800 #endif - #ifdef WINRT_ENABLED + #ifdef UWP_ENABLED #include #include #include @@ -124,7 +124,7 @@ IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, IP_Address::Addr #if defined(WINDOWS_ENABLED) -#if defined(WINRT_ENABLED) +#if defined(UWP_ENABLED) void IP_Unix::get_local_addresses(List *r_addresses) const { diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h index 3aaae82da2..5e8e8dfd7a 100644 --- a/drivers/unix/socket_helpers.h +++ b/drivers/unix/socket_helpers.h @@ -10,7 +10,7 @@ #endif #endif -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED #define in6addr_any IN6ADDR_ANY_INIT #endif diff --git a/drivers/windows/dir_access_windows.cpp b/drivers/windows/dir_access_windows.cpp index ad4e8f301c..00d9afe51e 100644 --- a/drivers/windows/dir_access_windows.cpp +++ b/drivers/windows/dir_access_windows.cpp @@ -349,7 +349,7 @@ DirAccessWindows::DirAccessWindows() { drive_count=0; -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED Windows::Storage::StorageFolder ^install_folder = Windows::ApplicationModel::Package::Current->InstalledLocation; change_dir(install_folder->Path->Data()); diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index 36dcab1d67..e28d68221b 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -125,7 +125,7 @@ void FileAccessWindows::close() { bool rename_error; -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED // WinRT has no PathFileExists, so we check attributes instead DWORD fileAttr; diff --git a/drivers/windows/mutex_windows.cpp b/drivers/windows/mutex_windows.cpp index f63415d0f8..f533626c30 100644 --- a/drivers/windows/mutex_windows.cpp +++ b/drivers/windows/mutex_windows.cpp @@ -81,7 +81,7 @@ MutexWindows::MutexWindows() { #ifdef WINDOWS_USE_MUTEX mutex = CreateMutex( NULL, FALSE, NULL ); #else - #ifdef WINRT_ENABLED + #ifdef UWP_ENABLED InitializeCriticalSectionEx( &mutex, 0, 0 ); #else InitializeCriticalSection( &mutex ); diff --git a/drivers/windows/semaphore_windows.cpp b/drivers/windows/semaphore_windows.cpp index 8d11d1b1c1..5ea98f341f 100644 --- a/drivers/windows/semaphore_windows.cpp +++ b/drivers/windows/semaphore_windows.cpp @@ -71,7 +71,7 @@ void SemaphoreWindows::make_default() { SemaphoreWindows::SemaphoreWindows() { -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED semaphore=CreateSemaphoreEx( NULL, 0, diff --git a/drivers/windows/shell_windows.cpp b/drivers/windows/shell_windows.cpp index c69d371a65..283a453be1 100644 --- a/drivers/windows/shell_windows.cpp +++ b/drivers/windows/shell_windows.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #ifdef WINDOWS_ENABLED -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED // Use Launcher class on windows 8 diff --git a/drivers/windows/thread_windows.cpp b/drivers/windows/thread_windows.cpp index 884575e81e..2056113412 100644 --- a/drivers/windows/thread_windows.cpp +++ b/drivers/windows/thread_windows.cpp @@ -28,7 +28,7 @@ /*************************************************************************/ #include "thread_windows.h" -#if defined(WINDOWS_ENABLED) && !defined(WINRT_ENABLED) +#if defined(WINDOWS_ENABLED) && !defined(UWP_ENABLED) #include "os/memory.h" diff --git a/main/input_default.cpp b/main/input_default.cpp index c60fcd2243..09b1d53c5f 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -739,7 +739,7 @@ static const char *s_ControllerMappings [] = "c2a94d6963726f736f66742058626f78,Wireless X360 Controller,leftx:a0,lefty:a1,dpdown:b14,rightstick:b10,rightshoulder:b5,rightx:a3,start:b7,righty:a4,dpleft:b11,lefttrigger:a2,x:b2,dpup:b13,back:b6,leftstick:b9,leftshoulder:b4,y:b3,a:b0,dpright:b12,righttrigger:a5,b:b1,", #endif - #ifdef WINRT_ENABLED + #ifdef UWP_ENABLED "__WINRT_GAMEPAD__,Xbox Controller,a:b2,b:b3,x:b4,y:b5,start:b0,back:b1,leftstick:b12,rightstick:b13,leftshoulder:b10,rightshoulder:b11,dpup:b6,dpdown:b7,dpleft:b8,dpright:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", #endif NULL diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py index 85d6d54a70..a78a7fec78 100644 --- a/platform/uwp/detect.py +++ b/platform/uwp/detect.py @@ -139,7 +139,7 @@ def configure(env): env["OBJSUFFIX"] = "." + arch + env["OBJSUFFIX"] env["LIBSUFFIX"] = "." + arch + env["LIBSUFFIX"] - env.Append(CCFLAGS=['/DWINRT_ENABLED']) + env.Append(CCFLAGS=['/DUWP_ENABLED']) env.Append(CCFLAGS=['/DWINDOWS_ENABLED']) env.Append(CCFLAGS=['/DTYPED_METHOD_BIND']) diff --git a/platform/uwp/thread_uwp.h b/platform/uwp/thread_uwp.h index e0d386a317..328d29bdc7 100644 --- a/platform/uwp/thread_uwp.h +++ b/platform/uwp/thread_uwp.h @@ -29,7 +29,7 @@ #ifndef THREAD_WINRT_H #define THREAD_WINRT_H -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED #include "os/thread.h" diff --git a/thirdparty/enet/win32.c b/thirdparty/enet/win32.c index 15edd7acbb..f8e0d4efd4 100644 --- a/thirdparty/enet/win32.c +++ b/thirdparty/enet/win32.c @@ -28,7 +28,7 @@ enet_initialize (void) return -1; } -#ifndef WINRT_ENABLED +#ifndef UWP_ENABLED timeBeginPeriod (1); #endif @@ -38,14 +38,14 @@ enet_initialize (void) void enet_deinitialize (void) { -#ifndef WINRT_ENABLED +#ifndef UWP_ENABLED timeEndPeriod (1); #endif WSACleanup (); } -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED enet_uint32 timeGetTime() { ULONGLONG ticks = GetTickCount64(); diff --git a/thirdparty/openssl/crypto/rand/rand_win.c b/thirdparty/openssl/crypto/rand/rand_win.c index 70fd52a7aa..da4c935a53 100644 --- a/thirdparty/openssl/crypto/rand/rand_win.c +++ b/thirdparty/openssl/crypto/rand/rand_win.c @@ -118,7 +118,7 @@ # ifndef _WIN32_WINNT # define _WIN32_WINNT 0x0400 # endif -#ifndef WINRT_ENABLED +#ifndef UWP_ENABLED # include # include #endif @@ -163,7 +163,7 @@ typedef struct tagCURSORINFO { # define CURSOR_SHOWING 0x00000001 # endif /* CURSOR_SHOWING */ -# if !defined(OPENSSL_SYS_WINCE) && !defined(WINRT_ENABLED) +# if !defined(OPENSSL_SYS_WINCE) && !defined(UWP_ENABLED) typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTW) (HCRYPTPROV *, LPCWSTR, LPCWSTR, DWORD, DWORD); typedef BOOL(WINAPI *CRYPTGENRANDOM) (HCRYPTPROV, DWORD, BYTE *); @@ -198,7 +198,7 @@ typedef NET_API_STATUS(NET_API_FUNCTION *NETFREE) (LPBYTE); # endif /* 1 */ # endif /* !OPENSSL_SYS_WINCE */ -#if !defined(WINRT_ENABLED) +#if !defined(UWP_ENABLED) int RAND_poll(void) { MEMORYSTATUS m; @@ -583,7 +583,7 @@ int RAND_poll(void) return (1); } -#endif // WINRT_ENABLED +#endif // UWP_ENABLED int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam) { @@ -687,7 +687,7 @@ static void readtimer(void) static void readscreen(void) { -# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(WINRT_ENABLED) +# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(UWP_ENABLED) HDC hScrDC; /* screen DC */ HBITMAP hBitmap; /* handle for our bitmap */ BITMAP bm; /* bitmap properties */ diff --git a/thirdparty/openssl/openssl/dtls1.h b/thirdparty/openssl/openssl/dtls1.h index a58aca248d..cdd1e4d86e 100644 --- a/thirdparty/openssl/openssl/dtls1.h +++ b/thirdparty/openssl/openssl/dtls1.h @@ -81,7 +81,7 @@ # include # endif # endif -#ifdef WINRT_ENABLED +#ifdef UWP_ENABLED #include #endif diff --git a/thirdparty/openssl/uwp.cpp b/thirdparty/openssl/uwp.cpp index c3a6f8bfcc..6bb0c22523 100644 --- a/thirdparty/openssl/uwp.cpp +++ b/thirdparty/openssl/uwp.cpp @@ -44,7 +44,7 @@ int RAND_poll(void) return 1; } -#if defined(WINRT_ENABLED) +#if defined(UWP_ENABLED) extern "C" { #include @@ -152,4 +152,4 @@ extern "C" void *OPENSSL_UplinkTable [26]= {0}; } //extern C -#endif /*defined(WINRT_ENABLED)*/ +#endif /*defined(UWP_ENABLED)*/ diff --git a/thirdparty/openssl/uwp_fix.patch b/thirdparty/openssl/uwp_fix.patch index caf180a75b..00d8b64d00 100644 --- a/thirdparty/openssl/uwp_fix.patch +++ b/thirdparty/openssl/uwp_fix.patch @@ -6,7 +6,7 @@ index 06670ae..70fd52a 100644 # ifndef _WIN32_WINNT # define _WIN32_WINNT 0x0400 # endif -+#ifndef WINRT_ENABLED ++#ifndef UWP_ENABLED # include # include +#endif @@ -18,7 +18,7 @@ index 06670ae..70fd52a 100644 # endif /* CURSOR_SHOWING */ -# if !defined(OPENSSL_SYS_WINCE) -+# if !defined(OPENSSL_SYS_WINCE) && !defined(WINRT_ENABLED) ++# if !defined(OPENSSL_SYS_WINCE) && !defined(UWP_ENABLED) typedef BOOL(WINAPI *CRYPTACQUIRECONTEXTW) (HCRYPTPROV *, LPCWSTR, LPCWSTR, DWORD, DWORD); typedef BOOL(WINAPI *CRYPTGENRANDOM) (HCRYPTPROV, DWORD, BYTE *); @@ -26,7 +26,7 @@ index 06670ae..70fd52a 100644 # endif /* 1 */ # endif /* !OPENSSL_SYS_WINCE */ -+#if !defined(WINRT_ENABLED) ++#if !defined(UWP_ENABLED) int RAND_poll(void) { MEMORYSTATUS m; @@ -34,7 +34,7 @@ index 06670ae..70fd52a 100644 return (1); } -+#endif // WINRT_ENABLED ++#endif // UWP_ENABLED + int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam) { @@ -44,7 +44,7 @@ index 06670ae..70fd52a 100644 static void readscreen(void) { -# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) -+# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(WINRT_ENABLED) ++# if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN) && !defined(UWP_ENABLED) HDC hScrDC; /* screen DC */ HBITMAP hBitmap; /* handle for our bitmap */ BITMAP bm; /* bitmap properties */ @@ -56,7 +56,7 @@ index 64ad3c8..a58aca2 100644 # include # endif # endif -+#ifdef WINRT_ENABLED ++#ifdef UWP_ENABLED +#include +#endif diff --git a/thirdparty/rtaudio/RtAudio.h b/thirdparty/rtaudio/RtAudio.h index 4392e95f32..aab109d907 100644 --- a/thirdparty/rtaudio/RtAudio.h +++ b/thirdparty/rtaudio/RtAudio.h @@ -7,7 +7,7 @@ #elif defined(UNIX_ENABLED) #define __LINUX_ALSA__ #elif defined(WINDOWS_ENABLED) - #if defined(WINRT_ENABLED) + #if defined(UWP_ENABLED) #define __RTAUDIO_DUMMY__ #else #define __WINDOWS_DS__ -- cgit v1.2.3 From 411faaa6f478f837aa40893eaadf67e2b5d57cec Mon Sep 17 00:00:00 2001 From: George Marques Date: Wed, 2 Nov 2016 19:22:49 -0200 Subject: Rename remaining WinRT references to UWP --- doc/base/classes.xml | 2 +- drivers/windows/file_access_windows.cpp | 2 +- main/input_default.cpp | 2 +- modules/freetype/SCsub | 2 +- modules/openssl/SCsub | 2 +- platform/uwp/app.cpp | 16 ++-- platform/uwp/app.h | 4 +- platform/uwp/detect.py | 2 +- platform/uwp/export/export.cpp | 58 ++++++------ platform/uwp/joystick_uwp.cpp | 22 ++--- platform/uwp/joystick_uwp.h | 10 +- platform/uwp/os_uwp.cpp | 154 +++++++++++++++---------------- platform/uwp/os_uwp.h | 14 +-- platform/uwp/thread_uwp.cpp | 24 ++--- platform/uwp/thread_uwp.h | 16 ++-- thirdparty/README.md | 2 +- thirdparty/openssl/uwp.cpp | 4 +- tools/dist/uwp_template/AppxManifest.xml | 2 +- 18 files changed, 169 insertions(+), 169 deletions(-) diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 92b208ff50..e1241c2654 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -23878,7 +23878,7 @@ - Return the name of the host OS. Possible values are: "Android", "BlackBerry 10", "Flash", "Haiku", "iOS", "HTML5", "OSX", "Server", "Windows", "WinRT", "X11" + Return the name of the host OS. Possible values are: "Android", "BlackBerry 10", "Flash", "Haiku", "iOS", "HTML5", "OSX", "Server", "Windows", "UWP", "X11" diff --git a/drivers/windows/file_access_windows.cpp b/drivers/windows/file_access_windows.cpp index e28d68221b..00e54e2b3e 100644 --- a/drivers/windows/file_access_windows.cpp +++ b/drivers/windows/file_access_windows.cpp @@ -126,7 +126,7 @@ void FileAccessWindows::close() { bool rename_error; #ifdef UWP_ENABLED - // WinRT has no PathFileExists, so we check attributes instead + // UWP has no PathFileExists, so we check attributes instead DWORD fileAttr; fileAttr = GetFileAttributesW(save_path.c_str()); diff --git a/main/input_default.cpp b/main/input_default.cpp index 09b1d53c5f..0995f7132d 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -740,7 +740,7 @@ static const char *s_ControllerMappings [] = #endif #ifdef UWP_ENABLED - "__WINRT_GAMEPAD__,Xbox Controller,a:b2,b:b3,x:b4,y:b5,start:b0,back:b1,leftstick:b12,rightstick:b13,leftshoulder:b10,rightshoulder:b11,dpup:b6,dpdown:b7,dpleft:b8,dpright:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", + "__UWP_GAMEPAD__,Xbox Controller,a:b2,b:b3,x:b4,y:b5,start:b0,back:b1,leftstick:b12,rightstick:b13,leftshoulder:b10,rightshoulder:b11,dpup:b6,dpdown:b7,dpleft:b8,dpright:b9,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,", #endif NULL }; diff --git a/modules/freetype/SCsub b/modules/freetype/SCsub index 5a5b87df50..e4dd1c36a0 100644 --- a/modules/freetype/SCsub +++ b/modules/freetype/SCsub @@ -54,7 +54,7 @@ if (env['builtin_freetype'] != 'no'): ] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - # Include header for WinRT to fix build issues + # Include header for UWP to fix build issues if "platform" in env and env["platform"] == "uwp": env.Append(CCFLAGS=['/FI', '"modules/freetype/uwpdef.h"']) diff --git a/modules/openssl/SCsub b/modules/openssl/SCsub index e379570c72..0e811ce8c9 100644 --- a/modules/openssl/SCsub +++ b/modules/openssl/SCsub @@ -679,7 +679,7 @@ if (env['builtin_openssl'] != 'no'): env_openssl.add_source_files(env.modules_sources, "*.cpp") env_openssl.add_source_files(env.modules_sources, "*.c") -# platform/winrt need to know openssl is available, pass to main env +# platform/uwp need to know openssl is available, pass to main env if "platform" in env and env["platform"] == "uwp": env.Append(CPPPATH=[thirdparty_dir]) env.Append(CPPFLAGS=['-DOPENSSL_ENABLED']) diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp index c2b7ba0641..539c1815f6 100644 --- a/platform/uwp/app.cpp +++ b/platform/uwp/app.cpp @@ -53,7 +53,7 @@ using namespace Windows::System; using namespace Windows::System::Threading::Core; using namespace Microsoft::WRL; -using namespace GodotWinRT; +using namespace GodotUWP; // Helper to convert a length in device-independent pixels (DIPs) to a length in physical pixels. inline float ConvertDipsToPixels(float dips, float dpi) @@ -63,7 +63,7 @@ inline float ConvertDipsToPixels(float dips, float dpi) } // Implementation of the IFrameworkViewSource interface, necessary to run our app. -ref class GodotWinrtViewSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource +ref class GodotUWPViewSource sealed : Windows::ApplicationModel::Core::IFrameworkViewSource { public: virtual Windows::ApplicationModel::Core::IFrameworkView^ CreateView() @@ -76,7 +76,7 @@ public: [Platform::MTAThread] int main(Platform::Array^) { - auto godotApplicationSource = ref new GodotWinrtViewSource(); + auto godotApplicationSource = ref new GodotUWPViewSource(); CoreApplication::Run(godotApplicationSource); return 0; } @@ -105,7 +105,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 OSWinrt; + os = new OSUWP; } @@ -157,7 +157,7 @@ void App::SetWindow(CoreWindow^ p_window) unsigned int argc; char** argv = get_command_line(&argc); - Main::setup("winrt", argc, argv, false); + Main::setup("uwp", argc, argv, false); // The CoreWindow has been created, so EGL can be initialized. ContextEGL* context = memnew(ContextEGL(window)); @@ -431,7 +431,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) { - OSWinrt::KeyEvent ke; + OSUWP::KeyEvent ke; InputModifierState mod; mod.meta = false; @@ -445,14 +445,14 @@ void App::key_event(Windows::UI::Core::CoreWindow^ sender, bool p_pressed, Windo if (key_args != nullptr) { - ke.type = OSWinrt::KeyEvent::MessageType::KEY_EVENT_MESSAGE; + ke.type = OSUWP::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 = OSWinrt::KeyEvent::MessageType::CHAR_EVENT_MESSAGE; + ke.type = OSUWP::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 91cac37985..f82de4d240 100644 --- a/platform/uwp/app.h +++ b/platform/uwp/app.h @@ -35,7 +35,7 @@ #include "os_uwp.h" #include "GLES2/gl2.h" -namespace GodotWinRT +namespace GodotUWP { ref class App sealed : public Windows::ApplicationModel::Core::IFrameworkView { @@ -97,7 +97,7 @@ namespace GodotWinRT EGLSurface mEglSurface; CoreWindow^ window; - OSWinrt* os; + OSUWP* os; int last_touch_x[32]; // 20 fingers, index 31 reserved for the mouse int last_touch_y[32]; diff --git a/platform/uwp/detect.py b/platform/uwp/detect.py index a78a7fec78..6eb4ca9caa 100644 --- a/platform/uwp/detect.py +++ b/platform/uwp/detect.py @@ -10,7 +10,7 @@ def is_active(): def get_name(): - return "WinRT" + return "UWP" def can_build(): diff --git a/platform/uwp/export/export.cpp b/platform/uwp/export/export.cpp index 6a35c1cebc..aab9ae8e39 100644 --- a/platform/uwp/export/export.cpp +++ b/platform/uwp/export/export.cpp @@ -432,9 +432,9 @@ public: ~AppxPackager(); }; -class EditorExportPlatformWinrt : public EditorExportPlatform { +class EditorExportPlatformUWP : public EditorExportPlatform { - OBJ_TYPE(EditorExportPlatformWinrt, EditorExportPlatform); + OBJ_TYPE(EditorExportPlatformUWP, EditorExportPlatform); Ref logo; @@ -528,8 +528,8 @@ public: virtual Error export_project(const String& p_path, bool p_debug, int p_flags = 0); - EditorExportPlatformWinrt(); - ~EditorExportPlatformWinrt(); + EditorExportPlatformUWP(); + ~EditorExportPlatformUWP(); }; @@ -1452,7 +1452,7 @@ Error AppxPackager::sign(const CertFile & p_cert, const AppxDigests & digests, P //////////////////////////////////////////////////////////////////// -bool EditorExportPlatformWinrt::_valid_resource_name(const String &p_name) const { +bool EditorExportPlatformUWP::_valid_resource_name(const String &p_name) const { if (p_name.empty()) return false; if (p_name.ends_with(".")) return false; @@ -1472,7 +1472,7 @@ bool EditorExportPlatformWinrt::_valid_resource_name(const String &p_name) const return true; } -bool EditorExportPlatformWinrt::_valid_guid(const String & p_guid) const { +bool EditorExportPlatformUWP::_valid_guid(const String & p_guid) const { Vector parts = p_guid.split("-"); @@ -1485,7 +1485,7 @@ bool EditorExportPlatformWinrt::_valid_guid(const String & p_guid) const { return true; } -bool EditorExportPlatformWinrt::_valid_bgcolor(const String & p_color) const { +bool EditorExportPlatformUWP::_valid_bgcolor(const String & p_color) const { if (p_color.empty()) return true; if (p_color.begins_with("#") && p_color.is_valid_html_color()) return true; @@ -1529,7 +1529,7 @@ bool EditorExportPlatformWinrt::_valid_bgcolor(const String & p_color) const { return false; } -bool EditorExportPlatformWinrt::_valid_image(const Ref p_image, int p_width, int p_height) const { +bool EditorExportPlatformUWP::_valid_image(const Ref p_image, int p_width, int p_height) const { if (!p_image.is_valid()) return false; @@ -1553,7 +1553,7 @@ bool EditorExportPlatformWinrt::_valid_image(const Ref p_image, in return valid_w && valid_h; } -Vector EditorExportPlatformWinrt::_fix_manifest(const Vector &p_template, bool p_give_internet) const { +Vector EditorExportPlatformUWP::_fix_manifest(const Vector &p_template, bool p_give_internet) const { String result = String::utf8((const char*)p_template.ptr(), p_template.size()); @@ -1659,7 +1659,7 @@ Vector EditorExportPlatformWinrt::_fix_manifest(const Vector & return r_ret; } -Vector EditorExportPlatformWinrt::_get_image_data(const String & p_path) { +Vector EditorExportPlatformUWP::_get_image_data(const String & p_path) { Vector data; Ref ref; @@ -1741,7 +1741,7 @@ Vector EditorExportPlatformWinrt::_get_image_data(const String & p_path return data; } -Error EditorExportPlatformWinrt::save_appx_file(void * p_userdata, const String & p_path, const Vector& p_data, int p_file, int p_total) { +Error EditorExportPlatformUWP::save_appx_file(void * p_userdata, const String & p_path, const Vector& p_data, int p_file, int p_total) { AppxPackager *packager = (AppxPackager*)p_userdata; String dst_path = p_path.replace_first("res://", "game/"); @@ -1751,7 +1751,7 @@ Error EditorExportPlatformWinrt::save_appx_file(void * p_userdata, const String return OK; } -bool EditorExportPlatformWinrt::_should_compress_asset(const String & p_path, const Vector& p_data) { +bool EditorExportPlatformUWP::_should_compress_asset(const String & p_path, const Vector& p_data) { /* TODO: This was copied verbatim from Android export. It should be * refactored to the parent class and also be used for .zip export. @@ -1800,7 +1800,7 @@ bool EditorExportPlatformWinrt::_should_compress_asset(const String & p_path, co return true; } -bool EditorExportPlatformWinrt::_set(const StringName& p_name, const Variant& p_value) { +bool EditorExportPlatformUWP::_set(const StringName& p_name, const Variant& p_value) { String n = p_name; @@ -1906,7 +1906,7 @@ bool EditorExportPlatformWinrt::_set(const StringName& p_name, const Variant& p_ return true; } -bool EditorExportPlatformWinrt::_get(const StringName& p_name, Variant &r_ret) const { +bool EditorExportPlatformUWP::_get(const StringName& p_name, Variant &r_ret) const { String n = p_name; @@ -2002,7 +2002,7 @@ bool EditorExportPlatformWinrt::_get(const StringName& p_name, Variant &r_ret) c return true; } -void EditorExportPlatformWinrt::_get_property_list(List* p_list) const { +void EditorExportPlatformUWP::_get_property_list(List* p_list) const { p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/debug", PROPERTY_HINT_GLOBAL_FILE, "appx")); p_list->push_back(PropertyInfo(Variant::STRING, "custom_package/release", PROPERTY_HINT_GLOBAL_FILE, "appx")); @@ -2071,14 +2071,14 @@ void EditorExportPlatformWinrt::_get_property_list(List* p_list) c } -bool EditorExportPlatformWinrt::can_export(String * r_error) const { +bool EditorExportPlatformUWP::can_export(String * r_error) const { String err; bool valid = true; - if (!exists_export_template("winrt_x86_debug.zip") || !exists_export_template("winrt_x86_release.zip") - || !exists_export_template("winrt_arm_debug.zip") || !exists_export_template("winrt_arm_release.zip") - || !exists_export_template("winrt_x64_debug.zip") || !exists_export_template("winrt_x64_release.zip")) { + if (!exists_export_template("uwp_x86_debug.zip") || !exists_export_template("uwp_x86_release.zip") + || !exists_export_template("uwp_arm_debug.zip") || !exists_export_template("uwp_arm_release.zip") + || !exists_export_template("uwp_x64_debug.zip") || !exists_export_template("uwp_x64_release.zip")) { valid = false; err += TTR("No export templates found.\nDownload and install export templates.") + "\n"; } @@ -2154,7 +2154,7 @@ bool EditorExportPlatformWinrt::can_export(String * r_error) const { return valid; } -Error EditorExportPlatformWinrt::export_project(const String & p_path, bool p_debug, int p_flags) { +Error EditorExportPlatformUWP::export_project(const String & p_path, bool p_debug, int p_flags) { String src_appx; @@ -2170,30 +2170,30 @@ Error EditorExportPlatformWinrt::export_project(const String & p_path, bool p_de if (p_debug) { switch (arch) { case X86: { - src_appx = find_export_template("winrt_x86_debug.zip", &err); + src_appx = find_export_template("uwp_x86_debug.zip", &err); break; } case X64: { - src_appx = find_export_template("winrt_x64_debug.zip", &err); + src_appx = find_export_template("uwp_x64_debug.zip", &err); break; } case ARM: { - src_appx = find_export_template("winrt_arm_debug.zip", &err); + src_appx = find_export_template("uwp_arm_debug.zip", &err); break; } } } else { switch (arch) { case X86: { - src_appx = find_export_template("winrt_x86_release.zip", &err); + src_appx = find_export_template("uwp_x86_release.zip", &err); break; } case X64: { - src_appx = find_export_template("winrt_x64_release.zip", &err); + src_appx = find_export_template("uwp_x64_release.zip", &err); break; } case ARM: { - src_appx = find_export_template("winrt_arm_release.zip", &err); + src_appx = find_export_template("uwp_arm_release.zip", &err); break; } } @@ -2337,7 +2337,7 @@ Error EditorExportPlatformWinrt::export_project(const String & p_path, bool p_de return OK; } -EditorExportPlatformWinrt::EditorExportPlatformWinrt() { +EditorExportPlatformUWP::EditorExportPlatformUWP() { Image img(_uwp_logo); logo = Ref(memnew(ImageTexture)); @@ -2381,11 +2381,11 @@ EditorExportPlatformWinrt::EditorExportPlatformWinrt() { certificate_pass = ""; } -EditorExportPlatformWinrt::~EditorExportPlatformWinrt() {} +EditorExportPlatformUWP::~EditorExportPlatformUWP() {} void register_uwp_exporter() { - Ref exporter = Ref(memnew(EditorExportPlatformWinrt)); + Ref exporter = Ref(memnew(EditorExportPlatformUWP)); EditorImportExport::get_singleton()->add_export_platform(exporter); } diff --git a/platform/uwp/joystick_uwp.cpp b/platform/uwp/joystick_uwp.cpp index bcd867b14c..ad0516992b 100644 --- a/platform/uwp/joystick_uwp.cpp +++ b/platform/uwp/joystick_uwp.cpp @@ -32,15 +32,15 @@ using namespace Windows::Gaming::Input; using namespace Windows::Foundation; -void JoystickWinrt::register_events() { +void JoystickUWP::register_events() { Gamepad::GamepadAdded += - ref new EventHandler(this, &JoystickWinrt::OnGamepadAdded); + ref new EventHandler(this, &JoystickUWP::OnGamepadAdded); Gamepad::GamepadRemoved += - ref new EventHandler(this, &JoystickWinrt::OnGamepadRemoved); + ref new EventHandler(this, &JoystickUWP::OnGamepadRemoved); } -uint32_t JoystickWinrt::process_controllers(uint32_t p_last_id) { +uint32_t JoystickUWP::process_controllers(uint32_t p_last_id) { for (int i = 0; i < MAX_CONTROLLERS; i++) { @@ -74,20 +74,20 @@ uint32_t JoystickWinrt::process_controllers(uint32_t p_last_id) { return p_last_id; } -JoystickWinrt::JoystickWinrt() { +JoystickUWP::JoystickUWP() { for (int i = 0; i < MAX_CONTROLLERS; i++) controllers[i].id = i; } -JoystickWinrt::JoystickWinrt(InputDefault * p_input) { +JoystickUWP::JoystickUWP(InputDefault * p_input) { input = p_input; - JoystickWinrt(); + JoystickUWP(); } -void JoystickWinrt::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { +void JoystickUWP::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { short idx = -1; @@ -106,10 +106,10 @@ void JoystickWinrt::OnGamepadAdded(Platform::Object ^ sender, Windows::Gaming::I controllers[idx].id = idx; controllers[idx].type = ControllerType::GAMEPAD_CONTROLLER; - input->joy_connection_changed(controllers[idx].id, true, "Xbox Controller", "__WINRT_GAMEPAD__"); + input->joy_connection_changed(controllers[idx].id, true, "Xbox Controller", "__UWP_GAMEPAD__"); } -void JoystickWinrt::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { +void JoystickUWP::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming::Input::Gamepad ^ value) { short idx = -1; @@ -136,7 +136,7 @@ void JoystickWinrt::OnGamepadRemoved(Platform::Object ^ sender, Windows::Gaming: input->joy_connection_changed(idx, false, "Xbox Controller"); } -InputDefault::JoyAxis JoystickWinrt::axis_correct(double p_val, bool p_negate, bool p_trigger) const { +InputDefault::JoyAxis JoystickUWP::axis_correct(double p_val, bool p_negate, bool p_trigger) const { InputDefault::JoyAxis jx; diff --git a/platform/uwp/joystick_uwp.h b/platform/uwp/joystick_uwp.h index 0ae8b35b02..47ec738a18 100644 --- a/platform/uwp/joystick_uwp.h +++ b/platform/uwp/joystick_uwp.h @@ -26,20 +26,20 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef JOYSTICK_WINRT_H -#define JOYSTICK_WINRT_H +#ifndef JOYSTICK_UWP_H +#define JOYSTICK_UWP_H #include "main/input_default.h" -ref class JoystickWinrt sealed { +ref class JoystickUWP sealed { internal: void register_events(); uint32_t process_controllers(uint32_t p_last_id); - JoystickWinrt(); - JoystickWinrt(InputDefault* p_input); + JoystickUWP(); + JoystickUWP(InputDefault* p_input); private: diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 23d0a6aa9b..fb1dc3be19 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -69,28 +69,28 @@ using namespace Windows::ApplicationModel::DataTransfer; using namespace concurrency; -int OSWinrt::get_video_driver_count() const { +int OSUWP::get_video_driver_count() const { return 1; } -const char * OSWinrt::get_video_driver_name(int p_driver) const { +const char * OSUWP::get_video_driver_name(int p_driver) const { return "GLES2"; } -OS::VideoMode OSWinrt::get_default_video_mode() const { +OS::VideoMode OSUWP::get_default_video_mode() const { return video_mode; } -Size2 OSWinrt::get_window_size() const { +Size2 OSUWP::get_window_size() const { Size2 size; size.width = video_mode.width; size.height = video_mode.height; return size; } -void OSWinrt::set_window_size(const Size2 p_size) { +void OSUWP::set_window_size(const Size2 p_size) { Windows::Foundation::Size new_size; new_size.Width = p_size.width; @@ -105,7 +105,7 @@ void OSWinrt::set_window_size(const Size2 p_size) { } } -void OSWinrt::set_window_fullscreen(bool p_enabled) { +void OSUWP::set_window_fullscreen(bool p_enabled) { ApplicationView^ view = ApplicationView::GetForCurrentView(); @@ -126,12 +126,12 @@ void OSWinrt::set_window_fullscreen(bool p_enabled) { } } -bool OSWinrt::is_window_fullscreen() const { +bool OSUWP::is_window_fullscreen() const { return ApplicationView::GetForCurrentView()->IsFullScreenMode; } -void OSWinrt::set_keep_screen_on(bool p_enabled) { +void OSUWP::set_keep_screen_on(bool p_enabled) { if (is_keep_screen_on() == p_enabled) return; @@ -143,11 +143,11 @@ void OSWinrt::set_keep_screen_on(bool p_enabled) { OS::set_keep_screen_on(p_enabled); } -int OSWinrt::get_audio_driver_count() const { +int OSUWP::get_audio_driver_count() const { return AudioDriverManagerSW::get_driver_count(); } -const char * OSWinrt::get_audio_driver_name(int p_driver) const { +const char * OSUWP::get_audio_driver_name(int p_driver) const { AudioDriverSW* driver = AudioDriverManagerSW::get_driver(p_driver); ERR_FAIL_COND_V( !driver, "" ); @@ -157,14 +157,14 @@ const char * OSWinrt::get_audio_driver_name(int p_driver) const { static MemoryPoolStatic *mempool_static=NULL; static MemoryPoolDynamic *mempool_dynamic=NULL; -void OSWinrt::initialize_core() { +void OSUWP::initialize_core() { last_button_state=0; //RedirectIOToConsole(); - ThreadWinrt::make_default(); + ThreadUWP::make_default(); SemaphoreWindows::make_default(); MutexWindows::make_default(); @@ -206,23 +206,23 @@ void OSWinrt::initialize_core() { cursor_shape=CURSOR_ARROW; } -bool OSWinrt::can_draw() const { +bool OSUWP::can_draw() const { return !minimized; }; -void OSWinrt::set_gl_context(ContextEGL* p_context) { +void OSUWP::set_gl_context(ContextEGL* p_context) { gl_context = p_context; }; -void OSWinrt::screen_size_changed() { +void OSUWP::screen_size_changed() { gl_context->reset(); }; -void OSWinrt::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { +void OSUWP::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) { main_loop=NULL; outside=true; @@ -285,7 +285,7 @@ void OSWinrt::initialize(const VideoMode& p_desired,int p_video_driver,int p_aud input = memnew( InputDefault ); - joystick = ref new JoystickWinrt(input); + joystick = ref new JoystickUWP(input); joystick->register_events(); AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton(); @@ -345,7 +345,7 @@ void OSWinrt::initialize(const VideoMode& p_desired,int p_video_driver,int p_aud } -void OSWinrt::set_clipboard(const String& p_text) { +void OSUWP::set_clipboard(const String& p_text) { DataPackage^ clip = ref new DataPackage(); clip->RequestedOperation = DataPackageOperation::Copy; @@ -354,7 +354,7 @@ void OSWinrt::set_clipboard(const String& p_text) { Clipboard::SetContent(clip); }; -String OSWinrt::get_clipboard() const { +String OSUWP::get_clipboard() const { if (managed_object->clipboard != nullptr) return managed_object->clipboard->Data(); @@ -363,7 +363,7 @@ String OSWinrt::get_clipboard() const { }; -void OSWinrt::input_event(InputEvent &p_event) { +void OSUWP::input_event(InputEvent &p_event) { p_event.ID = ++last_id; @@ -378,20 +378,20 @@ void OSWinrt::input_event(InputEvent &p_event) { } }; -void OSWinrt::delete_main_loop() { +void OSUWP::delete_main_loop() { if (main_loop) memdelete(main_loop); main_loop=NULL; } -void OSWinrt::set_main_loop( MainLoop * p_main_loop ) { +void OSUWP::set_main_loop( MainLoop * p_main_loop ) { input->set_main_loop(p_main_loop); main_loop=p_main_loop; } -void OSWinrt::finalize() { +void OSUWP::finalize() { if(main_loop) memdelete(main_loop); @@ -432,7 +432,7 @@ void OSWinrt::finalize() { joystick = nullptr; } -void OSWinrt::finalize_core() { +void OSUWP::finalize_core() { if (mempool_dynamic) memdelete( mempool_dynamic ); @@ -440,7 +440,7 @@ void OSWinrt::finalize_core() { } -void OSWinrt::vprint(const char* p_format, va_list p_list, bool p_stderr) { +void OSUWP::vprint(const char* p_format, va_list p_list, bool p_stderr) { char buf[16384+1]; int len = vsnprintf(buf,16384,p_format,p_list); @@ -467,14 +467,14 @@ void OSWinrt::vprint(const char* p_format, va_list p_list, bool p_stderr) { fflush(stdout); }; -void OSWinrt::alert(const String& p_alert,const String& p_title) { +void OSUWP::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, &OSWinrt::ManagedType::alert_close)); + UICommand^ close = ref new UICommand("Close", ref new UICommandInvokedHandler(managed_object, &OSUWP::ManagedType::alert_close)); msg->Commands->Append(close); msg->DefaultCommandIndex = 0; @@ -483,17 +483,17 @@ void OSWinrt::alert(const String& p_alert,const String& p_title) { msg->ShowAsync(); } -void OSWinrt::ManagedType::alert_close(IUICommand^ command) { +void OSUWP::ManagedType::alert_close(IUICommand^ command) { alert_close_handle = false; } -void OSWinrt::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) { +void OSUWP::ManagedType::on_clipboard_changed(Platform::Object ^ sender, Platform::Object ^ ev) { update_clipboard(); } -void OSWinrt::ManagedType::update_clipboard() { +void OSUWP::ManagedType::update_clipboard() { DataPackageView^ data = Clipboard::GetContent(); @@ -507,7 +507,7 @@ void OSWinrt::ManagedType::update_clipboard() { } } -void OSWinrt::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) { +void OSUWP::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ sender, AccelerometerReadingChangedEventArgs ^ args) { AccelerometerReading^ reading = args->Reading; @@ -518,7 +518,7 @@ void OSWinrt::ManagedType::on_accelerometer_reading_changed(Accelerometer ^ send )); } -void OSWinrt::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) { +void OSUWP::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender, MagnetometerReadingChangedEventArgs ^ args) { MagnetometerReading^ reading = args->Reading; @@ -529,7 +529,7 @@ void OSWinrt::ManagedType::on_magnetometer_reading_changed(Magnetometer ^ sender )); } -void OSWinrt::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) { +void OSUWP::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, GyrometerReadingChangedEventArgs ^ args) { GyrometerReading^ reading = args->Reading; @@ -540,7 +540,7 @@ void OSWinrt::ManagedType::on_gyroscope_reading_changed(Gyrometer ^ sender, Gyro )); } -void OSWinrt::set_mouse_mode(MouseMode p_mode) { +void OSUWP::set_mouse_mode(MouseMode p_mode) { if (p_mode == MouseMode::MOUSE_MODE_CAPTURED) { @@ -566,41 +566,41 @@ void OSWinrt::set_mouse_mode(MouseMode p_mode) { SetEvent(mouse_mode_changed); } -OSWinrt::MouseMode OSWinrt::get_mouse_mode() const{ +OSUWP::MouseMode OSUWP::get_mouse_mode() const{ return mouse_mode; } -Point2 OSWinrt::get_mouse_pos() const { +Point2 OSUWP::get_mouse_pos() const { return Point2(old_x, old_y); } -int OSWinrt::get_mouse_button_state() const { +int OSUWP::get_mouse_button_state() const { return last_button_state; } -void OSWinrt::set_window_title(const String& p_title) { +void OSUWP::set_window_title(const String& p_title) { } -void OSWinrt::set_video_mode(const VideoMode& p_video_mode,int p_screen) { +void OSUWP::set_video_mode(const VideoMode& p_video_mode,int p_screen) { video_mode = p_video_mode; } -OS::VideoMode OSWinrt::get_video_mode(int p_screen) const { +OS::VideoMode OSUWP::get_video_mode(int p_screen) const { return video_mode; } -void OSWinrt::get_fullscreen_mode_list(List *p_list,int p_screen) const { +void OSUWP::get_fullscreen_mode_list(List *p_list,int p_screen) const { } -void OSWinrt::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) { +void OSUWP::print_error(const char* p_function, const char* p_file, int p_line, const char* p_code, const char* p_rationale, ErrorType p_type) { const char* err_details; if (p_rationale && p_rationale[0]) @@ -625,12 +625,12 @@ void OSWinrt::print_error(const char* p_function, const char* p_file, int p_line } -String OSWinrt::get_name() { +String OSUWP::get_name() { - return "WinRT"; + return "UWP"; } -OS::Date OSWinrt::get_date(bool utc) const { +OS::Date OSUWP::get_date(bool utc) const { SYSTEMTIME systemtime; if (utc) @@ -646,7 +646,7 @@ OS::Date OSWinrt::get_date(bool utc) const { date.dst=false; return date; } -OS::Time OSWinrt::get_time(bool utc) const { +OS::Time OSUWP::get_time(bool utc) const { SYSTEMTIME systemtime; if (utc) @@ -661,7 +661,7 @@ OS::Time OSWinrt::get_time(bool utc) const { return time; } -OS::TimeZoneInfo OSWinrt::get_time_zone_info() const { +OS::TimeZoneInfo OSUWP::get_time_zone_info() const { TIME_ZONE_INFORMATION info; bool daylight = false; if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) @@ -678,7 +678,7 @@ OS::TimeZoneInfo OSWinrt::get_time_zone_info() const { return ret; } -uint64_t OSWinrt::get_unix_time() const { +uint64_t OSUWP::get_unix_time() const { FILETIME ft; SYSTEMTIME st; @@ -700,7 +700,7 @@ uint64_t OSWinrt::get_unix_time() const { return (*(uint64_t*)&ft - *(uint64_t*)&fep) / 10000000; }; -void OSWinrt::delay_usec(uint32_t p_usec) const { +void OSUWP::delay_usec(uint32_t p_usec) const { int msec = p_usec < 1000 ? 1 : p_usec / 1000; @@ -708,7 +708,7 @@ void OSWinrt::delay_usec(uint32_t p_usec) const { WaitForSingleObjectEx(GetCurrentThread(), msec, false); } -uint64_t OSWinrt::get_ticks_usec() const { +uint64_t OSUWP::get_ticks_usec() const { uint64_t ticks; uint64_t time; @@ -723,13 +723,13 @@ uint64_t OSWinrt::get_ticks_usec() const { } -void OSWinrt::process_events() { +void OSUWP::process_events() { last_id = joystick->process_controllers(last_id); process_key_events(); } -void OSWinrt::process_key_events() +void OSUWP::process_key_events() { for (int i = 0; i < key_event_pos; i++) { @@ -750,7 +750,7 @@ void OSWinrt::process_key_events() key_event_pos = 0; } -void OSWinrt::queue_key_event(KeyEvent & p_event) +void OSUWP::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. @@ -768,7 +768,7 @@ void OSWinrt::queue_key_event(KeyEvent & p_event) key_event_buffer[key_event_pos++] = p_event; } -void OSWinrt::set_cursor_shape(CursorShape p_shape) { +void OSUWP::set_cursor_shape(CursorShape p_shape) { ERR_FAIL_INDEX(p_shape, CURSOR_MAX); @@ -800,58 +800,58 @@ void OSWinrt::set_cursor_shape(CursorShape p_shape) { cursor_shape = p_shape; } -Error OSWinrt::execute(const String& p_path, const List& p_arguments,bool p_blocking,ProcessID *r_child_id,String* r_pipe,int *r_exitcode) { +Error OSUWP::execute(const String& p_path, const List& p_arguments,bool p_blocking,ProcessID *r_child_id,String* r_pipe,int *r_exitcode) { return FAILED; }; -Error OSWinrt::kill(const ProcessID& p_pid) { +Error OSUWP::kill(const ProcessID& p_pid) { return FAILED; }; -Error OSWinrt::set_cwd(const String& p_cwd) { +Error OSUWP::set_cwd(const String& p_cwd) { return FAILED; } -String OSWinrt::get_executable_path() const { +String OSUWP::get_executable_path() const { return ""; } -void OSWinrt::set_icon(const Image& p_icon) { +void OSUWP::set_icon(const Image& p_icon) { } -bool OSWinrt::has_environment(const String& p_var) const { +bool OSUWP::has_environment(const String& p_var) const { return false; }; -String OSWinrt::get_environment(const String& p_var) const { +String OSUWP::get_environment(const String& p_var) const { return ""; }; -String OSWinrt::get_stdin_string(bool p_block) { +String OSUWP::get_stdin_string(bool p_block) { return String(); } -void OSWinrt::move_window_to_foreground() { +void OSUWP::move_window_to_foreground() { } -Error OSWinrt::shell_open(String p_uri) { +Error OSUWP::shell_open(String p_uri) { return FAILED; } -String OSWinrt::get_locale() const { +String OSUWP::get_locale() const { #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP // this should work on phone 8.1, but it doesn't return "en"; @@ -861,46 +861,46 @@ String OSWinrt::get_locale() const { #endif } -void OSWinrt::release_rendering_thread() { +void OSUWP::release_rendering_thread() { gl_context->release_current(); } -void OSWinrt::make_rendering_thread() { +void OSUWP::make_rendering_thread() { gl_context->make_current(); } -void OSWinrt::swap_buffers() { +void OSUWP::swap_buffers() { gl_context->swap_buffers(); } -bool OSWinrt::has_touchscreen_ui_hint() const { +bool OSUWP::has_touchscreen_ui_hint() const { TouchCapabilities^ tc = ref new TouchCapabilities(); return tc->TouchPresent != 0 || UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; } -bool OSWinrt::has_virtual_keyboard() const { +bool OSUWP::has_virtual_keyboard() const { return UIViewSettings::GetForCurrentView()->UserInteractionMode == UserInteractionMode::Touch; } -void OSWinrt::show_virtual_keyboard(const String & p_existing_text, const Rect2 & p_screen_rect) { +void OSUWP::show_virtual_keyboard(const String & p_existing_text, const Rect2 & p_screen_rect) { InputPane^ pane = InputPane::GetForCurrentView(); pane->TryShow(); } -void OSWinrt::hide_virtual_keyboard() { +void OSUWP::hide_virtual_keyboard() { InputPane^ pane = InputPane::GetForCurrentView(); pane->TryHide(); } -void OSWinrt::run() { +void OSUWP::run() { if (!main_loop) return; @@ -927,13 +927,13 @@ void OSWinrt::run() { -MainLoop *OSWinrt::get_main_loop() const { +MainLoop *OSUWP::get_main_loop() const { return main_loop; } -String OSWinrt::get_data_dir() const { +String OSUWP::get_data_dir() const { Windows::Storage::StorageFolder ^data_folder = Windows::Storage::ApplicationData::Current->LocalFolder; @@ -941,7 +941,7 @@ String OSWinrt::get_data_dir() const { } -OSWinrt::OSWinrt() { +OSUWP::OSUWP() { key_event_pos=0; force_quit=false; @@ -973,7 +973,7 @@ OSWinrt::OSWinrt() { } -OSWinrt::~OSWinrt() +OSUWP::~OSUWP() { #ifdef STDOUT_FILE fclose(stdo); diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 98a3cc54cc..47eb095e11 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -26,8 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef OSWinrt_H -#define OSWinrt_H +#ifndef OSUWP_H +#define OSUWP_H #include "os/input.h" #include "os/os.h" @@ -60,7 +60,7 @@ /** @author Juan Linietsky */ -class OSWinrt : public OS { +class OSUWP : public OS { public: @@ -137,7 +137,7 @@ private: InputDefault *input; - JoystickWinrt^ joystick; + JoystickUWP^ joystick; Windows::System::Display::DisplayRequest^ display_request; @@ -159,7 +159,7 @@ private: internal: ManagedType() { alert_close_handle = false; } - property OSWinrt* os; + property OSUWP* os; }; ManagedType^ managed_object; Windows::Devices::Sensors::Accelerometer^ accelerometer; @@ -273,8 +273,8 @@ public: void queue_key_event(KeyEvent &p_event); - OSWinrt(); - ~OSWinrt(); + OSUWP(); + ~OSUWP(); }; diff --git a/platform/uwp/thread_uwp.cpp b/platform/uwp/thread_uwp.cpp index 5f7d1ca24b..a5a0920df6 100644 --- a/platform/uwp/thread_uwp.cpp +++ b/platform/uwp/thread_uwp.cpp @@ -30,9 +30,9 @@ #include "os/memory.h" -Thread* ThreadWinrt::create_func_winrt(ThreadCreateCallback p_callback,void *p_user,const Settings&) { +Thread* ThreadUWP::create_func_uwp(ThreadCreateCallback p_callback,void *p_user,const Settings&) { - ThreadWinrt* thread = memnew(ThreadWinrt); + ThreadUWP* thread = memnew(ThreadUWP); std::thread new_thread(p_callback, p_user); @@ -41,34 +41,34 @@ Thread* ThreadWinrt::create_func_winrt(ThreadCreateCallback p_callback,void *p_u return thread; }; -Thread::ID ThreadWinrt::get_thread_ID_func_winrt() { +Thread::ID ThreadUWP::get_thread_ID_func_uwp() { return std::hash()(std::this_thread::get_id()); }; -void ThreadWinrt::wait_to_finish_func_winrt(Thread* p_thread) { +void ThreadUWP::wait_to_finish_func_uwp(Thread* p_thread) { - ThreadWinrt *tp=static_cast(p_thread); + ThreadUWP *tp=static_cast(p_thread); tp->thread.join(); }; -Thread::ID ThreadWinrt::get_ID() const { +Thread::ID ThreadUWP::get_ID() const { return std::hash()(thread.get_id()); }; -void ThreadWinrt::make_default() { - create_func = create_func_winrt; - get_thread_ID_func = get_thread_ID_func_winrt; - wait_to_finish_func = wait_to_finish_func_winrt; +void ThreadUWP::make_default() { + create_func = create_func_uwp; + get_thread_ID_func = get_thread_ID_func_uwp; + wait_to_finish_func = wait_to_finish_func_uwp; }; -ThreadWinrt::ThreadWinrt() { +ThreadUWP::ThreadUWP() { }; -ThreadWinrt::~ThreadWinrt() { +ThreadUWP::~ThreadUWP() { }; diff --git a/platform/uwp/thread_uwp.h b/platform/uwp/thread_uwp.h index 328d29bdc7..95b9aeb62b 100644 --- a/platform/uwp/thread_uwp.h +++ b/platform/uwp/thread_uwp.h @@ -26,8 +26,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef THREAD_WINRT_H -#define THREAD_WINRT_H +#ifndef THREAD_UWP_H +#define THREAD_UWP_H #ifdef UWP_ENABLED @@ -35,15 +35,15 @@ #include -class ThreadWinrt : public Thread { +class ThreadUWP : public Thread { std::thread thread; - static Thread* create_func_winrt(ThreadCreateCallback p_callback,void *,const Settings&); - static ID get_thread_ID_func_winrt(); - static void wait_to_finish_func_winrt(Thread* p_thread); + static Thread* create_func_uwp(ThreadCreateCallback p_callback,void *,const Settings&); + static ID get_thread_ID_func_uwp(); + static void wait_to_finish_func_uwp(Thread* p_thread); - ThreadWinrt(); + ThreadUWP(); public: @@ -52,7 +52,7 @@ public: static void make_default(); - ~ThreadWinrt(); + ~ThreadUWP(); }; diff --git a/thirdparty/README.md b/thirdparty/README.md index f61812c71a..6423c63cf9 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -14,7 +14,7 @@ Files extracted from upstream source: - LICENSE file Important: Some files have been modified by Godot developers so that they work -for all platforms (especially WinRT). Check the diff with the 1.3.13 tarball +for all platforms (especially UWP). Check the diff with the 1.3.13 tarball before the next update. diff --git a/thirdparty/openssl/uwp.cpp b/thirdparty/openssl/uwp.cpp index 6bb0c22523..dcfd22b77f 100644 --- a/thirdparty/openssl/uwp.cpp +++ b/thirdparty/openssl/uwp.cpp @@ -1,7 +1,7 @@ /* Snippets extracted from https://github.com/Microsoft/openssl/blob/ec7e430e06e4e3ac87c183dee33cb216814cf980/ms/winrt.cpp * Adapted for Godot definitions */ -/* winrt.cpp +/* uwp.cpp * Copyright 2014 Microsoft Corporation * C++/CX Entropy/shims for Windows Phone/Windows Store platform * written by Alejandro Jimenez Martinez @@ -144,7 +144,7 @@ extern "C" { return 0; } - int winrt_GetTickCount(void) + int uwp_GetTickCount(void) { LARGE_INTEGER t; return(int) (QueryPerformanceCounter(&t) ? t.QuadPart : 0); diff --git a/tools/dist/uwp_template/AppxManifest.xml b/tools/dist/uwp_template/AppxManifest.xml index 48a2ba7eb3..d5e653708c 100644 --- a/tools/dist/uwp_template/AppxManifest.xml +++ b/tools/dist/uwp_template/AppxManifest.xml @@ -15,7 +15,7 @@ - + $name_on_tiles$ -- cgit v1.2.3