summaryrefslogtreecommitdiff
path: root/doc/classes/MultiplayerReplicator.xml
blob: 0778a7335f8cd523a3d606a9b82bc7f3f12583e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?xml version="1.0" encoding="UTF-8" ?>
<class name="MultiplayerReplicator" inherits="Object" version="4.0">
	<brief_description>
	</brief_description>
	<description>
	</description>
	<tutorials>
	</tutorials>
	<methods>
		<method name="decode_state">
			<return type="int" enum="Error" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="object" type="Object" />
			<argument index="2" name="data" type="PackedByteArray" />
			<argument index="3" name="initial" type="bool" default="true" />
			<description>
				Decode the given [code]data[/code] representing a spawnable state into [code]object[/code] using the configuration associated with the provided [code]scene_id[/code]. This function is called automatically when a client receives a server spawn for a scene with [constant REPLICATION_MODE_SERVER]. See [method spawn_config].
				Tip: You may find this function useful in servers when parsing spawn requests from clients, or when implementing your own logic with [constant REPLICATION_MODE_CUSTOM].
			</description>
		</method>
		<method name="despawn">
			<return type="int" enum="Error" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="object" type="Object" />
			<argument index="2" name="peer_id" type="int" default="0" />
			<description>
				Request a despawn for the scene identified by [code]scene_id[/code] to the given [code]peer_id[/code]. This will either trigger the default behaviour, or invoke the custom spawn/despawn callables specified in [method spawn_config]. See [method send_despawn] for the default behavior.
			</description>
		</method>
		<method name="encode_state">
			<return type="PackedByteArray" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="object" type="Object" />
			<argument index="2" name="initial" type="bool" default="true" />
			<description>
				Encode the given [code]object[/code] using the configuration associated with the provided [code]scene_id[/code]. This function is called automatically when the server spawns scenes with [constant REPLICATION_MODE_SERVER]. See [method spawn_config].
				Tip: You may find this function useful when requesting spawns from clients to server, or when implementing your own logic with [constant REPLICATION_MODE_CUSTOM].
			</description>
		</method>
		<method name="send_despawn">
			<return type="int" enum="Error" />
			<argument index="0" name="peer_id" type="int" />
			<argument index="1" name="scene_id" type="int" />
			<argument index="2" name="data" type="Variant" default="null" />
			<argument index="3" name="path" type="NodePath" default="NodePath(&quot;&quot;)" />
			<description>
				Sends a despawn request for the scene identified by [code]scene_id[/code] to the given [code]peer_id[/code] (see [method MultiplayerPeer.set_target_peer]). If the scene is configured as [constant REPLICATION_MODE_SERVER] (see [method spawn_config]) and the request is sent by the server (see [method MultiplayerAPI.is_network_server]), the receiving peer(s) will automatically queue for deletion the node at [code]path[/code] and emit the signal [signal despawned]. In all other cases no deletion happens, and the signal [signal despawn_requested] is emitted instead.
			</description>
		</method>
		<method name="send_spawn">
			<return type="int" enum="Error" />
			<argument index="0" name="peer_id" type="int" />
			<argument index="1" name="scene_id" type="int" />
			<argument index="2" name="data" type="Variant" default="null" />
			<argument index="3" name="path" type="NodePath" default="NodePath(&quot;&quot;)" />
			<description>
				Sends a spawn request for the scene identified by [code]scene_id[/code] to the given [code]peer_id[/code] (see [method MultiplayerPeer.set_target_peer]). If the scene is configured as [constant REPLICATION_MODE_SERVER] (see [method spawn_config]) and the request is sent by the server (see [method MultiplayerAPI.is_network_server]), the receiving peer(s) will automatically instantiate that scene, add it to the [SceneTree] at the given [code]path[/code] and emit the signal [signal spawned]. In all other cases no instantiation happens, and the signal [signal spawn_requested] is emitted instead.
			</description>
		</method>
		<method name="send_sync">
			<return type="int" enum="Error" />
			<argument index="0" name="peer_id" type="int" />
			<argument index="1" name="scene_id" type="int" />
			<argument index="2" name="data" type="PackedByteArray" />
			<argument index="3" name="transfer_mode" type="int" enum="MultiplayerPeer.TransferMode" default="2" />
			<argument index="4" name="channel" type="int" default="0" />
			<description>
				Sends a sync request for the instances of the scene identified by [code]scene_id[/code] to the given [code]peer_id[/code] (see [method MultiplayerPeer.set_target_peer]). This function can only be called manually when overriding the send and receive sync functions (see [method sync_config]).
			</description>
		</method>
		<method name="spawn">
			<return type="int" enum="Error" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="object" type="Object" />
			<argument index="2" name="peer_id" type="int" default="0" />
			<description>
				Request a spawn for the scene identified by [code]scene_id[/code] to the given [code]peer_id[/code]. This will either trigger the default behaviour, or invoke the custom spawn/despawn callables specified in [method spawn_config]. See [method send_spawn] for the default behavior.
			</description>
		</method>
		<method name="spawn_config">
			<return type="int" enum="Error" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="spawn_mode" type="int" enum="MultiplayerReplicator.ReplicationMode" />
			<argument index="2" name="properties" type="StringName[]" default="[]" />
			<argument index="3" name="custom_send" type="Callable" />
			<argument index="4" name="custom_receive" type="Callable" />
			<description>
				Configures the MultiplayerReplicator to track instances of the [PackedScene] identified by [code]scene_id[/code] (see [method ResourceLoader.get_resource_uid]) for the purpose of network replication. When [code]mode[/code] is [constant REPLICATION_MODE_SERVER], the specified [code]properties[/code] will also be replicated to clients during the initial spawn. You can optionally specify a [code]custom_send[/code] and a [code]custom_receive[/code] to override the default behaviour and customize the spawn/despawn proecess.
				Tip: You can use a custom property in the scene main script to return a customly optimized state representation.
			</description>
		</method>
		<method name="sync_all">
			<return type="int" enum="Error" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="peer_id" type="int" default="0" />
			<description>
				Manually request a sync for all the instances of the scene identified by [code]scene_id[/code]. This function will trigger the default sync behaviour, or call your send custom send callable if specified in [method sync_config].
				Note: The default implementation only allow syncing from server to clients.
			</description>
		</method>
		<method name="sync_config">
			<return type="int" enum="Error" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="interval" type="int" />
			<argument index="2" name="properties" type="StringName[]" default="[]" />
			<argument index="3" name="custom_send" type="Callable" />
			<argument index="4" name="custom_receive" type="Callable" />
			<description>
				Configures the MultiplayerReplicator to sync instances of the [PackedScene] identified by [code]scene_id[/code] (see [method ResourceLoader.get_resource_uid]) for the purpose of network replication at the desired [code]interval[/code] (in milliseconds). The specified [code]properties[/code] will be part of the state sync. You can optionally specify a [code]custom_send[/code] and a [code]custom_receive[/code] to override the default behaviour and customize the syncronization proecess.
				Tip: You can use a custom property in the scene main script to return a customly optimized state representation (having a single property that returns a PackedByteArray is higly recommended when dealing with many instances).
			</description>
		</method>
		<method name="track">
			<return type="void" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="object" type="Object" />
			<description>
				Track the given [code]object[/code] as an instance of the scene identified by [code]scene_id[/code]. This object will be passed to your custom sync callables (see [method sync_config]). Tracking and untracking is automatic in [constant REPLICATION_MODE_SERVER].
			</description>
		</method>
		<method name="untrack">
			<return type="void" />
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="object" type="Object" />
			<description>
				Untrack the given [code]object[/code]. This object will no longer be passed to your custom sync callables (see [method sync_config]). Tracking and untracking is automatic in [constant REPLICATION_MODE_SERVER].
			</description>
		</method>
	</methods>
	<signals>
		<signal name="despawn_requested">
			<argument index="0" name="id" type="int" />
			<argument index="1" name="scene_id" type="int" />
			<argument index="2" name="parent" type="Node" />
			<argument index="3" name="name" type="String" />
			<argument index="4" name="data" type="PackedByteArray" />
			<description>
				Emitted when a network despawn request has been received from a client, or for a [PackedScene] that has been configured as [constant REPLICATION_MODE_CUSTOM].
			</description>
		</signal>
		<signal name="despawned">
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="node" type="Node" />
			<description>
				Emitted on a client before deleting a local Node upon receiving a despawn request from the server.
			</description>
		</signal>
		<signal name="replicated_instance_added">
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="node" type="Node" />
			<description>
				Emitted when an instance of a [PackedScene] that has been configured for networking enters the [SceneTree]. See [method spawn_config].
			</description>
		</signal>
		<signal name="replicated_instance_removed">
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="node" type="Node" />
			<description>
				Emitted when an instance of a [PackedScene] that has been configured for networking leaves the [SceneTree]. See [method spawn_config].
			</description>
		</signal>
		<signal name="spawn_requested">
			<argument index="0" name="id" type="int" />
			<argument index="1" name="scene_id" type="int" />
			<argument index="2" name="parent" type="Node" />
			<argument index="3" name="name" type="String" />
			<argument index="4" name="data" type="PackedByteArray" />
			<description>
				Emitted when a network spawn request has been received from a client, or for a [PackedScene] that has been configured as [constant REPLICATION_MODE_CUSTOM].
			</description>
		</signal>
		<signal name="spawned">
			<argument index="0" name="scene_id" type="int" />
			<argument index="1" name="node" type="Node" />
			<description>
				Emitted on a client after a new Node is instantiated locally and added to the SceneTree upon receiving a spawn request from the server.
			</description>
		</signal>
	</signals>
	<constants>
		<constant name="REPLICATION_MODE_NONE" value="0" enum="ReplicationMode">
			Used with [method spawn_config] to identify a [PackedScene] that should not be replicated.
		</constant>
		<constant name="REPLICATION_MODE_SERVER" value="1" enum="ReplicationMode">
			Used with [method spawn_config] to identify a [PackedScene] that should be automatically replicated from server to clients.
		</constant>
		<constant name="REPLICATION_MODE_CUSTOM" value="2" enum="ReplicationMode">
			Used with [method spawn_config] to identify a [PackedScene] that can be manually replicated among peers.
		</constant>
	</constants>
</class>