2
0

MultiplayerReplicator.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="MultiplayerReplicator" inherits="Object" version="4.0">
  3. <brief_description>
  4. </brief_description>
  5. <description>
  6. </description>
  7. <tutorials>
  8. </tutorials>
  9. <methods>
  10. <method name="decode_state">
  11. <return type="int" enum="Error" />
  12. <argument index="0" name="scene_id" type="int" />
  13. <argument index="1" name="object" type="Object" />
  14. <argument index="2" name="data" type="PackedByteArray" />
  15. <argument index="3" name="initial" type="bool" default="true" />
  16. <description>
  17. 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].
  18. 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].
  19. </description>
  20. </method>
  21. <method name="despawn">
  22. <return type="int" enum="Error" />
  23. <argument index="0" name="scene_id" type="int" />
  24. <argument index="1" name="object" type="Object" />
  25. <argument index="2" name="peer_id" type="int" default="0" />
  26. <description>
  27. 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.
  28. </description>
  29. </method>
  30. <method name="encode_state">
  31. <return type="PackedByteArray" />
  32. <argument index="0" name="scene_id" type="int" />
  33. <argument index="1" name="object" type="Object" />
  34. <argument index="2" name="initial" type="bool" default="true" />
  35. <description>
  36. 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].
  37. 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].
  38. </description>
  39. </method>
  40. <method name="send_despawn">
  41. <return type="int" enum="Error" />
  42. <argument index="0" name="peer_id" type="int" />
  43. <argument index="1" name="scene_id" type="int" />
  44. <argument index="2" name="data" type="Variant" default="null" />
  45. <argument index="3" name="path" type="NodePath" default="NodePath(&quot;&quot;)" />
  46. <description>
  47. 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_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.
  48. </description>
  49. </method>
  50. <method name="send_spawn">
  51. <return type="int" enum="Error" />
  52. <argument index="0" name="peer_id" type="int" />
  53. <argument index="1" name="scene_id" type="int" />
  54. <argument index="2" name="data" type="Variant" default="null" />
  55. <argument index="3" name="path" type="NodePath" default="NodePath(&quot;&quot;)" />
  56. <description>
  57. 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_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.
  58. </description>
  59. </method>
  60. <method name="send_sync">
  61. <return type="int" enum="Error" />
  62. <argument index="0" name="peer_id" type="int" />
  63. <argument index="1" name="scene_id" type="int" />
  64. <argument index="2" name="data" type="PackedByteArray" />
  65. <argument index="3" name="transfer_mode" type="int" enum="TransferMode" default="2" />
  66. <argument index="4" name="channel" type="int" default="0" />
  67. <description>
  68. 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]).
  69. </description>
  70. </method>
  71. <method name="spawn">
  72. <return type="int" enum="Error" />
  73. <argument index="0" name="scene_id" type="int" />
  74. <argument index="1" name="object" type="Object" />
  75. <argument index="2" name="peer_id" type="int" default="0" />
  76. <description>
  77. 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.
  78. </description>
  79. </method>
  80. <method name="spawn_config">
  81. <return type="int" enum="Error" />
  82. <argument index="0" name="scene_id" type="int" />
  83. <argument index="1" name="spawn_mode" type="int" enum="MultiplayerReplicator.ReplicationMode" />
  84. <argument index="2" name="properties" type="StringName[]" default="[]" />
  85. <argument index="3" name="custom_send" type="Callable" />
  86. <argument index="4" name="custom_receive" type="Callable" />
  87. <description>
  88. 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.
  89. Tip: You can use a custom property in the scene main script to return a customly optimized state representation.
  90. </description>
  91. </method>
  92. <method name="sync_all">
  93. <return type="int" enum="Error" />
  94. <argument index="0" name="scene_id" type="int" />
  95. <argument index="1" name="peer_id" type="int" default="0" />
  96. <description>
  97. 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].
  98. [b]Note:[/b] The default implementation only allow syncing from server to clients.
  99. </description>
  100. </method>
  101. <method name="sync_config">
  102. <return type="int" enum="Error" />
  103. <argument index="0" name="scene_id" type="int" />
  104. <argument index="1" name="interval" type="int" />
  105. <argument index="2" name="properties" type="StringName[]" default="[]" />
  106. <argument index="3" name="custom_send" type="Callable" />
  107. <argument index="4" name="custom_receive" type="Callable" />
  108. <description>
  109. 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.
  110. 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).
  111. </description>
  112. </method>
  113. <method name="track">
  114. <return type="void" />
  115. <argument index="0" name="scene_id" type="int" />
  116. <argument index="1" name="object" type="Object" />
  117. <description>
  118. 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].
  119. </description>
  120. </method>
  121. <method name="untrack">
  122. <return type="void" />
  123. <argument index="0" name="scene_id" type="int" />
  124. <argument index="1" name="object" type="Object" />
  125. <description>
  126. 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].
  127. </description>
  128. </method>
  129. </methods>
  130. <signals>
  131. <signal name="despawn_requested">
  132. <argument index="0" name="id" type="int" />
  133. <argument index="1" name="scene_id" type="int" />
  134. <argument index="2" name="parent" type="Node" />
  135. <argument index="3" name="name" type="String" />
  136. <argument index="4" name="data" type="PackedByteArray" />
  137. <description>
  138. 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].
  139. </description>
  140. </signal>
  141. <signal name="despawned">
  142. <argument index="0" name="scene_id" type="int" />
  143. <argument index="1" name="node" type="Node" />
  144. <description>
  145. Emitted on a client before deleting a local Node upon receiving a despawn request from the server.
  146. </description>
  147. </signal>
  148. <signal name="replicated_instance_added">
  149. <argument index="0" name="scene_id" type="int" />
  150. <argument index="1" name="node" type="Node" />
  151. <description>
  152. Emitted when an instance of a [PackedScene] that has been configured for networking enters the [SceneTree]. See [method spawn_config].
  153. </description>
  154. </signal>
  155. <signal name="replicated_instance_removed">
  156. <argument index="0" name="scene_id" type="int" />
  157. <argument index="1" name="node" type="Node" />
  158. <description>
  159. Emitted when an instance of a [PackedScene] that has been configured for networking leaves the [SceneTree]. See [method spawn_config].
  160. </description>
  161. </signal>
  162. <signal name="spawn_requested">
  163. <argument index="0" name="id" type="int" />
  164. <argument index="1" name="scene_id" type="int" />
  165. <argument index="2" name="parent" type="Node" />
  166. <argument index="3" name="name" type="String" />
  167. <argument index="4" name="data" type="PackedByteArray" />
  168. <description>
  169. 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].
  170. </description>
  171. </signal>
  172. <signal name="spawned">
  173. <argument index="0" name="scene_id" type="int" />
  174. <argument index="1" name="node" type="Node" />
  175. <description>
  176. Emitted on a client after a new Node is instantiated locally and added to the SceneTree upon receiving a spawn request from the server.
  177. </description>
  178. </signal>
  179. </signals>
  180. <constants>
  181. <constant name="REPLICATION_MODE_NONE" value="0" enum="ReplicationMode">
  182. Used with [method spawn_config] to identify a [PackedScene] that should not be replicated.
  183. </constant>
  184. <constant name="REPLICATION_MODE_SERVER" value="1" enum="ReplicationMode">
  185. Used with [method spawn_config] to identify a [PackedScene] that should be automatically replicated from server to clients.
  186. </constant>
  187. <constant name="REPLICATION_MODE_CUSTOM" value="2" enum="ReplicationMode">
  188. Used with [method spawn_config] to identify a [PackedScene] that can be manually replicated among peers.
  189. </constant>
  190. </constants>
  191. </class>