summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp54
-rw-r--r--core/bind/core_bind.h3
-rw-r--r--core/compressed_translation.h2
-rw-r--r--core/container_type_validate.h2
-rw-r--r--core/image.h2
-rw-r--r--core/input/input.h2
-rw-r--r--core/input/input_event.h76
-rw-r--r--core/io/logger.cpp2
-rw-r--r--core/io/packet_peer.h8
-rw-r--r--core/io/packet_peer_udp.cpp65
-rw-r--r--core/io/packet_peer_udp.h15
-rw-r--r--core/io/stream_peer.h10
-rw-r--r--core/io/stream_peer_tcp.h10
-rw-r--r--core/io/translation_loader_po.cpp22
-rw-r--r--core/io/udp_server.cpp100
-rw-r--r--core/io/udp_server.h29
-rw-r--r--core/oa_hash_map.h2
-rw-r--r--core/object.h280
-rw-r--r--core/os/os.cpp4
-rw-r--r--core/os/os.h2
-rw-r--r--core/packed_data_container.h4
-rw-r--r--core/project_settings.cpp64
-rw-r--r--core/project_settings.h14
-rw-r--r--core/resource.h8
-rw-r--r--core/script_language.cpp33
-rw-r--r--core/script_language.h4
-rw-r--r--core/variant_call.cpp36
-rw-r--r--core/vector.h4
28 files changed, 578 insertions, 279 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index cb82dc7f8f..2f8b11652b 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1619,12 +1619,17 @@ Error _Directory::open(const String &p_path) {
memdelete(d);
}
d = alt;
+ dir_open = true;
return OK;
}
+bool _Directory::is_open() const {
+ return d && dir_open;
+}
+
Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
- ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
_list_skip_navigational = p_skip_navigational;
_list_skip_hidden = p_skip_hidden;
@@ -1633,7 +1638,7 @@ Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
}
String _Directory::get_next() {
- ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");
String next = d->get_next();
while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) {
@@ -1643,42 +1648,49 @@ String _Directory::get_next() {
}
bool _Directory::current_is_dir() const {
- ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), false, "Directory must be opened before use.");
return d->current_is_dir();
}
void _Directory::list_dir_end() {
- ERR_FAIL_COND_MSG(!d, "Directory must be opened before use.");
+ ERR_FAIL_COND_MSG(!is_open(), "Directory must be opened before use.");
d->list_dir_end();
}
int _Directory::get_drive_count() {
- ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), 0, "Directory must be opened before use.");
return d->get_drive_count();
}
String _Directory::get_drive(int p_drive) {
- ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");
return d->get_drive(p_drive);
}
int _Directory::get_current_drive() {
- ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), 0, "Directory must be opened before use.");
return d->get_current_drive();
}
Error _Directory::change_dir(String p_dir) {
- ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
- return d->change_dir(p_dir);
+ ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory is not configured properly.");
+ Error err = d->change_dir(p_dir);
+
+ if (err != OK) {
+ return err;
+ }
+ dir_open = true;
+
+ return OK;
}
String _Directory::get_current_dir() {
- ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");
return d->get_current_dir();
}
Error _Directory::make_dir(String p_dir) {
- ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory is not configured properly.");
if (!p_dir.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_dir);
Error err = d->make_dir(p_dir);
@@ -1689,7 +1701,7 @@ Error _Directory::make_dir(String p_dir) {
}
Error _Directory::make_dir_recursive(String p_dir) {
- ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory is not configured properly.");
if (!p_dir.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_dir);
Error err = d->make_dir_recursive(p_dir);
@@ -1700,8 +1712,7 @@ Error _Directory::make_dir_recursive(String p_dir) {
}
bool _Directory::file_exists(String p_file) {
- ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
-
+ ERR_FAIL_COND_V_MSG(!d, false, "Directory is not configured properly.");
if (!p_file.is_rel_path()) {
return FileAccess::exists(p_file);
}
@@ -1710,30 +1721,29 @@ bool _Directory::file_exists(String p_file) {
}
bool _Directory::dir_exists(String p_dir) {
- ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!d, false, "Directory is not configured properly.");
if (!p_dir.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_dir);
bool exists = d->dir_exists(p_dir);
memdelete(d);
return exists;
-
- } else {
- return d->dir_exists(p_dir);
}
+
+ return d->dir_exists(p_dir);
}
int _Directory::get_space_left() {
- ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), 0, "Directory must be opened before use.");
return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int
}
Error _Directory::copy(String p_from, String p_to) {
- ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
return d->copy(p_from, p_to);
}
Error _Directory::rename(String p_from, String p_to) {
- ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_from.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_from);
Error err = d->rename(p_from, p_to);
@@ -1745,7 +1755,7 @@ Error _Directory::rename(String p_from, String p_to) {
}
Error _Directory::remove(String p_name) {
- ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
+ ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
if (!p_name.is_rel_path()) {
DirAccess *d = DirAccess::create_for_path(p_name);
Error err = d->remove(p_name);
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index f9f5a4e7d7..a1fedf1bb8 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -457,6 +457,7 @@ VARIANT_ENUM_CAST(_File::CompressionMode);
class _Directory : public Reference {
GDCLASS(_Directory, Reference);
DirAccess *d;
+ bool dir_open = false;
protected:
static void _bind_methods();
@@ -464,6 +465,8 @@ protected:
public:
Error open(const String &p_path);
+ bool is_open() const;
+
Error list_dir_begin(bool p_skip_navigational = false, bool p_skip_hidden = false); // This starts dir listing.
String get_next();
bool current_is_dir() const;
diff --git a/core/compressed_translation.h b/core/compressed_translation.h
index 3c029bdf58..4f9c422e1e 100644
--- a/core/compressed_translation.h
+++ b/core/compressed_translation.h
@@ -79,7 +79,7 @@ protected:
static void _bind_methods();
public:
- virtual StringName get_message(const StringName &p_src_text) const; //overridable for other implementations
+ virtual StringName get_message(const StringName &p_src_text) const override; //overridable for other implementations
void generate(const Ref<Translation> &p_from);
PHashTranslation() {}
diff --git a/core/container_type_validate.h b/core/container_type_validate.h
index f2724e884d..8a361aa0ef 100644
--- a/core/container_type_validate.h
+++ b/core/container_type_validate.h
@@ -38,7 +38,7 @@ struct ContainerTypeValidate {
Variant::Type type = Variant::NIL;
StringName class_name;
Ref<Script> script;
- const char *where = "conatiner";
+ const char *where = "container";
_FORCE_INLINE_ bool can_reference(const ContainerTypeValidate &p_type) const {
if (type == p_type.type) {
diff --git a/core/image.h b/core/image.h
index 711bf5721c..d2572b072e 100644
--- a/core/image.h
+++ b/core/image.h
@@ -369,7 +369,7 @@ public:
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
Image(const char **p_xpm);
- virtual Ref<Resource> duplicate(bool p_subresources = false) const;
+ virtual Ref<Resource> duplicate(bool p_subresources = false) const override;
UsedChannels detect_used_channels(CompressSource p_source = COMPRESS_SOURCE_GENERIC);
void optimize_channels();
diff --git a/core/input/input.h b/core/input/input.h
index 91e3b83b95..775663503b 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -255,7 +255,7 @@ protected:
public:
void set_mouse_mode(MouseMode p_mode);
MouseMode get_mouse_mode() const;
- void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
+ void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
static Input *get_singleton();
diff --git a/core/input/input_event.h b/core/input/input_event.h
index dd1cc11982..815ba5ae80 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -266,7 +266,7 @@ protected:
public:
void set_pressed(bool p_pressed);
- virtual bool is_pressed() const;
+ virtual bool is_pressed() const override;
void set_keycode(uint32_t p_keycode);
uint32_t get_keycode() const;
@@ -278,17 +278,17 @@ public:
uint32_t get_unicode() const;
void set_echo(bool p_enable);
- virtual bool is_echo() const;
+ virtual bool is_echo() const override;
uint32_t get_keycode_with_modifiers() const;
uint32_t get_physical_keycode_with_modifiers() const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
- virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
+ virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
- virtual bool is_action_type() const { return true; }
+ virtual bool is_action_type() const override { return true; }
- virtual String as_text() const;
+ virtual String as_text() const override;
InputEventKey() {}
};
@@ -336,16 +336,16 @@ public:
int get_button_index() const;
void set_pressed(bool p_pressed);
- virtual bool is_pressed() const;
+ virtual bool is_pressed() const override;
void set_doubleclick(bool p_doubleclick);
bool is_doubleclick() const;
- virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
- virtual bool is_action_type() const { return true; }
- virtual String as_text() const;
+ virtual bool is_action_type() const override { return true; }
+ virtual String as_text() const override;
InputEventMouseButton() {}
};
@@ -374,10 +374,10 @@ public:
void set_speed(const Vector2 &p_speed);
Vector2 get_speed() const;
- virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual String as_text() const;
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
+ virtual String as_text() const override;
- virtual bool accumulate(const Ref<InputEvent> &p_event);
+ virtual bool accumulate(const Ref<InputEvent> &p_event) override;
InputEventMouseMotion() {}
};
@@ -397,12 +397,12 @@ public:
void set_axis_value(float p_value);
float get_axis_value() const;
- virtual bool is_pressed() const;
+ virtual bool is_pressed() const override;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
- virtual bool is_action_type() const { return true; }
- virtual String as_text() const;
+ virtual bool is_action_type() const override { return true; }
+ virtual String as_text() const override;
InputEventJoypadMotion() {}
};
@@ -421,16 +421,16 @@ public:
int get_button_index() const;
void set_pressed(bool p_pressed);
- virtual bool is_pressed() const;
+ virtual bool is_pressed() const override;
void set_pressure(float p_pressure);
float get_pressure() const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
- virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
+ virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
- virtual bool is_action_type() const { return true; }
- virtual String as_text() const;
+ virtual bool is_action_type() const override { return true; }
+ virtual String as_text() const override;
InputEventJoypadButton() {}
};
@@ -452,10 +452,10 @@ public:
Vector2 get_position() const;
void set_pressed(bool p_pressed);
- virtual bool is_pressed() const;
+ virtual bool is_pressed() const override;
- virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual String as_text() const;
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
+ virtual String as_text() const override;
InputEventScreenTouch() {}
};
@@ -483,8 +483,8 @@ public:
void set_speed(const Vector2 &p_speed);
Vector2 get_speed() const;
- virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual String as_text() const;
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
+ virtual String as_text() const override;
InputEventScreenDrag() {}
};
@@ -504,18 +504,18 @@ public:
StringName get_action() const;
void set_pressed(bool p_pressed);
- virtual bool is_pressed() const;
+ virtual bool is_pressed() const override;
void set_strength(float p_strength);
float get_strength() const;
virtual bool is_action(const StringName &p_action) const;
- virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const override;
- virtual bool shortcut_match(const Ref<InputEvent> &p_event) const;
- virtual bool is_action_type() const { return true; }
- virtual String as_text() const;
+ virtual bool shortcut_match(const Ref<InputEvent> &p_event) const override;
+ virtual bool is_action_type() const override { return true; }
+ virtual String as_text() const override;
InputEventAction() {}
};
@@ -544,8 +544,8 @@ public:
void set_factor(real_t p_factor);
real_t get_factor() const;
- virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual String as_text() const;
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
+ virtual String as_text() const override;
InputEventMagnifyGesture() {}
};
@@ -561,8 +561,8 @@ public:
void set_delta(const Vector2 &p_delta);
Vector2 get_delta() const;
- virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- virtual String as_text() const;
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const override;
+ virtual String as_text() const override;
InputEventPanGesture() {}
};
@@ -607,7 +607,7 @@ public:
void set_controller_value(const int p_controller_value);
int get_controller_value() const;
- virtual String as_text() const;
+ virtual String as_text() const override;
InputEventMIDI() {}
};
diff --git a/core/io/logger.cpp b/core/io/logger.cpp
index ef78b1194e..886e5695b1 100644
--- a/core/io/logger.cpp
+++ b/core/io/logger.cpp
@@ -152,7 +152,7 @@ void RotatedFileLogger::rotate_file() {
char timestamp[21];
OS::Date date = OS::get_singleton()->get_date();
OS::Time time = OS::get_singleton()->get_time();
- sprintf(timestamp, "-%04d-%02d-%02d-%02d-%02d-%02d", date.year, date.month, date.day, time.hour, time.min, time.sec);
+ sprintf(timestamp, "_%04d-%02d-%02d_%02d-%02d-%02d", date.year, date.month, date.day, time.hour, time.min, time.sec);
String backup_name = base_path.get_basename() + timestamp;
if (base_path.get_extension() != String()) {
diff --git a/core/io/packet_peer.h b/core/io/packet_peer.h
index f0ba50087f..92cdbc4151 100644
--- a/core/io/packet_peer.h
+++ b/core/io/packet_peer.h
@@ -90,11 +90,11 @@ protected:
static void _bind_methods();
public:
- virtual int get_available_packet_count() const;
- virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size);
- virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size);
+ virtual int get_available_packet_count() const override;
+ virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override;
+ virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override;
- virtual int get_max_packet_size() const;
+ virtual int get_max_packet_size() const override;
void set_stream_peer(const Ref<StreamPeer> &p_peer);
Ref<StreamPeer> get_stream_peer() const;
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index 862fca96fc..e633a56d54 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -31,12 +31,14 @@
#include "packet_peer_udp.h"
#include "core/io/ip.h"
+#include "core/io/udp_server.h"
void PacketPeerUDP::set_blocking_mode(bool p_enable) {
blocking = p_enable;
}
void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) {
+ ERR_FAIL_COND(udp_server);
broadcast = p_enabled;
if (_sock.is_valid() && _sock->is_open()) {
_sock->set_broadcasting_enabled(p_enabled);
@@ -44,6 +46,7 @@ void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) {
}
Error PacketPeerUDP::join_multicast_group(IP_Address 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);
@@ -58,6 +61,7 @@ Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_i
}
Error PacketPeerUDP::leave_multicast_group(IP_Address 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);
return _sock->leave_multicast_group(p_multi_address, p_if_name);
@@ -130,7 +134,7 @@ Error PacketPeerUDP::put_packet(const uint8_t *p_buffer, int p_buffer_size) {
}
do {
- if (connected) {
+ if (connected && !udp_server) {
err = _sock->send(p_buffer, p_buffer_size, sent);
} else {
err = _sock->sendto(p_buffer, p_buffer_size, sent, peer_addr, peer_port);
@@ -186,26 +190,25 @@ Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_
return OK;
}
-Error PacketPeerUDP::connect_socket(Ref<NetSocket> p_sock) {
- Error err;
- int read = 0;
- uint16_t r_port;
- IP_Address r_ip;
-
- err = p_sock->recvfrom(recv_buffer, sizeof(recv_buffer), read, r_ip, r_port, true);
- ERR_FAIL_COND_V(err != OK, err);
- err = p_sock->connect_to_host(r_ip, r_port);
- ERR_FAIL_COND_V(err != OK, err);
+Error PacketPeerUDP::connect_shared_socket(Ref<NetSocket> p_sock, IP_Address p_ip, uint16_t p_port, UDPServer *p_server) {
+ udp_server = p_server;
+ connected = true;
_sock = p_sock;
- peer_addr = r_ip;
- peer_port = r_port;
+ peer_addr = p_ip;
+ peer_port = p_port;
packet_ip = peer_addr;
packet_port = peer_port;
- connected = true;
return OK;
}
+void PacketPeerUDP::disconnect_shared_socket() {
+ udp_server = nullptr;
+ _sock = Ref<NetSocket>(NetSocket::create());
+ close();
+}
+
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);
@@ -243,7 +246,11 @@ bool PacketPeerUDP::is_connected_to_host() const {
}
void PacketPeerUDP::close() {
- if (_sock.is_valid()) {
+ if (udp_server) {
+ udp_server->remove_peer(peer_addr, peer_port);
+ udp_server = nullptr;
+ _sock = Ref<NetSocket>(NetSocket::create());
+ } else if (_sock.is_valid()) {
_sock->close();
}
rb.resize(16);
@@ -262,6 +269,9 @@ Error PacketPeerUDP::_poll() {
if (!_sock->is_open()) {
return FAILED;
}
+ if (udp_server) {
+ return OK; // Handled by UDPServer.
+ }
Error err;
int read;
@@ -284,24 +294,29 @@ Error PacketPeerUDP::_poll() {
return FAILED;
}
- if (rb.space_left() < read + 24) {
+ err = store_packet(ip, port, recv_buffer, read);
#ifdef TOOLS_ENABLED
+ if (err != OK) {
WARN_PRINT("Buffer full, dropping packets!");
-#endif
- continue;
}
-
- uint32_t port32 = port;
- rb.write(ip.get_ipv6(), 16);
- rb.write((uint8_t *)&port32, 4);
- rb.write((uint8_t *)&read, 4);
- rb.write(recv_buffer, read);
- ++queue_count;
+#endif
}
return OK;
}
+Error PacketPeerUDP::store_packet(IP_Address 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;
+ }
+ rb.write(p_ip.get_ipv6(), 16);
+ rb.write((uint8_t *)&p_port, 4);
+ rb.write((uint8_t *)&p_buf_size, 4);
+ rb.write(p_buf, p_buf_size);
+ ++queue_count;
+ return OK;
+}
+
bool PacketPeerUDP::is_listening() const {
return _sock.is_valid() && _sock->is_open();
}
diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h
index 23fc5460a6..9a44a1ebea 100644
--- a/core/io/packet_peer_udp.h
+++ b/core/io/packet_peer_udp.h
@@ -35,6 +35,8 @@
#include "core/io/net_socket.h"
#include "core/io/packet_peer.h"
+class UDPServer;
+
class PacketPeerUDP : public PacketPeer {
GDCLASS(PacketPeerUDP, PacketPeer);
@@ -55,6 +57,7 @@ protected:
bool connected = false;
bool blocking = true;
bool broadcast = false;
+ UDPServer *udp_server = nullptr;
Ref<NetSocket> _sock;
static void _bind_methods();
@@ -72,7 +75,9 @@ public:
Error wait();
bool is_listening() const;
- Error connect_socket(Ref<NetSocket> p_sock); // Used by UDPServer
+ 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
+ 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);
bool is_connected_to_host() const;
@@ -80,10 +85,10 @@ public:
int get_packet_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);
- Error get_packet(const uint8_t **r_buffer, int &r_buffer_size);
- int get_available_packet_count() const;
- int get_max_packet_size() const;
+ 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);
diff --git a/core/io/stream_peer.h b/core/io/stream_peer.h
index ec0b989ed8..39097a57f2 100644
--- a/core/io/stream_peer.h
+++ b/core/io/stream_peer.h
@@ -102,13 +102,13 @@ protected:
static void _bind_methods();
public:
- Error put_data(const uint8_t *p_data, int p_bytes);
- Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
+ Error put_data(const uint8_t *p_data, int p_bytes) override;
+ Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) override;
- Error get_data(uint8_t *p_buffer, int p_bytes);
- Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
+ Error get_data(uint8_t *p_buffer, int p_bytes) override;
+ Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) override;
- virtual int get_available_bytes() const;
+ virtual int get_available_bytes() const override;
void seek(int p_pos);
int get_size() const;
diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h
index ab98d494d6..45205866b4 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -72,7 +72,7 @@ public:
uint16_t get_connected_port() const;
void disconnect_from_host();
- int get_available_bytes() const;
+ int get_available_bytes() const override;
Status get_status();
void set_no_delay(bool p_enabled);
@@ -81,10 +81,10 @@ public:
Error poll(NetSocket::PollType p_type, int timeout = 0);
// Read/Write from StreamPeer
- Error put_data(const uint8_t *p_data, int p_bytes);
- Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);
- Error get_data(uint8_t *p_buffer, int p_bytes);
- Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received);
+ Error put_data(const uint8_t *p_data, int p_bytes) override;
+ Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) override;
+ Error get_data(uint8_t *p_buffer, int p_bytes) override;
+ Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) override;
StreamPeerTCP();
~StreamPeerTCP();
diff --git a/core/io/translation_loader_po.cpp b/core/io/translation_loader_po.cpp
index 0e0a948953..11aeddee09 100644
--- a/core/io/translation_loader_po.cpp
+++ b/core/io/translation_loader_po.cpp
@@ -35,7 +35,6 @@
RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
enum Status {
-
STATUS_NONE,
STATUS_READING_ID,
STATUS_READING_STRING,
@@ -56,6 +55,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
bool skip_this = false;
bool skip_next = false;
bool is_eof = false;
+ const String path = f->get_path();
while (!is_eof) {
String l = f->get_line().strip_edges();
@@ -65,7 +65,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
if (is_eof && l.empty()) {
if (status == STATUS_READING_ID) {
memdelete(f);
- ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected EOF while reading 'msgid' at file: ");
+ ERR_FAIL_V_MSG(RES(), "Unexpected EOF while reading 'msgid' at: " + path + ":" + itos(line));
} else {
break;
}
@@ -74,7 +74,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
if (l.begins_with("msgid")) {
if (status == STATUS_READING_ID) {
memdelete(f);
- ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgid', was expecting 'msgstr' while parsing: ");
+ ERR_FAIL_V_MSG(RES(), "Unexpected 'msgid', was expecting 'msgstr' while parsing: " + path + ":" + itos(line));
}
if (msg_id != "") {
@@ -96,7 +96,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
if (l.begins_with("msgstr")) {
if (status != STATUS_READING_ID) {
memdelete(f);
- ERR_FAIL_V_MSG(RES(), f->get_path() + ":" + itos(line) + " Unexpected 'msgstr', was expecting 'msgid' while parsing: ");
+ ERR_FAIL_V_MSG(RES(), "Unexpected 'msgstr', was expecting 'msgid' while parsing: " + path + ":" + itos(line));
}
l = l.substr(6, l.length()).strip_edges();
@@ -111,7 +111,10 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
continue; //nothing to read or comment
}
- ERR_FAIL_COND_V_MSG(!l.begins_with("\"") || status == STATUS_NONE, RES(), f->get_path() + ":" + itos(line) + " Invalid line '" + l + "' while parsing: ");
+ if (!l.begins_with("\"") || status == STATUS_NONE) {
+ memdelete(f);
+ ERR_FAIL_V_MSG(RES(), "Invalid line '" + l + "' while parsing: " + path + ":" + itos(line));
+ }
l = l.substr(1, l.length());
// Find final quote, ignoring escaped ones (\").
@@ -133,7 +136,10 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
escape_next = false;
}
- ERR_FAIL_COND_V_MSG(end_pos == -1, RES(), f->get_path() + ":" + itos(line) + ": Expected '\"' at end of message while parsing file.");
+ if (end_pos == -1) {
+ memdelete(f);
+ ERR_FAIL_V_MSG(RES(), "Expected '\"' at end of message while parsing: " + path + ":" + itos(line));
+ }
l = l.substr(0, end_pos);
l = l.c_unescape();
@@ -147,7 +153,6 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
line++;
}
- f->close();
memdelete(f);
if (status == STATUS_READING_STRING) {
@@ -160,7 +165,7 @@ RES TranslationLoaderPO::load_translation(FileAccess *f, Error *r_error) {
}
}
- ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + f->get_path() + ".");
+ ERR_FAIL_COND_V_MSG(config == "", RES(), "No config found in file: " + path + ".");
Vector<String> configs = config.split("\n");
for (int i = 0; i < configs.size(); i++) {
@@ -197,7 +202,6 @@ RES TranslationLoaderPO::load(const String &p_path, const String &p_original_pat
void TranslationLoaderPO::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("po");
- //p_extensions->push_back("mo"); //mo in the future...
}
bool TranslationLoaderPO::handles_type(const String &p_type) const {
diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp
index 1d329daf8b..acd15aadc6 100644
--- a/core/io/udp_server.cpp
+++ b/core/io/udp_server.cpp
@@ -32,10 +32,58 @@
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("is_listening"), &UDPServer::is_listening);
ClassDB::bind_method(D_METHOD("take_connection"), &UDPServer::take_connection);
ClassDB::bind_method(D_METHOD("stop"), &UDPServer::stop);
+ ClassDB::bind_method(D_METHOD("set_max_pending_connections", "max_pending_connections"), &UDPServer::set_max_pending_connections);
+ ClassDB::bind_method(D_METHOD("get_max_pending_connections"), &UDPServer::get_max_pending_connections);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "max_pending_connections", PROPERTY_HINT_RANGE, "0,256,1"), "set_max_pending_connections", "get_max_pending_connections");
+}
+
+Error UDPServer::poll() {
+ ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
+ if (!_sock->is_open()) {
+ return ERR_UNCONFIGURED;
+ }
+ Error err;
+ int read;
+ IP_Address ip;
+ uint16_t port;
+ while (true) {
+ err = _sock->recvfrom(recv_buffer, sizeof(recv_buffer), read, ip, port);
+ if (err != OK) {
+ if (err == ERR_BUSY) {
+ break;
+ }
+ return FAILED;
+ }
+ Peer p;
+ p.ip = ip;
+ p.port = port;
+ List<Peer>::Element *E = peers.find(p);
+ if (!E) {
+ E = pending.find(p);
+ }
+ if (E) {
+ E->get().peer->store_packet(ip, port, recv_buffer, read);
+ } else {
+ if (pending.size() >= max_pending_connections) {
+ // Drop connection.
+ continue;
+ }
+ // It's a new peer, add it to the pending list.
+ Peer peer;
+ peer.ip = ip;
+ peer.port = port;
+ peer.peer = memnew(PacketPeerUDP);
+ peer.peer->connect_shared_socket(_sock, ip, port, this);
+ peer.peer->store_packet(ip, port, recv_buffer, read);
+ pending.push_back(peer);
+ }
+ }
+ return OK;
}
Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) {
@@ -82,8 +130,24 @@ bool UDPServer::is_connection_available() const {
return false;
}
- Error err = _sock->poll(NetSocket::POLL_TYPE_IN, 0);
- return (err == OK);
+ return pending.size() > 0;
+}
+
+void UDPServer::set_max_pending_connections(int p_max) {
+ ERR_FAIL_COND_MSG(p_max < 0, "Max pending connections value must be a positive number (0 means refuse new connections).");
+ max_pending_connections = p_max;
+ while (p_max > pending.size()) {
+ List<Peer>::Element *E = pending.back();
+ if (!E) {
+ break;
+ }
+ memdelete(E->get().peer);
+ pending.erase(E);
+ }
+}
+
+int UDPServer::get_max_pending_connections() const {
+ return max_pending_connections;
}
Ref<PacketPeerUDP> UDPServer::take_connection() {
@@ -92,11 +156,20 @@ Ref<PacketPeerUDP> UDPServer::take_connection() {
return conn;
}
- conn = Ref<PacketPeerUDP>(memnew(PacketPeerUDP));
- conn->connect_socket(_sock);
- _sock = Ref<NetSocket>(NetSocket::create());
- listen(bind_port, bind_address);
- return conn;
+ Peer peer = pending[0];
+ pending.pop_front();
+ peers.push_back(peer);
+ return peer.peer;
+}
+
+void UDPServer::remove_peer(IP_Address p_ip, int p_port) {
+ Peer peer;
+ peer.ip = p_ip;
+ peer.port = p_port;
+ List<Peer>::Element *E = peers.find(peer);
+ if (E) {
+ peers.erase(E);
+ }
}
void UDPServer::stop() {
@@ -105,6 +178,19 @@ void UDPServer::stop() {
}
bind_port = 0;
bind_address = IP_Address();
+ List<Peer>::Element *E = peers.front();
+ while (E) {
+ E->get().peer->disconnect_shared_socket();
+ E = E->next();
+ }
+ E = pending.front();
+ while (E) {
+ E->get().peer->disconnect_shared_socket();
+ memdelete(E->get().peer);
+ E = E->next();
+ }
+ peers.clear();
+ pending.clear();
}
UDPServer::UDPServer() :
diff --git a/core/io/udp_server.h b/core/io/udp_server.h
index 90bb82b62b..3175b09b19 100644
--- a/core/io/udp_server.h
+++ b/core/io/udp_server.h
@@ -38,15 +38,40 @@ class UDPServer : public Reference {
GDCLASS(UDPServer, Reference);
protected:
- static void _bind_methods();
- int bind_port;
+ enum {
+ PACKET_BUFFER_SIZE = 65536
+ };
+
+ struct Peer {
+ PacketPeerUDP *peer;
+ IP_Address ip;
+ uint16_t port = 0;
+
+ bool operator==(const Peer &p_other) const {
+ return (ip == p_other.ip && port == p_other.port);
+ }
+ };
+ 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();
bool is_listening() const;
bool is_connection_available() const;
+ void set_max_pending_connections(int p_max);
+ int get_max_pending_connections() const;
Ref<PacketPeerUDP> take_connection();
void stop();
diff --git a/core/oa_hash_map.h b/core/oa_hash_map.h
index 775e17fdb5..6061366ab3 100644
--- a/core/oa_hash_map.h
+++ b/core/oa_hash_map.h
@@ -48,7 +48,7 @@
*
* Only used keys and values are constructed. For free positions there's space
* in the arrays for each, but that memory is kept uninitialized.
- *
+ *
* The assignment operator copy the pairs from one map to the other.
*/
template <class TKey, class TValue,
diff --git a/core/object.h b/core/object.h
index 5b46a0f93a..954be5304c 100644
--- a/core/object.h
+++ b/core/object.h
@@ -250,142 +250,142 @@ public: \
\
private:
-#define GDCLASS(m_class, m_inherits) \
-private: \
- void operator=(const m_class &p_rval) {} \
- mutable StringName _class_name; \
- friend class ClassDB; \
- \
-public: \
- virtual String get_class() const { \
- return String(#m_class); \
- } \
- virtual const StringName *_get_class_namev() const { \
- if (!_class_name) { \
- _class_name = get_class_static(); \
- } \
- return &_class_name; \
- } \
- static _FORCE_INLINE_ void *get_class_ptr_static() { \
- static int ptr; \
- return &ptr; \
- } \
- static _FORCE_INLINE_ String get_class_static() { \
- return String(#m_class); \
- } \
- static _FORCE_INLINE_ String get_parent_class_static() { \
- return m_inherits::get_class_static(); \
- } \
- static void get_inheritance_list_static(List<String> *p_inheritance_list) { \
- m_inherits::get_inheritance_list_static(p_inheritance_list); \
- p_inheritance_list->push_back(String(#m_class)); \
- } \
- static String get_category_static() { \
- String category = m_inherits::get_category_static(); \
- if (_get_category != m_inherits::_get_category) { \
- if (category != "") { \
- category += "/"; \
- } \
- category += _get_category(); \
- } \
- return category; \
- } \
- static String inherits_static() { \
- return String(#m_inherits); \
- } \
- virtual bool is_class(const String &p_class) const { return (p_class == (#m_class)) ? true : m_inherits::is_class(p_class); } \
- virtual bool is_class_ptr(void *p_ptr) const { return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); } \
- \
- static void get_valid_parents_static(List<String> *p_parents) { \
- if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \
- m_class::_get_valid_parents_static(p_parents); \
- } \
- \
- m_inherits::get_valid_parents_static(p_parents); \
- } \
- \
-protected: \
- _FORCE_INLINE_ static void (*_get_bind_methods())() { \
- return &m_class::_bind_methods; \
- } \
- \
-public: \
- static void initialize_class() { \
- static bool initialized = false; \
- if (initialized) { \
- return; \
- } \
- m_inherits::initialize_class(); \
- ClassDB::_add_class<m_class>(); \
- if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
- _bind_methods(); \
- } \
- initialized = true; \
- } \
- \
-protected: \
- virtual void _initialize_classv() { \
- initialize_class(); \
- } \
- _FORCE_INLINE_ bool (Object::*_get_get() const)(const StringName &p_name, Variant &) const { \
- return (bool (Object::*)(const StringName &, Variant &) const) & m_class::_get; \
- } \
- virtual bool _getv(const StringName &p_name, Variant &r_ret) const { \
- if (m_class::_get_get() != m_inherits::_get_get()) { \
- if (_get(p_name, r_ret)) { \
- return true; \
- } \
- } \
- return m_inherits::_getv(p_name, r_ret); \
- } \
- _FORCE_INLINE_ bool (Object::*_get_set() const)(const StringName &p_name, const Variant &p_property) { \
- return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \
- } \
- virtual bool _setv(const StringName &p_name, const Variant &p_property) { \
- if (m_inherits::_setv(p_name, p_property)) { \
- return true; \
- } \
- if (m_class::_get_set() != m_inherits::_get_set()) { \
- return _set(p_name, p_property); \
- } \
- return false; \
- } \
- _FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List<PropertyInfo> * p_list) const { \
- return (void (Object::*)(List<PropertyInfo> *) const) & m_class::_get_property_list; \
- } \
- virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const { \
- if (!p_reversed) { \
- m_inherits::_get_property_listv(p_list, p_reversed); \
- } \
- p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); \
- if (!_is_gpl_reversed()) { \
- ClassDB::get_property_list(#m_class, p_list, true, this); \
- } \
- if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
- _get_property_list(p_list); \
- } \
- if (_is_gpl_reversed()) { \
- ClassDB::get_property_list(#m_class, p_list, true, this); \
- } \
- if (p_reversed) { \
- m_inherits::_get_property_listv(p_list, p_reversed); \
- } \
- } \
- _FORCE_INLINE_ void (Object::*_get_notification() const)(int) { \
- return (void (Object::*)(int)) & m_class::_notification; \
- } \
- virtual void _notificationv(int p_notification, bool p_reversed) { \
- if (!p_reversed) { \
- m_inherits::_notificationv(p_notification, p_reversed); \
- } \
- if (m_class::_get_notification() != m_inherits::_get_notification()) { \
- _notification(p_notification); \
- } \
- if (p_reversed) { \
- m_inherits::_notificationv(p_notification, p_reversed); \
- } \
- } \
- \
+#define GDCLASS(m_class, m_inherits) \
+private: \
+ void operator=(const m_class &p_rval) {} \
+ mutable StringName _class_name; \
+ friend class ClassDB; \
+ \
+public: \
+ virtual String get_class() const override { \
+ return String(#m_class); \
+ } \
+ virtual const StringName *_get_class_namev() const override { \
+ if (!_class_name) { \
+ _class_name = get_class_static(); \
+ } \
+ return &_class_name; \
+ } \
+ static _FORCE_INLINE_ void *get_class_ptr_static() { \
+ static int ptr; \
+ return &ptr; \
+ } \
+ static _FORCE_INLINE_ String get_class_static() { \
+ return String(#m_class); \
+ } \
+ static _FORCE_INLINE_ String get_parent_class_static() { \
+ return m_inherits::get_class_static(); \
+ } \
+ static void get_inheritance_list_static(List<String> *p_inheritance_list) { \
+ m_inherits::get_inheritance_list_static(p_inheritance_list); \
+ p_inheritance_list->push_back(String(#m_class)); \
+ } \
+ static String get_category_static() { \
+ String category = m_inherits::get_category_static(); \
+ if (_get_category != m_inherits::_get_category) { \
+ if (category != "") { \
+ category += "/"; \
+ } \
+ category += _get_category(); \
+ } \
+ return category; \
+ } \
+ static String inherits_static() { \
+ return String(#m_inherits); \
+ } \
+ virtual bool is_class(const String &p_class) const override { return (p_class == (#m_class)) ? true : m_inherits::is_class(p_class); } \
+ virtual bool is_class_ptr(void *p_ptr) const override { return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); } \
+ \
+ static void get_valid_parents_static(List<String> *p_parents) { \
+ if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \
+ m_class::_get_valid_parents_static(p_parents); \
+ } \
+ \
+ m_inherits::get_valid_parents_static(p_parents); \
+ } \
+ \
+protected: \
+ _FORCE_INLINE_ static void (*_get_bind_methods())() { \
+ return &m_class::_bind_methods; \
+ } \
+ \
+public: \
+ static void initialize_class() { \
+ static bool initialized = false; \
+ if (initialized) { \
+ return; \
+ } \
+ m_inherits::initialize_class(); \
+ ClassDB::_add_class<m_class>(); \
+ if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
+ _bind_methods(); \
+ } \
+ initialized = true; \
+ } \
+ \
+protected: \
+ virtual void _initialize_classv() override { \
+ initialize_class(); \
+ } \
+ _FORCE_INLINE_ bool (Object::*_get_get() const)(const StringName &p_name, Variant &) const { \
+ return (bool (Object::*)(const StringName &, Variant &) const) & m_class::_get; \
+ } \
+ virtual bool _getv(const StringName &p_name, Variant &r_ret) const override { \
+ if (m_class::_get_get() != m_inherits::_get_get()) { \
+ if (_get(p_name, r_ret)) { \
+ return true; \
+ } \
+ } \
+ return m_inherits::_getv(p_name, r_ret); \
+ } \
+ _FORCE_INLINE_ bool (Object::*_get_set() const)(const StringName &p_name, const Variant &p_property) { \
+ return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \
+ } \
+ virtual bool _setv(const StringName &p_name, const Variant &p_property) override { \
+ if (m_inherits::_setv(p_name, p_property)) { \
+ return true; \
+ } \
+ if (m_class::_get_set() != m_inherits::_get_set()) { \
+ return _set(p_name, p_property); \
+ } \
+ return false; \
+ } \
+ _FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List<PropertyInfo> * p_list) const { \
+ return (void (Object::*)(List<PropertyInfo> *) const) & m_class::_get_property_list; \
+ } \
+ virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const override { \
+ if (!p_reversed) { \
+ m_inherits::_get_property_listv(p_list, p_reversed); \
+ } \
+ p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); \
+ if (!_is_gpl_reversed()) { \
+ ClassDB::get_property_list(#m_class, p_list, true, this); \
+ } \
+ if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
+ _get_property_list(p_list); \
+ } \
+ if (_is_gpl_reversed()) { \
+ ClassDB::get_property_list(#m_class, p_list, true, this); \
+ } \
+ if (p_reversed) { \
+ m_inherits::_get_property_listv(p_list, p_reversed); \
+ } \
+ } \
+ _FORCE_INLINE_ void (Object::*_get_notification() const)(int) { \
+ return (void (Object::*)(int)) & m_class::_notification; \
+ } \
+ virtual void _notificationv(int p_notification, bool p_reversed) override { \
+ if (!p_reversed) { \
+ m_inherits::_notificationv(p_notification, p_reversed); \
+ } \
+ if (m_class::_get_notification() != m_inherits::_get_notification()) { \
+ _notification(p_notification); \
+ } \
+ if (p_reversed) { \
+ m_inherits::_notificationv(p_notification, p_reversed); \
+ } \
+ } \
+ \
private:
#define OBJ_CATEGORY(m_category) \
@@ -394,10 +394,10 @@ protected: \
\
private:
-#define OBJ_SAVE_TYPE(m_class) \
-public: \
- virtual String get_save_class() const { return #m_class; } \
- \
+#define OBJ_SAVE_TYPE(m_class) \
+public: \
+ virtual String get_save_class() const override { return #m_class; } \
+ \
private:
class ScriptInstance;
diff --git a/core/os/os.cpp b/core/os/os.cpp
index 231069fcfb..dc8bd5ee69 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -163,6 +163,10 @@ bool OS::is_stdout_verbose() const {
return _verbose_stdout;
}
+bool OS::is_stdout_debug_enabled() const {
+ return _debug_stdout;
+}
+
void OS::dump_memory_to_file(const char *p_file) {
//Memory::dump_static_mem_to_file(p_file);
}
diff --git a/core/os/os.h b/core/os/os.h
index f21c0d4df7..48dae99188 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -50,6 +50,7 @@ class OS {
bool low_processor_usage_mode = false;
int low_processor_usage_mode_sleep_usec = 10000;
bool _verbose_stdout = false;
+ bool _debug_stdout = false;
String _local_clipboard;
uint64_t _msec_splash;
bool _no_window = false;
@@ -222,6 +223,7 @@ public:
virtual bool is_userfs_persistent() const { return true; }
bool is_stdout_verbose() const;
+ bool is_stdout_debug_enabled() const;
virtual void disable_crash_handler() {}
virtual bool is_disable_crash_handler() const { return false; }
diff --git a/core/packed_data_container.h b/core/packed_data_container.h
index b41e9aaefc..28ec9cc87c 100644
--- a/core/packed_data_container.h
+++ b/core/packed_data_container.h
@@ -72,7 +72,7 @@ protected:
static void _bind_methods();
public:
- virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const;
+ virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const override;
Error pack(const Variant &p_data);
int size() const;
@@ -97,7 +97,7 @@ public:
bool _is_dictionary() const;
int size() const;
- virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const;
+ virtual Variant getvar(const Variant &p_key, bool *r_valid = nullptr) const override;
PackedDataContainerRef() {}
};
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 7e96735d67..638987bb2f 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -144,6 +144,12 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
if (p_value.get_type() == Variant::NIL) {
props.erase(p_name);
+ if (p_name.operator String().begins_with("autoload/")) {
+ String node_name = p_name.operator String().split("/")[1];
+ if (autoloads.has(node_name)) {
+ remove_autoload(node_name);
+ }
+ }
} else {
if (p_name == CoreStringNames::get_singleton()->_custom_features) {
Vector<String> custom_feature_array = String(p_value).split(",");
@@ -181,6 +187,19 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
} else {
props[p_name] = VariantContainer(p_value, last_order++);
}
+ if (p_name.operator String().begins_with("autoload/")) {
+ String node_name = p_name.operator String().split("/")[1];
+ AutoloadInfo autoload;
+ autoload.name = node_name;
+ String path = p_value;
+ if (path.begins_with("*")) {
+ autoload.is_singleton = true;
+ autoload.path = path.substr(1);
+ } else {
+ autoload.path = path;
+ }
+ add_autoload(autoload);
+ }
}
return true;
@@ -469,6 +488,14 @@ Error ProjectSettings::setup(const String &p_path, const String &p_main_pack, bo
_load_settings_text(custom_settings);
}
}
+ // Using GLOBAL_GET on every block for compressing can be slow, so assigning here.
+ Compression::zstd_long_distance_matching = GLOBAL_GET("compression/formats/zstd/long_distance_matching");
+ Compression::zstd_level = GLOBAL_GET("compression/formats/zstd/compression_level");
+ Compression::zstd_window_log_size = GLOBAL_GET("compression/formats/zstd/window_log_size");
+
+ Compression::zlib_level = GLOBAL_GET("compression/formats/zlib/compression_level");
+
+ Compression::gzip_level = GLOBAL_GET("compression/formats/gzip/compression_level");
return err;
}
@@ -945,6 +972,29 @@ bool ProjectSettings::has_custom_feature(const String &p_feature) const {
return custom_features.has(p_feature);
}
+Map<StringName, ProjectSettings::AutoloadInfo> ProjectSettings::get_autoload_list() const {
+ return autoloads;
+}
+
+void ProjectSettings::add_autoload(const AutoloadInfo &p_autoload) {
+ ERR_FAIL_COND_MSG(p_autoload.name == StringName(), "Trying to add autoload with no name.");
+ autoloads[p_autoload.name] = p_autoload;
+}
+
+void ProjectSettings::remove_autoload(const StringName &p_autoload) {
+ ERR_FAIL_COND_MSG(!autoloads.has(p_autoload), "Trying to remove non-existent autoload.");
+ autoloads.erase(p_autoload);
+}
+
+bool ProjectSettings::has_autoload(const StringName &p_autoload) const {
+ return autoloads.has(p_autoload);
+}
+
+ProjectSettings::AutoloadInfo ProjectSettings::get_autoload(const StringName &p_name) const {
+ ERR_FAIL_COND_V_MSG(!autoloads.has(p_name), AutoloadInfo(), "Trying to get non-existent autoload.");
+ return autoloads[p_name];
+}
+
void ProjectSettings::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_setting", "name"), &ProjectSettings::has_setting);
ClassDB::bind_method(D_METHOD("set_setting", "name", "value"), &ProjectSettings::set_setting);
@@ -965,6 +1015,9 @@ void ProjectSettings::_bind_methods() {
}
ProjectSettings::ProjectSettings() {
+ // Initialization of engine variables should be done in the setup() method,
+ // so that the values can be overridden from project.godot or project.binary.
+
singleton = this;
Array events;
@@ -1164,18 +1217,17 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("debug/settings/profiler/max_functions", 16384);
custom_prop_info["debug/settings/profiler/max_functions"] = PropertyInfo(Variant::INT, "debug/settings/profiler/max_functions", PROPERTY_HINT_RANGE, "128,65535,1");
- //assigning here, because using GLOBAL_GET on every block for compressing can be slow
- Compression::zstd_long_distance_matching = GLOBAL_DEF("compression/formats/zstd/long_distance_matching", false);
+ GLOBAL_DEF("compression/formats/zstd/long_distance_matching", Compression::zstd_long_distance_matching);
custom_prop_info["compression/formats/zstd/long_distance_matching"] = PropertyInfo(Variant::BOOL, "compression/formats/zstd/long_distance_matching");
- Compression::zstd_level = GLOBAL_DEF("compression/formats/zstd/compression_level", 3);
+ GLOBAL_DEF("compression/formats/zstd/compression_level", Compression::zstd_level);
custom_prop_info["compression/formats/zstd/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zstd/compression_level", PROPERTY_HINT_RANGE, "1,22,1");
- Compression::zstd_window_log_size = GLOBAL_DEF("compression/formats/zstd/window_log_size", 27);
+ GLOBAL_DEF("compression/formats/zstd/window_log_size", Compression::zstd_window_log_size);
custom_prop_info["compression/formats/zstd/window_log_size"] = PropertyInfo(Variant::INT, "compression/formats/zstd/window_log_size", PROPERTY_HINT_RANGE, "10,30,1");
- Compression::zlib_level = GLOBAL_DEF("compression/formats/zlib/compression_level", Z_DEFAULT_COMPRESSION);
+ GLOBAL_DEF("compression/formats/zlib/compression_level", Compression::zlib_level);
custom_prop_info["compression/formats/zlib/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/zlib/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
- Compression::gzip_level = GLOBAL_DEF("compression/formats/gzip/compression_level", Z_DEFAULT_COMPRESSION);
+ GLOBAL_DEF("compression/formats/gzip/compression_level", Compression::gzip_level);
custom_prop_info["compression/formats/gzip/compression_level"] = PropertyInfo(Variant::INT, "compression/formats/gzip/compression_level", PROPERTY_HINT_RANGE, "-1,9,1");
}
diff --git a/core/project_settings.h b/core/project_settings.h
index 3ed80738a1..4aceafe3c0 100644
--- a/core/project_settings.h
+++ b/core/project_settings.h
@@ -47,6 +47,12 @@ public:
NO_BUILTIN_ORDER_BASE = 1 << 16
};
+ struct AutoloadInfo {
+ StringName name;
+ String path;
+ bool is_singleton = false;
+ };
+
protected:
struct VariantContainer {
int order = 0;
@@ -79,6 +85,8 @@ protected:
Set<String> custom_features;
Map<StringName, StringName> feature_overrides;
+ Map<StringName, AutoloadInfo> autoloads;
+
bool _set(const StringName &p_name, const Variant &p_value);
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
@@ -148,6 +156,12 @@ public:
bool has_custom_feature(const String &p_feature) const;
+ Map<StringName, AutoloadInfo> get_autoload_list() const;
+ void add_autoload(const AutoloadInfo &p_autoload);
+ void remove_autoload(const StringName &p_autoload);
+ bool has_autoload(const StringName &p_autoload) const;
+ AutoloadInfo get_autoload(const StringName &p_name) const;
+
ProjectSettings();
~ProjectSettings();
};
diff --git a/core/resource.h b/core/resource.h
index ad2f3ce913..7699d48735 100644
--- a/core/resource.h
+++ b/core/resource.h
@@ -40,15 +40,19 @@
#define RES_BASE_EXTENSION(m_ext) \
public: \
static void register_custom_data_to_otdb() { ClassDB::add_resource_base_extension(m_ext, get_class_static()); } \
- virtual String get_base_extension() const { return m_ext; } \
+ virtual String get_base_extension() const override { return m_ext; } \
\
private:
class Resource : public Reference {
GDCLASS(Resource, Reference);
OBJ_CATEGORY("Resources");
- RES_BASE_EXTENSION("res");
+public:
+ static void register_custom_data_to_otdb() { ClassDB::add_resource_base_extension("res", get_class_static()); }
+ virtual String get_base_extension() const { return "res"; }
+
+private:
Set<ObjectID> owners;
friend class ResBase;
diff --git a/core/script_language.cpp b/core/script_language.cpp
index 38a970f3c6..420a560782 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -352,6 +352,39 @@ ScriptCodeCompletionCache::ScriptCodeCompletionCache() {
singleton = this;
}
+void ScriptLanguage::get_core_type_words(List<String> *p_core_type_words) const {
+ p_core_type_words->push_back("String");
+ p_core_type_words->push_back("Vector2");
+ p_core_type_words->push_back("Vector2i");
+ p_core_type_words->push_back("Rect2");
+ p_core_type_words->push_back("Rect2i");
+ p_core_type_words->push_back("Vector3");
+ p_core_type_words->push_back("Vector3i");
+ p_core_type_words->push_back("Transform2D");
+ p_core_type_words->push_back("Plane");
+ p_core_type_words->push_back("Quat");
+ p_core_type_words->push_back("AABB");
+ p_core_type_words->push_back("Basis");
+ p_core_type_words->push_back("Transform");
+ p_core_type_words->push_back("Color");
+ p_core_type_words->push_back("StringName");
+ p_core_type_words->push_back("NodePath");
+ p_core_type_words->push_back("RID");
+ p_core_type_words->push_back("Callable");
+ p_core_type_words->push_back("Signal");
+ p_core_type_words->push_back("Dictionary");
+ p_core_type_words->push_back("Array");
+ p_core_type_words->push_back("PackedByteArray");
+ p_core_type_words->push_back("PackedInt32Array");
+ p_core_type_words->push_back("PackedInt64Array");
+ p_core_type_words->push_back("PackedFloat32Array");
+ p_core_type_words->push_back("PackedFloat64Array");
+ p_core_type_words->push_back("PackedStringArray");
+ p_core_type_words->push_back("PackedVector2Array");
+ p_core_type_words->push_back("PackedVector3Array");
+ p_core_type_words->push_back("PackedColorArray");
+}
+
void ScriptLanguage::frame() {
}
diff --git a/core/script_language.h b/core/script_language.h
index b6c2a47245..314b047027 100644
--- a/core/script_language.h
+++ b/core/script_language.h
@@ -116,7 +116,7 @@ class Script : public Resource {
OBJ_SAVE_TYPE(Script);
protected:
- virtual bool editor_can_reload_from_file() { return false; } // this is handled by editor better
+ virtual bool editor_can_reload_from_file() override { return false; } // this is handled by editor better
void _notification(int p_what);
static void _bind_methods();
@@ -256,6 +256,7 @@ struct ScriptCodeCompletionOption {
Kind kind = KIND_PLAIN_TEXT;
String display;
String insert_text;
+ Color font_color;
RES icon;
ScriptCodeCompletionOption() {}
@@ -299,6 +300,7 @@ public:
String message;
};
+ void get_core_type_words(List<String> *p_core_type_words) const;
virtual void get_reserved_words(List<String> *p_words) const = 0;
virtual void get_comment_delimiters(List<String> *p_delimiters) const = 0;
virtual void get_string_delimiters(List<String> *p_delimiters) const = 0;
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 308fa3c407..0aa1339401 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -701,6 +701,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedByteArray, uint8_t, remove);
VCALL_PARRMEM1(PackedByteArray, uint8_t, append);
VCALL_PARRMEM1(PackedByteArray, uint8_t, append_array);
+ VCALL_PARRMEM1R(PackedByteArray, uint8_t, has);
+ VCALL_PARRMEM0(PackedByteArray, uint8_t, sort);
VCALL_PARRMEM0(PackedByteArray, uint8_t, invert);
VCALL_PARRMEM2R(PackedByteArray, uint8_t, subarray);
@@ -714,6 +716,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedInt32Array, int32_t, remove);
VCALL_PARRMEM1(PackedInt32Array, int32_t, append);
VCALL_PARRMEM1(PackedInt32Array, int32_t, append_array);
+ VCALL_PARRMEM1R(PackedInt32Array, int32_t, has);
+ VCALL_PARRMEM0(PackedInt32Array, int32_t, sort);
VCALL_PARRMEM0(PackedInt32Array, int32_t, invert);
VCALL_PARRMEM0R(PackedInt64Array, int64_t, size);
@@ -726,6 +730,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedInt64Array, int64_t, remove);
VCALL_PARRMEM1(PackedInt64Array, int64_t, append);
VCALL_PARRMEM1(PackedInt64Array, int64_t, append_array);
+ VCALL_PARRMEM1R(PackedInt64Array, int64_t, has);
+ VCALL_PARRMEM0(PackedInt64Array, int64_t, sort);
VCALL_PARRMEM0(PackedInt64Array, int64_t, invert);
VCALL_PARRMEM0R(PackedFloat32Array, float, size);
@@ -738,6 +744,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedFloat32Array, float, remove);
VCALL_PARRMEM1(PackedFloat32Array, float, append);
VCALL_PARRMEM1(PackedFloat32Array, float, append_array);
+ VCALL_PARRMEM1R(PackedFloat32Array, float, has);
+ VCALL_PARRMEM0(PackedFloat32Array, float, sort);
VCALL_PARRMEM0(PackedFloat32Array, float, invert);
VCALL_PARRMEM0R(PackedFloat64Array, double, size);
@@ -750,6 +758,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedFloat64Array, double, remove);
VCALL_PARRMEM1(PackedFloat64Array, double, append);
VCALL_PARRMEM1(PackedFloat64Array, double, append_array);
+ VCALL_PARRMEM1R(PackedFloat64Array, double, has);
+ VCALL_PARRMEM0(PackedFloat64Array, double, sort);
VCALL_PARRMEM0(PackedFloat64Array, double, invert);
VCALL_PARRMEM0R(PackedStringArray, String, size);
@@ -762,6 +772,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedStringArray, String, remove);
VCALL_PARRMEM1(PackedStringArray, String, append);
VCALL_PARRMEM1(PackedStringArray, String, append_array);
+ VCALL_PARRMEM1R(PackedStringArray, String, has);
+ VCALL_PARRMEM0(PackedStringArray, String, sort);
VCALL_PARRMEM0(PackedStringArray, String, invert);
VCALL_PARRMEM0R(PackedVector2Array, Vector2, size);
@@ -774,6 +786,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedVector2Array, Vector2, remove);
VCALL_PARRMEM1(PackedVector2Array, Vector2, append);
VCALL_PARRMEM1(PackedVector2Array, Vector2, append_array);
+ VCALL_PARRMEM1R(PackedVector2Array, Vector2, has);
+ VCALL_PARRMEM0(PackedVector2Array, Vector2, sort);
VCALL_PARRMEM0(PackedVector2Array, Vector2, invert);
VCALL_PARRMEM0R(PackedVector3Array, Vector3, size);
@@ -786,6 +800,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedVector3Array, Vector3, remove);
VCALL_PARRMEM1(PackedVector3Array, Vector3, append);
VCALL_PARRMEM1(PackedVector3Array, Vector3, append_array);
+ VCALL_PARRMEM1R(PackedVector3Array, Vector3, has);
+ VCALL_PARRMEM0(PackedVector3Array, Vector3, sort);
VCALL_PARRMEM0(PackedVector3Array, Vector3, invert);
VCALL_PARRMEM0R(PackedColorArray, Color, size);
@@ -798,6 +814,8 @@ struct _VariantCall {
VCALL_PARRMEM1(PackedColorArray, Color, remove);
VCALL_PARRMEM1(PackedColorArray, Color, append);
VCALL_PARRMEM1(PackedColorArray, Color, append_array);
+ VCALL_PARRMEM1R(PackedColorArray, Color, has);
+ VCALL_PARRMEM0(PackedColorArray, Color, sort);
VCALL_PARRMEM0(PackedColorArray, Color, invert);
#define VCALL_PTR0(m_type, m_method) \
@@ -2085,6 +2103,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_BYTE_ARRAY, INT, PackedByteArray, insert, INT, "idx", INT, "byte", varray());
ADDFUNC1(PACKED_BYTE_ARRAY, NIL, PackedByteArray, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_BYTE_ARRAY, BOOL, PackedByteArray, has, INT, "value", varray());
+ ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, sort, varray());
ADDFUNC0(PACKED_BYTE_ARRAY, NIL, PackedByteArray, invert, varray());
ADDFUNC2R(PACKED_BYTE_ARRAY, PACKED_BYTE_ARRAY, PackedByteArray, subarray, INT, "from", INT, "to", varray());
@@ -2103,6 +2123,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_INT32_ARRAY, INT, PackedInt32Array, insert, INT, "idx", INT, "integer", varray());
ADDFUNC1(PACKED_INT32_ARRAY, NIL, PackedInt32Array, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_INT32_ARRAY, BOOL, PackedInt32Array, has, INT, "value", varray());
+ ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, sort, varray());
ADDFUNC0(PACKED_INT32_ARRAY, NIL, PackedInt32Array, invert, varray());
ADDFUNC0R(PACKED_INT64_ARRAY, INT, PackedInt64Array, size, varray());
@@ -2114,6 +2136,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_INT64_ARRAY, INT, PackedInt64Array, insert, INT, "idx", INT, "integer", varray());
ADDFUNC1(PACKED_INT64_ARRAY, NIL, PackedInt64Array, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_INT64_ARRAY, BOOL, PackedInt64Array, has, INT, "value", varray());
+ ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, sort, varray());
ADDFUNC0(PACKED_INT64_ARRAY, NIL, PackedInt64Array, invert, varray());
ADDFUNC0R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, size, varray());
@@ -2125,6 +2149,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_FLOAT32_ARRAY, INT, PackedFloat32Array, insert, INT, "idx", FLOAT, "value", varray());
ADDFUNC1(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_FLOAT32_ARRAY, BOOL, PackedFloat32Array, has, FLOAT, "value", varray());
+ ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, sort, varray());
ADDFUNC0(PACKED_FLOAT32_ARRAY, NIL, PackedFloat32Array, invert, varray());
ADDFUNC0R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, size, varray());
@@ -2136,6 +2162,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_FLOAT64_ARRAY, INT, PackedFloat64Array, insert, INT, "idx", FLOAT, "value", varray());
ADDFUNC1(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_FLOAT64_ARRAY, BOOL, PackedFloat64Array, has, FLOAT, "value", varray());
+ ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, sort, varray());
ADDFUNC0(PACKED_FLOAT64_ARRAY, NIL, PackedFloat64Array, invert, varray());
ADDFUNC0R(PACKED_STRING_ARRAY, INT, PackedStringArray, size, varray());
@@ -2147,6 +2175,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_STRING_ARRAY, INT, PackedStringArray, insert, INT, "idx", STRING, "string", varray());
ADDFUNC1(PACKED_STRING_ARRAY, NIL, PackedStringArray, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_STRING_ARRAY, BOOL, PackedStringArray, has, STRING, "value", varray());
+ ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, sort, varray());
ADDFUNC0(PACKED_STRING_ARRAY, NIL, PackedStringArray, invert, varray());
ADDFUNC0R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, size, varray());
@@ -2158,6 +2188,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_VECTOR2_ARRAY, INT, PackedVector2Array, insert, INT, "idx", VECTOR2, "vector2", varray());
ADDFUNC1(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_VECTOR2_ARRAY, BOOL, PackedVector2Array, has, VECTOR2, "value", varray());
+ ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, sort, varray());
ADDFUNC0(PACKED_VECTOR2_ARRAY, NIL, PackedVector2Array, invert, varray());
ADDFUNC0R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, size, varray());
@@ -2169,6 +2201,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_VECTOR3_ARRAY, INT, PackedVector3Array, insert, INT, "idx", VECTOR3, "vector3", varray());
ADDFUNC1(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_VECTOR3_ARRAY, BOOL, PackedVector3Array, has, VECTOR3, "value", varray());
+ ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, sort, varray());
ADDFUNC0(PACKED_VECTOR3_ARRAY, NIL, PackedVector3Array, invert, varray());
ADDFUNC0R(PACKED_COLOR_ARRAY, INT, PackedColorArray, size, varray());
@@ -2180,6 +2214,8 @@ void register_variant_methods() {
ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, remove, INT, "idx", varray());
ADDFUNC2R(PACKED_COLOR_ARRAY, INT, PackedColorArray, insert, INT, "idx", COLOR, "color", varray());
ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, resize, INT, "idx", varray());
+ ADDFUNC1R(PACKED_COLOR_ARRAY, BOOL, PackedColorArray, has, COLOR, "value", varray());
+ ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, sort, varray());
ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, invert, varray());
//pointerbased
diff --git a/core/vector.h b/core/vector.h
index 4c152fb084..5fb630c21c 100644
--- a/core/vector.h
+++ b/core/vector.h
@@ -92,6 +92,10 @@ public:
void append_array(Vector<T> p_other);
+ bool has(const T &p_val) {
+ return find(p_val, 0) != -1;
+ }
+
template <class C>
void sort_custom() {
int len = _cowdata.size();