Skip to content

Commit

Permalink
display ping
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathaneeckhout committed Feb 12, 2024
1 parent 1b77223 commit e8fc0c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
14 changes: 7 additions & 7 deletions scenes/player/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2050,11 +2050,11 @@ inventory = NodePath("../Inventory")

[node name="DebugPanel" parent="Camera2D/UILayer" node_paths=PackedStringArray("player") instance=ExtResource("38_607x8")]
visible = false
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -32.0
offset_right = 32.0
offset_bottom = 104.0
grow_horizontal = 2
anchors_preset = 1
anchor_left = 1.0
anchor_right = 1.0
offset_left = -512.0
offset_bottom = 256.0
grow_horizontal = 0
mouse_filter = 1
player = NodePath("../../..")
6 changes: 4 additions & 2 deletions scenes/player/debugpanel/DebugPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func _ready():
_plot_timer.timeout.connect(_on_plot_timer_timeout)
add_child(_plot_timer)

_my_plot_in = $Graph2D.add_plot_item("Kbps in", Color.GREEN, 1.0)
_my_plot_out = $Graph2D.add_plot_item("Kpbs out", Color.RED, 1.0)
_my_plot_in = %Graph2D.add_plot_item("Kbps in", Color.GREEN, 1.0)
_my_plot_out = %Graph2D.add_plot_item("Kpbs out", Color.RED, 1.0)


func _input(event):
Expand Down Expand Up @@ -89,3 +89,5 @@ func _on_plot_timer_timeout():
for i in range(_out_buffer.size() - 1, -1, -1):
var element: Array = _out_buffer[i]
_my_plot_out.add_point(Vector2(_clock_synchronizer.client_clock - element[1], element[0]))

%Ping.text = "Ping: %.2f" % (_clock_synchronizer.latency * 500) # 1000/2 = 500
12 changes: 10 additions & 2 deletions scenes/player/debugpanel/DebugPanel.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
[node name="DebugPanel" type="PanelContainer"]
script = ExtResource("1_0jtlh")

[node name="Graph2D" type="Control" parent="."]
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 2

[node name="Graph2D" type="Control" parent="VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(512, 256)
layout_mode = 2
script = ExtResource("2_8kj31")
x_max = 60.0
y_max = 10.0
background_color = Color(0, 0, 0, 0.501961)
background_color = Color(0, 0, 0, 0.25098)

[node name="Ping" type="Label" parent="VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "Ping: 0.00 ms"

0 comments on commit e8fc0c2

Please sign in to comment.