Added thread safe packet handlers
This commit is contained in:
@ -9,10 +9,14 @@ var history: Array[float] = []
|
||||
|
||||
func _init():
|
||||
history.resize(HISTORY_SIZE)
|
||||
thread_safe = true
|
||||
|
||||
func handle_packet(data: PackedByteArray):
|
||||
var id := data[0]
|
||||
var ping := get_time() - history[id]
|
||||
var ping := Time.get_unix_time_from_system() - history[id]
|
||||
emit.call_deferred(ping)
|
||||
|
||||
func emit(ping: float):
|
||||
changed.emit(ping)
|
||||
|
||||
func send_ping():
|
||||
@ -20,9 +24,6 @@ func send_ping():
|
||||
buffer.put_u8(Packet.PING)
|
||||
buffer.put_u8(count)
|
||||
%Client.send(buffer.data_array)
|
||||
history[count] = get_time()
|
||||
history[count] = Time.get_unix_time_from_system()
|
||||
count = (count + 1) % HISTORY_SIZE
|
||||
|
||||
func get_time() -> float:
|
||||
return Time.get_unix_time_from_system()
|
||||
|
||||
|
Reference in New Issue
Block a user