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

Commit

Permalink
send positional data every 50ms
Browse files Browse the repository at this point in the history
  • Loading branch information
valkyrienyanko committed Apr 26, 2022
1 parent ad535d9 commit bb9362f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Scripts/Netcode/Server/GameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public GameServer()
TimerGameLoop.Elapsed += TimerGameLoopCallback;
TimerGameLoop.AutoReset = true;

TimerNotifyClients = new Timer(2000);
TimerNotifyClients = new Timer(50);
TimerNotifyClients.Elapsed += TimerNotifyClientsCallback;
TimerNotifyClients.AutoReset = true;
}
Expand Down
10 changes: 9 additions & 1 deletion Scripts/Scenes/Game/ClientPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class ClientPlayer : OtherPlayer
private float Delta { get; set; }
private Direction DirectionHorizontal { get; set; }
private Direction DirectionVertical { get; set; }
private Direction PrevDirectionHorizontal { get; set; }
private Direction PrevDirectionVertical { get; set; }

public override void _Ready()
{
Expand All @@ -28,7 +30,7 @@ public override void _Ready()

if (GameClient.Running)
{
NotifyServerPlayerDirection = new Timer(500);
NotifyServerPlayerDirection = new Timer(50);
NotifyServerPlayerDirection.Elapsed += NotifyServerPlayerDirectionCallback;
NotifyServerPlayerDirection.AutoReset = true;
NotifyServerPlayerDirection.Enabled = true;
Expand All @@ -37,10 +39,16 @@ public override void _Ready()

public async void NotifyServerPlayerDirectionCallback(System.Object source, ElapsedEventArgs args)
{
if (DirectionHorizontal == PrevDirectionHorizontal && DirectionVertical == PrevDirectionVertical)
return;

await GameClient.Send(ClientPacketOpcode.PlayerDirectionPressed, new CPacketPlayerDirectionPressed {
DirectionHorizontal = DirectionHorizontal,
DirectionVertical = DirectionVertical
});

PrevDirectionHorizontal = DirectionHorizontal;
PrevDirectionVertical = DirectionVertical;
}

public override void _PhysicsProcess(float delta)
Expand Down

0 comments on commit bb9362f

Please sign in to comment.