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

Commit a0c8db4

Browse files
committed
LagCompensation property
1 parent c1eadfb commit a0c8db4

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

Engine/Client/Simulation.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ public class Simulation
2020

2121
public long CurrentTick { get; private set; }
2222

23-
public ICommandBuffer LocalCommandBuffer => _systems.CommandBuffer;
23+
/// <summary>
24+
/// Amount of ticks until a command gets executed
25+
/// </summary>
26+
public int LagCompensation { get; set; } = 10;
27+
28+
public readonly ICommandBuffer LocalCommandBuffer = new CommandBuffer();
2429
public readonly ICommandBuffer RemoteCommandBuffer;
2530

2631
private readonly object _currentTickLock = new object();
@@ -29,7 +34,7 @@ public class Simulation
2934
public Simulation(ISystems systems, ICommandBuffer remoteCommandBuffer)
3035
{
3136
_systems = systems;
32-
_systems.CommandBuffer = new CommandBuffer();
37+
_systems.CommandBuffer = LocalCommandBuffer;
3338

3439
RemoteCommandBuffer = remoteCommandBuffer;
3540
RemoteCommandBuffer.Inserted += (l, command) =>
@@ -51,7 +56,7 @@ public void Execute(ICommand command)
5156
{
5257
lock (_currentTickLock)
5358
{
54-
var executionTick = CurrentTick + 20;
59+
var executionTick = CurrentTick + LagCompensation;
5560

5661
//LocalCommandBuffer.Insert(nextTick, command);
5762
RemoteCommandBuffer.Insert(executionTick, command);

Engine/Core/Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<Reference Include="System.Xml" />
5757
</ItemGroup>
5858
<ItemGroup>
59+
<Compile Include="EventStore.cs" />
5960
<Compile Include="Generated\GameState\Components\GameStateHashCodeComponent.cs" />
6061
<Compile Include="Generated\GameState\Components\GameStatePlayerIdComponent.cs" />
6162
<Compile Include="Generated\GameState\Components\GameStatePausedComponent.cs" />

Engine/Core/EventStore.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using BEPUutilities;
7+
8+
namespace Lockstep.Core
9+
{
10+
class EventStore : IPositionListener
11+
{
12+
public void OnPosition(GameEntity entity, Vector2 value)
13+
{
14+
15+
}
16+
}
17+
}

Unity/Assets/Scenes/SampleScene.unity

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ Transform:
299299
m_PrefabInstance: {fileID: 0}
300300
m_PrefabAsset: {fileID: 0}
301301
m_GameObject: {fileID: 90465233}
302-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
303-
m_LocalPosition: {x: 7.8062973, y: 6.0821004, z: -7.0502815}
304-
m_LocalScale: {x: 1, y: 1, z: 1}
302+
m_LocalRotation: {x: 0.02568964, y: 0.28296393, z: 0.056058433, w: 0.9571462}
303+
m_LocalPosition: {x: 42, y: 42, z: 42}
304+
m_LocalScale: {x: 0, y: 0, z: 0}
305305
m_Children: []
306306
m_Father: {fileID: 0}
307307
m_RootOrder: 6
308-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
308+
m_LocalEulerAnglesHint: {x: 1, y: 33, z: 7}
309309
--- !u!114 &90465235
310310
MonoBehaviour:
311311
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)