first iteration with authorative movement
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
extends Node3D
|
||||
|
||||
const template := "FPS: %d\nPing: %d ms"
|
||||
|
||||
var runner_scene := preload("res://scenes/runner.tscn")
|
||||
var _ping := 0.0
|
||||
var _runners_node: Node3D
|
||||
|
||||
func _ready() -> void:
|
||||
_runners_node = get_node("RunnersNode")
|
||||
|
||||
func spawn_player(player_id) -> void:
|
||||
if multiplayer.is_server():
|
||||
var runner = runner_scene.instantiate()
|
||||
runner.player_id = player_id
|
||||
runner.name = str(player_id)
|
||||
|
||||
_runners_node.add_child(runner)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if DisplayServer.get_name() == "headless":
|
||||
return
|
||||
|
||||
%RichTextLabel.text = template % [
|
||||
Engine.get_frames_per_second(),
|
||||
_ping,
|
||||
]
|
||||
|
||||
func _get_timestamp() -> int:
|
||||
return floor(Time.get_unix_time_from_system() * 1000)
|
||||
|
||||
func _on_ping_timer_timeout() -> void:
|
||||
if multiplayer.is_server():
|
||||
%PingTimer.stop()
|
||||
return
|
||||
|
||||
_ping_call.rpc_id(1, _get_timestamp())
|
||||
|
||||
@rpc("any_peer", "call_remote", "unreliable", 99)
|
||||
func _ping_call(timestamp: int) -> void:
|
||||
if multiplayer.is_server():
|
||||
_ping_call.rpc_id(multiplayer.get_remote_sender_id(), timestamp)
|
||||
return
|
||||
|
||||
_ping = _get_timestamp() - timestamp
|
||||
Reference in New Issue
Block a user