Minor improvements
This commit is contained in:
parent
b01ae8543b
commit
1f6c128893
@ -1,4 +1,5 @@
|
|||||||
class_name Connection
|
class_name Connection
|
||||||
|
|
||||||
var peer: PacketPeerUDP
|
var peer: PacketPeerUDP
|
||||||
|
var address: String
|
||||||
var last_packet: int
|
var last_packet: int
|
@ -24,6 +24,7 @@ func _process(_delta):
|
|||||||
server.poll()
|
server.poll()
|
||||||
now = Time.get_ticks_msec()
|
now = Time.get_ticks_msec()
|
||||||
|
|
||||||
|
# Accept new connections
|
||||||
while server.is_connection_available():
|
while server.is_connection_available():
|
||||||
var peer: PacketPeerUDP = server.take_connection()
|
var peer: PacketPeerUDP = server.take_connection()
|
||||||
var address := "%s:%d" % [peer.get_packet_ip(), peer.get_packet_port()]
|
var address := "%s:%d" % [peer.get_packet_ip(), peer.get_packet_port()]
|
||||||
@ -31,11 +32,13 @@ func _process(_delta):
|
|||||||
if !clients.has(address):
|
if !clients.has(address):
|
||||||
var connection = Connection.new()
|
var connection = Connection.new()
|
||||||
connection.peer = peer
|
connection.peer = peer
|
||||||
|
connection.address = address
|
||||||
clients[address] = connection
|
clients[address] = connection
|
||||||
peer_connected(address)
|
peer_connected(connection)
|
||||||
|
|
||||||
clients[address].last_packet = now
|
clients[address].last_packet = now
|
||||||
|
|
||||||
|
# Process packets from clients
|
||||||
for key in clients:
|
for key in clients:
|
||||||
var client = clients[key]
|
var client = clients[key]
|
||||||
var peer = client.peer
|
var peer = client.peer
|
||||||
@ -46,6 +49,7 @@ func _process(_delta):
|
|||||||
client.last_packet = now
|
client.last_packet = now
|
||||||
packet_count += 1
|
packet_count += 1
|
||||||
|
|
||||||
|
# Show statistics
|
||||||
if now > last_statistics + 1000:
|
if now > last_statistics + 1000:
|
||||||
for address in clients.keys():
|
for address in clients.keys():
|
||||||
var last_packet_time = clients[address].last_packet
|
var last_packet_time = clients[address].last_packet
|
||||||
@ -58,8 +62,8 @@ func _process(_delta):
|
|||||||
packet_count = 0
|
packet_count = 0
|
||||||
last_statistics = Time.get_ticks_msec()
|
last_statistics = Time.get_ticks_msec()
|
||||||
|
|
||||||
func peer_connected(_address: String):
|
func peer_connected(c: Connection):
|
||||||
pass
|
print("[Server] Connected: ", c.address)
|
||||||
|
|
||||||
func peer_disconnected(address: String):
|
func peer_disconnected(c: Connection):
|
||||||
print("TIMEOUT ", address)
|
print("[Server] Disconnected: ", c.address)
|
||||||
|
@ -1,2 +1,7 @@
|
|||||||
class_name Player
|
class_name Player
|
||||||
extends Character
|
extends Character
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
var controller := PlayerController.new()
|
||||||
|
controller.character = self
|
||||||
|
add_child(controller)
|
@ -1,7 +1,9 @@
|
|||||||
class_name PlayerController
|
class_name PlayerController
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
## The character that we're controlling.
|
||||||
@export var character: Character
|
@export var character: Character
|
||||||
|
|
||||||
var move: Vector2
|
var move: Vector2
|
||||||
|
|
||||||
func _input(_event):
|
func _input(_event):
|
||||||
|
Loading…
Reference in New Issue
Block a user