38 lines
833 B
GDScript3
Raw Normal View History

2024-01-14 12:22:14 +01:00
extends Label
const HISTORY_SIZE = 8
var pingCount := 0
var pingSent: Array[float] = []
func _ready():
var timer := Timer.new()
add_child(timer)
timer.wait_time = 1
timer.connect("timeout", self._ping)
timer.start()
pingSent.resize(HISTORY_SIZE)
func _process(_delta):
2024-01-15 17:08:26 +01:00
pass
#if Client.udp.get_available_packet_count() > 0:
#var bytes := Client.udp.get_packet()
#var count := bytes.decode_u8(1)
#var timeSent := pingSent[count]
#var duration := Time.get_unix_time_from_system() - timeSent
#var ping := duration * 1000
#text = str(snapped(ping, 0.01))
2024-01-14 12:22:14 +01:00
func _ping():
var buffer := StreamPeerBuffer.new()
2024-01-15 17:08:26 +01:00
buffer.put_8(1)
2024-01-14 12:22:14 +01:00
buffer.put_8(pingCount)
Client.udp.put_packet(buffer.data_array)
pingSent[pingCount] = Time.get_unix_time_from_system()
pingCount += 1
if pingCount >= HISTORY_SIZE:
pingCount = 0