diff options
Diffstat (limited to 'core')
51 files changed, 389 insertions, 164 deletions
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 99cc51b95e..46629d742e 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -545,12 +545,12 @@ bool InputEventMouseButton::is_pressed() const { return pressed; } -void InputEventMouseButton::set_doubleclick(bool p_doubleclick) { - doubleclick = p_doubleclick; +void InputEventMouseButton::set_double_click(bool p_double_click) { + double_click = p_double_click; } -bool InputEventMouseButton::is_doubleclick() const { - return doubleclick; +bool InputEventMouseButton::is_double_click() const { + return double_click; } Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { @@ -569,7 +569,7 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co mb->set_button_mask(get_button_mask()); mb->set_pressed(pressed); - mb->set_doubleclick(doubleclick); + mb->set_double_click(double_click); mb->set_factor(factor); mb->set_button_index(button_index); @@ -636,7 +636,7 @@ String InputEventMouseButton::as_text() const { } // Double Click - if (doubleclick) { + if (double_click) { full_string += " (" + RTR("Double Click") + ")"; } @@ -645,7 +645,7 @@ String InputEventMouseButton::as_text() const { String InputEventMouseButton::to_string() { String p = is_pressed() ? "true" : "false"; - String d = doubleclick ? "true" : "false"; + String d = double_click ? "true" : "false"; int idx = get_button_index(); String button_string = itos(idx); @@ -671,7 +671,7 @@ String InputEventMouseButton::to_string() { // Work around the fact vformat can only take 5 substitutions but 6 need to be passed. String index_and_mods = vformat("button_index=%s mods=%s", button_index, mods); - return vformat("InputEventMouseButton: %s pressed=%s position=(%s) button_mask=%s doubleclick=%s", index_and_mods, p, String(get_position()), itos(get_button_mask()), d); + return vformat("InputEventMouseButton: %s pressed=%s position=(%s) button_mask=%s double_click=%s", index_and_mods, p, String(get_position()), itos(get_button_mask()), d); } void InputEventMouseButton::_bind_methods() { @@ -684,13 +684,13 @@ void InputEventMouseButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed); // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed); - ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick); - ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick); + ClassDB::bind_method(D_METHOD("set_double_click", "double_click"), &InputEventMouseButton::set_double_click); + ClassDB::bind_method(D_METHOD("is_double_click"), &InputEventMouseButton::is_double_click); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "factor"), "set_factor", "get_factor"); ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "double_click"), "set_double_click", "is_double_click"); } /////////////////////////////////// diff --git a/core/input/input_event.h b/core/input/input_event.h index a1e7df5969..5a33ee7b9c 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -33,7 +33,6 @@ #include "core/io/resource.h" #include "core/math/transform_2d.h" -#include "core/os/copymem.h" #include "core/string/ustring.h" #include "core/typedefs.h" @@ -295,7 +294,7 @@ class InputEventMouseButton : public InputEventMouse { float factor = 1; int button_index = 0; bool pressed = false; //otherwise released - bool doubleclick = false; //last even less than doubleclick time + bool double_click = false; //last even less than double click time protected: static void _bind_methods(); @@ -310,8 +309,8 @@ public: void set_pressed(bool p_pressed); virtual bool is_pressed() const override; - void set_doubleclick(bool p_doubleclick); - bool is_doubleclick() const; + void set_double_click(bool p_double_click); + bool is_double_click() const; virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index aab4e6593c..7421909650 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -474,6 +474,7 @@ const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { inputs = List<Ref<InputEvent>>(); inputs.push_back(InputEventKey::create_reference(KEY_TAB)); + inputs.push_back(InputEventKey::create_reference(KEY_ENTER)); default_builtin_cache.insert("ui_text_completion_accept", inputs); // Newlines diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 980234cbfc..6de626db99 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -32,7 +32,6 @@ #include "core/config/project_settings.h" #include "core/io/zip_io.h" -#include "core/os/copymem.h" #include "thirdparty/misc/fastlz.h" @@ -44,8 +43,8 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, case MODE_FASTLZ: { if (p_src_size < 16) { uint8_t src[16]; - zeromem(&src[p_src_size], 16 - p_src_size); - copymem(src, p_src, p_src_size); + memset(&src[p_src_size], 0, 16 - p_src_size); + memcpy(src, p_src, p_src_size); return fastlz_compress(src, 16, p_dst); } else { return fastlz_compress(p_src, p_src_size, p_dst); @@ -136,7 +135,7 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p if (p_dst_max_size < 16) { uint8_t dst[16]; ret_size = fastlz_decompress(p_src, p_src_size, dst, 16); - copymem(p_dst, dst, p_dst_max_size); + memcpy(p_dst, dst, p_dst_max_size); } else { ret_size = fastlz_decompress(p_src, p_src_size, p_dst, p_dst_max_size); } diff --git a/core/io/file_access_encrypted.cpp b/core/io/file_access_encrypted.cpp index 8ace897f18..13377a3a25 100644 --- a/core/io/file_access_encrypted.cpp +++ b/core/io/file_access_encrypted.cpp @@ -31,7 +31,6 @@ #include "file_access_encrypted.h" #include "core/crypto/crypto_core.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" #include "core/variant/variant.h" @@ -151,7 +150,7 @@ void FileAccessEncrypted::_release() { ERR_FAIL_COND(CryptoCore::md5(data.ptr(), data.size(), hash) != OK); // Bug? compressed.resize(len); - zeromem(compressed.ptrw(), len); + memset(compressed.ptrw(), 0, len); for (int i = 0; i < data.size(); i++) { compressed.write[i] = data[i]; } diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp index 58670d5246..af155a77a8 100644 --- a/core/io/file_access_memory.cpp +++ b/core/io/file_access_memory.cpp @@ -31,7 +31,6 @@ #include "file_access_memory.h" #include "core/config/project_settings.h" -#include "core/os/copymem.h" #include "core/os/dir_access.h" #include "core/templates/map.h" @@ -149,7 +148,7 @@ int FileAccessMemory::get_buffer(uint8_t *p_dst, int p_length) const { WARN_PRINT("Reading less data than requested"); } - copymem(p_dst, &data[pos], read); + memcpy(p_dst, &data[pos], read); pos += p_length; return read; @@ -176,6 +175,6 @@ void FileAccessMemory::store_buffer(const uint8_t *p_src, int p_length) { WARN_PRINT("Writing less data than requested"); } - copymem(&data[pos], p_src, write); + memcpy(&data[pos], p_src, write); pos += p_length; } diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 586c988974..397b577612 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -32,7 +32,6 @@ #include "file_access_zip.h" -#include "core/os/copymem.h" #include "core/os/file_access.h" ZipArchive *ZipArchive::instance = nullptr; @@ -120,7 +119,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V_MSG(!f, nullptr, "Cannot open file '" + packages[file.package].filename + "'."); zlib_filefunc_def io; - zeromem(&io, sizeof(io)); + memset(&io, 0, sizeof(io)); io.opaque = f; io.zopen_file = godot_open; diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 3863dce0f6..4b053d576c 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -633,7 +633,7 @@ PackedByteArray HTTPClient::read_response_body_chunk() { ret.resize(chunk.size() - 2); uint8_t *w = ret.ptrw(); - copymem(w, chunk.ptr(), chunk.size() - 2); + memcpy(w, chunk.ptr(), chunk.size() - 2); chunk.clear(); } diff --git a/core/io/image.cpp b/core/io/image.cpp index 873eb66f33..c36fa6e45f 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -34,7 +34,6 @@ #include "core/io/image_loader.h" #include "core/io/resource_loader.h" #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" #include "core/templates/hash_map.h" @@ -1537,7 +1536,7 @@ void Image::shrink_x2() { uint8_t *w = new_img.ptrw(); const uint8_t *r = data.ptr(); - copymem(w, &r[ofs], new_size); + memcpy(w, &r[ofs], new_size); } width = MAX(width / 2, 1); @@ -1932,7 +1931,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con uint8_t* wr = imgdata.ptrw(); - copymem(wr.ptr(), ptr, size); + memcpy(wr.ptr(), ptr, size); wr = uint8_t*(); Ref<Image> im; im.instance(); @@ -1982,7 +1981,7 @@ void Image::create(int p_width, int p_height, bool p_use_mipmaps, Format p_forma { uint8_t *w = data.ptrw(); - zeromem(w, size); + memset(w, 0, size); } width = p_width; @@ -3295,7 +3294,7 @@ Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const { { uint8_t *wr = new_data.ptrw(); const uint8_t *rd = data.ptr(); - copymem(wr, rd + ofs, size); + memcpy(wr, rd + ofs, size); } Ref<Image> image; @@ -3622,5 +3621,5 @@ Ref<Resource> Image::duplicate(bool p_subresources) const { } void Image::set_as_black() { - zeromem(data.ptrw(), data.size()); + memset(data.ptrw(), 0, data.size()); } diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index 218a612da2..0282609270 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -851,7 +851,7 @@ static void _encode_string(const String &p_string, uint8_t *&buf, int &r_len) { if (buf) { encode_uint32(utf8.length(), buf); buf += 4; - copymem(buf, utf8.get_data(), utf8.length()); + memcpy(buf, utf8.get_data(), utf8.length()); buf += utf8.length(); } @@ -995,7 +995,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (buf) { encode_uint32(utf8.length(), buf); buf += 4; - copymem(buf, utf8.get_data(), utf8.length()); + memcpy(buf, utf8.get_data(), utf8.length()); buf += pad + utf8.length(); } @@ -1079,7 +1079,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Transform2D val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - copymem(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 2 + j) * 4], &val.elements[i][j], sizeof(float)); } } } @@ -1130,7 +1130,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Basis val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * 4], &val.elements[i][j], sizeof(float)); } } } @@ -1143,7 +1143,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo Transform val = p_variant; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - copymem(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); + memcpy(&buf[(i * 3 + j) * 4], &val.basis.elements[i][j], sizeof(float)); } } @@ -1258,7 +1258,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (buf) { encode_uint32(utf8.length()+1,buf); buf+=4; - copymem(buf,utf8.get_data(),utf8.length()+1); + memcpy(buf,utf8.get_data(),utf8.length()+1); } r_len+=4+utf8.length()+1; @@ -1314,7 +1314,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo encode_uint32(datalen, buf); buf += 4; const uint8_t *r = data.ptr(); - copymem(buf, &r[0], datalen * datasize); + memcpy(buf, &r[0], datalen * datasize); buf += datalen * datasize; } @@ -1412,7 +1412,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo if (buf) { encode_uint32(utf8.length() + 1, buf); buf += 4; - copymem(buf, utf8.get_data(), utf8.length() + 1); + memcpy(buf, utf8.get_data(), utf8.length() + 1); buf += utf8.length() + 1; } diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index 94060cfe0b..8414ee7c0c 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -897,7 +897,7 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p // Special optimization when only the byte vector is sent. const Vector<uint8_t> data = *p_arg[0]; MAKE_ROOM(ofs + data.size()); - copymem(&(packet_cache.write[ofs]), data.ptr(), sizeof(uint8_t) * data.size()); + memcpy(&(packet_cache.write[ofs]), data.ptr(), sizeof(uint8_t) * data.size()); ofs += data.size(); } else { // Arguments diff --git a/core/io/net_socket.h b/core/io/net_socket.h index bc09477693..a632ad2ea7 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -67,6 +67,7 @@ public: virtual bool is_open() const = 0; virtual int get_available_bytes() const = 0; + virtual Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) const = 0; virtual Error set_broadcasting_enabled(bool p_enabled) = 0; // Returns OK if the socket option has been set successfully. virtual void set_blocking_enabled(bool p_enabled) = 0; diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index a0b97772e6..c6354b11b7 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -317,7 +317,7 @@ Error PackedDataContainer::pack(const Variant &p_data) { datalen = tmpdata.size(); data.resize(tmpdata.size()); uint8_t *w = data.ptrw(); - copymem(w, tmpdata.ptr(), tmpdata.size()); + memcpy(w, tmpdata.ptr(), tmpdata.size()); return OK; } diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 3f46f2706e..40e4ce4f77 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -159,10 +159,11 @@ int PacketPeerUDP::get_max_packet_size() const { return 512; // uhm maybe not } -Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { +Error PacketPeerUDP::bind(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; @@ -210,6 +211,7 @@ Error PacketPeerUDP::connect_to_host(const IP_Address &p_host, int p_port) { ERR_FAIL_COND_V(udp_server, ERR_LOCKED); ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, ERR_INVALID_PARAMETER, "The remote port number must be between 1 and 65535 (inclusive)."); Error err; @@ -316,7 +318,7 @@ Error PacketPeerUDP::store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_b return OK; } -bool PacketPeerUDP::is_listening() const { +bool PacketPeerUDP::is_bound() const { return _sock.is_valid() && _sock->is_open(); } @@ -328,6 +330,12 @@ int PacketPeerUDP::get_packet_port() const { return packet_port; } +int PacketPeerUDP::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) { ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets"); peer_addr = p_address; @@ -335,14 +343,15 @@ void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) { } void PacketPeerUDP::_bind_methods() { - ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536)); + ClassDB::bind_method(D_METHOD("bind", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::bind, DEFVAL("*"), DEFVAL(65536)); ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close); ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); - ClassDB::bind_method(D_METHOD("is_listening"), &PacketPeerUDP::is_listening); + ClassDB::bind_method(D_METHOD("is_bound"), &PacketPeerUDP::is_bound); ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &PacketPeerUDP::connect_to_host); ClassDB::bind_method(D_METHOD("is_connected_to_host"), &PacketPeerUDP::is_connected_to_host); ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port); + ClassDB::bind_method(D_METHOD("get_local_port"), &PacketPeerUDP::get_local_port); ClassDB::bind_method(D_METHOD("set_dest_address", "host", "port"), &PacketPeerUDP::_set_dest_address); ClassDB::bind_method(D_METHOD("set_broadcast_enabled", "enabled"), &PacketPeerUDP::set_broadcast_enabled); ClassDB::bind_method(D_METHOD("join_multicast_group", "multicast_address", "interface_name"), &PacketPeerUDP::join_multicast_group); diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 4bac6994fc..b9d11c465c 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -70,10 +70,10 @@ protected: public: void set_blocking_mode(bool p_enable); - Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); + Error bind(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); void close(); Error wait(); - bool is_listening() const; + bool is_bound() const; Error connect_shared_socket(Ref<NetSocket> p_sock, IP_Address p_ip, uint16_t p_port, UDPServer *ref); // Used by UDPServer void disconnect_shared_socket(); // Used by UDPServer @@ -83,6 +83,7 @@ public: IP_Address get_packet_address() const; int get_packet_port() const; + int get_local_port() const; void set_dest_address(const IP_Address &p_address, int p_port); Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 8560e2abc7..d46e9edafa 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -110,6 +110,12 @@ String Resource::get_name() const { return name; } +void Resource::update_configuration_warning() { + if (_update_configuration_warning) { + _update_configuration_warning(); + } +} + bool Resource::editor_can_reload_from_file() { return true; //by default yes } @@ -320,6 +326,7 @@ void Resource::setup_local_to_scene() { } Node *(*Resource::_get_local_scene_func)() = nullptr; +void (*Resource::_update_configuration_warning)() = nullptr; void Resource::set_as_translation_remapped(bool p_remapped) { if (remapped_list.in_list() == p_remapped) { diff --git a/core/io/resource.h b/core/io/resource.h index ae18ac0c8a..75a9f928f8 100644 --- a/core/io/resource.h +++ b/core/io/resource.h @@ -88,7 +88,9 @@ protected: public: static Node *(*_get_local_scene_func)(); //used by editor + static void (*_update_configuration_warning)(); //used by editor + void update_configuration_warning(); virtual bool editor_can_reload_from_file(); virtual void reset_state(); //for resources that use variable amount of properties, either via _validate_property or _get_property_list, this function needs to be implemented to correctly clear state virtual Error copy_from(const Ref<Resource> &p_resource); diff --git a/core/io/stream_peer.cpp b/core/io/stream_peer.cpp index 8407d55196..74154321b3 100644 --- a/core/io/stream_peer.cpp +++ b/core/io/stream_peer.cpp @@ -433,7 +433,7 @@ Error StreamPeerBuffer::put_data(const uint8_t *p_data, int p_bytes) { } uint8_t *w = data.ptrw(); - copymem(&w[pointer], p_data, p_bytes); + memcpy(&w[pointer], p_data, p_bytes); pointer += p_bytes; return OK; @@ -466,7 +466,7 @@ Error StreamPeerBuffer::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_ } const uint8_t *r = data.ptr(); - copymem(p_buffer, r + pointer, r_received); + memcpy(p_buffer, r + pointer, r_received); pointer += r_received; // FIXME: return what? OK or ERR_* diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 760710a9eb..9906b9e4c3 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -67,21 +67,40 @@ void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint peer_port = p_port; } -Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, uint16_t p_port) { +Error StreamPeerTCP::bind(int p_port, const IP_Address &p_host) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); - ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); - Error err; IP::Type ip_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + if (p_host.is_wildcard()) { + ip_type = IP::TYPE_ANY; + } + Error err = _sock->open(NetSocket::TYPE_TCP, ip_type); + if (err != OK) { + return err; + } + _sock->set_blocking_enabled(false); + return _sock->bind(p_host, p_port); +} - err = _sock->open(NetSocket::TYPE_TCP, ip_type); - ERR_FAIL_COND_V(err != OK, FAILED); +Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, int p_port) { + ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); + ERR_FAIL_COND_V(status != STATUS_NONE, ERR_ALREADY_IN_USE); + ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 1 || p_port > 65535, ERR_INVALID_PARAMETER, "The remote port number must be between 1 and 65535 (inclusive)."); - _sock->set_blocking_enabled(false); + if (!_sock->is_open()) { + IP::Type ip_type = p_host.is_ipv4() ? IP::TYPE_IPV4 : IP::TYPE_IPV6; + Error err = _sock->open(NetSocket::TYPE_TCP, ip_type); + if (err != OK) { + return err; + } + _sock->set_blocking_enabled(false); + } timeout = OS::get_singleton()->get_ticks_msec() + (((uint64_t)GLOBAL_GET("network/limits/tcp/connect_timeout_seconds")) * 1000); - err = _sock->connect_to_host(p_host, p_port); + Error err = _sock->connect_to_host(p_host, p_port); if (err == OK) { status = STATUS_CONNECTED; @@ -300,10 +319,16 @@ IP_Address StreamPeerTCP::get_connected_host() const { return peer_host; } -uint16_t StreamPeerTCP::get_connected_port() const { +int StreamPeerTCP::get_connected_port() const { return peer_port; } +int StreamPeerTCP::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + Error StreamPeerTCP::_connect(const String &p_address, int p_port) { IP_Address ip; if (p_address.is_valid_ip_address()) { @@ -319,11 +344,13 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { } void StreamPeerTCP::_bind_methods() { + ClassDB::bind_method(D_METHOD("bind", "port", "host"), &StreamPeerTCP::bind, DEFVAL("*")); ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &StreamPeerTCP::_connect); ClassDB::bind_method(D_METHOD("is_connected_to_host"), &StreamPeerTCP::is_connected_to_host); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status); ClassDB::bind_method(D_METHOD("get_connected_host"), &StreamPeerTCP::get_connected_host); ClassDB::bind_method(D_METHOD("get_connected_port"), &StreamPeerTCP::get_connected_port); + ClassDB::bind_method(D_METHOD("get_local_port"), &StreamPeerTCP::get_local_port); ClassDB::bind_method(D_METHOD("disconnect_from_host"), &StreamPeerTCP::disconnect_from_host); ClassDB::bind_method(D_METHOD("set_no_delay", "enabled"), &StreamPeerTCP::set_no_delay); diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 10b90908d4..3bc7b252dc 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -65,10 +65,12 @@ protected: public: void accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port); - Error connect_to_host(const IP_Address &p_host, uint16_t p_port); + Error bind(int p_port, const IP_Address &p_host); + Error connect_to_host(const IP_Address &p_host, int p_port); bool is_connected_to_host() const; IP_Address get_connected_host() const; - uint16_t get_connected_port() const; + int get_connected_port() const; + int get_local_port() const; void disconnect_from_host(); int get_available_bytes() const override; diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 323d2bbd7f..348be66ba4 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -34,6 +34,7 @@ void TCP_Server::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available); ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening); + ClassDB::bind_method(D_METHOD("get_local_port"), &TCP_Server::get_local_port); ClassDB::bind_method(D_METHOD("take_connection"), &TCP_Server::take_connection); ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop); } @@ -42,6 +43,7 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; @@ -74,6 +76,12 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { return OK; } +int TCP_Server::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + bool TCP_Server::is_listening() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index f06ddd2d99..58c04d87ec 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -49,6 +49,7 @@ protected: public: Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")); + int get_local_port() const; bool is_listening() const; bool is_connection_available() const; Ref<StreamPeerTCP> take_connection(); diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index f56fb431ef..99642f4af4 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -34,6 +34,7 @@ void UDPServer::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &UDPServer::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("poll"), &UDPServer::poll); ClassDB::bind_method(D_METHOD("is_connection_available"), &UDPServer::is_connection_available); + ClassDB::bind_method(D_METHOD("get_local_port"), &UDPServer::get_local_port); ClassDB::bind_method(D_METHOD("is_listening"), &UDPServer::is_listening); ClassDB::bind_method(D_METHOD("take_connection"), &UDPServer::take_connection); ClassDB::bind_method(D_METHOD("stop"), &UDPServer::stop); @@ -90,6 +91,7 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE); ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; @@ -112,11 +114,15 @@ Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { stop(); return err; } - bind_address = p_bind_address; - bind_port = p_port; return OK; } +int UDPServer::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + bool UDPServer::is_listening() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); @@ -176,8 +182,6 @@ void UDPServer::stop() { if (_sock.is_valid()) { _sock->close(); } - bind_port = 0; - bind_address = IP_Address(); List<Peer>::Element *E = peers.front(); while (E) { E->get().peer->disconnect_shared_socket(); diff --git a/core/io/udp_server.h b/core/io/udp_server.h index bbd2f951c9..298d4d4b63 100644 --- a/core/io/udp_server.h +++ b/core/io/udp_server.h @@ -53,21 +53,18 @@ protected: }; uint8_t recv_buffer[PACKET_BUFFER_SIZE]; - int bind_port = 0; - IP_Address bind_address; - List<Peer> peers; List<Peer> pending; int max_pending_connections = 16; Ref<NetSocket> _sock; - static void _bind_methods(); public: void remove_peer(IP_Address p_ip, int p_port); Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")); Error poll(); + int get_local_port() const; bool is_listening() const; bool is_connection_available() const; void set_max_pending_connections(int p_max); diff --git a/core/io/xml_parser.cpp b/core/io/xml_parser.cpp index d5eb32513b..a1f8e79adc 100644 --- a/core/io/xml_parser.cpp +++ b/core/io/xml_parser.cpp @@ -433,7 +433,7 @@ Error XMLParser::open_buffer(const Vector<uint8_t> &p_buffer) { length = p_buffer.size(); data = memnew_arr(char, length + 1); - copymem(data, p_buffer.ptr(), length); + memcpy(data, p_buffer.ptr(), length); data[length] = 0; P = data; return OK; diff --git a/core/io/zip_io.cpp b/core/io/zip_io.cpp index 4b4a46e198..fe46868dd0 100644 --- a/core/io/zip_io.cpp +++ b/core/io/zip_io.cpp @@ -30,8 +30,6 @@ #include "zip_io.h" -#include "core/os/copymem.h" - void *zipio_open(void *data, const char *p_fname, int mode) { FileAccess *&f = *(FileAccess **)data; @@ -103,7 +101,7 @@ int zipio_testerror(voidpf opaque, voidpf stream) { voidpf zipio_alloc(voidpf opaque, uInt items, uInt size) { voidpf ptr = memalloc(items * size); - zeromem(ptr, items * size); + memset(ptr, 0, items * size); return ptr; } diff --git a/core/math/basis.cpp b/core/math/basis.cpp index cc2b7c6611..50299902eb 100644 --- a/core/math/basis.cpp +++ b/core/math/basis.cpp @@ -31,7 +31,6 @@ #include "basis.h" #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" #define cofac(row1, col1, row2, col2) \ diff --git a/core/math/dynamic_bvh.h b/core/math/dynamic_bvh.h index 3fb22515a2..0b6286cd9d 100644 --- a/core/math/dynamic_bvh.h +++ b/core/math/dynamic_bvh.h @@ -343,7 +343,7 @@ void DynamicBVH::aabb_query(const AABB &p_box, QueryResult &r_result) { if (depth > threshold) { if (aux_stack.is_empty()) { aux_stack.resize(ALLOCA_STACK_SIZE * 2); - copymem(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); + memcpy(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); } else { aux_stack.resize(aux_stack.size() * 2); } @@ -399,7 +399,7 @@ void DynamicBVH::convex_query(const Plane *p_planes, int p_plane_count, const Ve if (depth > threshold) { if (aux_stack.is_empty()) { aux_stack.resize(ALLOCA_STACK_SIZE * 2); - copymem(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); + memcpy(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); } else { aux_stack.resize(aux_stack.size() * 2); } @@ -456,7 +456,7 @@ void DynamicBVH::ray_query(const Vector3 &p_from, const Vector3 &p_to, QueryResu if (depth > threshold) { if (aux_stack.is_empty()) { aux_stack.resize(ALLOCA_STACK_SIZE * 2); - copymem(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); + memcpy(aux_stack.ptr(), stack, ALLOCA_STACK_SIZE * sizeof(const Node *)); } else { aux_stack.resize(aux_stack.size() * 2); } diff --git a/core/math/face3.cpp b/core/math/face3.cpp index beb0a8e405..20c316c322 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -169,7 +169,7 @@ Vector3 Face3::get_median_point() const { } real_t Face3::get_area() const { - return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length(); + return vec3_cross(vertex[0] - vertex[1], vertex[0] - vertex[2]).length() * 0.5; } ClockDirection Face3::get_clock_dir() const { diff --git a/core/math/geometry_2d.cpp b/core/math/geometry_2d.cpp index feb1fb2fb8..7b2630b4ff 100644 --- a/core/math/geometry_2d.cpp +++ b/core/math/geometry_2d.cpp @@ -358,7 +358,7 @@ Vector<Point2i> Geometry2D::pack_rects(const Vector<Size2i> &p_sizes, const Size Vector<Vector3i> Geometry2D::partial_pack_rects(const Vector<Vector2i> &p_sizes, const Size2i &p_atlas_size) { Vector<stbrp_node> nodes; nodes.resize(p_atlas_size.width); - zeromem(nodes.ptrw(), sizeof(stbrp_node) * nodes.size()); + memset(nodes.ptrw(), 0, sizeof(stbrp_node) * nodes.size()); stbrp_context context; stbrp_init_target(&context, p_atlas_size.width, p_atlas_size.height, nodes.ptrw(), p_atlas_size.width); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 267f6a4fe2..c0d7649b65 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -103,6 +103,9 @@ public: static _ALWAYS_INLINE_ double log(double p_x) { return ::log(p_x); } static _ALWAYS_INLINE_ float log(float p_x) { return ::logf(p_x); } + static _ALWAYS_INLINE_ double log2(double p_x) { return ::log2(p_x); } + static _ALWAYS_INLINE_ float log2(float p_x) { return ::log2f(p_x); } + static _ALWAYS_INLINE_ double exp(double p_x) { return ::exp(p_x); } static _ALWAYS_INLINE_ float exp(float p_x) { return ::expf(p_x); } @@ -215,8 +218,8 @@ public: return value; } - static _ALWAYS_INLINE_ int posmod(int p_x, int p_y) { - int value = p_x % p_y; + static _ALWAYS_INLINE_ int64_t posmod(int64_t p_x, int64_t p_y) { + int64_t value = p_x % p_y; if ((value < 0 && p_y > 0) || (value > 0 && p_y < 0)) { value += p_y; } diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp index 1152c4e834..681c2a9717 100644 --- a/core/math/random_pcg.cpp +++ b/core/math/random_pcg.cpp @@ -39,7 +39,7 @@ RandomPCG::RandomPCG(uint64_t p_seed, uint64_t p_inc) : } void RandomPCG::randomize() { - seed((OS::get_singleton()->get_unix_time() + OS::get_singleton()->get_ticks_usec()) * pcg.state + PCG_DEFAULT_INC_64); + seed(((uint64_t)OS::get_singleton()->get_unix_time() + OS::get_singleton()->get_ticks_usec()) * pcg.state + PCG_DEFAULT_INC_64); } double RandomPCG::random(double p_from, double p_to) { diff --git a/core/math/transform.cpp b/core/math/transform.cpp index fab5d124fa..d4d7ff6d28 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -31,7 +31,6 @@ #include "transform.h" #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/string/print_string.h" void Transform::affine_invert() { diff --git a/core/object/callable_method_pointer.h b/core/object/callable_method_pointer.h index 115797a00c..8ba01be4e4 100644 --- a/core/object/callable_method_pointer.h +++ b/core/object/callable_method_pointer.h @@ -32,7 +32,6 @@ #define CALLABLE_METHOD_POINTER_H #include "core/object/object.h" -#include "core/os/copymem.h" #include "core/templates/hashfuncs.h" #include "core/templates/simple_type.h" #include "core/variant/binder_common.h" @@ -98,7 +97,7 @@ public: } CallableCustomMethodPointer(T *p_instance, void (T::*p_method)(P...)) { - zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes. data.instance = p_instance; #ifdef DEBUG_ENABLED data.object_id = p_instance->get_instance_id(); @@ -153,7 +152,7 @@ public: } CallableCustomMethodPointerRet(T *p_instance, R (T::*p_method)(P...)) { - zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes. data.instance = p_instance; #ifdef DEBUG_ENABLED data.object_id = p_instance->get_instance_id(); @@ -208,7 +207,7 @@ public: } CallableCustomMethodPointerRetC(T *p_instance, R (T::*p_method)(P...) const) { - zeromem(&data, sizeof(Data)); // Clear beforehand, may have padding bytes. + memset(&data, 0, sizeof(Data)); // Clear beforehand, may have padding bytes. data.instance = p_instance; #ifdef DEBUG_ENABLED data.object_id = p_instance->get_instance_id(); diff --git a/core/os/copymem.h b/core/os/copymem.h deleted file mode 100644 index 6fd559356c..0000000000 --- a/core/os/copymem.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************/ -/* copymem.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 COPYMEM_H -#define COPYMEM_H - -#include "core/typedefs.h" - -#ifdef PLATFORM_COPYMEM - -#include "platform_copymem.h" // included from platform/<current_platform>/platform_copymem.h" - -#else - -#include <string.h> - -#define copymem(to, from, count) memcpy(to, from, count) -#define zeromem(to, count) memset(to, 0, count) -#define movemem(to, from, count) memmove(to, from, count) - -#endif - -#endif // COPYMEM_H diff --git a/core/os/memory.cpp b/core/os/memory.cpp index 5910cb0e7b..a756c1d5dd 100644 --- a/core/os/memory.cpp +++ b/core/os/memory.cpp @@ -31,7 +31,6 @@ #include "memory.h" #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/templates/safe_refcount.h" #include <stdio.h> diff --git a/core/os/pool_allocator.cpp b/core/os/pool_allocator.cpp index 9be3a62e2f..74e9c24e04 100644 --- a/core/os/pool_allocator.cpp +++ b/core/os/pool_allocator.cpp @@ -31,7 +31,6 @@ #include "pool_allocator.h" #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/os/os.h" #include "core/string/print_string.h" @@ -42,7 +41,7 @@ do { \ void *_dst = &((unsigned char *)pool)[m_to_pos]; \ void *_src = &((unsigned char *)pool)[(m_entry).pos]; \ - movemem(_dst, _src, aligned((m_entry).len)); \ + memmove(_dst, _src, aligned((m_entry).len)); \ (m_entry).pos = m_to_pos; \ } while (0); diff --git a/core/string/optimized_translation.cpp b/core/string/optimized_translation.cpp index 53d0a8924d..268562d971 100644 --- a/core/string/optimized_translation.cpp +++ b/core/string/optimized_translation.cpp @@ -46,6 +46,7 @@ void OptimizedTranslation::generate(const Ref<Translation> &p_from) { // This method compresses a Translation instance. // Right now, it doesn't handle context or plurals, so Translation subclasses using plurals or context (i.e TranslationPO) shouldn't be compressed. #ifdef TOOLS_ENABLED + ERR_FAIL_COND(p_from.is_null()); List<StringName> keys; p_from->get_message_list(&keys); diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index cf0040353d..bdb66526a4 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -240,6 +240,71 @@ String String::word_wrap(int p_chars_per_line) const { return ret; } +Error String::parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path) const { + // Splits the URL into scheme, host, port, path. Strip credentials when present. + String base = *this; + r_scheme = ""; + r_host = ""; + r_port = 0; + r_path = ""; + int pos = base.find("://"); + // Scheme + if (pos != -1) { + r_scheme = base.substr(0, pos + 3).to_lower(); + base = base.substr(pos + 3, base.length() - pos - 3); + } + pos = base.find("/"); + // Path + if (pos != -1) { + r_path = base.substr(pos, base.length() - pos); + base = base.substr(0, pos); + } + // Host + pos = base.find("@"); + if (pos != -1) { + // Strip credentials + base = base.substr(pos + 1, base.length() - pos - 1); + } + if (base.begins_with("[")) { + // Literal IPv6 + pos = base.rfind("]"); + if (pos == -1) { + return ERR_INVALID_PARAMETER; + } + r_host = base.substr(1, pos - 1); + base = base.substr(pos + 1, base.length() - pos - 1); + } else { + // Anything else + if (base.get_slice_count(":") > 1) { + return ERR_INVALID_PARAMETER; + } + pos = base.rfind(":"); + if (pos == -1) { + r_host = base; + base = ""; + } else { + r_host = base.substr(0, pos); + base = base.substr(pos, base.length() - pos); + } + } + if (r_host.is_empty()) { + return ERR_INVALID_PARAMETER; + } + r_host = r_host.to_lower(); + // Port + if (base.begins_with(":")) { + base = base.substr(1, base.length() - 1); + if (!base.is_valid_integer()) { + return ERR_INVALID_PARAMETER; + } + r_port = base.to_int(); + if (r_port < 1 || r_port > 65535) { + return ERR_INVALID_PARAMETER; + } + } + return OK; +} + void String::copy_from(const char *p_cstr) { // copy Latin-1 encoded c-string directly if (!p_cstr) { @@ -3784,27 +3849,28 @@ String String::uri_encode() const { } String String::uri_decode() const { - String res; - for (int i = 0; i < length(); ++i) { - if (unicode_at(i) == '%' && i + 2 < length()) { - char32_t ord1 = unicode_at(i + 1); + CharString src = utf8(); + CharString res; + for (int i = 0; i < src.length(); ++i) { + if (src[i] == '%' && i + 2 < src.length()) { + char ord1 = src[i + 1]; if ((ord1 >= '0' && ord1 <= '9') || (ord1 >= 'A' && ord1 <= 'Z')) { - char32_t ord2 = unicode_at(i + 2); + char ord2 = src[i + 2]; if ((ord2 >= '0' && ord2 <= '9') || (ord2 >= 'A' && ord2 <= 'Z')) { char bytes[3] = { (char)ord1, (char)ord2, 0 }; res += (char)strtol(bytes, nullptr, 16); i += 2; } } else { - res += unicode_at(i); + res += src[i]; } - } else if (unicode_at(i) == '+') { + } else if (src[i] == '+') { res += ' '; } else { - res += unicode_at(i); + res += src[i]; } } - return String::utf8(res.ascii()); + return String::utf8(res); } String String::c_unescape() const { @@ -4765,7 +4831,7 @@ Vector<uint8_t> String::to_ascii_buffer() const { size_t len = charstr.length(); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, charstr.ptr(), len); + memcpy(w, charstr.ptr(), len); return retval; } @@ -4781,7 +4847,7 @@ Vector<uint8_t> String::to_utf8_buffer() const { size_t len = charstr.length(); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, charstr.ptr(), len); + memcpy(w, charstr.ptr(), len); return retval; } @@ -4797,7 +4863,7 @@ Vector<uint8_t> String::to_utf16_buffer() const { size_t len = charstr.length() * sizeof(char16_t); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, (const void *)charstr.ptr(), len); + memcpy(w, (const void *)charstr.ptr(), len); return retval; } @@ -4812,7 +4878,7 @@ Vector<uint8_t> String::to_utf32_buffer() const { size_t len = s->length() * sizeof(char32_t); retval.resize(len); uint8_t *w = retval.ptrw(); - copymem(w, (const void *)s->ptr(), len); + memcpy(w, (const void *)s->ptr(), len); return retval; } diff --git a/core/string/ustring.h b/core/string/ustring.h index 1e362d7683..a56845deff 100644 --- a/core/string/ustring.h +++ b/core/string/ustring.h @@ -416,6 +416,7 @@ public: String c_unescape() const; String json_escape() const; String word_wrap(int p_chars_per_line) const; + Error parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path) const; String property_name_encode() const; diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index ffd17b7ee9..5f22e08eb8 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -32,7 +32,6 @@ #define LOCAL_VECTOR_H #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/templates/sort_array.h" #include "core/templates/vector.h" @@ -216,7 +215,7 @@ public: Vector<T> ret; ret.resize(size()); T *w = ret.ptrw(); - copymem(w, data, sizeof(T) * count); + memcpy(w, data, sizeof(T) * count); return ret; } @@ -224,7 +223,7 @@ public: Vector<uint8_t> ret; ret.resize(count * sizeof(T)); uint8_t *w = ret.ptrw(); - copymem(w, data, sizeof(T) * count); + memcpy(w, data, sizeof(T) * count); return ret; } diff --git a/core/templates/oa_hash_map.h b/core/templates/oa_hash_map.h index 1d4176eb10..2c7c64cd78 100644 --- a/core/templates/oa_hash_map.h +++ b/core/templates/oa_hash_map.h @@ -32,7 +32,6 @@ #define OA_HASH_MAP_H #include "core/math/math_funcs.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/templates/hashfuncs.h" diff --git a/core/templates/vector.h b/core/templates/vector.h index a56a941dbc..dae8874a87 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -38,7 +38,6 @@ */ #include "core/error/error_macros.h" -#include "core/os/copymem.h" #include "core/os/memory.h" #include "core/templates/cowdata.h" #include "core/templates/sort_array.h" @@ -66,6 +65,7 @@ private: public: bool push_back(T p_elem); _FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias + void fill(T p_elem); void remove(int p_index) { _cowdata.remove(p_index); } void erase(const T &p_val) { @@ -134,7 +134,7 @@ public: Vector<uint8_t> to_byte_array() const { Vector<uint8_t> ret; ret.resize(size() * sizeof(T)); - copymem(ret.ptrw(), ptr(), sizeof(T) * size()); + memcpy(ret.ptrw(), ptr(), sizeof(T) * size()); return ret; } @@ -223,4 +223,12 @@ bool Vector<T>::push_back(T p_elem) { return false; } +template <class T> +void Vector<T>::fill(T p_elem) { + T *p = ptrw(); + for (int i = 0; i < size(); i++) { + p[i] = p_elem; + } +} + #endif // VECTOR_H diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 2ad728ec5e..2fb2dd4a30 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -208,6 +208,11 @@ void Array::insert(int p_pos, const Variant &p_value) { _p->array.insert(p_pos, p_value); } +void Array::fill(const Variant &p_value) { + ERR_FAIL_COND(!_p->typed.validate(p_value, "fill")); + _p->array.fill(p_value); +} + void Array::erase(const Variant &p_value) { ERR_FAIL_COND(!_p->typed.validate(p_value, "erase")); _p->array.erase(p_value); diff --git a/core/variant/array.h b/core/variant/array.h index 6b58ed12cb..5ce977ee4b 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -74,6 +74,7 @@ public: void insert(int p_pos, const Variant &p_value); void remove(int p_pos); + void fill(const Variant &p_value); Variant front() const; Variant back() const; diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index 86bbf43266..830e0a5cbd 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -122,6 +122,18 @@ struct VariantObjectClassChecker { } }; +template <typename T> +class Ref; + +template <typename T> +struct VariantObjectClassChecker<const Ref<T> &> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + const Ref<T> node = p_variant; + return node.ptr() || !obj; + } +}; + template <> struct VariantObjectClassChecker<Node *> { static _FORCE_INLINE_ bool check(const Variant &p_variant) { diff --git a/core/variant/callable.cpp b/core/variant/callable.cpp index a1d9c5ed2f..e06b3e07ef 100644 --- a/core/variant/callable.cpp +++ b/core/variant/callable.cpp @@ -54,6 +54,20 @@ void Callable::call(const Variant **p_arguments, int p_argcount, Variant &r_retu } } +void Callable::rpc(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const { + if (is_null()) { + r_call_error.error = CallError::CALL_ERROR_INSTANCE_IS_NULL; + r_call_error.argument = 0; + r_call_error.expected = 0; + } else if (!is_custom()) { + r_call_error.error = CallError::CALL_ERROR_INVALID_METHOD; + r_call_error.argument = 0; + r_call_error.expected = 0; + } else { + custom->rpc(p_id, p_arguments, p_argcount, r_call_error); + } +} + Callable Callable::bind(const Variant **p_arguments, int p_argcount) const { Vector<Variant> args; args.resize(p_argcount); @@ -283,6 +297,12 @@ Callable::~Callable() { } } +void CallableCustom::rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const { + r_call_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; + r_call_error.argument = 0; + r_call_error.expected = 0; +} + const Callable *CallableCustom::get_base_comparator() const { return nullptr; } diff --git a/core/variant/callable.h b/core/variant/callable.h index 090fd888e2..d91bebfa5f 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -70,6 +70,8 @@ public: void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, CallError &r_call_error) const; void call_deferred(const Variant **p_arguments, int p_argcount) const; + void rpc(int p_id, const Variant **p_arguments, int p_argcount, CallError &r_call_error) const; + _FORCE_INLINE_ bool is_null() const { return method == StringName() && object == 0; } @@ -124,6 +126,7 @@ public: virtual CompareLessFunc get_compare_less_func() const = 0; virtual ObjectID get_object() const = 0; //must always be able to provide an object virtual void call(const Variant **p_arguments, int p_argcount, Variant &r_return_value, Callable::CallError &r_call_error) const = 0; + virtual void rpc(int p_peer_id, const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) const; virtual const Callable *get_base_comparator() const; CallableCustom(); diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 7f83e27dfe..455e924568 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -493,6 +493,58 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c } \ }; +#define VARARG_CLASS1(m_class, m_method_name, m_method_ptr, m_arg_type) \ + struct Method_##m_class##_##m_method_name { \ + static void call(Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { \ + m_method_ptr(base, p_args, p_argcount, r_ret, r_error); \ + } \ + static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \ + Callable::CallError ce; \ + m_method_ptr(base, p_args, p_argcount, *r_ret, ce); \ + } \ + static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \ + LocalVector<Variant> vars; \ + vars.resize(p_argcount); \ + LocalVector<const Variant *> vars_ptrs; \ + vars_ptrs.resize(p_argcount); \ + for (int i = 0; i < p_argcount; i++) { \ + vars[i] = PtrToArg<Variant>::convert(p_args[i]); \ + vars_ptrs[i] = &vars[i]; \ + } \ + Variant base = PtrToArg<m_class>::convert(p_base); \ + Variant ret; \ + Callable::CallError ce; \ + m_method_ptr(&base, (const Variant **)&vars_ptrs[0], p_argcount, ret, ce); \ + } \ + static int get_argument_count() { \ + return 1; \ + } \ + static Variant::Type get_argument_type(int p_arg) { \ + return m_arg_type; \ + } \ + static Variant::Type get_return_type() { \ + return Variant::NIL; \ + } \ + static bool has_return_type() { \ + return false; \ + } \ + static bool is_const() { \ + return true; \ + } \ + static bool is_static() { \ + return false; \ + } \ + static bool is_vararg() { \ + return true; \ + } \ + static Variant::Type get_base_type() { \ + return GetTypeInfo<m_class>::VARIANT_TYPE; \ + } \ + static StringName get_name() { \ + return #m_method_name; \ + } \ + }; + struct _VariantCall { static String func_PackedByteArray_get_string_from_ascii(PackedByteArray *p_instance) { String s; @@ -500,7 +552,7 @@ struct _VariantCall { const uint8_t *r = p_instance->ptr(); CharString cs; cs.resize(p_instance->size() + 1); - copymem(cs.ptrw(), r, p_instance->size()); + memcpy(cs.ptrw(), r, p_instance->size()); cs[p_instance->size()] = 0; s = cs.get_data(); @@ -792,6 +844,27 @@ struct _VariantCall { callable->call_deferred(p_args, p_argcount); } + static void func_Callable_rpc(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v); + callable->rpc(0, p_args, p_argcount, r_error); + } + + static void func_Callable_rpc_id(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { + if (p_argcount == 0) { + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.argument = 0; + r_error.expected = 1; + + } else if (p_args[0]->get_type() != Variant::INT) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; + r_error.argument = 0; + r_error.expected = Variant::INT; + } else { + Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v); + callable->rpc(*p_args[0], &p_args[1], p_argcount - 1, r_error); + } + } + static void func_Callable_bind(Variant *v, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) { Callable *callable = VariantGetInternalPtr<Callable>::get_ptr(v); r_ret = callable->bind(p_args, p_argcount); @@ -1219,6 +1292,10 @@ Variant Variant::get_constant_value(Variant::Type p_type, const StringName &p_va VARARG_CLASS(m_type, m_name, m_method, m_has_return, m_ret_type) \ register_builtin_method<Method_##m_type##_##m_name>(sarray(), Vector<Variant>()); +#define bind_custom1(m_type, m_name, m_method, m_arg_type, m_arg_name) \ + VARARG_CLASS1(m_type, m_name, m_method, m_arg_type) \ + register_builtin_method<Method_##m_type##_##m_name>(sarray(m_arg_name), Vector<Variant>()); + static void _register_variant_builtin_methods() { _VariantCall::constant_data = memnew_arr(_VariantCall::ConstantData, Variant::VARIANT_MAX); builtin_method_info = memnew_arr(BuiltinMethodMap, Variant::VARIANT_MAX); @@ -1532,6 +1609,8 @@ static void _register_variant_builtin_methods() { bind_custom(Callable, call, _VariantCall::func_Callable_call, true, Variant); bind_custom(Callable, call_deferred, _VariantCall::func_Callable_call_deferred, false, Variant); + bind_custom(Callable, rpc, _VariantCall::func_Callable_rpc, false, Variant); + bind_custom1(Callable, rpc_id, _VariantCall::func_Callable_rpc_id, Variant::INT, "peer_id"); bind_custom(Callable, bind, _VariantCall::func_Callable_bind, true, Callable); /* Signal */ @@ -1647,6 +1726,7 @@ static void _register_variant_builtin_methods() { bind_method(Array, resize, sarray("size"), varray()); bind_method(Array, insert, sarray("position", "value"), varray()); bind_method(Array, remove, sarray("position"), varray()); + bind_method(Array, fill, sarray("value"), varray()); bind_method(Array, erase, sarray("value"), varray()); bind_method(Array, front, sarray(), varray()); bind_method(Array, back, sarray(), varray()); @@ -1677,6 +1757,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedByteArray, append_array, sarray("array"), varray()); bind_method(PackedByteArray, remove, sarray("index"), varray()); bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedByteArray, fill, sarray("value"), varray()); bind_method(PackedByteArray, resize, sarray("new_size"), varray()); bind_method(PackedByteArray, has, sarray("value"), varray()); bind_method(PackedByteArray, reverse, sarray(), varray()); @@ -1731,6 +1812,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt32Array, append_array, sarray("array"), varray()); bind_method(PackedInt32Array, remove, sarray("index"), varray()); bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedInt32Array, fill, sarray("value"), varray()); bind_method(PackedInt32Array, resize, sarray("new_size"), varray()); bind_method(PackedInt32Array, has, sarray("value"), varray()); bind_method(PackedInt32Array, reverse, sarray(), varray()); @@ -1749,6 +1831,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt64Array, append_array, sarray("array"), varray()); bind_method(PackedInt64Array, remove, sarray("index"), varray()); bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedInt64Array, fill, sarray("value"), varray()); bind_method(PackedInt64Array, resize, sarray("new_size"), varray()); bind_method(PackedInt64Array, has, sarray("value"), varray()); bind_method(PackedInt64Array, reverse, sarray(), varray()); @@ -1767,6 +1850,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat32Array, append_array, sarray("array"), varray()); bind_method(PackedFloat32Array, remove, sarray("index"), varray()); bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedFloat32Array, fill, sarray("value"), varray()); bind_method(PackedFloat32Array, resize, sarray("new_size"), varray()); bind_method(PackedFloat32Array, has, sarray("value"), varray()); bind_method(PackedFloat32Array, reverse, sarray(), varray()); @@ -1785,6 +1869,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat64Array, append_array, sarray("array"), varray()); bind_method(PackedFloat64Array, remove, sarray("index"), varray()); bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedFloat64Array, fill, sarray("value"), varray()); bind_method(PackedFloat64Array, resize, sarray("new_size"), varray()); bind_method(PackedFloat64Array, has, sarray("value"), varray()); bind_method(PackedFloat64Array, reverse, sarray(), varray()); @@ -1803,6 +1888,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedStringArray, append_array, sarray("array"), varray()); bind_method(PackedStringArray, remove, sarray("index"), varray()); bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedStringArray, fill, sarray("value"), varray()); bind_method(PackedStringArray, resize, sarray("new_size"), varray()); bind_method(PackedStringArray, has, sarray("value"), varray()); bind_method(PackedStringArray, reverse, sarray(), varray()); @@ -1821,6 +1907,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector2Array, append_array, sarray("array"), varray()); bind_method(PackedVector2Array, remove, sarray("index"), varray()); bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedVector2Array, fill, sarray("value"), varray()); bind_method(PackedVector2Array, resize, sarray("new_size"), varray()); bind_method(PackedVector2Array, has, sarray("value"), varray()); bind_method(PackedVector2Array, reverse, sarray(), varray()); @@ -1839,6 +1926,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector3Array, append_array, sarray("array"), varray()); bind_method(PackedVector3Array, remove, sarray("index"), varray()); bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray()); + bind_method(PackedVector3Array, fill, sarray("value"), varray()); bind_method(PackedVector3Array, resize, sarray("new_size"), varray()); bind_method(PackedVector3Array, has, sarray("value"), varray()); bind_method(PackedVector3Array, reverse, sarray(), varray()); @@ -1857,6 +1945,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedColorArray, append_array, sarray("array"), varray()); bind_method(PackedColorArray, remove, sarray("index"), varray()); bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray()); + bind_method(PackedColorArray, fill, sarray("value"), varray()); bind_method(PackedColorArray, resize, sarray("new_size"), varray()); bind_method(PackedColorArray, has, sarray("value"), varray()); bind_method(PackedColorArray, reverse, sarray(), varray()); diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index e0a3cf4215..8cfa793c0e 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -257,6 +257,14 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + +#if defined(DEBUG_ENABLED) + if (b < 0 || a < 0) { + *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; + r_valid = false; + return; + } +#endif *r_ret = a << b; r_valid = true; } @@ -276,6 +284,14 @@ public: static void evaluate(const Variant &p_left, const Variant &p_right, Variant *r_ret, bool &r_valid) { const A &a = *VariantGetInternalPtr<A>::get_ptr(&p_left); const B &b = *VariantGetInternalPtr<B>::get_ptr(&p_right); + +#if defined(DEBUG_ENABLED) + if (b < 0 || a < 0) { + *r_ret = "Invalid operands for bit shifting. Only positive operands are supported."; + r_valid = false; + return; + } +#endif *r_ret = a >> b; r_valid = true; } @@ -1365,10 +1381,10 @@ void register_op(Variant::Operator p_op, Variant::Type p_type_a, Variant::Type p } void Variant::_register_variant_operators() { - zeromem(operator_return_type_table, sizeof(operator_return_type_table)); - zeromem(operator_evaluator_table, sizeof(operator_evaluator_table)); - zeromem(validated_operator_evaluator_table, sizeof(validated_operator_evaluator_table)); - zeromem(ptr_operator_evaluator_table, sizeof(ptr_operator_evaluator_table)); + memset(operator_return_type_table, 0, sizeof(operator_return_type_table)); + memset(operator_evaluator_table, 0, sizeof(operator_evaluator_table)); + memset(validated_operator_evaluator_table, 0, sizeof(validated_operator_evaluator_table)); + memset(ptr_operator_evaluator_table, 0, sizeof(ptr_operator_evaluator_table)); register_op<OperatorEvaluatorAdd<int64_t, int64_t, int64_t>>(Variant::OP_ADD, Variant::INT, Variant::INT); register_op<OperatorEvaluatorAdd<double, int64_t, double>>(Variant::OP_ADD, Variant::INT, Variant::FLOAT); diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index f154ab1ed6..553f2b23a2 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -93,6 +93,10 @@ struct VariantUtilityFunctions { return Math::fposmod(b, r); } + static inline int64_t posmod(int64_t b, int64_t r) { + return Math::posmod(b, r); + } + static inline double floor(double x) { return Math::floor(x); } @@ -1154,6 +1158,7 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(sqrt, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(fmod, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(fposmod, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(posmod, sarray("x", "y"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(floor, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(ceil, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(round, sarray("x"), Variant::UTILITY_FUNC_TYPE_MATH); |