Changed to vehicle sensor instead of single sensor types
This commit is contained in:
@@ -12,23 +12,55 @@ var last_broadcast = 0
|
||||
|
||||
var ip_address: String = ""
|
||||
|
||||
var thread: Thread
|
||||
var mutex: Mutex
|
||||
var signal_queue = []
|
||||
var exit_thread = false
|
||||
|
||||
func _ready():
|
||||
_try_set_ip()
|
||||
udp.set_broadcast_enabled(true)
|
||||
udp.set_dest_address("192.168.0.255", 5000)
|
||||
SensorSignals.new_sensor_connected.connect(_on_sensor_connected)
|
||||
|
||||
thread = Thread.new()
|
||||
mutex = Mutex.new()
|
||||
|
||||
thread.start(_thread_function)
|
||||
|
||||
func _process(delta):
|
||||
if ip_address.length() == 0:
|
||||
_try_set_ip()
|
||||
return
|
||||
func _process(delta: float) -> void:
|
||||
mutex.lock()
|
||||
last_broadcast += delta
|
||||
if last_broadcast >= current_broadcast_rate:
|
||||
# Try to contact server
|
||||
last_broadcast = 0
|
||||
var broadcast_str = ip_address + "|%s" % Time.get_datetime_string_from_system(true)
|
||||
print('Broadcasting to UDP: ', broadcast_str)
|
||||
udp.put_packet(broadcast_str.to_utf8_buffer())
|
||||
mutex.unlock()
|
||||
|
||||
func _exit_tree() -> void:
|
||||
mutex.lock()
|
||||
exit_thread = true
|
||||
mutex.unlock()
|
||||
thread.wait_to_finish()
|
||||
|
||||
func _thread_function():
|
||||
while true:
|
||||
mutex.lock()
|
||||
var should_exit = exit_thread
|
||||
mutex.unlock()
|
||||
if should_exit:
|
||||
break
|
||||
|
||||
if ip_address.length() == 0:
|
||||
_try_set_ip()
|
||||
return
|
||||
mutex.lock()
|
||||
var do_broadcast = last_broadcast >= current_broadcast_rate
|
||||
mutex.unlock()
|
||||
if do_broadcast:
|
||||
# Try to contact server
|
||||
mutex.lock()
|
||||
last_broadcast = 0
|
||||
mutex.unlock()
|
||||
var broadcast_str = ip_address + "|%s" % Time.get_datetime_string_from_system(true)
|
||||
print('Broadcasting to UDP: ', broadcast_str)
|
||||
udp.put_packet(broadcast_str.to_utf8_buffer())
|
||||
|
||||
func _try_set_ip():
|
||||
for address in IP.get_local_addresses():
|
||||
|
||||
Reference in New Issue
Block a user