diff options
Diffstat (limited to 'core')
32 files changed, 408 insertions, 272 deletions
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index 25dd408dce..0d699cdacb 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -1104,6 +1104,8 @@ ProjectSettings::ProjectSettings() { } extensions.push_back("shader"); + GLOBAL_DEF("editor/run/main_run_args", ""); + GLOBAL_DEF("editor/script/search_in_file_extensions", extensions); custom_prop_info["editor/script/search_in_file_extensions"] = PropertyInfo(Variant::PACKED_STRING_ARRAY, "editor/script/search_in_file_extensions"); diff --git a/core/debugger/remote_debugger_peer.cpp b/core/debugger/remote_debugger_peer.cpp index 90b0975159..39113eda14 100644 --- a/core/debugger/remote_debugger_peer.cpp +++ b/core/debugger/remote_debugger_peer.cpp @@ -152,7 +152,7 @@ void RemoteDebuggerPeerTCP::_read_in() { } Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) { - IP_Address ip; + IPAddress ip; if (p_host.is_valid_ip_address()) { ip = p_host; } else { diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 31b7d658d0..4cc73bcd22 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -171,7 +171,7 @@ void FileAccessNetworkClient::_thread_func(void *s) { } Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) { - IP_Address ip; + IPAddress ip; if (p_host.is_valid_ip_address()) { ip = p_host; diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 4b053d576c..0cf870e7e7 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -77,7 +77,7 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl, if (conn_host.is_valid_ip_address()) { // Host contains valid IP - Error err = tcp_connection->connect_to_host(IP_Address(conn_host), p_port); + Error err = tcp_connection->connect_to_host(IPAddress(conn_host), p_port); if (err) { status = STATUS_CANT_CONNECT; return err; @@ -328,7 +328,7 @@ Error HTTPClient::poll() { return OK; // Still resolving case IP::RESOLVER_STATUS_DONE: { - IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving); + IPAddress host = IP::get_singleton()->get_resolve_item_address(resolving); Error err = tcp_connection->connect_to_host(host, conn_port); IP::get_singleton()->erase_resolve_item(resolving); resolving = IP::RESOLVER_INVALID_ID; diff --git a/core/io/ip.cpp b/core/io/ip.cpp index e1d9c19f10..eb7814054b 100644 --- a/core/io/ip.cpp +++ b/core/io/ip.cpp @@ -41,13 +41,13 @@ VARIANT_ENUM_CAST(IP::ResolverStatus); struct _IP_ResolverPrivate { struct QueueItem { SafeNumeric<IP::ResolverStatus> status; - IP_Address response; + IPAddress response; String hostname; IP::Type type; void clear() { status.set(IP::RESOLVER_STATUS_NONE); - response = IP_Address(); + response = IPAddress(); type = IP::TYPE_NONE; hostname = ""; }; @@ -101,23 +101,23 @@ struct _IP_ResolverPrivate { } } - HashMap<String, IP_Address> cache; + HashMap<String, IPAddress> cache; static String get_cache_key(String p_hostname, IP::Type p_type) { return itos(p_type) + p_hostname; } }; -IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { +IPAddress IP::resolve_hostname(const String &p_hostname, IP::Type p_type) { MutexLock lock(resolver->mutex); String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type); if (resolver->cache.has(key) && resolver->cache[key].is_valid()) { - IP_Address res = resolver->cache[key]; + IPAddress res = resolver->cache[key]; return res; } - IP_Address res = _resolve_hostname(p_hostname, p_type); + IPAddress res = _resolve_hostname(p_hostname, p_type); resolver->cache[key] = res; return res; } @@ -139,7 +139,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ resolver->queue[id].response = resolver->cache[key]; resolver->queue[id].status.set(IP::RESOLVER_STATUS_DONE); } else { - resolver->queue[id].response = IP_Address(); + resolver->queue[id].response = IPAddress(); resolver->queue[id].status.set(IP::RESOLVER_STATUS_WAITING); if (resolver->thread.is_started()) { resolver->sem.post(); @@ -164,15 +164,15 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const { return resolver->queue[p_id].status.get(); } -IP_Address IP::get_resolve_item_address(ResolverID p_id) const { - ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address()); +IPAddress IP::get_resolve_item_address(ResolverID p_id) const { + ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IPAddress()); MutexLock lock(resolver->mutex); if (resolver->queue[p_id].status.get() != IP::RESOLVER_STATUS_DONE) { ERR_PRINT("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet."); resolver->mutex.unlock(); - return IP_Address(); + return IPAddress(); } return resolver->queue[p_id].response; @@ -201,9 +201,9 @@ void IP::clear_cache(const String &p_hostname) { Array IP::_get_local_addresses() const { Array addresses; - List<IP_Address> ip_addresses; + List<IPAddress> ip_addresses; get_local_addresses(&ip_addresses); - for (List<IP_Address>::Element *E = ip_addresses.front(); E; E = E->next()) { + for (List<IPAddress>::Element *E = ip_addresses.front(); E; E = E->next()) { addresses.push_back(E->get()); } @@ -222,7 +222,7 @@ Array IP::_get_local_interfaces() const { rc["index"] = c.index; Array ips; - for (const List<IP_Address>::Element *F = c.ip_addresses.front(); F; F = F->next()) { + for (const List<IPAddress>::Element *F = c.ip_addresses.front(); F; F = F->next()) { ips.push_front(F->get()); } rc["addresses"] = ips; @@ -233,11 +233,11 @@ Array IP::_get_local_interfaces() const { return results; } -void IP::get_local_addresses(List<IP_Address> *r_addresses) const { +void IP::get_local_addresses(List<IPAddress> *r_addresses) const { Map<String, Interface_Info> interfaces; get_local_interfaces(&interfaces); for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) { - for (const List<IP_Address>::Element *F = E->get().ip_addresses.front(); F; F = F->next()) { + for (const List<IPAddress>::Element *F = E->get().ip_addresses.front(); F; F = F->next()) { r_addresses->push_front(F->get()); } } diff --git a/core/io/ip.h b/core/io/ip.h index ae080b8e26..0c4a83257d 100644 --- a/core/io/ip.h +++ b/core/io/ip.h @@ -69,7 +69,7 @@ protected: static IP *singleton; static void _bind_methods(); - virtual IP_Address _resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY) = 0; + virtual IPAddress _resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY) = 0; Array _get_local_addresses() const; Array _get_local_interfaces() const; @@ -80,15 +80,15 @@ public: String name; String name_friendly; String index; - List<IP_Address> ip_addresses; + List<IPAddress> ip_addresses; }; - IP_Address resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY); + IPAddress resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY); // async resolver hostname ResolverID resolve_hostname_queue_item(const String &p_hostname, Type p_type = TYPE_ANY); ResolverStatus get_resolve_item_status(ResolverID p_id) const; - IP_Address get_resolve_item_address(ResolverID p_id) const; - virtual void get_local_addresses(List<IP_Address> *r_addresses) const; + IPAddress get_resolve_item_address(ResolverID p_id) const; + virtual void get_local_addresses(List<IPAddress> *r_addresses) const; virtual void get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const = 0; void erase_resolve_item(ResolverID p_id); diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp index 5f98eb69e8..1c1ac8a88f 100644 --- a/core/io/ip_address.cpp +++ b/core/io/ip_address.cpp @@ -30,14 +30,14 @@ #include "ip_address.h" /* -IP_Address::operator Variant() const { +IPAddress::operator Variant() const { return operator String(); }*/ #include <stdio.h> #include <string.h> -IP_Address::operator String() const { +IPAddress::operator String() const { if (wildcard) { return "*"; } @@ -90,7 +90,7 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) { p_dst[1] = ret & 0xff; } -void IP_Address::_parse_ipv6(const String &p_string) { +void IPAddress::_parse_ipv6(const String &p_string) { static const int parts_total = 8; int parts[parts_total] = { 0 }; int parts_count = 0; @@ -146,7 +146,7 @@ void IP_Address::_parse_ipv6(const String &p_string) { } } -void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) { +void IPAddress::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) { String ip; if (p_start != 0) { ip = p_string.substr(p_start, p_string.length() - p_start); @@ -161,33 +161,33 @@ void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret } } -void IP_Address::clear() { +void IPAddress::clear() { memset(&field8[0], 0, sizeof(field8)); valid = false; wildcard = false; } -bool IP_Address::is_ipv4() const { +bool IPAddress::is_ipv4() const { return (field32[0] == 0 && field32[1] == 0 && field16[4] == 0 && field16[5] == 0xffff); } -const uint8_t *IP_Address::get_ipv4() const { +const uint8_t *IPAddress::get_ipv4() const { ERR_FAIL_COND_V_MSG(!is_ipv4(), &(field8[12]), "IPv4 requested, but current IP is IPv6."); // Not the correct IPv4 (it's an IPv6), but we don't want to return a null pointer risking an engine crash. return &(field8[12]); } -void IP_Address::set_ipv4(const uint8_t *p_ip) { +void IPAddress::set_ipv4(const uint8_t *p_ip) { clear(); valid = true; field16[5] = 0xffff; field32[3] = *((const uint32_t *)p_ip); } -const uint8_t *IP_Address::get_ipv6() const { +const uint8_t *IPAddress::get_ipv6() const { return field8; } -void IP_Address::set_ipv6(const uint8_t *p_buf) { +void IPAddress::set_ipv6(const uint8_t *p_buf) { clear(); valid = true; for (int i = 0; i < 16; i++) { @@ -195,7 +195,7 @@ void IP_Address::set_ipv6(const uint8_t *p_buf) { } } -IP_Address::IP_Address(const String &p_string) { +IPAddress::IPAddress(const String &p_string) { clear(); if (p_string == "*") { @@ -225,7 +225,7 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) { p_dst[3] = (p_n >> 0) & 0xff; } -IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) { +IPAddress::IPAddress(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) { clear(); valid = true; if (!is_v6) { diff --git a/core/io/ip_address.h b/core/io/ip_address.h index 49bf83d72f..05da675704 100644 --- a/core/io/ip_address.h +++ b/core/io/ip_address.h @@ -33,7 +33,7 @@ #include "core/string/ustring.h" -struct IP_Address { +struct IPAddress { private: union { uint8_t field8[16]; @@ -50,7 +50,7 @@ protected: public: //operator Variant() const; - bool operator==(const IP_Address &p_ip) const { + bool operator==(const IPAddress &p_ip) const { if (p_ip.valid != valid) { return false; } @@ -65,7 +65,7 @@ public: return true; } - bool operator!=(const IP_Address &p_ip) const { + bool operator!=(const IPAddress &p_ip) const { if (p_ip.valid != valid) { return true; } @@ -91,9 +91,9 @@ public: void set_ipv6(const uint8_t *p_buf); operator String() const; - IP_Address(const String &p_string); - IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6 = false); - IP_Address() { clear(); } + IPAddress(const String &p_string); + IPAddress(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6 = false); + IPAddress() { clear(); } }; #endif // IP_ADDRESS_H diff --git a/core/io/net_socket.h b/core/io/net_socket.h index a632ad2ea7..98ff9562d9 100644 --- a/core/io/net_socket.h +++ b/core/io/net_socket.h @@ -55,27 +55,27 @@ public: virtual Error open(Type p_type, IP::Type &ip_type) = 0; virtual void close() = 0; - virtual Error bind(IP_Address p_addr, uint16_t p_port) = 0; + virtual Error bind(IPAddress p_addr, uint16_t p_port) = 0; virtual Error listen(int p_max_pending) = 0; - virtual Error connect_to_host(IP_Address p_addr, uint16_t p_port) = 0; + virtual Error connect_to_host(IPAddress p_addr, uint16_t p_port) = 0; virtual Error poll(PollType p_type, int timeout) const = 0; virtual Error recv(uint8_t *p_buffer, int p_len, int &r_read) = 0; - virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port, bool p_peek = false) = 0; + virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IPAddress &r_ip, uint16_t &r_port, bool p_peek = false) = 0; virtual Error send(const uint8_t *p_buffer, int p_len, int &r_sent) = 0; - virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) = 0; - virtual Ref<NetSocket> accept(IP_Address &r_ip, uint16_t &r_port) = 0; + virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port) = 0; + virtual Ref<NetSocket> accept(IPAddress &r_ip, uint16_t &r_port) = 0; 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 get_socket_address(IPAddress *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; virtual void set_ipv6_only_enabled(bool p_enabled) = 0; virtual void set_tcp_no_delay_enabled(bool p_enabled) = 0; virtual void set_reuse_address_enabled(bool p_enabled) = 0; - virtual Error join_multicast_group(const IP_Address &p_multi_address, String p_if_name) = 0; - virtual Error leave_multicast_group(const IP_Address &p_multi_address, String p_if_name) = 0; + virtual Error join_multicast_group(const IPAddress &p_multi_address, String p_if_name) = 0; + virtual Error leave_multicast_group(const IPAddress &p_multi_address, String p_if_name) = 0; }; #endif // NET_SOCKET_H diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp index c6354b11b7..52169987fd 100644 --- a/core/io/packed_data_container.cpp +++ b/core/io/packed_data_container.cpp @@ -123,6 +123,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const { const uint8_t *rd = data.ptr(); + ERR_FAIL_COND_V(!rd, 0); const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); @@ -149,6 +150,10 @@ int PackedDataContainer::_size(uint32_t p_ofs) const { Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, bool &err) const { const uint8_t *rd = data.ptr(); + if (!rd) { + err = true; + ERR_FAIL_COND_V(!rd, Variant()); + } const uint8_t *r = &rd[p_ofs]; uint32_t type = decode_uint32(r); diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 40e4ce4f77..f951a5158c 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -45,7 +45,7 @@ void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) { } } -Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) { +Error PacketPeerUDP::join_multicast_group(IPAddress p_multi_address, String p_if_name) { ERR_FAIL_COND_V(udp_server, ERR_LOCKED); ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!p_multi_address.is_valid(), ERR_INVALID_PARAMETER); @@ -60,7 +60,7 @@ Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_i return _sock->join_multicast_group(p_multi_address, p_if_name); } -Error PacketPeerUDP::leave_multicast_group(IP_Address p_multi_address, String p_if_name) { +Error PacketPeerUDP::leave_multicast_group(IPAddress p_multi_address, String p_if_name) { ERR_FAIL_COND_V(udp_server, ERR_LOCKED); ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE); ERR_FAIL_COND_V(!_sock->is_open(), ERR_UNCONFIGURED); @@ -72,7 +72,7 @@ String PacketPeerUDP::_get_packet_ip() const { } Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) { - IP_Address ip; + IPAddress ip; if (p_address.is_valid_ip_address()) { ip = p_address; } else { @@ -159,7 +159,7 @@ int PacketPeerUDP::get_max_packet_size() const { return 512; // uhm maybe not } -Error PacketPeerUDP::bind(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) { +Error PacketPeerUDP::bind(int p_port, const IPAddress &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); @@ -190,7 +190,7 @@ Error PacketPeerUDP::bind(int p_port, const IP_Address &p_bind_address, int p_re return OK; } -Error PacketPeerUDP::connect_shared_socket(Ref<NetSocket> p_sock, IP_Address p_ip, uint16_t p_port, UDPServer *p_server) { +Error PacketPeerUDP::connect_shared_socket(Ref<NetSocket> p_sock, IPAddress p_ip, uint16_t p_port, UDPServer *p_server) { udp_server = p_server; connected = true; _sock = p_sock; @@ -207,7 +207,7 @@ void PacketPeerUDP::disconnect_shared_socket() { close(); } -Error PacketPeerUDP::connect_to_host(const IP_Address &p_host, int p_port) { +Error PacketPeerUDP::connect_to_host(const IPAddress &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); @@ -276,7 +276,7 @@ Error PacketPeerUDP::_poll() { Error err; int read; - IP_Address ip; + IPAddress ip; uint16_t port; while (true) { @@ -306,7 +306,7 @@ Error PacketPeerUDP::_poll() { return OK; } -Error PacketPeerUDP::store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size) { +Error PacketPeerUDP::store_packet(IPAddress p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size) { if (rb.space_left() < p_buf_size + 24) { return ERR_OUT_OF_MEMORY; } @@ -322,7 +322,7 @@ bool PacketPeerUDP::is_bound() const { return _sock.is_valid() && _sock->is_open(); } -IP_Address PacketPeerUDP::get_packet_address() const { +IPAddress PacketPeerUDP::get_packet_address() const { return packet_ip; } @@ -336,7 +336,7 @@ int PacketPeerUDP::get_local_port() const { return local_port; } -void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) { +void PacketPeerUDP::set_dest_address(const IPAddress &p_address, int p_port) { ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets"); peer_addr = p_address; peer_port = p_port; diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index b9d11c465c..40d3c44e40 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -48,11 +48,11 @@ protected: RingBuffer<uint8_t> rb; uint8_t recv_buffer[PACKET_BUFFER_SIZE]; uint8_t packet_buffer[PACKET_BUFFER_SIZE]; - IP_Address packet_ip; + IPAddress packet_ip; int packet_port = 0; int queue_count = 0; - IP_Address peer_addr; + IPAddress peer_addr; int peer_port = 0; bool connected = false; bool blocking = true; @@ -70,29 +70,29 @@ protected: public: void set_blocking_mode(bool p_enable); - Error bind(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536); + Error bind(int p_port, const IPAddress &p_bind_address = IPAddress("*"), int p_recv_buffer_size = 65536); void close(); Error wait(); 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 + Error connect_shared_socket(Ref<NetSocket> p_sock, IPAddress p_ip, uint16_t p_port, UDPServer *ref); // Used by UDPServer void disconnect_shared_socket(); // Used by UDPServer - Error store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size); // Used internally and by UDPServer - Error connect_to_host(const IP_Address &p_host, int p_port); + Error store_packet(IPAddress p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size); // Used internally and by UDPServer + Error connect_to_host(const IPAddress &p_host, int p_port); bool is_connected_to_host() const; - IP_Address get_packet_address() const; + IPAddress 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); + void set_dest_address(const IPAddress &p_address, int p_port); Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; int get_available_packet_count() const override; int get_max_packet_size() const override; void set_broadcast_enabled(bool p_enabled); - Error join_multicast_group(IP_Address p_multi_address, String p_if_name); - Error leave_multicast_group(IP_Address p_multi_address, String p_if_name); + Error join_multicast_group(IPAddress p_multi_address, String p_if_name); + Error leave_multicast_group(IPAddress p_multi_address, String p_if_name); PacketPeerUDP(); ~PacketPeerUDP(); diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index dcf71bb4a9..040e55b9db 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -114,25 +114,24 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions) } RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) { + // Check user-defined loader if there's any. Hard fail if it returns an error. if (get_script_instance() && get_script_instance()->has_method("load")) { Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads, p_cache_mode); - if (res.get_type() == Variant::INT) { + if (res.get_type() == Variant::INT) { // Error code, abort. if (r_error) { *r_error = (Error)res.operator int64_t(); } - - } else { + return RES(); + } else { // Success, pass on result. if (r_error) { *r_error = OK; } return res; } - - return res; } - ERR_FAIL_V_MSG(RES(), "Failed to load resource '" + p_path + "', ResourceFormatLoader::load was not implemented for this resource type."); + ERR_FAIL_V_MSG(RES(), "Failed to load resource '" + p_path + "'. ResourceFormatLoader::load was not implemented for this resource type."); } void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 9906b9e4c3..5b794274ca 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -56,7 +56,7 @@ Error StreamPeerTCP::_poll_connection() { return ERR_CONNECTION_ERROR; } -void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port) { +void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IPAddress p_host, uint16_t p_port) { _sock = p_sock; _sock->set_blocking_enabled(false); @@ -67,7 +67,7 @@ void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint peer_port = p_port; } -Error StreamPeerTCP::bind(int p_port, const IP_Address &p_host) { +Error StreamPeerTCP::bind(int p_port, const IPAddress &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_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); @@ -84,7 +84,7 @@ Error StreamPeerTCP::bind(int p_port, const IP_Address &p_host) { return _sock->bind(p_host, p_port); } -Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, int p_port) { +Error StreamPeerTCP::connect_to_host(const IPAddress &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); @@ -283,7 +283,7 @@ void StreamPeerTCP::disconnect_from_host() { timeout = 0; status = STATUS_NONE; - peer_host = IP_Address(); + peer_host = IPAddress(); peer_port = 0; } @@ -315,7 +315,7 @@ int StreamPeerTCP::get_available_bytes() const { return _sock->get_available_bytes(); } -IP_Address StreamPeerTCP::get_connected_host() const { +IPAddress StreamPeerTCP::get_connected_host() const { return peer_host; } @@ -330,7 +330,7 @@ int StreamPeerTCP::get_local_port() const { } Error StreamPeerTCP::_connect(const String &p_address, int p_port) { - IP_Address ip; + IPAddress ip; if (p_address.is_valid_ip_address()) { ip = p_address; } else { diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 3bc7b252dc..a2a7f447d8 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -52,7 +52,7 @@ protected: Ref<NetSocket> _sock; uint64_t timeout = 0; Status status = STATUS_NONE; - IP_Address peer_host; + IPAddress peer_host; uint16_t peer_port = 0; Error _connect(const String &p_address, int p_port); @@ -63,12 +63,12 @@ protected: static void _bind_methods(); public: - void accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port); + void accept_socket(Ref<NetSocket> p_sock, IPAddress 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); + Error bind(int p_port, const IPAddress &p_host); + Error connect_to_host(const IPAddress &p_host, int p_port); bool is_connected_to_host() const; - IP_Address get_connected_host() const; + IPAddress get_connected_host() const; int get_connected_port() const; int get_local_port() const; void disconnect_from_host(); diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 348be66ba4..b760a9ef80 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -30,16 +30,16 @@ #include "tcp_server.h" -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); +void TCPServer::_bind_methods() { + ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCPServer::listen, DEFVAL("*")); + ClassDB::bind_method(D_METHOD("is_connection_available"), &TCPServer::is_connection_available); + ClassDB::bind_method(D_METHOD("is_listening"), &TCPServer::is_listening); + ClassDB::bind_method(D_METHOD("get_local_port"), &TCPServer::get_local_port); + ClassDB::bind_method(D_METHOD("take_connection"), &TCPServer::take_connection); + ClassDB::bind_method(D_METHOD("stop"), &TCPServer::stop); } -Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { +Error TCPServer::listen(uint16_t p_port, const IPAddress &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); @@ -76,19 +76,19 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { return OK; } -int TCP_Server::get_local_port() const { +int TCPServer::get_local_port() const { uint16_t local_port; _sock->get_socket_address(nullptr, &local_port); return local_port; } -bool TCP_Server::is_listening() const { +bool TCPServer::is_listening() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); return _sock->is_open(); } -bool TCP_Server::is_connection_available() const { +bool TCPServer::is_connection_available() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); if (!_sock->is_open()) { @@ -99,14 +99,14 @@ bool TCP_Server::is_connection_available() const { return (err == OK); } -Ref<StreamPeerTCP> TCP_Server::take_connection() { +Ref<StreamPeerTCP> TCPServer::take_connection() { Ref<StreamPeerTCP> conn; if (!is_connection_available()) { return conn; } Ref<NetSocket> ns; - IP_Address ip; + IPAddress ip; uint16_t port = 0; ns = _sock->accept(ip, port); if (!ns.is_valid()) { @@ -118,16 +118,16 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() { return conn; } -void TCP_Server::stop() { +void TCPServer::stop() { if (_sock.is_valid()) { _sock->close(); } } -TCP_Server::TCP_Server() : +TCPServer::TCPServer() : _sock(Ref<NetSocket>(NetSocket::create())) { } -TCP_Server::~TCP_Server() { +TCPServer::~TCPServer() { stop(); } diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h index 58c04d87ec..abefa53c6f 100644 --- a/core/io/tcp_server.h +++ b/core/io/tcp_server.h @@ -36,8 +36,8 @@ #include "core/io/stream_peer.h" #include "core/io/stream_peer_tcp.h" -class TCP_Server : public Reference { - GDCLASS(TCP_Server, Reference); +class TCPServer : public Reference { + GDCLASS(TCPServer, Reference); protected: enum { @@ -48,7 +48,7 @@ protected: static void _bind_methods(); public: - Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*")); + Error listen(uint16_t p_port, const IPAddress &p_bind_address = IPAddress("*")); int get_local_port() const; bool is_listening() const; bool is_connection_available() const; @@ -56,8 +56,8 @@ public: void stop(); // Stop listening - TCP_Server(); - ~TCP_Server(); + TCPServer(); + ~TCPServer(); }; #endif // TCP_SERVER_H diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp index 99642f4af4..6a1af0c2a9 100644 --- a/core/io/udp_server.cpp +++ b/core/io/udp_server.cpp @@ -50,7 +50,7 @@ Error UDPServer::poll() { } Error err; int read; - IP_Address ip; + IPAddress ip; uint16_t port; while (true) { err = _sock->recvfrom(recv_buffer, sizeof(recv_buffer), read, ip, port); @@ -87,7 +87,7 @@ Error UDPServer::poll() { return OK; } -Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) { +Error UDPServer::listen(uint16_t p_port, const IPAddress &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); @@ -168,7 +168,7 @@ Ref<PacketPeerUDP> UDPServer::take_connection() { return peer.peer; } -void UDPServer::remove_peer(IP_Address p_ip, int p_port) { +void UDPServer::remove_peer(IPAddress p_ip, int p_port) { Peer peer; peer.ip = p_ip; peer.port = p_port; diff --git a/core/io/udp_server.h b/core/io/udp_server.h index 298d4d4b63..60d03f37f0 100644 --- a/core/io/udp_server.h +++ b/core/io/udp_server.h @@ -44,7 +44,7 @@ protected: struct Peer { PacketPeerUDP *peer; - IP_Address ip; + IPAddress ip; uint16_t port = 0; bool operator==(const Peer &p_other) const { @@ -61,8 +61,8 @@ protected: 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("*")); + void remove_peer(IPAddress p_ip, int p_port); + Error listen(uint16_t p_port, const IPAddress &p_bind_address = IPAddress("*")); Error poll(); int get_local_port() const; bool is_listening() const; diff --git a/core/math/color.cpp b/core/math/color.cpp index 8affb07e8c..64abd6dd08 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -379,11 +379,11 @@ int Color::find_named_color(const String &p_name) { name = name.replace("_", ""); name = name.replace("'", ""); name = name.replace(".", ""); - name = name.to_lower(); + name = name.to_upper(); int idx = 0; while (named_colors[idx].name != nullptr) { - if (name == named_colors[idx].name) { + if (name == String(named_colors[idx].name).replace("_", "")) { return idx; } idx++; diff --git a/core/math/color_names.inc b/core/math/color_names.inc index e5b935ea9c..2020bdbfca 100644 --- a/core/math/color_names.inc +++ b/core/math/color_names.inc @@ -9,152 +9,155 @@ struct NamedColor { Color color; }; +// NOTE: This data is duplicated in the file: +// modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs + static NamedColor named_colors[] = { - { "aliceblue", Color(0.94, 0.97, 1.00) }, - { "antiquewhite", Color(0.98, 0.92, 0.84) }, - { "aqua", Color(0.00, 1.00, 1.00) }, - { "aquamarine", Color(0.50, 1.00, 0.83) }, - { "azure", Color(0.94, 1.00, 1.00) }, - { "beige", Color(0.96, 0.96, 0.86) }, - { "bisque", Color(1.00, 0.89, 0.77) }, - { "black", Color(0.00, 0.00, 0.00) }, - { "blanchedalmond", Color(1.00, 0.92, 0.80) }, - { "blue", Color(0.00, 0.00, 1.00) }, - { "blueviolet", Color(0.54, 0.17, 0.89) }, - { "brown", Color(0.65, 0.16, 0.16) }, - { "burlywood", Color(0.87, 0.72, 0.53) }, - { "cadetblue", Color(0.37, 0.62, 0.63) }, - { "chartreuse", Color(0.50, 1.00, 0.00) }, - { "chocolate", Color(0.82, 0.41, 0.12) }, - { "coral", Color(1.00, 0.50, 0.31) }, - { "cornflower", Color(0.39, 0.58, 0.93) }, - { "cornsilk", Color(1.00, 0.97, 0.86) }, - { "crimson", Color(0.86, 0.08, 0.24) }, - { "cyan", Color(0.00, 1.00, 1.00) }, - { "darkblue", Color(0.00, 0.00, 0.55) }, - { "darkcyan", Color(0.00, 0.55, 0.55) }, - { "darkgoldenrod", Color(0.72, 0.53, 0.04) }, - { "darkgray", Color(0.66, 0.66, 0.66) }, - { "darkgreen", Color(0.00, 0.39, 0.00) }, - { "darkkhaki", Color(0.74, 0.72, 0.42) }, - { "darkmagenta", Color(0.55, 0.00, 0.55) }, - { "darkolivegreen", Color(0.33, 0.42, 0.18) }, - { "darkorange", Color(1.00, 0.55, 0.00) }, - { "darkorchid", Color(0.60, 0.20, 0.80) }, - { "darkred", Color(0.55, 0.00, 0.00) }, - { "darksalmon", Color(0.91, 0.59, 0.48) }, - { "darkseagreen", Color(0.56, 0.74, 0.56) }, - { "darkslateblue", Color(0.28, 0.24, 0.55) }, - { "darkslategray", Color(0.18, 0.31, 0.31) }, - { "darkturquoise", Color(0.00, 0.81, 0.82) }, - { "darkviolet", Color(0.58, 0.00, 0.83) }, - { "deeppink", Color(1.00, 0.08, 0.58) }, - { "deepskyblue", Color(0.00, 0.75, 1.00) }, - { "dimgray", Color(0.41, 0.41, 0.41) }, - { "dodgerblue", Color(0.12, 0.56, 1.00) }, - { "firebrick", Color(0.70, 0.13, 0.13) }, - { "floralwhite", Color(1.00, 0.98, 0.94) }, - { "forestgreen", Color(0.13, 0.55, 0.13) }, - { "fuchsia", Color(1.00, 0.00, 1.00) }, - { "gainsboro", Color(0.86, 0.86, 0.86) }, - { "ghostwhite", Color(0.97, 0.97, 1.00) }, - { "gold", Color(1.00, 0.84, 0.00) }, - { "goldenrod", Color(0.85, 0.65, 0.13) }, - { "gray", Color(0.75, 0.75, 0.75) }, - { "green", Color(0.00, 1.00, 0.00) }, - { "greenyellow", Color(0.68, 1.00, 0.18) }, - { "honeydew", Color(0.94, 1.00, 0.94) }, - { "hotpink", Color(1.00, 0.41, 0.71) }, - { "indianred", Color(0.80, 0.36, 0.36) }, - { "indigo", Color(0.29, 0.00, 0.51) }, - { "ivory", Color(1.00, 1.00, 0.94) }, - { "khaki", Color(0.94, 0.90, 0.55) }, - { "lavender", Color(0.90, 0.90, 0.98) }, - { "lavenderblush", Color(1.00, 0.94, 0.96) }, - { "lawngreen", Color(0.49, 0.99, 0.00) }, - { "lemonchiffon", Color(1.00, 0.98, 0.80) }, - { "lightblue", Color(0.68, 0.85, 0.90) }, - { "lightcoral", Color(0.94, 0.50, 0.50) }, - { "lightcyan", Color(0.88, 1.00, 1.00) }, - { "lightgoldenrod", Color(0.98, 0.98, 0.82) }, - { "lightgray", Color(0.83, 0.83, 0.83) }, - { "lightgreen", Color(0.56, 0.93, 0.56) }, - { "lightpink", Color(1.00, 0.71, 0.76) }, - { "lightsalmon", Color(1.00, 0.63, 0.48) }, - { "lightseagreen", Color(0.13, 0.70, 0.67) }, - { "lightskyblue", Color(0.53, 0.81, 0.98) }, - { "lightslategray", Color(0.47, 0.53, 0.60) }, - { "lightsteelblue", Color(0.69, 0.77, 0.87) }, - { "lightyellow", Color(1.00, 1.00, 0.88) }, - { "lime", Color(0.00, 1.00, 0.00) }, - { "limegreen", Color(0.20, 0.80, 0.20) }, - { "linen", Color(0.98, 0.94, 0.90) }, - { "magenta", Color(1.00, 0.00, 1.00) }, - { "maroon", Color(0.69, 0.19, 0.38) }, - { "mediumaquamarine", Color(0.40, 0.80, 0.67) }, - { "mediumblue", Color(0.00, 0.00, 0.80) }, - { "mediumorchid", Color(0.73, 0.33, 0.83) }, - { "mediumpurple", Color(0.58, 0.44, 0.86) }, - { "mediumseagreen", Color(0.24, 0.70, 0.44) }, - { "mediumslateblue", Color(0.48, 0.41, 0.93) }, - { "mediumspringgreen", Color(0.00, 0.98, 0.60) }, - { "mediumturquoise", Color(0.28, 0.82, 0.80) }, - { "mediumvioletred", Color(0.78, 0.08, 0.52) }, - { "midnightblue", Color(0.10, 0.10, 0.44) }, - { "mintcream", Color(0.96, 1.00, 0.98) }, - { "mistyrose", Color(1.00, 0.89, 0.88) }, - { "moccasin", Color(1.00, 0.89, 0.71) }, - { "navajowhite", Color(1.00, 0.87, 0.68) }, - { "navyblue", Color(0.00, 0.00, 0.50) }, - { "oldlace", Color(0.99, 0.96, 0.90) }, - { "olive", Color(0.50, 0.50, 0.00) }, - { "olivedrab", Color(0.42, 0.56, 0.14) }, - { "orange", Color(1.00, 0.65, 0.00) }, - { "orangered", Color(1.00, 0.27, 0.00) }, - { "orchid", Color(0.85, 0.44, 0.84) }, - { "palegoldenrod", Color(0.93, 0.91, 0.67) }, - { "palegreen", Color(0.60, 0.98, 0.60) }, - { "paleturquoise", Color(0.69, 0.93, 0.93) }, - { "palevioletred", Color(0.86, 0.44, 0.58) }, - { "papayawhip", Color(1.00, 0.94, 0.84) }, - { "peachpuff", Color(1.00, 0.85, 0.73) }, - { "peru", Color(0.80, 0.52, 0.25) }, - { "pink", Color(1.00, 0.75, 0.80) }, - { "plum", Color(0.87, 0.63, 0.87) }, - { "powderblue", Color(0.69, 0.88, 0.90) }, - { "purple", Color(0.63, 0.13, 0.94) }, - { "rebeccapurple", Color(0.40, 0.20, 0.60) }, - { "red", Color(1.00, 0.00, 0.00) }, - { "rosybrown", Color(0.74, 0.56, 0.56) }, - { "royalblue", Color(0.25, 0.41, 0.88) }, - { "saddlebrown", Color(0.55, 0.27, 0.07) }, - { "salmon", Color(0.98, 0.50, 0.45) }, - { "sandybrown", Color(0.96, 0.64, 0.38) }, - { "seagreen", Color(0.18, 0.55, 0.34) }, - { "seashell", Color(1.00, 0.96, 0.93) }, - { "sienna", Color(0.63, 0.32, 0.18) }, - { "silver", Color(0.75, 0.75, 0.75) }, - { "skyblue", Color(0.53, 0.81, 0.92) }, - { "slateblue", Color(0.42, 0.35, 0.80) }, - { "slategray", Color(0.44, 0.50, 0.56) }, - { "snow", Color(1.00, 0.98, 0.98) }, - { "springgreen", Color(0.00, 1.00, 0.50) }, - { "steelblue", Color(0.27, 0.51, 0.71) }, - { "tan", Color(0.82, 0.71, 0.55) }, - { "teal", Color(0.00, 0.50, 0.50) }, - { "thistle", Color(0.85, 0.75, 0.85) }, - { "tomato", Color(1.00, 0.39, 0.28) }, - { "transparent", Color(1.00, 1.00, 1.00, 0.00) }, - { "turquoise", Color(0.25, 0.88, 0.82) }, - { "violet", Color(0.93, 0.51, 0.93) }, - { "webgray", Color(0.50, 0.50, 0.50) }, - { "webgreen", Color(0.00, 0.50, 0.00) }, - { "webmaroon", Color(0.50, 0.00, 0.00) }, - { "webpurple", Color(0.50, 0.00, 0.50) }, - { "wheat", Color(0.96, 0.87, 0.70) }, - { "white", Color(1.00, 1.00, 1.00) }, - { "whitesmoke", Color(0.96, 0.96, 0.96) }, - { "yellow", Color(1.00, 1.00, 0.00) }, - { "yellowgreen", Color(0.60, 0.80, 0.20) }, + { "ALICE_BLUE", Color(0.94, 0.97, 1.00) }, + { "ANTIQUE_WHITE", Color(0.98, 0.92, 0.84) }, + { "AQUA", Color(0.00, 1.00, 1.00) }, + { "AQUAMARINE", Color(0.50, 1.00, 0.83) }, + { "AZURE", Color(0.94, 1.00, 1.00) }, + { "BEIGE", Color(0.96, 0.96, 0.86) }, + { "BISQUE", Color(1.00, 0.89, 0.77) }, + { "BLACK", Color(0.00, 0.00, 0.00) }, + { "BLANCHED_ALMOND", Color(1.00, 0.92, 0.80) }, + { "BLUE", Color(0.00, 0.00, 1.00) }, + { "BLUE_VIOLET", Color(0.54, 0.17, 0.89) }, + { "BROWN", Color(0.65, 0.16, 0.16) }, + { "BURLYWOOD", Color(0.87, 0.72, 0.53) }, + { "CADET_BLUE", Color(0.37, 0.62, 0.63) }, + { "CHARTREUSE", Color(0.50, 1.00, 0.00) }, + { "CHOCOLATE", Color(0.82, 0.41, 0.12) }, + { "CORAL", Color(1.00, 0.50, 0.31) }, + { "CORNFLOWER_BLUE", Color(0.39, 0.58, 0.93) }, + { "CORNSILK", Color(1.00, 0.97, 0.86) }, + { "CRIMSON", Color(0.86, 0.08, 0.24) }, + { "CYAN", Color(0.00, 1.00, 1.00) }, + { "DARK_BLUE", Color(0.00, 0.00, 0.55) }, + { "DARK_CYAN", Color(0.00, 0.55, 0.55) }, + { "DARK_GOLDENROD", Color(0.72, 0.53, 0.04) }, + { "DARK_GRAY", Color(0.66, 0.66, 0.66) }, + { "DARK_GREEN", Color(0.00, 0.39, 0.00) }, + { "DARK_KHAKI", Color(0.74, 0.72, 0.42) }, + { "DARK_MAGENTA", Color(0.55, 0.00, 0.55) }, + { "DARK_OLIVE_GREEN", Color(0.33, 0.42, 0.18) }, + { "DARK_ORANGE", Color(1.00, 0.55, 0.00) }, + { "DARK_ORCHID", Color(0.60, 0.20, 0.80) }, + { "DARK_RED", Color(0.55, 0.00, 0.00) }, + { "DARK_SALMON", Color(0.91, 0.59, 0.48) }, + { "DARK_SEA_GREEN", Color(0.56, 0.74, 0.56) }, + { "DARK_SLATE_BLUE", Color(0.28, 0.24, 0.55) }, + { "DARK_SLATE_GRAY", Color(0.18, 0.31, 0.31) }, + { "DARK_TURQUOISE", Color(0.00, 0.81, 0.82) }, + { "DARK_VIOLET", Color(0.58, 0.00, 0.83) }, + { "DEEP_PINK", Color(1.00, 0.08, 0.58) }, + { "DEEP_SKY_BLUE", Color(0.00, 0.75, 1.00) }, + { "DIM_GRAY", Color(0.41, 0.41, 0.41) }, + { "DODGER_BLUE", Color(0.12, 0.56, 1.00) }, + { "FIREBRICK", Color(0.70, 0.13, 0.13) }, + { "FLORAL_WHITE", Color(1.00, 0.98, 0.94) }, + { "FOREST_GREEN", Color(0.13, 0.55, 0.13) }, + { "FUCHSIA", Color(1.00, 0.00, 1.00) }, + { "GAINSBORO", Color(0.86, 0.86, 0.86) }, + { "GHOST_WHITE", Color(0.97, 0.97, 1.00) }, + { "GOLD", Color(1.00, 0.84, 0.00) }, + { "GOLDENROD", Color(0.85, 0.65, 0.13) }, + { "GRAY", Color(0.75, 0.75, 0.75) }, + { "GREEN", Color(0.00, 1.00, 0.00) }, + { "GREEN_YELLOW", Color(0.68, 1.00, 0.18) }, + { "HONEYDEW", Color(0.94, 1.00, 0.94) }, + { "HOT_PINK", Color(1.00, 0.41, 0.71) }, + { "INDIAN_RED", Color(0.80, 0.36, 0.36) }, + { "INDIGO", Color(0.29, 0.00, 0.51) }, + { "IVORY", Color(1.00, 1.00, 0.94) }, + { "KHAKI", Color(0.94, 0.90, 0.55) }, + { "LAVENDER", Color(0.90, 0.90, 0.98) }, + { "LAVENDER_BLUSH", Color(1.00, 0.94, 0.96) }, + { "LAWN_GREEN", Color(0.49, 0.99, 0.00) }, + { "LEMON_CHIFFON", Color(1.00, 0.98, 0.80) }, + { "LIGHT_BLUE", Color(0.68, 0.85, 0.90) }, + { "LIGHT_CORAL", Color(0.94, 0.50, 0.50) }, + { "LIGHT_CYAN", Color(0.88, 1.00, 1.00) }, + { "LIGHT_GOLDENROD", Color(0.98, 0.98, 0.82) }, + { "LIGHT_GRAY", Color(0.83, 0.83, 0.83) }, + { "LIGHT_GREEN", Color(0.56, 0.93, 0.56) }, + { "LIGHT_PINK", Color(1.00, 0.71, 0.76) }, + { "LIGHT_SALMON", Color(1.00, 0.63, 0.48) }, + { "LIGHT_SEA_GREEN", Color(0.13, 0.70, 0.67) }, + { "LIGHT_SKY_BLUE", Color(0.53, 0.81, 0.98) }, + { "LIGHT_SLATE_GRAY", Color(0.47, 0.53, 0.60) }, + { "LIGHT_STEEL_BLUE", Color(0.69, 0.77, 0.87) }, + { "LIGHT_YELLOW", Color(1.00, 1.00, 0.88) }, + { "LIME", Color(0.00, 1.00, 0.00) }, + { "LIME_GREEN", Color(0.20, 0.80, 0.20) }, + { "LINEN", Color(0.98, 0.94, 0.90) }, + { "MAGENTA", Color(1.00, 0.00, 1.00) }, + { "MAROON", Color(0.69, 0.19, 0.38) }, + { "MEDIUM_AQUAMARINE", Color(0.40, 0.80, 0.67) }, + { "MEDIUM_BLUE", Color(0.00, 0.00, 0.80) }, + { "MEDIUM_ORCHID", Color(0.73, 0.33, 0.83) }, + { "MEDIUM_PURPLE", Color(0.58, 0.44, 0.86) }, + { "MEDIUM_SEA_GREEN", Color(0.24, 0.70, 0.44) }, + { "MEDIUM_SLATE_BLUE", Color(0.48, 0.41, 0.93) }, + { "MEDIUM_SPRING_GREEN", Color(0.00, 0.98, 0.60) }, + { "MEDIUM_TURQUOISE", Color(0.28, 0.82, 0.80) }, + { "MEDIUM_VIOLET_RED", Color(0.78, 0.08, 0.52) }, + { "MIDNIGHT_BLUE", Color(0.10, 0.10, 0.44) }, + { "MINT_CREAM", Color(0.96, 1.00, 0.98) }, + { "MISTY_ROSE", Color(1.00, 0.89, 0.88) }, + { "MOCCASIN", Color(1.00, 0.89, 0.71) }, + { "NAVAJO_WHITE", Color(1.00, 0.87, 0.68) }, + { "NAVY_BLUE", Color(0.00, 0.00, 0.50) }, + { "OLD_LACE", Color(0.99, 0.96, 0.90) }, + { "OLIVE", Color(0.50, 0.50, 0.00) }, + { "OLIVE_DRAB", Color(0.42, 0.56, 0.14) }, + { "ORANGE", Color(1.00, 0.65, 0.00) }, + { "ORANGE_RED", Color(1.00, 0.27, 0.00) }, + { "ORCHID", Color(0.85, 0.44, 0.84) }, + { "PALE_GOLDENROD", Color(0.93, 0.91, 0.67) }, + { "PALE_GREEN", Color(0.60, 0.98, 0.60) }, + { "PALE_TURQUOISE", Color(0.69, 0.93, 0.93) }, + { "PALE_VIOLET_RED", Color(0.86, 0.44, 0.58) }, + { "PAPAYA_WHIP", Color(1.00, 0.94, 0.84) }, + { "PEACH_PUFF", Color(1.00, 0.85, 0.73) }, + { "PERU", Color(0.80, 0.52, 0.25) }, + { "PINK", Color(1.00, 0.75, 0.80) }, + { "PLUM", Color(0.87, 0.63, 0.87) }, + { "POWDER_BLUE", Color(0.69, 0.88, 0.90) }, + { "PURPLE", Color(0.63, 0.13, 0.94) }, + { "REBECCA_PURPLE", Color(0.40, 0.20, 0.60) }, + { "RED", Color(1.00, 0.00, 0.00) }, + { "ROSY_BROWN", Color(0.74, 0.56, 0.56) }, + { "ROYAL_BLUE", Color(0.25, 0.41, 0.88) }, + { "SADDLE_BROWN", Color(0.55, 0.27, 0.07) }, + { "SALMON", Color(0.98, 0.50, 0.45) }, + { "SANDY_BROWN", Color(0.96, 0.64, 0.38) }, + { "SEA_GREEN", Color(0.18, 0.55, 0.34) }, + { "SEASHELL", Color(1.00, 0.96, 0.93) }, + { "SIENNA", Color(0.63, 0.32, 0.18) }, + { "SILVER", Color(0.75, 0.75, 0.75) }, + { "SKY_BLUE", Color(0.53, 0.81, 0.92) }, + { "SLATE_BLUE", Color(0.42, 0.35, 0.80) }, + { "SLATE_GRAY", Color(0.44, 0.50, 0.56) }, + { "SNOW", Color(1.00, 0.98, 0.98) }, + { "SPRING_GREEN", Color(0.00, 1.00, 0.50) }, + { "STEEL_BLUE", Color(0.27, 0.51, 0.71) }, + { "TAN", Color(0.82, 0.71, 0.55) }, + { "TEAL", Color(0.00, 0.50, 0.50) }, + { "THISTLE", Color(0.85, 0.75, 0.85) }, + { "TOMATO", Color(1.00, 0.39, 0.28) }, + { "TRANSPARENT", Color(1.00, 1.00, 1.00, 0.00) }, + { "TURQUOISE", Color(0.25, 0.88, 0.82) }, + { "VIOLET", Color(0.93, 0.51, 0.93) }, + { "WEB_GRAY", Color(0.50, 0.50, 0.50) }, + { "WEB_GREEN", Color(0.00, 0.50, 0.00) }, + { "WEB_MAROON", Color(0.50, 0.00, 0.00) }, + { "WEB_PURPLE", Color(0.50, 0.00, 0.50) }, + { "WHEAT", Color(0.96, 0.87, 0.70) }, + { "WHITE", Color(1.00, 1.00, 1.00) }, + { "WHITE_SMOKE", Color(0.96, 0.96, 0.96) }, + { "YELLOW", Color(1.00, 1.00, 0.00) }, + { "YELLOW_GREEN", Color(0.60, 0.80, 0.20) }, { nullptr, Color() }, }; diff --git a/core/math/geometry_2d.h b/core/math/geometry_2d.h index 4b5aef352f..4958b5ac6a 100644 --- a/core/math/geometry_2d.h +++ b/core/math/geometry_2d.h @@ -395,6 +395,45 @@ public: H.resize(k); return H; } + + static Vector<Point2i> bresenham_line(const Point2i &p_start, const Point2i &p_end) { + Vector<Point2i> points; + + Vector2i delta = (p_end - p_start).abs() * 2; + Vector2i step = (p_end - p_start).sign(); + Vector2i current = p_start; + + if (delta.x > delta.y) { + int err = delta.x / 2; + + for (; current.x != p_end.x; current.x += step.x) { + points.push_back(current); + + err -= delta.y; + if (err < 0) { + current.y += step.y; + err += delta.x; + } + } + } else { + int err = delta.y / 2; + + for (; current.y != p_end.y; current.y += step.y) { + points.push_back(current); + + err -= delta.x; + if (err < 0) { + current.x += step.x; + err += delta.y; + } + } + } + + points.push_back(current); + + return points; + } + static Vector<Vector<Vector2>> decompose_polygon_in_convex(Vector<Point2> polygon); static void make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size); diff --git a/core/math/vector2.h b/core/math/vector2.h index 81bc71d590..edc6e3a3ef 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -280,6 +280,14 @@ struct Vector2i { return p_idx ? y : x; } + Vector2i min(const Vector2i &p_vector2i) const { + return Vector2(MIN(x, p_vector2i.x), MIN(y, p_vector2i.y)); + } + + Vector2i max(const Vector2i &p_vector2i) const { + return Vector2(MAX(x, p_vector2i.x), MAX(y, p_vector2i.y)); + } + Vector2i operator+(const Vector2i &p_v) const; void operator+=(const Vector2i &p_v); Vector2i operator-(const Vector2i &p_v) const; diff --git a/core/object/script_language.h b/core/object/script_language.h index f9898ccd0c..bb46c718b2 100644 --- a/core/object/script_language.h +++ b/core/object/script_language.h @@ -303,6 +303,7 @@ public: void get_core_type_words(List<String> *p_core_type_words) const; virtual void get_reserved_words(List<String> *p_words) const = 0; + virtual bool is_control_flow_keyword(String p_string) const = 0; virtual void get_comment_delimiters(List<String> *p_delimiters) const = 0; virtual void get_string_delimiters(List<String> *p_delimiters) const = 0; virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const = 0; diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index d6a5eff10d..f1b1b98bea 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -156,7 +156,7 @@ void register_core_types() { ClassDB::register_virtual_class<StreamPeer>(); ClassDB::register_class<StreamPeerBuffer>(); ClassDB::register_class<StreamPeerTCP>(); - ClassDB::register_class<TCP_Server>(); + ClassDB::register_class<TCPServer>(); ClassDB::register_class<PacketPeerUDP>(); ClassDB::register_class<UDPServer>(); ClassDB::register_custom_instance_class<PacketPeerDTLS>(); diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 2fb2dd4a30..3c7e2a0719 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -361,6 +361,79 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { // l return new_arr; } +Array Array::filter(const Callable &p_callable) const { + Array new_arr; + new_arr.resize(size()); + int accepted_count = 0; + + for (int i = 0; i < size(); i++) { + const Variant **argptrs = (const Variant **)alloca(sizeof(Variant *)); + argptrs[0] = &get(i); + + Variant result; + Callable::CallError ce; + p_callable.call(argptrs, 1, result, ce); + if (ce.error != Callable::CallError::CALL_OK) { + ERR_FAIL_V_MSG(Array(), "Error calling method from 'filter': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + } + + if (result.operator bool()) { + new_arr[accepted_count] = get(i); + accepted_count++; + } + } + + new_arr.resize(accepted_count); + + return new_arr; +} + +Array Array::map(const Callable &p_callable) const { + Array new_arr; + new_arr.resize(size()); + + for (int i = 0; i < size(); i++) { + const Variant **argptrs = (const Variant **)alloca(sizeof(Variant *)); + argptrs[0] = &get(i); + + Variant result; + Callable::CallError ce; + p_callable.call(argptrs, 1, result, ce); + if (ce.error != Callable::CallError::CALL_OK) { + ERR_FAIL_V_MSG(Array(), "Error calling method from 'map': " + Variant::get_callable_error_text(p_callable, argptrs, 1, ce)); + } + + new_arr[i] = result; + } + + return new_arr; +} + +Variant Array::reduce(const Callable &p_callable, const Variant &p_accum) const { + int start = 0; + Variant ret = p_accum; + if (ret == Variant() && size() > 0) { + ret = front(); + start = 1; + } + + for (int i = start; i < size(); i++) { + const Variant **argptrs = (const Variant **)alloca(sizeof(Variant *) * 2); + argptrs[0] = &ret; + argptrs[1] = &get(i); + + Variant result; + Callable::CallError ce; + p_callable.call(argptrs, 2, result, ce); + if (ce.error != Callable::CallError::CALL_OK) { + ERR_FAIL_V_MSG(Variant(), "Error calling method from 'reduce': " + Variant::get_callable_error_text(p_callable, argptrs, 2, ce)); + } + ret = result; + } + + return ret; +} + struct _ArrayVariantSort { _FORCE_INLINE_ bool operator()(const Variant &p_l, const Variant &p_r) const { bool valid = false; diff --git a/core/variant/array.h b/core/variant/array.h index 5ce977ee4b..540dcb1f4e 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -101,6 +101,9 @@ public: Array duplicate(bool p_deep = false) const; Array slice(int p_begin, int p_end, int p_step = 1, bool p_deep = false) const; + Array filter(const Callable &p_callable) const; + Array map(const Callable &p_callable) const; + Variant reduce(const Callable &p_callable, const Variant &p_accum) const; bool operator<(const Array &p_array) const; bool operator<=(const Array &p_array) const; diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index c294592b63..e91029f330 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -364,7 +364,7 @@ MAKE_VECARR(Plane); } \ } -// Special case for IP_Address. +// Special case for IPAddress. #define MAKE_STRINGCONV_BY_REFERENCE(m_type) \ template <> \ @@ -387,7 +387,7 @@ MAKE_VECARR(Plane); } \ } -MAKE_STRINGCONV_BY_REFERENCE(IP_Address); +MAKE_STRINGCONV_BY_REFERENCE(IPAddress); template <> struct PtrToArg<Vector<Face3>> { diff --git a/core/variant/type_info.h b/core/variant/type_info.h index f61ff29b8f..d5b6d85dfb 100644 --- a/core/variant/type_info.h +++ b/core/variant/type_info.h @@ -168,7 +168,7 @@ MAKE_TYPE_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY) MAKE_TYPE_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY) MAKE_TYPE_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY) -MAKE_TYPE_INFO(IP_Address, Variant::STRING) +MAKE_TYPE_INFO(IPAddress, Variant::STRING) //objectID template <> diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 015cee09a7..333dd8e8d1 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -2346,15 +2346,15 @@ Variant::operator Orientation() const { return (Orientation) operator int(); } -Variant::operator IP_Address() const { +Variant::operator IPAddress() const { if (type == PACKED_FLOAT32_ARRAY || type == PACKED_INT32_ARRAY || type == PACKED_FLOAT64_ARRAY || type == PACKED_INT64_ARRAY || type == PACKED_BYTE_ARRAY) { Vector<int> addr = operator Vector<int>(); if (addr.size() == 4) { - return IP_Address(addr.get(0), addr.get(1), addr.get(2), addr.get(3)); + return IPAddress(addr.get(0), addr.get(1), addr.get(2), addr.get(3)); } } - return IP_Address(operator String()); + return IPAddress(operator String()); } Variant::Variant(bool p_bool) { @@ -2831,7 +2831,7 @@ void Variant::operator=(const Variant &p_variant) { } } -Variant::Variant(const IP_Address &p_address) { +Variant::Variant(const IPAddress &p_address) { type = STRING; memnew_placement(_data._mem, String(p_address)); } diff --git a/core/variant/variant.h b/core/variant/variant.h index 0acafc64fa..7f3c3477fc 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -359,7 +359,7 @@ public: operator Side() const; operator Orientation() const; - operator IP_Address() const; + operator IPAddress() const; Object *get_validated_object() const; Object *get_validated_object_with_check(bool &r_previously_freed) const; @@ -421,7 +421,7 @@ public: Variant(const Vector<::RID> &p_array); // helper Variant(const Vector<Vector2> &p_array); // helper - Variant(const IP_Address &p_address); + Variant(const IPAddress &p_address); // If this changes the table in variant_op must be updated enum Operator { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 455e924568..efaaa8cd19 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1745,6 +1745,9 @@ static void _register_variant_builtin_methods() { bind_method(Array, reverse, sarray(), varray()); bind_method(Array, duplicate, sarray("deep"), varray(false)); bind_method(Array, slice, sarray("begin", "end", "step", "deep"), varray(1, false)); + bind_method(Array, filter, sarray("method"), varray()); + bind_method(Array, map, sarray("method"), varray()); + bind_method(Array, reduce, sarray("method", "accum"), varray(Variant())); bind_method(Array, max, sarray(), varray()); bind_method(Array, min, sarray(), varray()); |