Added upload and download statistics
This commit is contained in:
parent
8370afd9a1
commit
252d55b30f
@ -3,7 +3,11 @@ extends NetworkNode
|
||||
@export var host: String
|
||||
@export var port: int
|
||||
|
||||
signal download_changed(down: int)
|
||||
signal upload_changed(up: int)
|
||||
|
||||
var socket := PacketPeerUDP.new()
|
||||
var upload := 0
|
||||
|
||||
func _enter_tree():
|
||||
socket.connect_to_host(host, port)
|
||||
@ -17,4 +21,14 @@ func _enter_tree():
|
||||
func _process(_delta):
|
||||
while socket.get_available_packet_count() > 0:
|
||||
var packet := socket.get_packet()
|
||||
handle_packet(packet, socket)
|
||||
handle_packet(packet, socket)
|
||||
|
||||
func update_statistics():
|
||||
download_changed.emit(download)
|
||||
upload_changed.emit(upload)
|
||||
download = 0
|
||||
upload = 0
|
||||
|
||||
func send(data: PackedByteArray):
|
||||
socket.put_packet(data)
|
||||
upload += data.size()
|
@ -32,7 +32,7 @@ func send_login():
|
||||
var buffer := StreamPeerBuffer.new()
|
||||
buffer.put_8(Packet.LOGIN)
|
||||
buffer.put_data(JSON.stringify([Global.username, password]).to_utf8_buffer())
|
||||
%Client.socket.put_packet(buffer.data_array)
|
||||
%Client.send(buffer.data_array)
|
||||
print("[%s] Connecting..." % Global.username)
|
||||
|
||||
func is_logged_in() -> bool:
|
||||
|
@ -19,7 +19,7 @@ func send_ping():
|
||||
var buffer := StreamPeerBuffer.new()
|
||||
buffer.put_8(Packet.PING)
|
||||
buffer.put_8(count)
|
||||
%Client.socket.put_packet(buffer.data_array)
|
||||
%Client.send(buffer.data_array)
|
||||
history[count] = get_time()
|
||||
count += 1
|
||||
|
||||
|
@ -40,4 +40,4 @@ func send_position():
|
||||
buffer.put_float(Global.player.position.x)
|
||||
# buffer.put_float(Global.player.position.y)
|
||||
buffer.put_float(Global.player.position.z)
|
||||
%Client.socket.put_packet(buffer.data_array)
|
||||
%Client.send(buffer.data_array)
|
||||
|
@ -2,6 +2,7 @@ class_name NetworkNode
|
||||
extends Node
|
||||
|
||||
var handlers: Array[Node] = []
|
||||
var download := 0
|
||||
|
||||
func _init():
|
||||
handlers.resize(256)
|
||||
@ -21,3 +22,4 @@ func handle_packet(packet: PackedByteArray, peer: PacketPeer):
|
||||
return
|
||||
|
||||
handler.handle_packet(packet.slice(1), peer)
|
||||
download += packet.size()
|
||||
|
@ -1,6 +1,10 @@
|
||||
extends Control
|
||||
|
||||
var on_ping_changed: Signal
|
||||
var on_download_changed: Signal
|
||||
var on_upload_changed: Signal
|
||||
|
||||
func _enter_tree():
|
||||
on_ping_changed = %Ping.changed
|
||||
on_ping_changed = %Ping.changed
|
||||
on_download_changed = %Client.download_changed
|
||||
on_upload_changed = %Client.upload_changed
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://dagn5bf7ou3sd"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://dagn5bf7ou3sd"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cch67vqpsmtej" path="res://ui/debug/DebugLabel.tscn" id="1_7s8uu"]
|
||||
[ext_resource type="Script" path="res://ui/UI.gd" id="1_l5b6o"]
|
||||
@ -6,6 +6,8 @@
|
||||
[ext_resource type="Script" path="res://ui/debug/PingLabel.gd" id="3_xjdws"]
|
||||
[ext_resource type="Script" path="res://ui/debug/PositionLabel.gd" id="4_beqf6"]
|
||||
[ext_resource type="Script" path="res://ui/debug/VelocityLabel.gd" id="5_8lm6a"]
|
||||
[ext_resource type="Script" path="res://ui/debug/UploadLabel.gd" id="7_cfnpx"]
|
||||
[ext_resource type="Script" path="res://ui/debug/DownloadLabel.gd" id="8_ogt38"]
|
||||
|
||||
[node name="UI" type="Control"]
|
||||
layout_mode = 3
|
||||
@ -47,3 +49,11 @@ script = ExtResource("4_beqf6")
|
||||
[node name="Velocity" parent="CanvasLayer/BottomLeftMargin/VBoxContainer" instance=ExtResource("1_7s8uu")]
|
||||
layout_mode = 2
|
||||
script = ExtResource("5_8lm6a")
|
||||
|
||||
[node name="Send" parent="CanvasLayer/BottomLeftMargin/VBoxContainer" instance=ExtResource("1_7s8uu")]
|
||||
layout_mode = 2
|
||||
script = ExtResource("7_cfnpx")
|
||||
|
||||
[node name="Receive" parent="CanvasLayer/BottomLeftMargin/VBoxContainer" instance=ExtResource("1_7s8uu")]
|
||||
layout_mode = 2
|
||||
script = ExtResource("8_ogt38")
|
||||
|
7
client/ui/debug/DownloadLabel.gd
Normal file
7
client/ui/debug/DownloadLabel.gd
Normal file
@ -0,0 +1,7 @@
|
||||
extends DebugLabel
|
||||
|
||||
func _ready():
|
||||
owner.on_download_changed.connect(on_download_changed)
|
||||
|
||||
func on_download_changed(download):
|
||||
text = "%d bytes" % download
|
7
client/ui/debug/UploadLabel.gd
Normal file
7
client/ui/debug/UploadLabel.gd
Normal file
@ -0,0 +1,7 @@
|
||||
extends DebugLabel
|
||||
|
||||
func _ready():
|
||||
owner.on_upload_changed.connect(on_upload_changed)
|
||||
|
||||
func on_upload_changed(upload):
|
||||
text = "%d bytes" % upload
|
@ -57,6 +57,9 @@ packet_type = 10
|
||||
script = ExtResource("7_rjgcp")
|
||||
packet_type = 12
|
||||
|
||||
[node name="Statistics" type="Timer" parent="Client"]
|
||||
autostart = true
|
||||
|
||||
[node name="World" type="Node3D" parent="."]
|
||||
|
||||
[node name="Sun" type="DirectionalLight3D" parent="World"]
|
||||
@ -130,3 +133,4 @@ mesh = SubResource("QuadMesh_7yiqd")
|
||||
|
||||
[connection signal="timeout" from="Client/Ping/Timer" to="Client/Ping" method="send_ping"]
|
||||
[connection signal="timeout" from="Client/Login/Timer" to="Client/Login" method="send_login"]
|
||||
[connection signal="timeout" from="Client/Statistics" to="Client" method="update_statistics"]
|
||||
|
Loading…
Reference in New Issue
Block a user