diff options
-rw-r--r-- | core/os/os.h | 4 | ||||
-rw-r--r-- | doc/classes/Time.xml | 13 | ||||
-rw-r--r-- | drivers/unix/os_unix.cpp | 8 | ||||
-rw-r--r-- | drivers/unix/os_unix.h | 4 | ||||
-rw-r--r-- | modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs | 28 | ||||
-rw-r--r-- | modules/mono/glue/callable_glue.cpp | 79 | ||||
-rw-r--r-- | modules/mono/glue/glue_header.h | 2 | ||||
-rw-r--r-- | modules/websocket/emws_peer.cpp | 7 | ||||
-rw-r--r-- | modules/websocket/wsl_peer.cpp | 8 | ||||
-rw-r--r-- | platform/uwp/os_uwp.cpp | 9 | ||||
-rw-r--r-- | platform/uwp/os_uwp.h | 4 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 14 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 4 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/renderer_scene_render_rd.cpp | 4 |
14 files changed, 152 insertions, 36 deletions
diff --git a/core/os/os.h b/core/os/os.h index 6d7bc47407..2700759fef 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -204,8 +204,8 @@ public: String name; }; - virtual Date get_date(bool local = false) const = 0; - virtual Time get_time(bool local = false) const = 0; + virtual Date get_date(bool p_utc = false) const = 0; + virtual Time get_time(bool p_utc = false) const = 0; virtual TimeZoneInfo get_time_zone_info() const = 0; virtual double get_unix_time() const; diff --git a/doc/classes/Time.xml b/doc/classes/Time.xml index d8e1d874f7..b66ec83eaf 100644 --- a/doc/classes/Time.xml +++ b/doc/classes/Time.xml @@ -6,7 +6,8 @@ <description> The Time singleton allows converting time between various formats and also getting time information from the system. This class conforms with as many of the ISO 8601 standards as possible. All dates follow the Proleptic Gregorian calendar. As such, the day before [code]1582-10-15[/code] is [code]1582-10-14[/code], not [code]1582-10-04[/code]. The year before 1 AD (aka 1 BC) is number [code]0[/code], with the year before that (2 BC) being [code]-1[/code], etc. - Conversion methods assume "the same timezone", and do not handle timezone conversions or DST automatically. Unix epoch assumes UTC. Leap seconds are also not handled, they must be done manually if desired. Suffixes such as "Z" are not handled, you need to strip them away manually. + Conversion methods assume "the same timezone", and do not handle timezone conversions or DST automatically. Leap seconds are also not handled, they must be done manually if desired. Suffixes such as "Z" are not handled, you need to strip them away manually. + When getting time information from the system, the time can either be in the local timezone or UTC depending on the [code]utc[/code] parameter. However, the [method get_unix_time_from_system] method always returns the time in UTC. [b]Important:[/b] The [code]_from_system[/code] methods use the system clock that the user can manually set. [b]Never use[/b] this method for precise time calculation since its results are subject to automatic adjustments by the user or the operating system. [b]Always use[/b] [method get_ticks_usec] or [method get_ticks_msec] for precise time calculation instead, since they are guaranteed to be monotonic (i.e. never decrease). </description> <tutorials> @@ -82,7 +83,7 @@ <argument index="0" name="utc" type="bool" default="false" /> <argument index="1" name="use_space" type="bool" default="false" /> <description> - Returns the current date and time as a dictionary of keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]weekday[/code], [code]dst[/code] (Daylight Savings Time), [code]hour[/code], [code]minute[/code], and [code]second[/code]. + Returns the current date and time as an ISO 8601 date and time string (YYYY-MM-DDTHH:MM:SS). The returned values are in the system's local time when [code]utc[/code] is false, otherwise they are in UTC. If [code]use_space[/code] is true, use a space instead of the letter T in the middle. </description> @@ -152,9 +153,9 @@ <description> Converts a dictionary of time values to a Unix timestamp. The given dictionary can be populated with the following keys: [code]year[/code], [code]month[/code], [code]day[/code], [code]hour[/code], [code]minute[/code], and [code]second[/code]. Any other entries (including [code]dst[/code]) are ignored. - If the dictionary is empty, [code]0[/code] is returned. If some keys are omitted, they default to the equivalent values for the Unix epoch timestamp 0 (1970-01-01 at 00:00:00 UTC). + If the dictionary is empty, [code]0[/code] is returned. If some keys are omitted, they default to the equivalent values for the Unix epoch timestamp 0 (1970-01-01 at 00:00:00). You can pass the output from [method get_datetime_dict_from_unix_time] directly into this function and get the same as what was put in. - [b]Note:[/b] Unix timestamps are usually in UTC, the given datetime dict may not be. + [b]Note:[/b] Unix timestamps are often in UTC. This method does not do any timezone conversion, so the timestamp will be in the same timezone as the given datetime dictionary. </description> </method> <method name="get_unix_time_from_datetime_string" qualifiers="const"> @@ -162,13 +163,13 @@ <argument index="0" name="datetime" type="String" /> <description> Converts the given ISO 8601 date and/or time string to a Unix timestamp. The string can contain a date only, a time only, or both. - [b]Note:[/b] Unix timestamps are usually in UTC, the given datetime string may not be. + [b]Note:[/b] Unix timestamps are often in UTC. This method does not do any timezone conversion, so the timestamp will be in the same timezone as the given datetime string. </description> </method> <method name="get_unix_time_from_system" qualifiers="const"> <return type="float" /> <description> - Returns the current Unix timestamp in seconds based on the system time in UTC. + Returns the current Unix timestamp in seconds based on the system time in UTC. This method is implemented by the operating system and always returns the time in UTC. </description> </method> </methods> diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 193825a73f..1bc88a86f7 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -160,10 +160,10 @@ double OS_Unix::get_unix_time() const { return (double)tv_now.tv_sec + double(tv_now.tv_usec) / 1000000; }; -OS::Date OS_Unix::get_date(bool utc) const { +OS::Date OS_Unix::get_date(bool p_utc) const { time_t t = time(nullptr); struct tm lt; - if (utc) { + if (p_utc) { gmtime_r(&t, <); } else { localtime_r(&t, <); @@ -181,10 +181,10 @@ OS::Date OS_Unix::get_date(bool utc) const { return ret; } -OS::Time OS_Unix::get_time(bool utc) const { +OS::Time OS_Unix::get_time(bool p_utc) const { time_t t = time(nullptr); struct tm lt; - if (utc) { + if (p_utc) { gmtime_r(&t, <); } else { localtime_r(&t, <); diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index eb36bf4255..cbc870d385 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -72,8 +72,8 @@ public: virtual String get_name() const override; - virtual Date get_date(bool utc) const override; - virtual Time get_time(bool utc) const override; + virtual Date get_date(bool p_utc) const override; + virtual Time get_time(bool p_utc) const override; virtual TimeZoneInfo get_time_zone_info() const override; virtual double get_unix_time() const override; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs index a28a46896b..2722b64e6d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Callable.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace Godot { @@ -71,5 +72,32 @@ namespace Godot _method = null; _delegate = @delegate; } + + /// <summary> + /// Calls the method represented by this <see cref="Callable"/>. + /// Arguments can be passed and should match the method's signature. + /// </summary> + /// <param name="args">Arguments that will be passed to the method call.</param> + /// <returns>The value returned by the method.</returns> + public object Call(params object[] args) + { + return godot_icall_Callable_Call(ref this, args); + } + + /// <summary> + /// Calls the method represented by this <see cref="Callable"/> in deferred mode, i.e. during the idle frame. + /// Arguments can be passed and should match the method's signature. + /// </summary> + /// <param name="args">Arguments that will be passed to the method call.</param> + public void CallDeferred(params object[] args) + { + godot_icall_Callable_CallDeferred(ref this, args); + } + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern object godot_icall_Callable_Call(ref Callable callable, object[] args); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern void godot_icall_Callable_CallDeferred(ref Callable callable, object[] args); } } diff --git a/modules/mono/glue/callable_glue.cpp b/modules/mono/glue/callable_glue.cpp new file mode 100644 index 0000000000..54b65fdb94 --- /dev/null +++ b/modules/mono/glue/callable_glue.cpp @@ -0,0 +1,79 @@ +/*************************************************************************/ +/* callable_glue.cpp */ +/*************************************************************************/ +/* 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. */ +/*************************************************************************/ + +#ifdef MONO_GLUE_ENABLED + +#include "../mono_gd/gd_mono_marshal.h" +#include "arguments_vector.h" + +MonoObject *godot_icall_Callable_Call(GDMonoMarshal::M_Callable *p_callable, MonoArray *p_args) { + Callable callable = GDMonoMarshal::managed_to_callable(*p_callable); + + int argc = mono_array_length(p_args); + + ArgumentsVector<Variant> arg_store(argc); + ArgumentsVector<const Variant *> args(argc); + + for (int i = 0; i < argc; i++) { + MonoObject *elem = mono_array_get(p_args, MonoObject *, i); + arg_store.set(i, GDMonoMarshal::mono_object_to_variant(elem)); + args.set(i, &arg_store.get(i)); + } + + Variant result; + Callable::CallError error; + callable.call(args.ptr(), argc, result, error); + + return GDMonoMarshal::variant_to_mono_object(result); +} + +void godot_icall_Callable_CallDeferred(GDMonoMarshal::M_Callable *p_callable, MonoArray *p_args) { + Callable callable = GDMonoMarshal::managed_to_callable(*p_callable); + + int argc = mono_array_length(p_args); + + ArgumentsVector<Variant> arg_store(argc); + ArgumentsVector<const Variant *> args(argc); + + for (int i = 0; i < argc; i++) { + MonoObject *elem = mono_array_get(p_args, MonoObject *, i); + arg_store.set(i, GDMonoMarshal::mono_object_to_variant(elem)); + args.set(i, &arg_store.get(i)); + } + + callable.call_deferred(args.ptr(), argc); +} + +void godot_register_callable_icalls() { + GDMonoUtils::add_internal_call("Godot.Callable::godot_icall_Callable_Call", godot_icall_Callable_Call); + GDMonoUtils::add_internal_call("Godot.Callable::godot_icall_Callable_CallDeferred", godot_icall_Callable_CallDeferred); +} + +#endif // MONO_GLUE_ENABLED diff --git a/modules/mono/glue/glue_header.h b/modules/mono/glue/glue_header.h index eed3bd2167..074220bb9b 100644 --- a/modules/mono/glue/glue_header.h +++ b/modules/mono/glue/glue_header.h @@ -36,6 +36,7 @@ void godot_register_collections_icalls(); void godot_register_gd_icalls(); void godot_register_string_name_icalls(); void godot_register_nodepath_icalls(); +void godot_register_callable_icalls(); void godot_register_object_icalls(); void godot_register_rid_icalls(); void godot_register_string_icalls(); @@ -50,6 +51,7 @@ void godot_register_glue_header_icalls() { godot_register_gd_icalls(); godot_register_string_name_icalls(); godot_register_nodepath_icalls(); + godot_register_callable_icalls(); godot_register_object_icalls(); godot_register_rid_icalls(); godot_register_string_icalls(); diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index d7263dcf43..035d036b90 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -54,11 +54,14 @@ Error EMWSPeer::read_msg(const uint8_t *p_data, uint32_t p_size, bool p_is_strin } Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(_out_buf_size && ((uint64_t)godot_js_websocket_buffered_amount(peer_sock) >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY); + ERR_FAIL_COND_V(_out_buf_size && ((uint64_t)godot_js_websocket_buffered_amount(peer_sock) + p_buffer_size >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY); int is_bin = write_mode == WebSocketPeer::WRITE_MODE_BINARY ? 1 : 0; - godot_js_websocket_send(peer_sock, p_buffer, p_buffer_size, is_bin); + if (godot_js_websocket_send(peer_sock, p_buffer, p_buffer_size, is_bin) != 0) { + return FAILED; + } + return OK; } diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 7f027e1c0d..fc520ec57c 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -242,15 +242,15 @@ void WSLPeer::poll() { Error WSLPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { ERR_FAIL_COND_V(!is_connected_to_host(), FAILED); ERR_FAIL_COND_V(_out_pkt_size && (wslay_event_get_queued_msg_count(_data->ctx) >= (1ULL << _out_pkt_size)), ERR_OUT_OF_MEMORY); - ERR_FAIL_COND_V(_out_buf_size && (wslay_event_get_queued_msg_length(_data->ctx) >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY); + ERR_FAIL_COND_V(_out_buf_size && (wslay_event_get_queued_msg_length(_data->ctx) + p_buffer_size >= (1ULL << _out_buf_size)), ERR_OUT_OF_MEMORY); - struct wslay_event_msg msg; // Should I use fragmented? + struct wslay_event_msg msg; msg.opcode = write_mode == WRITE_MODE_TEXT ? WSLAY_TEXT_FRAME : WSLAY_BINARY_FRAME; msg.msg = p_buffer; msg.msg_length = p_buffer_size; - wslay_event_queue_msg(_data->ctx, &msg); - if (wslay_event_send(_data->ctx) < 0) { + // Queue & send message. + if (wslay_event_queue_msg(_data->ctx, &msg) != 0 || wslay_event_send(_data->ctx) != 0) { close_now(); return FAILED; } diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index daf3c14f3b..1a84f5da38 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -441,12 +441,13 @@ String OS_UWP::get_name() const { return "UWP"; } -OS::Date OS_UWP::get_date(bool utc) const { +OS::Date OS_UWP::get_date(bool p_utc) const { SYSTEMTIME systemtime; - if (utc) + if (utc) { GetSystemTime(&systemtime); - else + } else { GetLocalTime(&systemtime); + } Date date; date.day = systemtime.wDay; @@ -457,7 +458,7 @@ OS::Date OS_UWP::get_date(bool utc) const { return date; } -OS::Time OS_UWP::get_time(bool utc) const { +OS::Time OS_UWP::get_time(bool p_utc) const { SYSTEMTIME systemtime; if (utc) GetSystemTime(&systemtime); diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 9398573ee1..74a9e96b2c 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -185,8 +185,8 @@ public: virtual String get_name() const; - virtual Date get_date(bool utc) const; - virtual Time get_time(bool utc) const; + virtual Date get_date(bool p_utc) const; + virtual Time get_time(bool p_utc) const; virtual TimeZoneInfo get_time_zone_info() const; virtual uint64_t get_unix_time() const; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 6c02bf1e16..22c0219ea6 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -290,12 +290,13 @@ String OS_Windows::get_name() const { return "Windows"; } -OS::Date OS_Windows::get_date(bool utc) const { +OS::Date OS_Windows::get_date(bool p_utc) const { SYSTEMTIME systemtime; - if (utc) + if (p_utc) { GetSystemTime(&systemtime); - else + } else { GetLocalTime(&systemtime); + } Date date; date.day = systemtime.wDay; @@ -306,12 +307,13 @@ OS::Date OS_Windows::get_date(bool utc) const { return date; } -OS::Time OS_Windows::get_time(bool utc) const { +OS::Time OS_Windows::get_time(bool p_utc) const { SYSTEMTIME systemtime; - if (utc) + if (p_utc) { GetSystemTime(&systemtime); - else + } else { GetLocalTime(&systemtime); + } Time time; time.hour = systemtime.wHour; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index d24afa91eb..b8eca956c8 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -122,8 +122,8 @@ public: virtual void initialize_joypads() override {} - virtual Date get_date(bool utc) const override; - virtual Time get_time(bool utc) const override; + virtual Date get_date(bool p_utc) const override; + virtual Time get_time(bool p_utc) const override; virtual TimeZoneInfo get_time_zone_info() const override; virtual double get_unix_time() const override; diff --git a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp index 0db1722f33..3d8ae4c944 100644 --- a/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp +++ b/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp @@ -3589,7 +3589,7 @@ void RendererSceneRenderRD::FogShaderData::get_instance_param_list(List<Renderer p.info = ShaderLanguage::uniform_to_property_info(E->get()); p.info.name = E->key(); //supply name p.index = E->get().instance_index; - p.default_value = ShaderLanguage::constant_value_to_variant(E->get().default_value, E->get().type, E->get().hint); + p.default_value = ShaderLanguage::constant_value_to_variant(E->get().default_value, E->get().type, E->get().array_size, E->get().hint); p_param_list->push_back(p); } } @@ -3614,7 +3614,7 @@ Variant RendererSceneRenderRD::FogShaderData::get_default_parameter(const String if (uniforms.has(p_parameter)) { ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter]; Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value; - return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.hint); + return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint); } return Variant(); } |