summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/input/input_event.h1
-rw-r--r--core/io/compression.cpp7
-rw-r--r--core/io/file_access_encrypted.cpp3
-rw-r--r--core/io/file_access_memory.cpp5
-rw-r--r--core/io/file_access_zip.cpp3
-rw-r--r--core/io/http_client.cpp2
-rw-r--r--core/io/image.cpp11
-rw-r--r--core/io/marshalls.cpp16
-rw-r--r--core/io/multiplayer_api.cpp2
-rw-r--r--core/io/net_socket.h1
-rw-r--r--core/io/packed_data_container.cpp2
-rw-r--r--core/io/packet_peer_udp.cpp17
-rw-r--r--core/io/packet_peer_udp.h5
-rw-r--r--core/io/stream_peer.cpp4
-rw-r--r--core/io/stream_peer_tcp.cpp43
-rw-r--r--core/io/stream_peer_tcp.h6
-rw-r--r--core/io/tcp_server.cpp8
-rw-r--r--core/io/tcp_server.h1
-rw-r--r--core/io/udp_server.cpp12
-rw-r--r--core/io/udp_server.h5
-rw-r--r--core/io/xml_parser.cpp2
-rw-r--r--core/io/zip_io.cpp4
-rw-r--r--core/math/basis.cpp1
-rw-r--r--core/math/dynamic_bvh.h6
-rw-r--r--core/math/face3.cpp2
-rw-r--r--core/math/geometry_2d.cpp2
-rw-r--r--core/math/math_funcs.h3
-rw-r--r--core/math/random_pcg.cpp2
-rw-r--r--core/math/transform.cpp1
-rw-r--r--core/object/callable_method_pointer.h7
-rw-r--r--core/os/copymem.h50
-rw-r--r--core/os/memory.cpp1
-rw-r--r--core/os/pool_allocator.cpp3
-rw-r--r--core/string/node_path.h2
-rw-r--r--core/string/translation.cpp2
-rw-r--r--core/string/translation_po.cpp20
-rw-r--r--core/string/ustring.cpp8
-rw-r--r--core/templates/local_vector.h5
-rw-r--r--core/templates/oa_hash_map.h1
-rw-r--r--core/templates/safe_refcount.h1
-rw-r--r--core/templates/vector.h12
-rw-r--r--core/variant/array.cpp5
-rw-r--r--core/variant/array.h1
-rw-r--r--core/variant/binder_common.h12
-rw-r--r--core/variant/variant_call.cpp45
-rw-r--r--core/variant/variant_op.cpp8
46 files changed, 175 insertions, 185 deletions
diff --git a/core/input/input_event.h b/core/input/input_event.h
index a1e7df5969..94aa68db33 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"
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/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..8cf13efdb6 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); }
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index 9609620469..1152c4e834 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_ticks_usec() * pcg.state + PCG_DEFAULT_INC_64);
+ seed((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/node_path.h b/core/string/node_path.h
index 26e15636d9..a277ab26fa 100644
--- a/core/string/node_path.h
+++ b/core/string/node_path.h
@@ -66,8 +66,6 @@ public:
void prepend_period();
- NodePath get_parent() const;
-
_FORCE_INLINE_ uint32_t hash() const {
if (!data) {
return 0;
diff --git a/core/string/translation.cpp b/core/string/translation.cpp
index ade5f7b4d8..153f0190fd 100644
--- a/core/string/translation.cpp
+++ b/core/string/translation.cpp
@@ -835,7 +835,7 @@ Vector<String> Translation::_get_message_list() const {
void Translation::_set_messages(const Dictionary &p_messages) {
List<Variant> keys;
p_messages.get_key_list(&keys);
- for (auto E = keys.front(); E; E = E->next()) {
+ for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
translation_map[E->get()] = p_messages[E->get()];
}
}
diff --git a/core/string/translation_po.cpp b/core/string/translation_po.cpp
index 2efadaa9b7..ad768f7140 100644
--- a/core/string/translation_po.cpp
+++ b/core/string/translation_po.cpp
@@ -47,14 +47,14 @@ void TranslationPO::print_translation_map() {
List<StringName> context_l;
translation_map.get_key_list(&context_l);
- for (auto E = context_l.front(); E; E = E->next()) {
+ for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) {
StringName ctx = E->get();
file->store_line(" ===== Context: " + String::utf8(String(ctx).utf8()) + " ===== ");
const HashMap<StringName, Vector<StringName>> &inner_map = translation_map[ctx];
List<StringName> id_l;
inner_map.get_key_list(&id_l);
- for (auto E2 = id_l.front(); E2; E2 = E2->next()) {
+ for (List<StringName>::Element *E2 = id_l.front(); E2; E2 = E2->next()) {
StringName id = E2->get();
file->store_line("msgid: " + String::utf8(String(id).utf8()));
for (int i = 0; i < inner_map[id].size(); i++) {
@@ -74,7 +74,7 @@ Dictionary TranslationPO::_get_messages() const {
List<StringName> context_l;
translation_map.get_key_list(&context_l);
- for (auto E = context_l.front(); E; E = E->next()) {
+ for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) {
StringName ctx = E->get();
const HashMap<StringName, Vector<StringName>> &id_str_map = translation_map[ctx];
@@ -82,7 +82,7 @@ Dictionary TranslationPO::_get_messages() const {
List<StringName> id_l;
id_str_map.get_key_list(&id_l);
// Save list of id and strs associated with a context in a temporary dictionary.
- for (auto E2 = id_l.front(); E2; E2 = E2->next()) {
+ for (List<StringName>::Element *E2 = id_l.front(); E2; E2 = E2->next()) {
StringName id = E2->get();
d2[id] = id_str_map[id];
}
@@ -98,14 +98,14 @@ void TranslationPO::_set_messages(const Dictionary &p_messages) {
List<Variant> context_l;
p_messages.get_key_list(&context_l);
- for (auto E = context_l.front(); E; E = E->next()) {
+ for (List<Variant>::Element *E = context_l.front(); E; E = E->next()) {
StringName ctx = E->get();
const Dictionary &id_str_map = p_messages[ctx];
HashMap<StringName, Vector<StringName>> temp_map;
List<Variant> id_l;
id_str_map.get_key_list(&id_l);
- for (auto E2 = id_l.front(); E2; E2 = E2->next()) {
+ for (List<Variant>::Element *E2 = id_l.front(); E2; E2 = E2->next()) {
StringName id = E2->get();
temp_map[id] = id_str_map[id];
}
@@ -121,7 +121,7 @@ Vector<String> TranslationPO::_get_message_list() const {
get_message_list(&msgs);
Vector<String> v;
- for (auto E = msgs.front(); E; E = E->next()) {
+ for (List<StringName>::Element *E = msgs.front(); E; E = E->next()) {
v.push_back(E->get());
}
@@ -281,7 +281,7 @@ void TranslationPO::get_message_list(List<StringName> *r_messages) const {
List<StringName> context_l;
translation_map.get_key_list(&context_l);
- for (auto E = context_l.front(); E; E = E->next()) {
+ for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) {
if (String(E->get()) != "") {
continue;
}
@@ -289,7 +289,7 @@ void TranslationPO::get_message_list(List<StringName> *r_messages) const {
List<StringName> msgid_l;
translation_map[E->get()].get_key_list(&msgid_l);
- for (auto E2 = msgid_l.front(); E2; E2 = E2->next()) {
+ for (List<StringName>::Element *E2 = msgid_l.front(); E2; E2 = E2->next()) {
r_messages->push_back(E2->get());
}
}
@@ -300,7 +300,7 @@ int TranslationPO::get_message_count() const {
translation_map.get_key_list(&context_l);
int count = 0;
- for (auto E = context_l.front(); E; E = E->next()) {
+ for (List<StringName>::Element *E = context_l.front(); E; E = E->next()) {
count += translation_map[E->get()].size();
}
return count;
diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp
index cf0040353d..c8d71c3236 100644
--- a/core/string/ustring.cpp
+++ b/core/string/ustring.cpp
@@ -4765,7 +4765,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 +4781,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 +4797,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 +4812,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/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/safe_refcount.h b/core/templates/safe_refcount.h
index 91a34ecd54..e9e5695f80 100644
--- a/core/templates/safe_refcount.h
+++ b/core/templates/safe_refcount.h
@@ -36,6 +36,7 @@
#if !defined(NO_THREADS)
#include <atomic>
+#include <type_traits>
// Design goals for these classes:
// - No automatic conversions or arithmetic operators,
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/variant_call.cpp b/core/variant/variant_call.cpp
index 61f3f7d82e..deaccc6304 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -143,36 +143,6 @@ static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_bas
}
template <class R, class T, class... P>
-static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...), Variant *v) {
- VariantTypeAdjust<R>::adjust(v);
-}
-
-template <class R, class T, class... P>
-static _FORCE_INLINE_ void vc_change_return_type(R (T::*method)(P...) const, Variant *v) {
- VariantTypeAdjust<R>::adjust(v);
-}
-
-template <class T, class... P>
-static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...), Variant *v) {
- VariantInternal::clear(v);
-}
-
-template <class T, class... P>
-static _FORCE_INLINE_ void vc_change_return_type(void (T::*method)(P...) const, Variant *v) {
- VariantInternal::clear(v);
-}
-
-template <class R, class... P>
-static _FORCE_INLINE_ void vc_change_return_type(R (*method)(P...), Variant *v) {
- VariantTypeAdjust<R>::adjust(v);
-}
-
-template <class... P>
-static _FORCE_INLINE_ void vc_change_return_type(void (*method)(P...), Variant *v) {
- VariantInternal::clear(v);
-}
-
-template <class R, class T, class... P>
static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...)) {
return sizeof...(P);
}
@@ -333,7 +303,6 @@ static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) con
vc_method_call(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
} \
static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
- vc_change_return_type(m_method_ptr, r_ret); \
vc_validated_call(m_method_ptr, base, p_args, r_ret); \
} \
static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
@@ -384,7 +353,6 @@ static _FORCE_INLINE_ void vc_static_ptrcall(void (*method)(P...), const void **
vc_static_method_call(m_method_ptr, p_args, p_argcount, r_ret, p_defvals, r_error); \
} \
static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
- vc_change_return_type(m_method_ptr, r_ret); \
vc_validated_static_call(m_method_ptr, p_args, r_ret); \
} \
static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
@@ -435,7 +403,6 @@ static _FORCE_INLINE_ void vc_ptrcall(void (*method)(T *, P...), void *p_base, c
vc_method_call_static(m_method_ptr, base, p_args, p_argcount, r_ret, p_defvals, r_error); \
} \
static void validated_call(Variant *base, const Variant **p_args, int p_argcount, Variant *r_ret) { \
- vc_change_return_type(m_method_ptr, r_ret); \
vc_validated_call_static(m_method_ptr, base, p_args, r_ret); \
} \
static void ptrcall(void *p_base, const void **p_args, void *r_ret, int p_argcount) { \
@@ -533,7 +500,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();
@@ -1680,6 +1647,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());
@@ -1710,6 +1678,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());
@@ -1764,6 +1733,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());
@@ -1782,6 +1752,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());
@@ -1800,6 +1771,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());
@@ -1818,6 +1790,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());
@@ -1836,6 +1809,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());
@@ -1854,6 +1828,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());
@@ -1872,6 +1847,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());
@@ -1890,6 +1866,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..6cbc98d14d 100644
--- a/core/variant/variant_op.cpp
+++ b/core/variant/variant_op.cpp
@@ -1365,10 +1365,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);