ping icons

This commit is contained in:
RandomityGuy 2024-07-04 01:32:53 +05:30
parent 98de4cff1c
commit d893ca30e6
4 changed files with 18 additions and 7 deletions

View file

@ -1938,6 +1938,7 @@ class Marble extends GameObject {
marbleUpdate.netFlags = this.netFlags; marbleUpdate.netFlags = this.netFlags;
marbleUpdate.gravityDirection = this.currentUp; marbleUpdate.gravityDirection = this.currentUp;
marbleUpdate.trapdoorUpdates = this.trapdoorContacts; marbleUpdate.trapdoorUpdates = this.trapdoorContacts;
marbleUpdate.pingTicks = connection != null ? connection.pingTicks : 0;
marbleUpdate.serialize(b); marbleUpdate.serialize(b);
this.trapdoorContacts = []; this.trapdoorContacts = [];

View file

@ -118,13 +118,14 @@ class ProfilerUI {
+ 'Server Move Queue Size: ${Net.isClient ? @:privateAccess MarbleGame.instance.world.lastMoves.myMarbleUpdate.moveQueueSize : 0}\n' + 'Server Move Queue Size: ${Net.isClient ? @:privateAccess MarbleGame.instance.world.lastMoves.myMarbleUpdate.moveQueueSize : 0}\n'
+ 'Last Sent Move: ${Net.isClient ? lastSentMove : 0}\n' + 'Last Sent Move: ${Net.isClient ? lastSentMove : 0}\n'
+ 'Last Ack Move: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.lastAckMoveId : 0}\n' + 'Last Ack Move: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.lastAckMoveId : 0}\n'
+ 'Move Ack RTT: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.ackRTT : 0}'; + 'Move Ack RTT: ${Net.isClient ? @:privateAccess Net.clientConnection.moveManager.ackRTT : 0}'
+ 'Ping: ${Net.clientConnection.pingTicks}';
} }
if (Net.isHost) { if (Net.isHost) {
var strs = []; var strs = [];
strs.push('World Ticks: ${MarbleGame.instance.world.timeState.ticks}'); strs.push('World Ticks: ${MarbleGame.instance.world.timeState.ticks}');
for (dc => cc in Net.clients) { for (dc => cc in Net.clients) {
strs.push('${cc.id} move: sz ${@:privateAccess cc.moveManager.getQueueSize()} avg ${@:privateAccess cc.moveManager.serverAvgMoveListSize}'); strs.push('${cc.id} move: sz ${@:privateAccess cc.moveManager.getQueueSize()} avg ${@:privateAccess cc.moveManager.serverAvgMoveListSize}, ping: ${cc.pingTicks}');
} }
instance.networkStats.text = strs.join('\n'); instance.networkStats.text = strs.join('\n');

View file

@ -716,6 +716,8 @@ class Net {
var marbleUpdatePacket = new MarbleUpdatePacket(); var marbleUpdatePacket = new MarbleUpdatePacket();
marbleUpdatePacket.deserialize(input); marbleUpdatePacket.deserialize(input);
var cc = marbleUpdatePacket.clientId; var cc = marbleUpdatePacket.clientId;
var client = cc != Net.clientId ? clientIdMap[cc] : Net.clientConnection;
client.pingTicks = marbleUpdatePacket.pingTicks;
if (MarbleGame.instance.world != null && !MarbleGame.instance.world._disposed) { if (MarbleGame.instance.world != null && !MarbleGame.instance.world._disposed) {
var m = MarbleGame.instance.world.lastMoves; var m = MarbleGame.instance.world.lastMoves;
m.enqueue(marbleUpdatePacket); m.enqueue(marbleUpdatePacket);
@ -726,9 +728,13 @@ class Net {
var movePacket = new MarbleMovePacket(); var movePacket = new MarbleMovePacket();
movePacket.deserialize(input); movePacket.deserialize(input);
var cc = clientIdMap[movePacket.clientId]; var cc = clientIdMap[movePacket.clientId];
if (cc.state == GAME) if (cc.state == GAME) {
var startRecvId = cc.moveManager.getQueueSize();
for (move in movePacket.moves) for (move in movePacket.moves)
cc.queueMove(move); cc.queueMove(move);
var endRecvId = cc.moveManager.getQueueSize();
cc.pingTicks = movePacket.moves.length - (endRecvId - startRecvId);
}
} }
case PowerupPickup: case PowerupPickup:

View file

@ -71,16 +71,18 @@ class MarbleUpdatePacket implements NetPacket {
var oob:Bool; var oob:Bool;
var powerUpId:Int; var powerUpId:Int;
var moveQueueSize:Int; var moveQueueSize:Int;
var pingTicks:Int;
var netFlags:Int; var netFlags:Int;
var trapdoorUpdates:Map<Int, Int> = []; var trapdoorUpdates:Map<Int, Int> = [];
public function new() {} public function new() {}
public inline function serialize(b:OutputBitStream) { public inline function serialize(b:OutputBitStream) {
b.writeByte(clientId); b.writeInt(clientId, 6);
MoveManager.packMove(move, b); MoveManager.packMove(move, b);
b.writeUInt16(serverTicks); b.writeUInt16(serverTicks);
b.writeByte(moveQueueSize); b.writeInt(moveQueueSize, 6);
b.writeInt(pingTicks, 6);
b.writeFloat(position.x); b.writeFloat(position.x);
b.writeFloat(position.y); b.writeFloat(position.y);
b.writeFloat(position.z); b.writeFloat(position.z);
@ -160,10 +162,11 @@ class MarbleUpdatePacket implements NetPacket {
} }
public inline function deserialize(b:InputBitStream) { public inline function deserialize(b:InputBitStream) {
clientId = b.readByte(); clientId = b.readInt(6);
move = MoveManager.unpackMove(b); move = MoveManager.unpackMove(b);
serverTicks = b.readUInt16(); serverTicks = b.readUInt16();
moveQueueSize = b.readByte(); moveQueueSize = b.readInt(6);
pingTicks = b.readInt(6);
position = new Vector(b.readFloat(), b.readFloat(), b.readFloat()); position = new Vector(b.readFloat(), b.readFloat(), b.readFloat());
velocity = new Vector(b.readFloat(), b.readFloat(), b.readFloat()); velocity = new Vector(b.readFloat(), b.readFloat(), b.readFloat());
omega = new Vector(b.readFloat(), b.readFloat(), b.readFloat()); omega = new Vector(b.readFloat(), b.readFloat(), b.readFloat());