From 00d851a4e8d1956aea183cdc088e0b74160e7ad0 Mon Sep 17 00:00:00 2001 From: Florent Berthaut <florent.berthaut@univ-lille.fr> Date: Tue, 10 Oct 2023 18:51:03 +0200 Subject: [PATCH] Fixed network on godot4 --- README.md | 16 ++++++++++------ core/IvmiScene.gd | 12 +++++++----- core/net/IvmiDiscov.gd | 7 +++++-- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d4ec284..81a144b 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ IvmiScene provides a number of settings to help you design immersive instruments * XR Mode * ... + ### IVMI-node IVMI-node are the main components of any IVMI instruments. IVMI-node contains IVMI-properties. By inheriting IVMI-node.gd you are able to define a specific behavior/feedback for each IVMI-property change that occur within the node. You can for example write a code that change the size of the node's mesh when the node is selected. @@ -115,18 +116,21 @@ IVMI-node are the main components of any IVMI instruments. IVMI-node contains IV extends IvmiNode func _ready(): - #Optionally define a node type + # Call default IvmiNode constructor + super._ready() + + # Optionally define a node type _set_ivmi_type("my_node") - #Add custom properties with array of values + # Add custom properties with array of values _add_property("selected", [0]) -func set_property(prop, vals) : - #call default properties handling - super.set_property(prop, vals) +func _set_property(prop, vals) : + # Call default properties handling + super._set_property(prop, vals) - #handle custom properties + # Handle custom properties if prop == "selected": if vals[0]: get_node("MeshInstance").scale.x = 3 diff --git a/core/IvmiScene.gd b/core/IvmiScene.gd index c56a78f..be13df7 100644 --- a/core/IvmiScene.gd +++ b/core/IvmiScene.gd @@ -278,11 +278,13 @@ func _on_found_server(server_ip, port) : #_network_client.connect_to_server(server_ip, port) pass NetProto.Enet : - print("IVMI : Connecting to server ", server_ip, " ", port) - var peer = ENetMultiplayerPeer.new() - peer.create_client(server_ip, port) - multiplayer.multiplayer_peer = peer - multiplayer.connected_to_server.connect(_on_network_ready) + if !_is_connected or _server_ip!=server_ip : + print("IVMI : Connecting to server ", server_ip, " ", port) + var peer = ENetMultiplayerPeer.new() + _server_ip=server_ip + peer.create_client(server_ip, port) + multiplayer.multiplayer_peer = peer + multiplayer.connected_to_server.connect(_on_network_ready) func _on_timeout() : diff --git a/core/net/IvmiDiscov.gd b/core/net/IvmiDiscov.gd index 2bf8d10..c80801c 100644 --- a/core/net/IvmiDiscov.gd +++ b/core/net/IvmiDiscov.gd @@ -25,8 +25,11 @@ func start() : print("IVMI : Starting Network Discovery") var mcadd = "239.215.216.217" var mcprt = 8173 + if _is_server : + _osc_discov.set_output(mcadd, mcprt) + else : + _osc_discov.set_input_port(mcprt) _osc_discov.set_multicast(mcadd) - _osc_discov.set_output(mcadd, mcprt) #retrieve local address _local_addr = "127.0.0.1" @@ -39,7 +42,7 @@ func _process(delta) : if _is_server : _ping_time+=delta if _ping_time>5.0 : - _osc_discov.send_msg("/ivmi/hello_from_server","s",[_local_addr, _port]) + _osc_discov.send_msg("/ivmi/hello_from_server","sf",[_local_addr, _port]) _ping_time=0 while _osc_discov.has_msg() : var msg = _osc_discov.get_msg() -- GitLab