From e53f01a7afe5d47266510e525af142c5418334cd Mon Sep 17 00:00:00 2001 From: mhilbrunner Date: Thu, 15 Mar 2018 19:10:18 +0100 Subject: [PATCH] [DOCS] Node: Networking updates, fix outdated and missing docs (cherry picked from commit 5a3e841c60fa2b3cdbb44ec1012e67d2a0c71b92) --- doc/classes/Node.xml | 80 ++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 29 deletions(-) diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 98b3e2b498d..d1ea149496a 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -13,7 +13,8 @@ Nodes can also process input events. When present, the [method _input] function will be called for each input that the program receives. In many cases, this can be overkill (unless used for simple projects), and the [method _unhandled_input] function might be preferred; it is called when the input event was not handled by anyone else (typically, GUI [Control] nodes), ensuring that the node only receives the events that were meant for it. To keep track of the scene hierarchy (especially when instancing scenes into other scenes), an "owner" can be set for the node with [method set_owner]. This keeps track of who instanced what. This is mostly useful when writing editors and tools, though. Finally, when a node is freed with [method free] or [method queue_free], it will also free all its children. - [b]Networking with nodes:[/b] After connecting to a server (or making one, see [NetworkedMultiplayerENet]) it is possible to use the built-in RPC (remote procedure call) system to communicate over the network. By calling [method rpc] with a method name, it will be called locally and in all connected peers (peers = clients and the server that accepts connections), with behaviour varying depending on the network mode ([method set_network_mode]) of the receiving peer. To identify which node receives the RPC call Godot will use its [NodePath] (make sure node names are the same on all peers). + [b]Groups:[/b] Nodes can be added to as many groups as you want to be easy to manage, you could create groups like "enemies" or "collectables" for example, depending on your game. See [method add_to_group], [method is_in_group] and [method remove_from_group]. You can then retrieve all nodes in these groups, iterate them and even call methods on groups via the methods on [SceneTree]. + [b]Networking with nodes:[/b] After connecting to a server (or making one, see [NetworkedMultiplayerENet]) it is possible to use the built-in RPC (remote procedure call) system to communicate over the network. By calling [method rpc] with a method name, it will be called locally and in all connected peers (peers = clients and the server that accepts connections). To identify which node receives the RPC call Godot will use its [NodePath] (make sure node names are the same on all peers). Also take a look at the high-level networking tutorial and corresponding demos. http://docs.godotengine.org/en/3.0/getting_started/step_by_step/scenes_and_nodes.html @@ -45,6 +46,8 @@ Called when there is an input event. The input event propagates through the node tree until a node consumes it. It is only called if input processing is enabled, which is done automatically if this method is overridden, and can be toggled with [method set_process_input]. + To consume the input event and stop it propagating further to other nodes, [method SceneTree.set_input_as_handled] can be called. + For gameplay input, [method _unhandled_input] and [method _unhandled_key_input] are usually a better fit as they allow the GUI to intercept the events first. @@ -74,7 +77,8 @@ Called when the node is "ready", i.e. when both the node and its children have entered the scene tree. If the node has children, their [method _ready] callbacks get triggered first, and the parent node will receive the ready notification afterwards. - Corresponds to the NOTIFICATION_READY notification in [method Object._notification]. + Corresponds to the NOTIFICATION_READY notification in [method Object._notification]. See also the [code]onready[/code] keyword for variables. + Usually used for initialization. For even earlier initialization, [method Object._init] may be used. Also see [method _enter_tree]. @@ -83,8 +87,10 @@ - Propagated to all nodes when the previous InputEvent is not consumed by any nodes. + Propagated to all nodes when the previous [InputEvent] is not consumed by any nodes. It is only called if unhandled input processing is enabled, which is done automatically if this method is overridden, and can be toggled with [method set_process_unhandled_input]. + To consume the input event and stop it propagating further to other nodes, [method SceneTree.set_input_as_handled] can be called. + For gameplay input, this and [method _unhandled_key_input] are usually a better fit than [method _input] as they allow the GUI to intercept the events first. @@ -93,6 +99,10 @@ + Propagated to all nodes when the previous [InputEventKey] is not consumed by any nodes. + It is only called if unhandled key input processing is enabled, which is done automatically if this method is overridden, and can be toggled with [method set_process_unhandled_key_input]. + To consume the input event and stop it propagating further to other nodes, [method SceneTree.set_input_as_handled] can be called. + For gameplay input, this and [method _unhandled_input] are usually a better fit than [method _input] as they allow the GUI to intercept the events first. @@ -129,7 +139,7 @@ - Adds the node to a group. Groups are helpers to name and organize a subset of nodes, for example "enemies" or "collectables". A node can be in any number of groups. Nodes can be assigned a group at any time, but will not be added until they are inside the scene tree (see [method is_inside_tree]). + Adds the node to a group. Groups are helpers to name and organize a subset of nodes, for example "enemies" or "collectables". A node can be in any number of groups. Nodes can be assigned a group at any time, but will not be added until they are inside the scene tree (see [method is_inside_tree]). See notes in the description, and the group methods in [SceneTree]. @@ -203,7 +213,7 @@ - Returns the peer ID of the network master for this node. + Returns the peer ID of the network master for this node. See [method set_network_master]. @@ -262,7 +272,7 @@ - Returns the relative path from the current node to the specified node in "node" argument. Both nodes must be in the same scene, or the function will fail. + Returns the relative [NodePath] from this node to the specified [code]node[/code]. Both nodes must be in the same scene or the function will fail. @@ -290,6 +300,7 @@ + Returns [code]true[/code] if this is an instance load placeholder. See [InstancePlaceholder]. @@ -354,7 +365,7 @@ - Returns [code]true[/code] if this node is in the specified group. + Returns [code]true[/code] if this node is in the specified group. See notes in the description, and the group methods in [SceneTree]. @@ -368,6 +379,7 @@ + Returns [code]true[/code] if the local system is the master of this node. @@ -381,6 +393,7 @@ + Returns [code]true[/code] if internal physics processing is enabled (see [method set_physics_process_internal]). @@ -401,6 +414,7 @@ + Returns [code]true[/code] if internal processing is enabled (see [method set_process_internal]). @@ -432,6 +446,7 @@ + Prints all stray nodes (nodes outside the [SceneTree]). Used for debugging. Works only in debug builds. @@ -522,7 +537,7 @@ - Removes a node from a group. + Removes a node from a group. See notes in the description, and the group methods in [SceneTree]. @@ -549,7 +564,7 @@ - Sends a remote procedure call request to all peers on the network (and locally), optionally sending additional data as arguments. Call request will be received by nodes with the same [NodePath]. + Sends a remote procedure call request for the given [code]method[/code] to peers on the network (and locally), optionally sending all additional arguments as arguments to the method called by the RPC. The call request will only be received by nodes with the same [NodePath], including the exact same node name. Behaviour depends on the RPC configuration for the given method, see [method rpc_config]. Methods are not exposed to RPCs by default. Also see [method rset] and [method rset_config] for properties. Returns an empty [Variant]. Note that you can only safely use RPCs on clients after you received the [code]connected_to_server[/code] signal from the [SceneTree]. You also need to keep track of the connection state, either by the [SceneTree] signals like [code]server_disconnected[/code] or by checking [code]SceneTree.network_peer.get_connection_status() == CONNECTION_CONNECTED[/code]. @@ -560,7 +575,7 @@ - Changes the method's RPC mode (one of RPC_MODE_* constants). + Changes the RPC mode for the given [code]method[/code] to the given [code]mode[/code]. See [enum RPCMode]. An alternative is annotating methods and properties with the corresponding keywords ([code]remote[/code], [code]sync[/code], [code]master[/code], [code]slave[/code]). By default, methods are not exposed to networking (and RPCs). Also see [method rset] and [method rset_config] for properties. @@ -571,7 +586,7 @@ - Sends a [method rpc] to a specific peer identified by [i]peer_id[/i]. + Sends a [method rpc] to a specific peer identified by [code]peer_id[/code]. Returns an empty [Variant]. @@ -580,7 +595,7 @@ - Sends a [method rpc] using an unreliable protocol. + Sends a [method rpc] using an unreliable protocol. Returns an empty [Variant]. @@ -591,7 +606,7 @@ - Sends a [method rpc] to a specific peer identified by [i]peer_id[/i] using an unreliable protocol. + Sends a [method rpc] to a specific peer identified by [code]peer_id[/code] using an unreliable protocol. Returns an empty [Variant]. @@ -602,7 +617,7 @@ - Remotely changes property's value on other peers (and locally). + Remotely changes a property's value on other peers (and locally). Behaviour depends on the RPC configuration for the given property, see [method rset_config]. Also see [method rpc] for RPCs for methods, most information applies to this method as well. @@ -613,7 +628,7 @@ - Changes the property's RPC mode (one of RPC_MODE_* constants). + Changes the RPC mode for the given [code]property[/code] to the given [code]mode[/code]. See [enum RPCMode]. An alternative is annotating methods and properties with the corresponding keywords ([code]remote[/code], [code]sync[/code], [code]master[/code], [code]slave[/code]). By default, properties are not exposed to networking (and RPCs). Also see [method rpc] and [method rpc_config] for methods. @@ -626,7 +641,7 @@ - Remotely changes property's value on a specific peer identified by [i]peer_id[/i]. + Remotely changes the property's value on a specific peer identified by [code]peer_id[/code]. @@ -637,7 +652,7 @@ - Remotely changes property's value on other peers (and locally) using an unreliable protocol. + Remotely changes the property's value on other peers (and locally) using an unreliable protocol. @@ -650,7 +665,7 @@ - Remotely changes property's value on a specific peer identified by [i]peer_id[/i] using an unreliable protocol. + Remotely changes property's value on a specific peer identified by [code]peer_id[/code] using an unreliable protocol. @@ -670,7 +685,7 @@ - Sets the node network master to the peer with the given peer ID. The network master is the peer that has authority over it on the network. Inherited from the parent node by default, which ultimately defaults to peer ID 1 (the server). + Sets the node's network master to the peer with the given peer ID. The network master is the peer that has authority over the node on the network. Useful in conjunction with the [code]master[/code] and [code]slave[/code] keywords. Inherited from the parent node by default, which ultimately defaults to peer ID 1 (the server). If [code]recursive[/code], the given peer is recursively set as the master for all children of this node. @@ -688,6 +703,7 @@ + Enables or disables internal physics for this node. Internal physics processing happens in isolation from the normal [method]_physics_process[/code] calls and is used by some nodes internally to guarantee proper functioning even if the node is paused or physics processing is disabled for scripting ([method set_physics_process]). Only useful for advanced uses to manipulate built-in nodes behaviour. @@ -714,6 +730,7 @@ + Enables or disabled internal processing for this node. Internal processing happens in isolation from the normal [method]_process[/code] calls and is used by some nodes internally to guarantee proper functioning even if the node is paused or processing is disabled for scripting ([method set_process]). Only useful for advanced uses to manipulate built-in nodes behaviour. @@ -740,6 +757,7 @@ + Sets whether this is an instance load placeholder. See [InstancePlaceholder]. @@ -748,13 +766,13 @@ When a scene is instanced from a file, its topmost node contains the filename from which it was loaded. - The name of the node. This name is unique among the siblings (other child nodes from the same parent). - When set to an existing name, the node will be automatically renamed + The name of the node. This name is unique among the siblings (other child nodes from the same parent). When set to an existing name, the node will be automatically renamed The node owner. A node can have any other node as owner (as long as it is a valid parent, grandparent, etc. ascending in the tree). When saving a node (using SceneSaver) all the nodes it owns will be saved with it. This allows for the creation of complex [SceneTree]s, with instancing and subinstancing. + Pause mode. How the node will behave if the [SceneTree] is paused. @@ -775,7 +793,7 @@ - Emitted when the node is still active but about to exit the tree. This is the right place for de-initialization. + Emitted when the node is still active but about to exit the tree. This is the right place for de-initialization (or a "destructor", if you will). @@ -823,33 +841,37 @@ Notification received when the node's [NodePath] changed. + Notification received when translations may have changed. Can be triggered by the user changing the locale. Can be used to respond to language changes, for example to change the UI strings on the fly. Useful when working with the built-in translation support, like [method Object.tr]. + Notification received every frame when the internal process flag is set (see [method set_process_internal]). + Notification received every frame when the internal physics process flag is set (see [method set_physics_process_internal]). + Used with [method rpc_config] or [method rset_config] to disable a method or property for all RPC calls, making it unavailable. Default for all methods. - Call a method remotely. + Used with [method rpc_config] or [method rset_config] to set a method to be called or a property to be changed only on the remote end, not locally. Analogous to the [code]remote[/code] keyword. - Call a method both remotely and locally. + Used with [method rpc_config] or [method rset_config] to set a method to be called or a property to be changed both on the remote end and locally. Analogous to the [code]sync[/code] keyword. - Call a method if the Node is Master. + Used with [method rpc_config] or [method rset_config] to set a method to be called or a property to be changed only on the network master for this node. Analogous to the [code]master[/code] keyword. See [method set_network_master]. - Call a method if the Node is Slave. + Used with [method rpc_config] or [method rset_config] to set a method to be called or a property to be changed only on slaves for this node. Analogous to the [code]slave[/code] keyword. See [method set_network_master]. - Inherits pause mode from parent. For root node, it is equivalent to PAUSE_MODE_STOP. + Inherits pause mode from the node's parent. For the root node, it is equivalent to PAUSE_MODE_STOP. Default. - Stop processing when SceneTree is paused. + Stop processing when the [SceneTree] is paused. - Continue to process regardless of SceneTree pause state. + Continue to process regardless of the [SceneTree] pause state. Duplicate the node's signals.