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

Commit

Permalink
Merge pull request #20 from proepkes/develop
Browse files Browse the repository at this point in the history
Cleanup all input entities
  • Loading branch information
proepkes authored Jan 25, 2019
2 parents 7bd23e6 + 29562ae commit 3e1a018
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Engine/Client/Implementations/LocalDataReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void Init()
InitReceived?.Invoke(this, EventArgs.Empty);
}

public void AddFrame(Frame frame)
public void Receive(Frame frame)
{
FrameReceived?.Invoke(this, frame);
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/Client/Implementations/NetworkedDataReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Lockstep.Network.Utils;

namespace Lockstep.Client.Implementations
{
{
public class NetworkedDataReceiver : IDataReceiver
{
private readonly INetwork _network;
Expand Down
4 changes: 0 additions & 4 deletions Engine/Client/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

namespace Lockstep.Client
{
/// <summary>
/// This simulation listens for received data from the client and reacts accordingly. 'Executed' commands are first sent to the server.
/// The final execution is done when the corresponding frame-packet arrives - this adds minimum 1 RTT delay to commands.
/// </summary>
public class Simulation
{
public event EventHandler Started;
Expand Down
1 change: 1 addition & 0 deletions Engine/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceContainer.cs" />
<Compile Include="Systems\CalculateHashCode.cs" />
<Compile Include="Systems\Input\CleanupInput.cs" />
<Compile Include="Systems\Input\EmitInput.cs" />
<Compile Include="Systems\Input\OnSpawnInputDoLoadEntityIntoGame.cs" />
<Compile Include="Systems\Navigation\NavigationTick.cs" />
Expand Down
4 changes: 3 additions & 1 deletion Engine/Core/Features/InputFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public InputFeature(Contexts contexts, ServiceContainer serviceContainer)
//TODO: Add InputValidationSystem by matching input with playerId
Add(new EmitInput(contexts));

Add(new OnSpawnInputDoLoadEntityIntoGame(contexts, serviceContainer.Get<IGameService>()));
Add(new OnSpawnInputDoLoadEntityIntoGame(contexts, serviceContainer.Get<IGameService>()));

Add(new CleanupInput(contexts));
}
}
}
15 changes: 7 additions & 8 deletions Engine/Core/LockstepSystems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
namespace Lockstep.Core
{
public sealed class LockstepSystems : Entitas.Systems, ISystems
{
private IFrameBuffer _frameBuffer;
private readonly Contexts _contexts;

{
public long HashCode => _contexts.gameState.hashCode.value;

public void SetFrameBuffer(IFrameBuffer frameBuffer)
{
_frameBuffer = frameBuffer;
}
private IFrameBuffer _frameBuffer;
private readonly Contexts _contexts;

public LockstepSystems(Contexts contexts, params IService[] additionalServices)
{
Expand All @@ -36,6 +31,10 @@ public LockstepSystems(Contexts contexts, params IService[] additionalServices)
Add(new HashCodeFeature(contexts, serviceContainer));
}

public void SetFrameBuffer(IFrameBuffer frameBuffer)
{
_frameBuffer = frameBuffer;
}

public void Tick()
{
Expand Down
19 changes: 19 additions & 0 deletions Engine/Core/Systems/Input/CleanupInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Entitas;

namespace Lockstep.Core.Systems.Input
{
public class CleanupInput : ICleanupSystem
{
private readonly InputContext _inputContext;

public CleanupInput(Contexts contexts)
{
_inputContext = contexts.input;
}

public void Cleanup()
{
_inputContext.DestroyAllEntities();
}
}
}
2 changes: 1 addition & 1 deletion Engine/Server/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Server
{
public class Room
{
private const int TargetFps = 20;
private const int TargetFps = 50;

private byte _nextPlayerId;
private readonly int _size;
Expand Down
2 changes: 1 addition & 1 deletion Engine/Test/InputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void TestGameEntityHasUniqueId()
[Fact]
public void TestCommandIsExecuted()
{
var command = new Mock<ICommand>();
var command = new Mock<ICommand>();

new Simulation(new LockstepSystems(new Contexts()), new LocalDataReceiver()).Execute(command.Object);

Expand Down
Binary file modified Unity/Assets/Integration/Lockstep.Client.dll
Binary file not shown.
Binary file modified Unity/Assets/Integration/Lockstep.Client.pdb
Binary file not shown.
Binary file modified Unity/Assets/Integration/Lockstep.Core.dll
Binary file not shown.
Binary file modified Unity/Assets/Integration/Lockstep.Core.dll.mdb
Binary file not shown.
Binary file modified Unity/Assets/Integration/Lockstep.Core.pdb
Binary file not shown.
9 changes: 5 additions & 4 deletions Unity/Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 28ef8c68bade09b41aca258d42a632f2, type: 3}
m_Name:
m_EditorClassIdentifier:
lastTab: 2
lastTab: 0
movementSettingsFoldout: 0
zoomingSettingsFoldout: 0
rotationSettingsFoldout: 0
Expand All @@ -155,7 +155,7 @@ MonoBehaviour:
inputSettingsFoldout: 0
useFixedUpdate: 0
keyboardMovementSpeed: 30
screenEdgeMovementSpeed: 3
screenEdgeMovementSpeed: 9
followingSpeed: 5
rotationSped: 3
panningSpeed: 10
Expand Down Expand Up @@ -186,7 +186,7 @@ MonoBehaviour:
zoomOutKey: 113
useScrollwheelZooming: 1
zoomingAxis: Mouse ScrollWheel
useKeyboardRotation: 1
useKeyboardRotation: 0
rotateRightKey: 120
rotateLeftKey: 122
useMouseRotation: 0
Expand Down Expand Up @@ -557,7 +557,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
EntityDatabase: {fileID: 11400000, guid: a0d4789ca6cc5ab42a1264102206ac3f, type: 2}
IP: 127.0.0.1
ServerIp: 127.0.0.1
ServerPort: 9050
--- !u!114 &1524441392
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions Unity/Assets/Scripts/Camera/Source.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/densylkin/RTS_Camera
7 changes: 7 additions & 0 deletions Unity/Assets/Scripts/Camera/Source.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Unity/Assets/Scripts/RTSNetworkedSimulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ public class RTSNetworkedSimulation : MonoBehaviour

private bool _simulationStarted;
private LockstepSystems _systems;
private NetworkedDataSource _dataSource;
private NetworkedDataReceiver _dataReceiver;

private void Awake()
{
Instance = this;
_dataSource = new NetworkedDataSource(_client)
_dataReceiver = new NetworkedDataReceiver(_client)
.RegisterCommand(() => new SpawnCommand())
.RegisterCommand(() => new NavigateCommand());

_systems = new LockstepSystems(Contexts.sharedInstance, new UnityGameService(EntityDatabase),
new UnityLogger());

_simulation =
new Simulation(_systems, _dataSource);
new Simulation(_systems, _dataReceiver);


_simulation.Started += (sender, args) => _simulationStarted = true;
_simulation.Ticked += (id, frame) =>
_simulation.Ticked += id =>
{
_dataSource.Receive(MessageTag.HashCode, new HashCode {FrameNumber = id, Value = Contexts.sharedInstance.gameState.hashCode.value});
_dataReceiver.Receive(MessageTag.HashCode, new HashCode {FrameNumber = id, Value = _systems.HashCode});
};
}

Expand Down

0 comments on commit 3e1a018

Please sign in to comment.