add send id system (#75)

addresses https://codeberg.org/StreamGraph/StreamGraph/issues/59#issuecomment-1572604

Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/75
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-02-22 07:23:25 +00:00 committed by yagich
parent c7e003ffe6
commit f57374f3e2
19 changed files with 34 additions and 24 deletions

View file

@ -20,6 +20,8 @@ var incoming_connections: Dictionary
## A list of [Port]s on this node. ## A list of [Port]s on this node.
var ports: Array[Port] var ports: Array[Port]
var _last_send_id: String
## The deck this node belongs to. ## The deck this node belongs to.
var _belonging_to: Deck var _belonging_to: Deck
## A unique identifier for this node. ## A unique identifier for this node.
@ -127,18 +129,26 @@ func remove_port(port_idx: int) -> void:
## Send data to all outgoing connections on port [param from_output_port]. ## Send data to all outgoing connections on port [param from_output_port].
func send(from_output_port: int, data: Variant, extra_data: Array = []) -> void: func send(from_output_port: int, data: Variant, send_id: String = UUID.v4()) -> void:
if outgoing_connections.get(from_output_port) == null: if outgoing_connections.get(from_output_port) == null:
return return
for node: String in outgoing_connections[from_output_port]: for node: String in outgoing_connections[from_output_port]:
for input_port: int in outgoing_connections[from_output_port][node]: for input_port: int in outgoing_connections[from_output_port][node]:
get_node(node)._receive(input_port, data, extra_data) get_node(node).handle_receive(input_port, data, send_id)
func handle_receive(to_input_port: int, data: Variant, send_id: String) -> void:
if send_id == _last_send_id:
return
_last_send_id = send_id
_receive(to_input_port, data)
## Virtual function that's called when this node receives data from another node's [method send] call. ## Virtual function that's called when this node receives data from another node's [method send] call.
@warning_ignore("unused_parameter") @warning_ignore("unused_parameter")
func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: func _receive(to_input_port: int, data: Variant) -> void:
pass pass

View file

@ -17,7 +17,7 @@ func _init():
func _receive(_to_input_port : int, data: Variant, _extra_data: Array = []) -> void: func _receive(_to_input_port : int, data: Variant) -> void:
thread = Thread.new() thread = Thread.new()
thread.start(handle_delay.bind(data)) thread.start(handle_delay.bind(data))

View file

@ -25,9 +25,9 @@ func _init() -> void:
) )
func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: func _receive(to_input_port: int, data: Variant) -> void:
if to_input_port != 1: if to_input_port != 1:
return return
if await resolve_input_port_value_async(0): if await resolve_input_port_value_async(0):
send(0, data, extra_data) send(0, data)

View file

@ -34,7 +34,7 @@ func _value_request(_on_port: int) -> Variant:
return a == b return a == b
func _receive(on_port: int, data: Variant, _extra_data: Array = []) -> void: func _receive(on_port: int, data: Variant) -> void:
if on_port == 0: if on_port == 0:
var b = await resolve_input_port_value_async(1) var b = await resolve_input_port_value_async(1)
if data == b: if data == b:

View file

@ -32,7 +32,7 @@ func _init() -> void:
) )
func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: func _receive(to_input_port: int, data: Variant) -> void:
if to_input_port != 1: if to_input_port != 1:
return return

View file

@ -34,7 +34,7 @@ func _init() -> void:
) )
func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> void: func _receive(to_input_port: int, _data: Variant) -> void:
if to_input_port != 2: if to_input_port != 2:
return return

View file

@ -73,8 +73,8 @@ func recalculate_ports() -> void:
extra_ports.append(port.port_type) extra_ports.append(port.port_type)
func _receive(to_input_port: int, data: Variant, extra_data: Array = []): func _receive(to_input_port: int, data: Variant):
input_node.send(get_input_ports()[to_input_port].index_of_type, data, extra_data) input_node.send(get_input_ports()[to_input_port].index_of_type, data)
func _value_request(from_port: int) -> Variant: func _value_request(from_port: int) -> Variant:

View file

@ -74,5 +74,5 @@ func _post_load() -> void:
) )
func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: func _receive(to_input_port: int, data: Variant) -> void:
group_node.send(group_node.get_output_ports()[to_input_port].index_of_type, data, extra_data) group_node.send(group_node.get_output_ports()[to_input_port].index_of_type, data)

View file

@ -26,7 +26,7 @@ func _init() -> void:
) )
func _receive(on_virtual_port: int, _data: Variant, _extra_data: Array = []) -> void: func _receive(on_virtual_port: int, _data: Variant) -> void:
if on_virtual_port != 0: if on_virtual_port != 0:
return return

View file

@ -46,7 +46,7 @@ func _init() -> void:
) )
func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> void: func _receive(to_input_port: int, _data: Variant) -> void:
#{ "scene_item_transform": { "alignment": 5, "bounds_alignment": 0, "bounds_height": 0, "bounds_type": "OBS_BOUNDS_NONE", "bounds_width": 0, "crop_bottom": 0, "crop_left": 0, "crop_right": 0, "crop_top": 0, "height": 257, "position_x": 1800, "position_y": 414, "rotation": 0, "scale_x": 1, "scale_y": 1, "source_height": 257, "source_width": 146, "width": 146 }} #{ "scene_item_transform": { "alignment": 5, "bounds_alignment": 0, "bounds_height": 0, "bounds_type": "OBS_BOUNDS_NONE", "bounds_width": 0, "crop_bottom": 0, "crop_left": 0, "crop_right": 0, "crop_top": 0, "height": 257, "position_x": 1800, "position_y": 414, "rotation": 0, "scale_x": 1, "scale_y": 1, "source_height": 257, "source_width": 146, "width": 146 }}
if to_input_port != 3: if to_input_port != 3:
return return

View file

@ -25,7 +25,7 @@ func _init() -> void:
) )
func _receive(on_input_port: int, _data: Variant, _extra_data: Array = []) -> void: func _receive(on_input_port: int, _data: Variant) -> void:
if on_input_port != 1: if on_input_port != 1:
return return

View file

@ -37,7 +37,7 @@ func _init() -> void:
) )
func _receive(on_virtual_port: int, _data: Variant, _extra_data: Array = []) -> void: func _receive(on_virtual_port: int, _data: Variant) -> void:
if on_virtual_port != 2: if on_virtual_port != 2:
return return

View file

@ -28,7 +28,7 @@ func _init() -> void:
add_input_port(DeckType.Types.BOOL, "Send", "button") add_input_port(DeckType.Types.BOOL, "Send", "button")
func _receive(to_input_port: int, data: Variant, _extra_data: Array = []) -> void: func _receive(to_input_port: int, data: Variant) -> void:
if to_input_port == 6: if to_input_port == 6:
send(0, false) send(0, false)
send(1, 1.0) send(1, 1.0)

View file

@ -23,7 +23,7 @@ func _init():
func _receive(to_input_port, _data: Variant, _extra_data: Array = []): func _receive(to_input_port, _data: Variant):
if to_input_port != 2: if to_input_port != 2:

View file

@ -19,7 +19,7 @@ func _init():
func _receive(to_input_port, _data: Variant, _extra_data: Array = []): func _receive(to_input_port, _data: Variant):
if to_input_port != 1: if to_input_port != 1:

View file

@ -19,7 +19,7 @@ func _init():
func _receive(to_input_port, _data: Variant, _extra_data: Array = []): func _receive(to_input_port, _data: Variant):
if to_input_port != 1: if to_input_port != 1:

View file

@ -17,7 +17,7 @@ func _init():
func _receive(to_input_port, _data: Variant, _extra_data: Array = []): func _receive(to_input_port, _data: Variant):
if to_input_port != 1: if to_input_port != 1:

View file

@ -28,7 +28,7 @@ func _init():
func _receive(to_input_port, _data: Variant, _extra_data: Array = []): func _receive(to_input_port, _data: Variant):
if to_input_port != 2: if to_input_port != 2:

View file

@ -13,5 +13,5 @@ func _init() -> void:
func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void: func _receive(to_input_port: int, data: Variant) -> void:
pass pass