diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/javascript/http_client.h.inc | 51 | ||||
-rw-r--r-- | platform/javascript/http_client_javascript.cpp | 101 | ||||
-rw-r--r-- | platform/javascript/http_client_javascript.h | 108 | ||||
-rw-r--r-- | platform/osx/display_server_osx.mm | 6 |
4 files changed, 147 insertions, 119 deletions
diff --git a/platform/javascript/http_client.h.inc b/platform/javascript/http_client.h.inc deleted file mode 100644 index 6544d41c98..0000000000 --- a/platform/javascript/http_client.h.inc +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************/ -/* http_client.h.inc */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -// HTTPClient's additional private members in the javascript platform - -Error make_request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len); -static void _parse_headers(int p_len, const char **p_headers, void *p_ref); - -int js_id = 0; -// 64 KiB by default (favors fast download speeds at the cost of memory usage). -int read_limit = 65536; -Status status = STATUS_DISCONNECTED; - -String host; -int port = -1; -bool use_tls = false; - -int polled_response_code = 0; -Vector<String> response_headers; -Vector<uint8_t> response_buffer; - -#ifdef DEBUG_ENABLED -uint64_t last_polling_frame = 0; -#endif diff --git a/platform/javascript/http_client_javascript.cpp b/platform/javascript/http_client_javascript.cpp index a6cf4b0eb8..f7d78abcea 100644 --- a/platform/javascript/http_client_javascript.cpp +++ b/platform/javascript/http_client_javascript.cpp @@ -28,45 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "core/io/http_client.h" +#include "http_client_javascript.h" -#ifdef __cplusplus -extern "C" { -#endif - -#include "stddef.h" - -typedef enum { - GODOT_JS_FETCH_STATE_REQUESTING = 0, - GODOT_JS_FETCH_STATE_BODY = 1, - GODOT_JS_FETCH_STATE_DONE = 2, - GODOT_JS_FETCH_STATE_ERROR = -1, -} godot_js_fetch_state_t; - -extern int godot_js_fetch_create(const char *p_method, const char *p_url, const char **p_headers, int p_headers_len, const uint8_t *p_body, int p_body_len); -extern int godot_js_fetch_read_headers(int p_id, void (*parse_callback)(int p_size, const char **p_headers, void *p_ref), void *p_ref); -extern int godot_js_fetch_read_chunk(int p_id, uint8_t *p_buf, int p_buf_size); -extern void godot_js_fetch_free(int p_id); -extern godot_js_fetch_state_t godot_js_fetch_state_get(int p_id); -extern int godot_js_fetch_body_length_get(int p_id); -extern int godot_js_fetch_http_status_get(int p_id); -extern int godot_js_fetch_is_chunked(int p_id); - -#ifdef __cplusplus -} -#endif - -void HTTPClient::_parse_headers(int p_len, const char **p_headers, void *p_ref) { - HTTPClient *client = static_cast<HTTPClient *>(p_ref); +void HTTPClientJavaScript::_parse_headers(int p_len, const char **p_headers, void *p_ref) { + HTTPClientJavaScript *client = static_cast<HTTPClientJavaScript *>(p_ref); for (int i = 0; i < p_len; i++) { client->response_headers.push_back(String::utf8(p_headers[i])); } } -Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { +Error HTTPClientJavaScript::connect_to_host(const String &p_host, int p_port, bool p_ssl, bool p_verify_host) { close(); if (p_ssl && !p_verify_host) { - WARN_PRINT("Disabling HTTPClient's host verification is not supported for the HTML5 platform, host will be verified"); + WARN_PRINT("Disabling HTTPClientJavaScript's host verification is not supported for the HTML5 platform, host will be verified"); } port = p_port; @@ -97,15 +71,15 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, return OK; } -void HTTPClient::set_connection(const Ref<StreamPeer> &p_connection) { - ERR_FAIL_MSG("Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); +void HTTPClientJavaScript::set_connection(const Ref<StreamPeer> &p_connection) { + ERR_FAIL_MSG("Accessing an HTTPClientJavaScript's StreamPeer is not supported for the HTML5 platform."); } -Ref<StreamPeer> HTTPClient::get_connection() const { - ERR_FAIL_V_MSG(REF(), "Accessing an HTTPClient's StreamPeer is not supported for the HTML5 platform."); +Ref<StreamPeer> HTTPClientJavaScript::get_connection() const { + ERR_FAIL_V_MSG(REF(), "Accessing an HTTPClientJavaScript's StreamPeer is not supported for the HTML5 platform."); } -Error HTTPClient::make_request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len) { +Error HTTPClientJavaScript::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_len) { ERR_FAIL_INDEX_V(p_method, METHOD_MAX, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V_MSG(p_method == METHOD_TRACE || p_method == METHOD_CONNECT, ERR_UNAVAILABLE, "HTTP methods TRACE and CONNECT are not supported for the HTML5 platform."); ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_INVALID_PARAMETER); @@ -128,22 +102,7 @@ Error HTTPClient::make_request(Method p_method, const String &p_url, const Vecto return OK; } -Error HTTPClient::request_raw(Method p_method, const String &p_url, const Vector<String> &p_headers, const Vector<uint8_t> &p_body) { - if (p_body.is_empty()) { - return make_request(p_method, p_url, p_headers, nullptr, 0); - } - return make_request(p_method, p_url, p_headers, p_body.ptr(), p_body.size()); -} - -Error HTTPClient::request(Method p_method, const String &p_url, const Vector<String> &p_headers, const String &p_body) { - if (p_body.is_empty()) { - return make_request(p_method, p_url, p_headers, nullptr, 0); - } - const CharString cs = p_body.utf8(); - return make_request(p_method, p_url, p_headers, (const uint8_t *)cs.get_data(), cs.size() - 1); -} - -void HTTPClient::close() { +void HTTPClientJavaScript::close() { host = ""; port = -1; use_tls = false; @@ -157,23 +116,23 @@ void HTTPClient::close() { } } -HTTPClient::Status HTTPClient::get_status() const { +HTTPClientJavaScript::Status HTTPClientJavaScript::get_status() const { return status; } -bool HTTPClient::has_response() const { +bool HTTPClientJavaScript::has_response() const { return response_headers.size() > 0; } -bool HTTPClient::is_response_chunked() const { +bool HTTPClientJavaScript::is_response_chunked() const { return godot_js_fetch_is_chunked(js_id); } -int HTTPClient::get_response_code() const { +int HTTPClientJavaScript::get_response_code() const { return polled_response_code; } -Error HTTPClient::get_response_headers(List<String> *r_response) { +Error HTTPClientJavaScript::get_response_headers(List<String> *r_response) { if (!response_headers.size()) { return ERR_INVALID_PARAMETER; } @@ -184,11 +143,11 @@ Error HTTPClient::get_response_headers(List<String> *r_response) { return OK; } -int HTTPClient::get_response_body_length() const { +int HTTPClientJavaScript::get_response_body_length() const { return godot_js_fetch_body_length_get(js_id); } -PackedByteArray HTTPClient::read_response_body_chunk() { +PackedByteArray HTTPClientJavaScript::read_response_body_chunk() { ERR_FAIL_COND_V(status != STATUS_BODY, PackedByteArray()); if (response_buffer.size() != read_limit) { @@ -213,23 +172,23 @@ PackedByteArray HTTPClient::read_response_body_chunk() { return chunk; } -void HTTPClient::set_blocking_mode(bool p_enable) { - ERR_FAIL_COND_MSG(p_enable, "HTTPClient blocking mode is not supported for the HTML5 platform."); +void HTTPClientJavaScript::set_blocking_mode(bool p_enable) { + ERR_FAIL_COND_MSG(p_enable, "HTTPClientJavaScript blocking mode is not supported for the HTML5 platform."); } -bool HTTPClient::is_blocking_mode_enabled() const { +bool HTTPClientJavaScript::is_blocking_mode_enabled() const { return false; } -void HTTPClient::set_read_chunk_size(int p_size) { +void HTTPClientJavaScript::set_read_chunk_size(int p_size) { read_limit = p_size; } -int HTTPClient::get_read_chunk_size() const { +int HTTPClientJavaScript::get_read_chunk_size() const { return read_limit; } -Error HTTPClient::poll() { +Error HTTPClientJavaScript::poll() { switch (status) { case STATUS_DISCONNECTED: return ERR_UNCONFIGURED; @@ -263,7 +222,7 @@ Error HTTPClient::poll() { #ifdef DEBUG_ENABLED // forcing synchronous requests is not possible on the web if (last_polling_frame == Engine::get_singleton()->get_process_frames()) { - WARN_PRINT("HTTPClient polled multiple times in one frame, " + WARN_PRINT("HTTPClientJavaScript polled multiple times in one frame, " "but request cannot progress more than once per " "frame on the HTML5 platform."); } @@ -294,9 +253,15 @@ Error HTTPClient::poll() { return OK; } -HTTPClient::HTTPClient() { +HTTPClient *HTTPClientJavaScript::_create_func() { + return memnew(HTTPClientJavaScript); +} + +HTTPClient *(*HTTPClient::_create)() = HTTPClientJavaScript::_create_func; + +HTTPClientJavaScript::HTTPClientJavaScript() { } -HTTPClient::~HTTPClient() { +HTTPClientJavaScript::~HTTPClientJavaScript() { close(); } diff --git a/platform/javascript/http_client_javascript.h b/platform/javascript/http_client_javascript.h new file mode 100644 index 0000000000..33f91f67b6 --- /dev/null +++ b/platform/javascript/http_client_javascript.h @@ -0,0 +1,108 @@ +/*************************************************************************/ +/* http_client_javascript.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef HTTP_CLIENT_JAVASCRIPT_H +#define HTTP_CLIENT_JAVASCRIPT_H + +#include "core/io/http_client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stddef.h" + +typedef enum { + GODOT_JS_FETCH_STATE_REQUESTING = 0, + GODOT_JS_FETCH_STATE_BODY = 1, + GODOT_JS_FETCH_STATE_DONE = 2, + GODOT_JS_FETCH_STATE_ERROR = -1, +} godot_js_fetch_state_t; + +extern int godot_js_fetch_create(const char *p_method, const char *p_url, const char **p_headers, int p_headers_len, const uint8_t *p_body, int p_body_len); +extern int godot_js_fetch_read_headers(int p_id, void (*parse_callback)(int p_size, const char **p_headers, void *p_ref), void *p_ref); +extern int godot_js_fetch_read_chunk(int p_id, uint8_t *p_buf, int p_buf_size); +extern void godot_js_fetch_free(int p_id); +extern godot_js_fetch_state_t godot_js_fetch_state_get(int p_id); +extern int godot_js_fetch_body_length_get(int p_id); +extern int godot_js_fetch_http_status_get(int p_id); +extern int godot_js_fetch_is_chunked(int p_id); + +#ifdef __cplusplus +} +#endif + +class HTTPClientJavaScript : public HTTPClient { +private: + int js_id = 0; + Status status = STATUS_DISCONNECTED; + + // 64 KiB by default (favors fast download speeds at the cost of memory usage). + int read_limit = 65536; + + String host; + int port = -1; + bool use_tls = false; + + int polled_response_code = 0; + Vector<String> response_headers; + Vector<uint8_t> response_buffer; + +#ifdef DEBUG_ENABLED + uint64_t last_polling_frame = 0; +#endif + + static void _parse_headers(int p_len, const char **p_headers, void *p_ref); + +public: + static HTTPClient *_create_func(); + + Error request(Method p_method, const String &p_url, const Vector<String> &p_headers, const uint8_t *p_body, int p_body_size) override; + + Error connect_to_host(const String &p_host, int p_port = -1, bool p_ssl = false, bool p_verify_host = true) override; + void set_connection(const Ref<StreamPeer> &p_connection) override; + Ref<StreamPeer> get_connection() const override; + void close() override; + Status get_status() const override; + bool has_response() const override; + bool is_response_chunked() const override; + int get_response_code() const override; + Error get_response_headers(List<String> *r_response) override; + int get_response_body_length() const override; + PackedByteArray read_response_body_chunk() override; + void set_blocking_mode(bool p_enable) override; + bool is_blocking_mode_enabled() const override; + void set_read_chunk_size(int p_size) override; + int get_read_chunk_size() const override; + Error poll() override; + HTTPClientJavaScript(); + ~HTTPClientJavaScript(); +}; +#endif // HTTP_CLIENT_JAVASCRIPT_H diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index ec51ec78d3..4a672a4b17 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -2120,6 +2120,12 @@ void DisplayServerOSX::mouse_set_mode(MouseMode p_mode) { ignore_warp = true; warp_events.clear(); mouse_mode = p_mode; + + if (mouse_mode == MOUSE_MODE_VISIBLE || mouse_mode == MOUSE_MODE_CONFINED) { + CursorShape p_shape = cursor_shape; + cursor_shape = DisplayServer::CURSOR_MAX; + cursor_set_shape(p_shape); + } } DisplayServer::MouseMode DisplayServerOSX::mouse_get_mode() const { |