Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit bb9362f

Browse files
send positional data every 50ms
1 parent ad535d9 commit bb9362f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Scripts/Netcode/Server/GameServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public GameServer()
2525
TimerGameLoop.Elapsed += TimerGameLoopCallback;
2626
TimerGameLoop.AutoReset = true;
2727

28-
TimerNotifyClients = new Timer(2000);
28+
TimerNotifyClients = new Timer(50);
2929
TimerNotifyClients.Elapsed += TimerNotifyClientsCallback;
3030
TimerNotifyClients.AutoReset = true;
3131
}

Scripts/Scenes/Game/ClientPlayer.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public class ClientPlayer : OtherPlayer
1919
private float Delta { get; set; }
2020
private Direction DirectionHorizontal { get; set; }
2121
private Direction DirectionVertical { get; set; }
22+
private Direction PrevDirectionHorizontal { get; set; }
23+
private Direction PrevDirectionVertical { get; set; }
2224

2325
public override void _Ready()
2426
{
@@ -28,7 +30,7 @@ public override void _Ready()
2830

2931
if (GameClient.Running)
3032
{
31-
NotifyServerPlayerDirection = new Timer(500);
33+
NotifyServerPlayerDirection = new Timer(50);
3234
NotifyServerPlayerDirection.Elapsed += NotifyServerPlayerDirectionCallback;
3335
NotifyServerPlayerDirection.AutoReset = true;
3436
NotifyServerPlayerDirection.Enabled = true;
@@ -37,10 +39,16 @@ public override void _Ready()
3739

3840
public async void NotifyServerPlayerDirectionCallback(System.Object source, ElapsedEventArgs args)
3941
{
42+
if (DirectionHorizontal == PrevDirectionHorizontal && DirectionVertical == PrevDirectionVertical)
43+
return;
44+
4045
await GameClient.Send(ClientPacketOpcode.PlayerDirectionPressed, new CPacketPlayerDirectionPressed {
4146
DirectionHorizontal = DirectionHorizontal,
4247
DirectionVertical = DirectionVertical
4348
});
49+
50+
PrevDirectionHorizontal = DirectionHorizontal;
51+
PrevDirectionVertical = DirectionVertical;
4452
}
4553

4654
public override void _PhysicsProcess(float delta)

0 commit comments

Comments
 (0)