diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/bind/core_bind.cpp | 12 | ||||
-rw-r--r-- | core/bind/core_bind.h | 3 | ||||
-rw-r--r-- | core/io/multiplayer_api.cpp | 79 | ||||
-rw-r--r-- | core/io/multiplayer_api.h | 13 | ||||
-rw-r--r-- | core/io/packet_peer.cpp | 2 | ||||
-rw-r--r-- | core/method_bind.h | 28 | ||||
-rw-r--r-- | core/object.h | 2 | ||||
-rw-r--r-- | core/os/os.cpp | 1 | ||||
-rw-r--r-- | core/os/os.h | 13 | ||||
-rw-r--r-- | core/script_language.h | 2 |
10 files changed, 127 insertions, 28 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 9c484f313e..3270b33f1c 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -336,6 +336,14 @@ void _OS::set_borderless_window(bool p_borderless) { OS::get_singleton()->set_borderless_window(p_borderless); } +bool _OS::get_window_per_pixel_transparency_enabled() const { + return OS::get_singleton()->get_window_per_pixel_transparency_enabled(); +} + +void _OS::set_window_per_pixel_transparency_enabled(bool p_enabled) { + OS::get_singleton()->set_window_per_pixel_transparency_enabled(p_enabled); +} + bool _OS::get_borderless_window() const { return OS::get_singleton()->get_borderless_window(); } @@ -1068,6 +1076,9 @@ void _OS::_bind_methods() { ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window); ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window); + ClassDB::bind_method(D_METHOD("get_window_per_pixel_transparency_enabled"), &_OS::get_window_per_pixel_transparency_enabled); + ClassDB::bind_method(D_METHOD("set_window_per_pixel_transparency_enabled", "enabled"), &_OS::set_window_per_pixel_transparency_enabled); + ClassDB::bind_method(D_METHOD("set_ime_position", "position"), &_OS::set_ime_position); ClassDB::bind_method(D_METHOD("set_screen_orientation", "orientation"), &_OS::set_screen_orientation); @@ -1185,6 +1196,7 @@ void _OS::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation"); ADD_GROUP("Window", "window_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_per_pixel_transparency_enabled"), "set_window_per_pixel_transparency_enabled", "get_window_per_pixel_transparency_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_fullscreen"), "set_window_fullscreen", "is_window_fullscreen"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_maximized"), "set_window_maximized", "is_window_maximized"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_minimized"), "set_window_minimized", "is_window_minimized"); diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 625cac25a0..a363f5970f 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -180,6 +180,9 @@ public: virtual void set_borderless_window(bool p_borderless); virtual bool get_borderless_window() const; + virtual bool get_window_per_pixel_transparency_enabled() const; + virtual void set_window_per_pixel_transparency_enabled(bool p_enabled); + virtual void set_ime_position(const Point2 &p_pos); Error native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); diff --git a/core/io/multiplayer_api.cpp b/core/io/multiplayer_api.cpp index cbe7f87d92..456d29520f 100644 --- a/core/io/multiplayer_api.cpp +++ b/core/io/multiplayer_api.cpp @@ -47,11 +47,11 @@ void MultiplayerAPI::set_root_node(Node *p_node) { void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer) { if (network_peer.is_valid()) { - network_peer->disconnect("peer_connected", this, "add_peer"); - network_peer->disconnect("peer_disconnected", this, "del_peer"); - network_peer->disconnect("connection_succeeded", this, "connected_to_server"); - network_peer->disconnect("connection_failed", this, "connection_failed"); - network_peer->disconnect("server_disconnected", this, "server_disconnected"); + network_peer->disconnect("peer_connected", this, "_add_peer"); + network_peer->disconnect("peer_disconnected", this, "_del_peer"); + network_peer->disconnect("connection_succeeded", this, "_connected_to_server"); + network_peer->disconnect("connection_failed", this, "_connection_failed"); + network_peer->disconnect("server_disconnected", this, "_server_disconnected"); clear(); } @@ -61,11 +61,11 @@ void MultiplayerAPI::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_pee ERR_FAIL_COND(p_peer.is_valid() && p_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED); if (network_peer.is_valid()) { - network_peer->connect("peer_connected", this, "add_peer"); - network_peer->connect("peer_disconnected", this, "del_peer"); - network_peer->connect("connection_succeeded", this, "connected_to_server"); - network_peer->connect("connection_failed", this, "connection_failed"); - network_peer->connect("server_disconnected", this, "server_disconnected"); + network_peer->connect("peer_connected", this, "_add_peer"); + network_peer->connect("peer_disconnected", this, "_del_peer"); + network_peer->connect("connection_succeeded", this, "_connected_to_server"); + network_peer->connect("connection_failed", this, "_connection_failed"); + network_peer->connect("server_disconnected", this, "_server_disconnected"); } } @@ -76,7 +76,7 @@ Ref<NetworkedMultiplayerPeer> MultiplayerAPI::get_network_peer() const { void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) { ERR_FAIL_COND(root_node == NULL); - ERR_FAIL_COND(p_packet_len < 5); + ERR_FAIL_COND(p_packet_len < 1); uint8_t packet_type = p_packet[0]; @@ -123,6 +123,11 @@ void MultiplayerAPI::_process_packet(int p_from, const uint8_t *p_packet, int p_ } } break; + + case NETWORK_COMMAND_RAW: { + + _process_raw(p_from, p_packet, p_packet_len); + } break; } } @@ -259,6 +264,8 @@ void MultiplayerAPI::_process_simplify_path(int p_from, const uint8_t *p_packet, void MultiplayerAPI::_process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) { + ERR_FAIL_COND(p_packet_len < 2); + String paths; paths.parse_utf8((const char *)&p_packet[1], p_packet_len - 1); @@ -458,29 +465,29 @@ void MultiplayerAPI::_send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p } } -void MultiplayerAPI::add_peer(int p_id) { +void MultiplayerAPI::_add_peer(int p_id) { connected_peers.insert(p_id); path_get_cache.insert(p_id, PathGetCache()); emit_signal("network_peer_connected", p_id); } -void MultiplayerAPI::del_peer(int p_id) { +void MultiplayerAPI::_del_peer(int p_id) { connected_peers.erase(p_id); path_get_cache.erase(p_id); //I no longer need your cache, sorry emit_signal("network_peer_disconnected", p_id); } -void MultiplayerAPI::connected_to_server() { +void MultiplayerAPI::_connected_to_server() { emit_signal("connected_to_server"); } -void MultiplayerAPI::connection_failed() { +void MultiplayerAPI::_connection_failed() { emit_signal("connection_failed"); } -void MultiplayerAPI::server_disconnected() { +void MultiplayerAPI::_server_disconnected() { emit_signal("server_disconnected"); } @@ -648,6 +655,34 @@ void MultiplayerAPI::rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const _send_rpc(p_node, p_peer_id, p_unreliable, true, p_property, &vptr, 1); } +Error MultiplayerAPI::send_bytes(PoolVector<uint8_t> p_data, int p_to) { + + ERR_FAIL_COND_V(p_data.size() < 1, ERR_INVALID_DATA); + ERR_FAIL_COND_V(!network_peer.is_valid(), ERR_UNCONFIGURED); + ERR_FAIL_COND_V(network_peer->get_connection_status() != NetworkedMultiplayerPeer::CONNECTION_CONNECTED, ERR_UNCONFIGURED); + + MAKE_ROOM(p_data.size() + 1); + PoolVector<uint8_t>::Read r = p_data.read(); + packet_cache[0] = NETWORK_COMMAND_RAW; + memcpy(&packet_cache[1], &r[0], p_data.size()); + network_peer->set_target_peer(p_to); + return network_peer->put_packet(packet_cache.ptr(), p_data.size() + 1); +} + +void MultiplayerAPI::_process_raw(int p_from, const uint8_t *p_packet, int p_packet_len) { + + ERR_FAIL_COND(p_packet_len < 2); + + PoolVector<uint8_t> out; + int len = p_packet_len - 1; + out.resize(len); + { + PoolVector<uint8_t>::Write w = out.write(); + memcpy(&w[0], &p_packet[1], len); + } + emit_signal("network_peer_packet", p_from, out); +} + int MultiplayerAPI::get_network_unique_id() const { ERR_FAIL_COND_V(!network_peer.is_valid(), 0); @@ -686,20 +721,21 @@ Vector<int> MultiplayerAPI::get_network_connected_peers() const { void MultiplayerAPI::_bind_methods() { ClassDB::bind_method(D_METHOD("set_root_node", "node"), &MultiplayerAPI::set_root_node); + ClassDB::bind_method(D_METHOD("send_bytes", "bytes", "id"), &MultiplayerAPI::send_bytes, DEFVAL(NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST)); ClassDB::bind_method(D_METHOD("has_network_peer"), &MultiplayerAPI::has_network_peer); ClassDB::bind_method(D_METHOD("get_network_peer"), &MultiplayerAPI::get_network_peer); ClassDB::bind_method(D_METHOD("get_network_unique_id"), &MultiplayerAPI::get_network_unique_id); ClassDB::bind_method(D_METHOD("is_network_server"), &MultiplayerAPI::is_network_server); ClassDB::bind_method(D_METHOD("get_rpc_sender_id"), &MultiplayerAPI::get_rpc_sender_id); - ClassDB::bind_method(D_METHOD("add_peer", "id"), &MultiplayerAPI::add_peer); - ClassDB::bind_method(D_METHOD("del_peer", "id"), &MultiplayerAPI::del_peer); + ClassDB::bind_method(D_METHOD("_add_peer", "id"), &MultiplayerAPI::_add_peer); + ClassDB::bind_method(D_METHOD("_del_peer", "id"), &MultiplayerAPI::_del_peer); ClassDB::bind_method(D_METHOD("set_network_peer", "peer"), &MultiplayerAPI::set_network_peer); ClassDB::bind_method(D_METHOD("poll"), &MultiplayerAPI::poll); ClassDB::bind_method(D_METHOD("clear"), &MultiplayerAPI::clear); - ClassDB::bind_method(D_METHOD("connected_to_server"), &MultiplayerAPI::connected_to_server); - ClassDB::bind_method(D_METHOD("connection_failed"), &MultiplayerAPI::connection_failed); - ClassDB::bind_method(D_METHOD("server_disconnected"), &MultiplayerAPI::server_disconnected); + ClassDB::bind_method(D_METHOD("_connected_to_server"), &MultiplayerAPI::_connected_to_server); + ClassDB::bind_method(D_METHOD("_connection_failed"), &MultiplayerAPI::_connection_failed); + ClassDB::bind_method(D_METHOD("_server_disconnected"), &MultiplayerAPI::_server_disconnected); ClassDB::bind_method(D_METHOD("get_network_connected_peers"), &MultiplayerAPI::get_network_connected_peers); ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &MultiplayerAPI::set_refuse_new_network_connections); ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &MultiplayerAPI::is_refusing_new_network_connections); @@ -708,6 +744,7 @@ void MultiplayerAPI::_bind_methods() { ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id"))); + ADD_SIGNAL(MethodInfo("network_peer_packet", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::POOL_BYTE_ARRAY, "packet"))); ADD_SIGNAL(MethodInfo("connected_to_server")); ADD_SIGNAL(MethodInfo("connection_failed")); ADD_SIGNAL(MethodInfo("server_disconnected")); diff --git a/core/io/multiplayer_api.h b/core/io/multiplayer_api.h index e7c6ffbea6..25f445004d 100644 --- a/core/io/multiplayer_api.h +++ b/core/io/multiplayer_api.h @@ -43,6 +43,7 @@ protected: Node *_process_get_node(int p_from, const uint8_t *p_packet, int p_packet_len); void _process_rpc(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset); void _process_rset(Node *p_node, const StringName &p_name, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset); + void _process_raw(int p_from, const uint8_t *p_packet, int p_packet_len); void _send_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount); bool _send_confirm_path(NodePath p_path, PathSentCache *psc, int p_from); @@ -53,6 +54,7 @@ public: NETWORK_COMMAND_REMOTE_SET, NETWORK_COMMAND_SIMPLIFY_PATH, NETWORK_COMMAND_CONFIRM_PATH, + NETWORK_COMMAND_RAW, }; void poll(); @@ -60,17 +62,18 @@ public: void set_root_node(Node *p_node); void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_peer); Ref<NetworkedMultiplayerPeer> get_network_peer() const; + Error send_bytes(PoolVector<uint8_t> p_data, int p_to = NetworkedMultiplayerPeer::TARGET_PEER_BROADCAST); // Called by Node.rpc void rpcp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount); // Called by Node.rset void rsetp(Node *p_node, int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value); - void add_peer(int p_id); - void del_peer(int p_id); - void connected_to_server(); - void connection_failed(); - void server_disconnected(); + void _add_peer(int p_id); + void _del_peer(int p_id); + void _connected_to_server(); + void _connection_failed(); + void _server_disconnected(); bool has_network_peer() const { return network_peer.is_valid(); } Vector<int> get_network_connected_peers() const; diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp index bd851ebb6d..b777a9f960 100644 --- a/core/io/packet_peer.cpp +++ b/core/io/packet_peer.cpp @@ -172,6 +172,7 @@ Error PacketPeerStream::_poll_buffer() const { ERR_FAIL_COND_V(peer.is_null(), ERR_UNCONFIGURED); int read = 0; + ERR_FAIL_COND_V(input_buffer.size() < ring_buffer.space_left(), ERR_UNAVAILABLE); Error err = peer->get_partial_data(&input_buffer[0], ring_buffer.space_left(), read); if (err) return err; @@ -223,6 +224,7 @@ Error PacketPeerStream::get_packet(const uint8_t **r_buffer, int &r_buffer_size) uint32_t len = decode_uint32(lbuf); ERR_FAIL_COND_V(remaining < (int)len, ERR_UNAVAILABLE); + ERR_FAIL_COND_V(input_buffer.size() < len, ERR_UNAVAILABLE); ring_buffer.read(lbuf, 4); //get rid of first 4 bytes ring_buffer.read(&input_buffer[0], len); // read packet diff --git a/core/method_bind.h b/core/method_bind.h index e02d64c935..41b500c401 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -128,10 +128,36 @@ struct VariantCaster<const T &> { // Object enum casts must go here VARIANT_ENUM_CAST(Object::ConnectFlags); +template <typename T> +struct VariantObjectClassChecker { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + return true; + } +}; + +template <> +struct VariantObjectClassChecker<Node *> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Node *node = p_variant; + return node || !obj; + } +}; + +template <> +struct VariantObjectClassChecker<Control *> { + static _FORCE_INLINE_ bool check(const Variant &p_variant) { + Object *obj = p_variant; + Control *control = p_variant; + return control || !obj; + } +}; + #define CHECK_ARG(m_arg) \ if ((m_arg - 1) < p_arg_count) { \ Variant::Type argtype = get_argument_type(m_arg - 1); \ - if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype)) { \ + if (!Variant::can_convert_strict(p_args[m_arg - 1]->get_type(), argtype) || \ + !VariantObjectClassChecker<P##m_arg>::check(*p_args[m_arg - 1])) { \ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; \ r_error.argument = m_arg - 1; \ r_error.expected = argtype; \ diff --git a/core/object.h b/core/object.h index c405e22557..7963a43fd6 100644 --- a/core/object.h +++ b/core/object.h @@ -55,7 +55,7 @@ enum PropertyHint { PROPERTY_HINT_RANGE, ///< hint_text = "min,max,step,slider; //slider is optional" PROPERTY_HINT_EXP_RANGE, ///< hint_text = "min,max,step", exponential edit PROPERTY_HINT_ENUM, ///< hint_text= "val1,val2,val3,etc" - PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease) + PROPERTY_HINT_EXP_EASING, /// exponential easing function (Math::ease) use "attenuation" hint string to revert (flip h), "full" to also include in/out. (ie: "attenuation,inout") PROPERTY_HINT_LENGTH, ///< hint_text= "length" (as integer) PROPERTY_HINT_SPRITE_FRAME, PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer) diff --git a/core/os/os.cpp b/core/os/os.cpp index 854d554b10..5eed10e30c 100644 --- a/core/os/os.cpp +++ b/core/os/os.cpp @@ -672,6 +672,7 @@ OS::OS() { _render_thread_mode = RENDER_THREAD_SAFE; _allow_hidpi = false; + _allow_layered = false; _stack_bottom = (void *)(&stack_bottom); _logger = NULL; diff --git a/core/os/os.h b/core/os/os.h index f6404468b1..b36f94060c 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -65,6 +65,7 @@ class OS { int _exit_code; int _orientation; bool _allow_hidpi; + bool _allow_layered; bool _use_vsync; char *last_error; @@ -102,6 +103,8 @@ public: bool maximized; bool always_on_top; bool use_vsync; + bool layered_splash; + bool layered; float get_aspect() const { return (float)width / (float)height; } VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false) { width = p_width; @@ -112,6 +115,8 @@ public: maximized = p_maximized; always_on_top = p_always_on_top; use_vsync = p_use_vsync; + layered = false; + layered_splash = false; } }; @@ -220,6 +225,13 @@ public: virtual void set_borderless_window(bool p_borderless) {} virtual bool get_borderless_window() { return 0; } + virtual bool get_window_per_pixel_transparency_enabled() const { return false; } + virtual void set_window_per_pixel_transparency_enabled(bool p_enabled) {} + + virtual uint8_t *get_layered_buffer_data() { return NULL; } + virtual Size2 get_layered_buffer_size() { return Size2(0, 0); } + virtual void swap_layered_buffer() {} + virtual void set_ime_position(const Point2 &p_pos) {} virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) {} @@ -481,6 +493,7 @@ public: virtual void force_process_input(){}; bool has_feature(const String &p_feature); + bool is_layered_allowed() const { return _allow_layered; } bool is_hidpi_allowed() const { return _allow_hidpi; } OS(); virtual ~OS(); diff --git a/core/script_language.h b/core/script_language.h index 55a20c7478..b4c55cac9e 100644 --- a/core/script_language.h +++ b/core/script_language.h @@ -236,6 +236,8 @@ public: virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const = 0; virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) = 0; + virtual void add_named_global_constant(const StringName &p_name, const Variant &p_value) {} + virtual void remove_named_global_constant(const StringName &p_name) {} /* MULTITHREAD FUNCTIONS */ |