MultiplayerAPIExtension

package
v0.0.0-...-5fa07e4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package MultiplayerAPIExtension provides methods for working with MultiplayerAPIExtension object instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advanced

type Advanced = class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

type Any

type Any interface {
	gd.IsClass
	AsMultiplayerAPIExtension() Instance
}

type Implementation

type Implementation = implementation

Implementation implements Interface with empty methods.

type Instance

type Instance [1]gdclass.MultiplayerAPIExtension

This class can be used to augment or replace the default [MultiplayerAPI] implementation via script or extensions. The following example augment the default implementation ([SceneMultiplayer]) by logging every RPC being made, and every object being configured for replication. [codeblocks] [gdscript] extends MultiplayerAPIExtension class_name LogMultiplayer

# We want to augment the default SceneMultiplayer. var base_multiplayer = SceneMultiplayer.new()

func _init():

# Just passthrough base signals (copied to var to avoid cyclic reference)
var cts = connected_to_server
var cf = connection_failed
var pc = peer_connected
var pd = peer_disconnected
base_multiplayer.connected_to_server.connect(func(): cts.emit())
base_multiplayer.connection_failed.connect(func(): cf.emit())
base_multiplayer.peer_connected.connect(func(id): pc.emit(id))
base_multiplayer.peer_disconnected.connect(func(id): pd.emit(id))

func _poll():

return base_multiplayer.poll()

# Log RPC being made and forward it to the default multiplayer. func _rpc(peer: int, object: Object, method: StringName, args: Array) -> Error:

print("Got RPC for %d: %s::%s(%s)" % [peer, object, method, args])
return base_multiplayer.rpc(peer, object, method, args)

# Log configuration add. E.g. root path (nullptr, NodePath), replication (Node, Spawner|Synchronizer), custom. func _object_configuration_add(object, config: Variant) -> Error:

if config is MultiplayerSynchronizer:
    print("Adding synchronization configuration for %s. Synchronizer: %s" % [object, config])
elif config is MultiplayerSpawner:
    print("Adding node %s to the spawn list. Spawner: %s" % [object, config])
return base_multiplayer.object_configuration_add(object, config)

# Log configuration remove. E.g. root path (nullptr, NodePath), replication (Node, Spawner|Synchronizer), custom. func _object_configuration_remove(object, config: Variant) -> Error:

if config is MultiplayerSynchronizer:
    print("Removing synchronization configuration for %s. Synchronizer: %s" % [object, config])
elif config is MultiplayerSpawner:
    print("Removing node %s from the spawn list. Spawner: %s" % [object, config])
return base_multiplayer.object_configuration_remove(object, config)

# These can be optional, but in our case we want to augment SceneMultiplayer, so forward everything. func _set_multiplayer_peer(p_peer: MultiplayerPeer):

base_multiplayer.multiplayer_peer = p_peer

func _get_multiplayer_peer() -> MultiplayerPeer:

return base_multiplayer.multiplayer_peer

func _get_unique_id() -> int:

return base_multiplayer.get_unique_id()

func _get_peer_ids() -> PackedInt32Array:

return base_multiplayer.get_peers()

[/gdscript] [/codeblocks] Then in your main scene or in an autoload call [method SceneTree.set_multiplayer] to start using your custom [MultiplayerAPI]: [codeblocks] [gdscript] # autoload.gd func _enter_tree():

# Sets our custom multiplayer as the main one in SceneTree.

get_tree().set_multiplayer(LogMultiplayer.new()) [/gdscript] [/codeblocks] Native extensions can alternatively use the [method MultiplayerAPI.set_default_interface] method during initialization to configure themselves as the default implementation.

See [Interface] for methods that can be overridden by a [Class] that extends it.

%!(EXTRA string=MultiplayerAPIExtension)

var Nil Instance

Nil is a nil/null instance of the class. Equivalent to the zero value.

func New

func New() Instance

func (Instance) AsMultiplayerAPI

func (self Instance) AsMultiplayerAPI() MultiplayerAPI.Instance

func (Instance) AsMultiplayerAPIExtension

func (self Instance) AsMultiplayerAPIExtension() Instance

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) AsRefCounted

func (self Instance) AsRefCounted() [1]gd.RefCounted

func (*Instance) UnsafePointer

func (self *Instance) UnsafePointer() unsafe.Pointer

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type Interface

type Interface interface {
	//Callback for [method MultiplayerAPI.poll].
	Poll() error
	//Called when the [member MultiplayerAPI.multiplayer_peer] is set.
	SetMultiplayerPeer(multiplayer_peer [1]gdclass.MultiplayerPeer)
	//Called when the [member MultiplayerAPI.multiplayer_peer] is retrieved.
	GetMultiplayerPeer() [1]gdclass.MultiplayerPeer
	//Callback for [method MultiplayerAPI.get_unique_id].
	GetUniqueId() int
	//Callback for [method MultiplayerAPI.get_peers].
	GetPeerIds() []int32
	//Callback for [method MultiplayerAPI.rpc].
	Rpc(peer int, obj Object.Instance, method string, args []any) error
	//Callback for [method MultiplayerAPI.get_remote_sender_id].
	GetRemoteSenderId() int
	//Callback for [method MultiplayerAPI.object_configuration_add].
	ObjectConfigurationAdd(obj Object.Instance, configuration any) error
	//Callback for [method MultiplayerAPI.object_configuration_remove].
	ObjectConfigurationRemove(obj Object.Instance, configuration any) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL