Skip to content
This repository was archived by the owner on Oct 22, 2023. It is now read-only.

Commit e5f656a

Browse files
committed
Remove debug messages
Minor cleanup Tested with 0 Lagcompensation, 550 ms ping, 10% drop
1 parent 2b349ba commit e5f656a

File tree

12 files changed

+32
-56
lines changed

12 files changed

+32
-56
lines changed

Engine/Client/Simulation.cs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ public class Simulation
1515
/// <summary>
1616
/// Amount of ticks until a command gets executed
1717
/// </summary>
18-
public uint LagCompensation { get; set; } = 10;
18+
public uint LagCompensation { get; set; }
1919

2020
public byte LocalPlayerId { get; private set; }
2121

2222
public bool Running { get; set; }
2323

24-
public readonly ICommandBuffer RemoteCommandBuffer;
25-
private readonly ILogService _logger;
24+
public readonly ICommandBuffer RemoteCommandBuffer;
2625

2726
public float _tickDt;
2827
public float _accumulatedTime;
@@ -38,9 +37,7 @@ public Simulation(ISystems systems, ICommandBuffer remoteCommandBuffer)
3837
{
3938
_systems = systems;
4039

41-
RemoteCommandBuffer = remoteCommandBuffer;
42-
43-
_logger = systems.Services.Get<ILogService>();
40+
RemoteCommandBuffer = remoteCommandBuffer;
4441
}
4542

4643
public void Start(Init init)
@@ -73,10 +70,7 @@ public void Update(float deltaTime)
7370
_accumulatedTime += deltaTime;
7471

7572
while (_accumulatedTime >= _tickDt)
76-
{
77-
78-
_logger.Warn(" ========= " + (_systems.CurrentTick + 1) + " ========= ");
79-
73+
{
8074
Tick();
8175

8276
_accumulatedTime -= _tickDt;
@@ -108,9 +102,7 @@ private void SyncCommandBuffer()
108102
var currentRemoteFrame = RemoteCommandBuffer.LastInsertedFrame;
109103

110104
if (LastValidatedFrame < currentRemoteFrame)
111-
{
112-
_logger.Warn("Catching up: " + LastValidatedFrame + " -> " + currentRemoteFrame + " of " + _systems.CurrentTick);
113-
105+
{
114106
var revertFrame = currentRemoteFrame; //We guess everything was predicted correctly
115107

116108
for (var remoteFrame = LastValidatedFrame + 1; remoteFrame <= currentRemoteFrame; remoteFrame++)
@@ -124,39 +116,29 @@ private void SyncCommandBuffer()
124116

125117
if (remoteFrame < revertFrame)
126118
{
127-
//Store the first frame where predicion was false (frame has commands)
119+
//Store the first frame where prediction was false (frame has commands)
128120
revertFrame = remoteFrame;
129121
}
130122

131123
//Merge commands into the local command buffer
132124
foreach (var commandPerPlayer in allPlayerCommands)
133-
{
134-
135-
_logger.Warn("Insert remote commands from " + remoteFrame);
125+
{
136126
LocalCommandBuffer.Insert(remoteFrame, commandPerPlayer.Key, commandPerPlayer.Value.ToArray());
137127
}
138128
}
139129

140130
//Only rollback if we are ahead (network can be ahead when lag compensation is higher than lag itself)
141-
//if (_systems.CurrentTick > revertTick)
131+
if (_systems.CurrentTick > revertFrame)
142132
{
143133
var targetTick = _systems.CurrentTick;
144134

145135
//Revert everything that happened one tick after the last validated input
146136
_systems.RevertFromTick(revertFrame + 1);
147137

148-
//Execute all commands again, beginning from the first frame that contains remote input
138+
//Execute all commands again, beginning from the first frame that contains remote input up to our last local state
149139
while (revertFrame <= targetTick)
150-
{
151-
if (LocalCommandBuffer.GetMany(_systems.CurrentTick).Length > 0)
152-
{
153-
154-
_logger.Warn("Execute " + LocalCommandBuffer.GetMany(revertFrame).Length + " commands from tick " + revertFrame);
155-
}
156-
157-
_logger.Warn(">>>>========= " + (revertFrame) + " ========= ");
140+
{
158141
_systems.Tick(LocalCommandBuffer.GetMany(revertFrame));
159-
160142
revertFrame++;
161143
}
162144
}

Engine/Core/Features/StatefulFeature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ namespace Lockstep.Core.Features
44
{
55
public abstract class StatefulFeature : Feature, IStateSystem
66
{
7-
public void RevertToTick(uint tick)
7+
public void RevertFromTick(uint tick)
88
{
99
foreach (var system in _executeSystems)
1010
{
1111
if (system is IStateSystem stateSystem)
1212
{
13-
stateSystem.RevertToTick(tick);
13+
stateSystem.RevertFromTick(tick);
1414
}
1515
}
1616
}

Engine/Core/GameSystems.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
using Lockstep.Core.Data;
33
using Lockstep.Core.Features;
44
using Lockstep.Core.Interfaces;
5-
using Lockstep.Core.Systems.GameState;
6-
using Lockstep.Core.Systems.Input;
5+
using Lockstep.Core.Systems.GameState;
76

87
namespace Lockstep.Core
98
{
@@ -51,10 +50,14 @@ public void RevertFromTick(uint tick)
5150
{
5251
if (system is IStateSystem stateSystem)
5352
{
54-
stateSystem.RevertToTick(tick);
53+
stateSystem.RevertFromTick(tick);
5554
}
5655
}
57-
56+
57+
//Example: tick = 50, currentTick = 60
58+
//All ticks from 50 to 60 are reverted
59+
//The state is now the same it was as in 49
60+
//=> Set new tick to 49 (= tick - 1)
5861
Contexts.gameState.ReplaceTick(tick - 1);
5962
}
6063
}

Engine/Core/Interfaces/IStateSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
public interface IStateSystem
44
{
5-
void RevertToTick(uint tick);
5+
void RevertFromTick(uint tick);
66
}
77
}

Engine/Core/Systems/Input/OnSpawnInputCreateEntity.cs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ public class OnSpawnInputCreateEntity : ReactiveSystem<InputEntity>, IStateSyste
1414
private readonly GameContext _gameContext;
1515
private readonly GameStateContext _gameStateContext;
1616

17-
private readonly Dictionary<uint, List<uint>> _createdEntities = new Dictionary<uint, List<uint>>();
18-
private readonly ILogService _logger;
17+
private readonly Dictionary<uint, List<uint>> _createdEntities = new Dictionary<uint, List<uint>>();
1918

2019
public OnSpawnInputCreateEntity(Contexts contexts, ServiceContainer services) : base(contexts.input)
2120
{
22-
_gameService = services.Get<IGameService>();
23-
_logger = services.Get<ILogService>();
21+
_gameService = services.Get<IGameService>();
2422
_gameContext = contexts.game;
2523
_gameStateContext = contexts.gameState;
2624
}
@@ -54,31 +52,24 @@ protected override void Execute(List<InputEntity> inputs)
5452

5553
_createdEntities[_gameStateContext.tick.value].Add(_nextEntityId);
5654
_nextEntityId++;
57-
}
58-
59-
_logger?.Warn(_gameStateContext.tick.value + ": " + inputs.Count + " added");
55+
}
6056
}
6157

62-
public void RevertToTick(uint tick)
63-
{
64-
var t = tick;
65-
var count = 0;
58+
public void RevertFromTick(uint tick)
59+
{
6660
for (;tick <= _gameStateContext.tick.value; tick++)
6761
{
6862
if (_createdEntities.ContainsKey(tick))
6963
{
7064
foreach (var entityId in _createdEntities[tick])
7165
{
7266
_gameContext.GetEntities().First(entity => entity.id.value == entityId).Destroy();
73-
_nextEntityId--;
74-
count++;
67+
_nextEntityId--;
7568
}
7669

7770
_createdEntities[tick].Clear();
7871
}
79-
}
80-
81-
_logger?.Warn(t + " -> " + tick + ": " + count + " destroyed");
72+
}
8273
}
8374
}
8475
}

Engine/Server/Room.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Threading;
2+
using System.Collections.Generic;
43
using Lockstep.Network;
54
using Lockstep.Network.Messages;
65
using Lockstep.Network.Utils;
@@ -12,7 +11,7 @@ namespace Server
1211
/// </summary>
1312
public class Room
1413
{
15-
private const int TargetFps = 20;
14+
private const int TargetFps = 40;
1615

1716
private byte _nextPlayerId;
1817
private readonly int _size;
@@ -107,7 +106,8 @@ private void OnClientDisconnected(int clientId)
107106

108107
private void StartSimulationOnConnectedPeers()
109108
{
110-
Serializer writer = new Serializer();
109+
var writer = new Serializer();
110+
111111
//Create a new seed and send it with a start-message to all clients
112112
//The message also contains the respective player-id and the servers' frame rate
113113
var seed = new Random().Next(int.MinValue, int.MaxValue);

Server.LiteNetLib/Server.LiteNetLib/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Program
1010
static void Main(string[] args)
1111
{
1212
int roomSize = 2;
13-
int waitInSeconds = 1;
13+
int waitInSeconds = 5;
1414

1515
var sw = new Stopwatch();
1616
sw.Start();
-512 Bytes
Binary file not shown.
-40 Bytes
Binary file not shown.
-512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)