diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/node.cpp | 133 | ||||
-rw-r--r-- | scene/main/node.h | 24 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 16 | ||||
-rw-r--r-- | scene/main/scene_tree.h | 3 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 54 | ||||
-rw-r--r-- | scene/main/viewport.h | 1 |
6 files changed, 85 insertions, 146 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 3643aedb85..6199f52ec5 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -40,7 +40,6 @@ #include "viewport.h" VARIANT_ENUM_CAST(Node::PauseMode); -VARIANT_ENUM_CAST(Node::RPCMode); void Node::_notification(int p_notification) { @@ -485,18 +484,18 @@ bool Node::is_network_master() const { /***** RPC CONFIG ********/ -void Node::rpc_config(const StringName &p_method, RPCMode p_mode) { +void Node::rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_mode) { - if (p_mode == RPC_MODE_DISABLED) { + if (p_mode == MultiplayerAPI::RPC_MODE_DISABLED) { data.rpc_methods.erase(p_method); } else { data.rpc_methods[p_method] = p_mode; }; } -void Node::rset_config(const StringName &p_property, RPCMode p_mode) { +void Node::rset_config(const StringName &p_property, MultiplayerAPI::RPCMode p_mode) { - if (p_mode == RPC_MODE_DISABLED) { + if (p_mode == MultiplayerAPI::RPC_MODE_DISABLED) { data.rpc_properties.erase(p_property); } else { data.rpc_properties[p_property] = p_mode; @@ -718,121 +717,14 @@ void Node::set_custom_multiplayer(Ref<MultiplayerAPI> p_multiplayer) { multiplayer = p_multiplayer; } -const Map<StringName, Node::RPCMode>::Element *Node::get_node_rpc_mode(const StringName &p_method) { +const Map<StringName, MultiplayerAPI::RPCMode>::Element *Node::get_node_rpc_mode(const StringName &p_method) { return data.rpc_methods.find(p_method); } -const Map<StringName, Node::RPCMode>::Element *Node::get_node_rset_mode(const StringName &p_property) { +const Map<StringName, MultiplayerAPI::RPCMode>::Element *Node::get_node_rset_mode(const StringName &p_property) { return data.rpc_properties.find(p_property); } -bool Node::can_call_rpc(const StringName &p_method, int p_from) const { - - const Map<StringName, RPCMode>::Element *E = data.rpc_methods.find(p_method); - if (E) { - - switch (E->get()) { - - case RPC_MODE_DISABLED: { - return false; - } break; - case RPC_MODE_REMOTE: { - return true; - } break; - case RPC_MODE_SYNC: { - return true; - } break; - case RPC_MODE_MASTER: { - return is_network_master(); - } break; - case RPC_MODE_SLAVE: { - return !is_network_master() && p_from == get_network_master(); - } break; - } - } - - if (get_script_instance()) { - //attempt with script - ScriptInstance::RPCMode rpc_mode = get_script_instance()->get_rpc_mode(p_method); - - switch (rpc_mode) { - - case ScriptInstance::RPC_MODE_DISABLED: { - return false; - } break; - case ScriptInstance::RPC_MODE_REMOTE: { - return true; - } break; - case ScriptInstance::RPC_MODE_SYNC: { - return true; - } break; - case ScriptInstance::RPC_MODE_MASTER: { - return is_network_master(); - } break; - case ScriptInstance::RPC_MODE_SLAVE: { - return !is_network_master() && p_from == get_network_master(); - } break; - } - } - - ERR_PRINTS("RPC from " + itos(p_from) + " on unauthorized method attempted: " + String(p_method) + " on base: " + String(Variant(this))); - return false; -} - -bool Node::can_call_rset(const StringName &p_property, int p_from) const { - - const Map<StringName, RPCMode>::Element *E = data.rpc_properties.find(p_property); - if (E) { - - switch (E->get()) { - - case RPC_MODE_DISABLED: { - return false; - } break; - case RPC_MODE_REMOTE: { - return true; - } break; - case RPC_MODE_SYNC: { - return true; - } break; - case RPC_MODE_MASTER: { - return is_network_master(); - } break; - case RPC_MODE_SLAVE: { - return !is_network_master() && p_from == get_network_master(); - } break; - } - } - - if (get_script_instance()) { - //attempt with script - ScriptInstance::RPCMode rpc_mode = get_script_instance()->get_rset_mode(p_property); - - switch (rpc_mode) { - - case ScriptInstance::RPC_MODE_DISABLED: { - return false; - } break; - case ScriptInstance::RPC_MODE_REMOTE: { - return true; - } break; - case ScriptInstance::RPC_MODE_SYNC: { - return true; - } break; - case ScriptInstance::RPC_MODE_MASTER: { - return is_network_master(); - } break; - case ScriptInstance::RPC_MODE_SLAVE: { - return !is_network_master() && p_from == get_network_master(); - } break; - } - } - - ERR_PRINTS("RSET from " + itos(p_from) + " on unauthorized property attempted: " + String(p_property) + " on base: " + String(Variant(this))); - - return false; -} - bool Node::can_process() const { ERR_FAIL_COND_V(!is_inside_tree(), false); @@ -1203,6 +1095,10 @@ void Node::add_child(Node *p_child, bool p_legible_unique_name) { } void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name) { + + ERR_FAIL_NULL(p_node); + ERR_FAIL_NULL(p_child); + add_child(p_child, p_legible_unique_name); if (is_a_parent_of(p_node)) { @@ -2038,8 +1934,9 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const if (E->get().usage & PROPERTY_USAGE_DO_NOT_SHARE_ON_DUPLICATE) { Resource *res = Object::cast_to<Resource>(value); - if (res) // Duplicate only if it's a resource + if (res) { // Duplicate only if it's a resource current_node->set(name, res->duplicate()); + } } else { @@ -2802,12 +2699,6 @@ void Node::_bind_methods() { BIND_CONSTANT(NOTIFICATION_INTERNAL_PROCESS); BIND_CONSTANT(NOTIFICATION_INTERNAL_PHYSICS_PROCESS); - BIND_ENUM_CONSTANT(RPC_MODE_DISABLED); - BIND_ENUM_CONSTANT(RPC_MODE_REMOTE); - BIND_ENUM_CONSTANT(RPC_MODE_SYNC); - BIND_ENUM_CONSTANT(RPC_MODE_MASTER); - BIND_ENUM_CONSTANT(RPC_MODE_SLAVE); - BIND_ENUM_CONSTANT(PAUSE_MODE_INHERIT); BIND_ENUM_CONSTANT(PAUSE_MODE_STOP); BIND_ENUM_CONSTANT(PAUSE_MODE_PROCESS); diff --git a/scene/main/node.h b/scene/main/node.h index 540f34cba7..341349de79 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -65,15 +65,6 @@ public: #endif }; - enum RPCMode { - - RPC_MODE_DISABLED, //no rpc for this method, calls to this will be blocked (default) - RPC_MODE_REMOTE, // using rpc() on it will call method / set property in all other peers - RPC_MODE_SYNC, // using rpc() on it will call method / set property in all other peers and locally - RPC_MODE_MASTER, // usinc rpc() on it will call method on wherever the master is, be it local or remote - RPC_MODE_SLAVE, // usinc rpc() on it will call method for all slaves, be it local or remote - }; - struct Comparator { bool operator()(const Node *p_a, const Node *p_b) const { return p_b->is_greater_than(p_a); } @@ -120,8 +111,8 @@ private: Node *pause_owner; int network_master; - Map<StringName, RPCMode> rpc_methods; - Map<StringName, RPCMode> rpc_properties; + Map<StringName, MultiplayerAPI::RPCMode> rpc_methods; + Map<StringName, MultiplayerAPI::RPCMode> rpc_properties; // variables used to properly sort the node when processing, ignored otherwise //should move all the stuff below to bits @@ -404,8 +395,8 @@ public: int get_network_master() const; bool is_network_master() const; - void rpc_config(const StringName &p_method, RPCMode p_mode); // config a local method for RPC - void rset_config(const StringName &p_property, RPCMode p_mode); // config a local property for RPC + void rpc_config(const StringName &p_method, MultiplayerAPI::RPCMode p_mode); // config a local method for RPC + void rset_config(const StringName &p_property, MultiplayerAPI::RPCMode p_mode); // config a local property for RPC void rpc(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode void rpc_unreliable(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode @@ -423,11 +414,8 @@ public: Ref<MultiplayerAPI> get_multiplayer() const; Ref<MultiplayerAPI> get_custom_multiplayer() const; void set_custom_multiplayer(Ref<MultiplayerAPI> p_multiplayer); - const Map<StringName, RPCMode>::Element *get_node_rpc_mode(const StringName &p_method); - const Map<StringName, RPCMode>::Element *get_node_rset_mode(const StringName &p_property); - - bool can_call_rpc(const StringName &p_method, int p_from) const; - bool can_call_rset(const StringName &p_property, int p_from) const; + const Map<StringName, MultiplayerAPI::RPCMode>::Element *get_node_rpc_mode(const StringName &p_method); + const Map<StringName, MultiplayerAPI::RPCMode>::Element *get_node_rset_mode(const StringName &p_property); Node(); ~Node(); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 607dbebf6c..8d6e57b335 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -485,7 +485,9 @@ bool SceneTree::idle(float p_time) { idle_process_time = p_time; - multiplayer->poll(); + if (multiplayer_poll) { + multiplayer->poll(); + } emit_signal("idle_frame"); @@ -1672,6 +1674,14 @@ Ref<MultiplayerAPI> SceneTree::get_multiplayer() const { return multiplayer; } +void SceneTree::set_multiplayer_poll_enabled(bool p_enabled) { + multiplayer_poll = p_enabled; +} + +bool SceneTree::is_multiplayer_poll_enabled() const { + return multiplayer_poll; +} + void SceneTree::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) { ERR_FAIL_COND(!p_multiplayer.is_valid()); @@ -1802,6 +1812,8 @@ void SceneTree::_bind_methods() { ClassDB::bind_method(D_METHOD("set_multiplayer", "multiplayer"), &SceneTree::set_multiplayer); ClassDB::bind_method(D_METHOD("get_multiplayer"), &SceneTree::get_multiplayer); + ClassDB::bind_method(D_METHOD("set_multiplayer_poll_enabled", "enabled"), &SceneTree::set_multiplayer_poll_enabled); + ClassDB::bind_method(D_METHOD("is_multiplayer_poll_enabled"), &SceneTree::is_multiplayer_poll_enabled); ClassDB::bind_method(D_METHOD("set_network_peer", "peer"), &SceneTree::set_network_peer); ClassDB::bind_method(D_METHOD("get_network_peer"), &SceneTree::get_network_peer); ClassDB::bind_method(D_METHOD("is_network_server"), &SceneTree::is_network_server); @@ -1830,6 +1842,7 @@ void SceneTree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "network_peer", PROPERTY_HINT_RESOURCE_TYPE, "NetworkedMultiplayerPeer", 0), "set_network_peer", "get_network_peer"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "root", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "", "get_root"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multiplayer", PROPERTY_HINT_RESOURCE_TYPE, "MultiplayerAPI", 0), "set_multiplayer", "get_multiplayer"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multiplayer_poll"), "set_multiplayer_poll_enabled", "is_multiplayer_poll_enabled"); ADD_SIGNAL(MethodInfo("tree_changed")); ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node"))); @@ -1934,6 +1947,7 @@ SceneTree::SceneTree() { root->set_world(Ref<World>(memnew(World))); // Initialize network state + multiplayer_poll = true; set_multiplayer(Ref<MultiplayerAPI>(memnew(MultiplayerAPI))); //root->set_world_2d( Ref<World2D>( memnew( World2D ))); diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h index 6e0156546e..aa8d78b1e1 100644 --- a/scene/main/scene_tree.h +++ b/scene/main/scene_tree.h @@ -186,6 +186,7 @@ private: ///network/// Ref<MultiplayerAPI> multiplayer; + bool multiplayer_poll; void _network_peer_connected(int p_id); void _network_peer_disconnected(int p_id); @@ -411,6 +412,8 @@ public: //network API Ref<MultiplayerAPI> get_multiplayer() const; + void set_multiplayer_poll_enabled(bool p_enabled); + bool is_multiplayer_poll_enabled() const; void set_multiplayer(Ref<MultiplayerAPI> p_multiplayer); void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer); Ref<NetworkedMultiplayerPeer> get_network_peer() const; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index ca9be9823a..a894b82a94 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -144,7 +144,7 @@ void ViewportTexture::_bind_methods() { ClassDB::bind_method(D_METHOD("set_viewport_path_in_scene", "path"), &ViewportTexture::set_viewport_path_in_scene); ClassDB::bind_method(D_METHOD("get_viewport_path_in_scene"), &ViewportTexture::get_viewport_path_in_scene); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "viewport_path"), "set_viewport_path_in_scene", "get_viewport_path_in_scene"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "viewport_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Viewport"), "set_viewport_path_in_scene", "get_viewport_path_in_scene"); } ViewportTexture::ViewportTexture() { @@ -1308,13 +1308,37 @@ void Viewport::_gui_cancel_tooltip() { } } +String Viewport::_gui_get_tooltip(Control *p_control, const Vector2 &p_pos) { + + Vector2 pos = p_pos; + String tooltip; + + while (p_control) { + + tooltip = p_control->get_tooltip(pos); + + if (tooltip != String()) + break; + pos = p_control->get_transform().xform(pos); + + if (p_control->data.mouse_filter == Control::MOUSE_FILTER_STOP) + break; + if (p_control->is_set_as_toplevel()) + break; + + p_control = p_control->get_parent_control(); + } + + return tooltip; +} + void Viewport::_gui_show_tooltip() { if (!gui.tooltip) { return; } - String tooltip = gui.tooltip->get_tooltip(gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos)); + String tooltip = _gui_get_tooltip(gui.tooltip, gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos)); if (tooltip.length() == 0) return; // bye @@ -1388,12 +1412,14 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu Control *control = Object::cast_to<Control>(ci); if (control) { - control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev); + + control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); //signal should be first, so it's possible to override an event (and then accept it) if (gui.key_event_accepted) break; if (!control->is_inside_tree()) break; - control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); + control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev); + if (!control->is_inside_tree() || control->is_set_as_toplevel()) break; if (gui.key_event_accepted) @@ -1864,7 +1890,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (gui.tooltip_popup) { if (can_tooltip) { - String tooltip = over->get_tooltip(gui.tooltip->get_global_transform().xform_inv(mpos)); + String tooltip = _gui_get_tooltip(over, gui.tooltip->get_global_transform().xform_inv(mpos)); if (tooltip.length() == 0) _gui_cancel_tooltip(); @@ -1886,7 +1912,23 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { mm->set_position(pos); - Control::CursorShape cursor_shape = over->get_cursor_shape(pos); + Control::CursorShape cursor_shape = Control::CURSOR_ARROW; + { + Control *c = over; + Vector2 cpos = pos; + while (c) { + cursor_shape = c->get_cursor_shape(cpos); + cpos = c->get_transform().xform(cpos); + if (cursor_shape != Control::CURSOR_ARROW) + break; + if (c->data.mouse_filter == Control::MOUSE_FILTER_STOP) + break; + if (c->is_set_as_toplevel()) + break; + c = c->get_parent_control(); + } + } + OS::get_singleton()->set_cursor_shape((OS::CursorShape)cursor_shape); if (over->can_process()) { diff --git a/scene/main/viewport.h b/scene/main/viewport.h index c1ef58de69..3000398540 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -312,6 +312,7 @@ private: void _gui_remove_root_control(List<Control *>::Element *RI); void _gui_remove_subwindow_control(List<Control *>::Element *SI); + String _gui_get_tooltip(Control *p_control, const Vector2 &p_pos); void _gui_cancel_tooltip(); void _gui_show_tooltip(); |