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

Commit b61ec94

Browse files
committed
Replace Frame with direct commandarray
Testing Local/Networkbuffer (debugging)
1 parent 8b8842e commit b61ec94

File tree

12 files changed

+80
-59
lines changed

12 files changed

+80
-59
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,6 @@ Unity/Assembly-CSharp-Editor\.csproj
271271
/Unity/Assets/Integration/FixMath.NET.pdb.meta
272272
/Unity/Assets/Integration/ECS.pdb.meta
273273
/Unity/Assets/Integration/BEPUutilities.pdb.meta
274+
/Unity/Assets/Editor Default Resources
275+
/Unity/Assets/Scripts/Debug.meta
276+
/Unity/Assets/Editor Default Resources.meta

Engine/Client/CommandBuffer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ namespace Lockstep.Client.Implementations
77
{
88
public class CommandBuffer : ICommandBuffer
99
{
10-
private readonly Dictionary<ulong, List<ICommand>> _commands = new Dictionary<ulong, List<ICommand>>();
10+
private readonly Dictionary<long, List<ICommand>> _commands = new Dictionary<long, List<ICommand>>();
1111

12-
public ulong Count
12+
public long Count
1313
{
1414
get
1515
{
1616
lock (_commands)
1717
{
18-
return _commands.Keys.Max();
18+
return _commands.LongCount();
1919
}
2020
}
2121
}
2222

23-
public ulong ItemIndex { get; private set; }
23+
public long ItemIndex { get; private set; }
2424

25-
public ulong Remaining => Count - ItemIndex;
25+
public long Remaining => Count - ItemIndex;
2626

27-
public void Insert(ulong frameNumber, ICommand command)
27+
public void Insert(long frameNumber, ICommand command)
2828
{
2929
lock (_commands)
3030
{

Engine/Client/Simulation.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Lockstep.Client
1212
{
1313
public class Simulation
1414
{
15-
public event Action<ulong> Ticked;
15+
public event Action<long> Ticked;
1616

1717
public bool Running { get; set; }
1818

@@ -22,18 +22,19 @@ public class Simulation
2222
public float _tickDt;
2323
public float _accumulatedTime;
2424

25-
public ulong CurrentTick { get; private set; }
25+
public long CurrentTick { get; private set; }
2626

27-
private readonly CommandBuffer _networkCommandBuffer;
28-
private readonly IDictionary<ushort, Func<ISerializableCommand>> _commandFactories = new Dictionary<ushort, Func<ISerializableCommand>>();
27+
public ICommandBuffer LocalCommandBuffer => _systems.CommandBuffer;
28+
public readonly CommandBuffer NetworkCommandBuffer;
2929

30+
private readonly IDictionary<ushort, Func<ISerializableCommand>> _commandFactories = new Dictionary<ushort, Func<ISerializableCommand>>();
3031

3132
public Simulation(ISystems systems, INetwork network)
3233
{
3334
_systems = systems;
3435
_systems.CommandBuffer = new CommandBuffer();
3536

36-
_networkCommandBuffer = new CommandBuffer();
37+
NetworkCommandBuffer = new CommandBuffer();
3738

3839
_network = network;
3940
_network.DataReceived += OnDataReceived;
@@ -52,7 +53,7 @@ public void RegisterCommand(Func<ISerializableCommand> commandFactory)
5253

5354
public void Execute(ISerializableCommand command)
5455
{
55-
//Execute the command locally in the next tick
56+
//Execute the command locally on the next tick
5657
_systems.CommandBuffer.Insert(CurrentTick + 1, command);
5758

5859
//Tell the server
@@ -113,15 +114,15 @@ private void OnDataReceived(byte[] data)
113114
StartSimulation(init.TargetFPS);
114115
break;
115116
case MessageTag.Input:
116-
var frameNumber = reader.GetULong();
117+
var frameNumber = reader.GetLong();
117118
var tag = reader.GetUShort();
118119

119120
if (_commandFactories.ContainsKey(tag))
120121
{
121122
var newCommand = _commandFactories[tag].Invoke();
122123
newCommand.Deserialize(reader);
123124

124-
_networkCommandBuffer.Insert(frameNumber, newCommand);
125+
NetworkCommandBuffer.Insert(frameNumber, newCommand);
125126
}
126127

127128
break;

Engine/Core/Core.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -137,7 +137,6 @@
137137
<Compile Include="Components\GameState\PausedComponent.cs" />
138138
<Compile Include="Components\Input\EntityIdsComponent.cs" />
139139
<Compile Include="Data\AgentConfig.cs" />
140-
<Compile Include="Data\Frame.cs" />
141140
<Compile Include="Data\ICommand.cs" />
142141
<Compile Include="DefaultServices\DefaultGameService.cs" />
143142
<Compile Include="DefaultServices\DefaultHashService.cs" />

Engine/Core/Data/Frame.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

Engine/Core/Interfaces/ICommandBuffer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace Lockstep.Core.Interfaces
44
{
55
public interface ICommandBuffer
66
{
7-
ulong Count { get; }
8-
ulong ItemIndex { get; }
9-
ulong Remaining { get; }
7+
long Count { get; }
8+
long ItemIndex { get; }
9+
long Remaining { get; }
1010

11-
void Insert(ulong frameNumber, ICommand command);
11+
void Insert(long frameNumber, ICommand command);
1212

1313
ICommand[] GetNext();
1414
}
512 Bytes
Binary file not shown.
24 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

Unity/Assets/Scenes/SampleScene.unity

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,38 @@ Transform:
273273
m_LocalScale: {x: 1, y: 1, z: 1}
274274
m_Children: []
275275
m_Father: {fileID: 0}
276-
m_RootOrder: 1
276+
m_RootOrder: 2
277277
m_LocalEulerAnglesHint: {x: 45, y: 0, z: 0}
278+
--- !u!1 &90465233
279+
GameObject:
280+
m_ObjectHideFlags: 0
281+
m_CorrespondingSourceObject: {fileID: 0}
282+
m_PrefabInstance: {fileID: 0}
283+
m_PrefabAsset: {fileID: 0}
284+
serializedVersion: 6
285+
m_Component:
286+
- component: {fileID: 90465234}
287+
m_Layer: 0
288+
m_Name: Just_Delete_Me
289+
m_TagString: Untagged
290+
m_Icon: {fileID: 0}
291+
m_NavMeshLayer: 0
292+
m_StaticEditorFlags: 0
293+
m_IsActive: 1
294+
--- !u!4 &90465234
295+
Transform:
296+
m_ObjectHideFlags: 0
297+
m_CorrespondingSourceObject: {fileID: 0}
298+
m_PrefabInstance: {fileID: 0}
299+
m_PrefabAsset: {fileID: 0}
300+
m_GameObject: {fileID: 90465233}
301+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
302+
m_LocalPosition: {x: 7.8062973, y: 6.0821004, z: -7.0502815}
303+
m_LocalScale: {x: 1, y: 1, z: 1}
304+
m_Children: []
305+
m_Father: {fileID: 0}
306+
m_RootOrder: 6
307+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
278308
--- !u!1 &97464389
279309
GameObject:
280310
m_ObjectHideFlags: 0
@@ -370,7 +400,7 @@ RectTransform:
370400
- {fileID: 1690724855}
371401
- {fileID: 1923207267}
372402
m_Father: {fileID: 0}
373-
m_RootOrder: 5
403+
m_RootOrder: 1
374404
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
375405
m_AnchorMin: {x: 0, y: 0}
376406
m_AnchorMax: {x: 0, y: 0}
@@ -458,7 +488,7 @@ Transform:
458488
m_LocalScale: {x: 1, y: 1, z: 1}
459489
m_Children: []
460490
m_Father: {fileID: 0}
461-
m_RootOrder: 3
491+
m_RootOrder: 4
462492
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
463493
--- !u!1 &739202181
464494
GameObject:
@@ -556,9 +586,9 @@ MonoBehaviour:
556586
m_Script: {fileID: 11500000, guid: 6fcb7be03dda3f642b1a24576215f536, type: 3}
557587
m_Name:
558588
m_EditorClassIdentifier:
559-
EntityDatabase: {fileID: 11400000, guid: a0d4789ca6cc5ab42a1264102206ac3f, type: 2}
560589
ServerIp: 127.0.0.1
561590
ServerPort: 9050
591+
EntityDatabase: {fileID: 11400000, guid: a0d4789ca6cc5ab42a1264102206ac3f, type: 2}
562592
--- !u!114 &1524441392
563593
MonoBehaviour:
564594
m_ObjectHideFlags: 0
@@ -586,7 +616,7 @@ Transform:
586616
m_LocalScale: {x: 1, y: 1, z: 1}
587617
m_Children: []
588618
m_Father: {fileID: 0}
589-
m_RootOrder: 2
619+
m_RootOrder: 3
590620
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
591621
--- !u!1 &1549690249
592622
GameObject:
@@ -908,5 +938,5 @@ Transform:
908938
m_LocalScale: {x: 1, y: 1, z: 1}
909939
m_Children: []
910940
m_Father: {fileID: 0}
911-
m_RootOrder: 4
941+
m_RootOrder: 5
912942
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

0 commit comments

Comments
 (0)