public ClientSimulationController( ILogger logger, GameServerConnection connection, ClientUdpPacketTransport transport, PacketJitterBuffer jitterBuffer) { this._connection = connection ?? throw new ArgumentNullException(nameof(connection)); this._transport = transport ?? throw new ArgumentNullException(nameof(transport)); this._jitterBuffer = jitterBuffer ?? throw new ArgumentNullException(nameof(jitterBuffer)); this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public GameServerClient( ILogger logger, IJsonSerializer jsonSerializer, PacketJitterBuffer jitterBuffer, NetworkTransportConfig transportConfig) { this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); this._jsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer)); this._connection = new GameServerConnection { State = GameServerConnection.ConnectionState.None, PacketEncryptor = new XorPacketEncryptor(), }; this._jitterBuffer = jitterBuffer ?? throw new ArgumentNullException(nameof(jitterBuffer)); this._transportConfig = transportConfig ?? throw new ArgumentNullException(nameof(transportConfig)); }
public GameClient( ILogger logger, IJsonSerializer jsonSerializer, IClientConfig config) { this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); this._jitterBuffer = new PacketJitterBuffer(this._logger, config.Jitter.Capacity); this._entityServerToClientMap = new NetworkEntityMap(config.Ecs.InitialEntityPoolCapacity); this._world = new World(config.Ecs); this._physicsWorld = new VolatilePhysicsWorld(historyLength: config.Simulation.SnapShotCount); this._systems = new Systems(this._world); this._fixedSystems = new Systems(this._world) .Add(new ClientEntityReplicationSystem()) .Add(new PhysicsSystem()) .Inject(this._world) .Inject(this._physicsWorld) .Inject(this._jitterBuffer) .Inject(this._entityServerToClientMap); this._simulation = new ClientSimulation <InputComponent>( config.Simulation, this._world, this._systems, this._fixedSystems); this._simulation.Create(); this._server = new GameServerClient( this._logger, jsonSerializer, this._jitterBuffer, config.NetworkTransport); }
public void Test() { var logger = new TestLogger(); var capacity = 4; var jitterBuffer = new PacketJitterBuffer(logger, capacity); // // Simple test: add packets in order. // jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 1, });; jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 2, }); jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 3, }); Assert.Equal(3, jitterBuffer.Count); ReplicationPacket packet = default; Assert.False(jitterBuffer.TryRead(FrameIndex.Zero, ref packet)); Assert.True(jitterBuffer.TryRead(FrameIndex.Zero + 1, ref packet)); Assert.Equal(1, packet.FrameNumber); Assert.True(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); Assert.Equal(2, packet.FrameNumber); Assert.True(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); Assert.Equal(3, packet.FrameNumber); Assert.False(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); // // Test: Add packets out of order // jitterBuffer.Clear(FrameIndex.Zero); // Reverse order jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 3, });; jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 2, }); jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 1, }); Assert.Equal(3, jitterBuffer.Count); Assert.False(jitterBuffer.TryRead(FrameIndex.Zero, ref packet)); Assert.True(jitterBuffer.TryRead(FrameIndex.Zero + 1, ref packet)); Assert.Equal(1, packet.FrameNumber); Assert.True(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); Assert.Equal(2, packet.FrameNumber); Assert.True(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); Assert.Equal(3, packet.FrameNumber); Assert.False(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); // // Test: Add packets out of order with an interleaved read. // jitterBuffer.Clear(FrameIndex.Zero); // Reverse order jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 4, });; jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 3, }); jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 1, }); Assert.Equal(3, jitterBuffer.Count); Assert.False(jitterBuffer.TryRead(FrameIndex.Zero, ref packet)); Assert.True(jitterBuffer.TryRead(FrameIndex.Zero + 1, ref packet)); Assert.Equal(1, packet.FrameNumber); jitterBuffer.AddPacket(new ReplicationPacket { FrameNumber = 2, }); Assert.True(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); Assert.Equal(2, packet.FrameNumber); Assert.True(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); Assert.Equal(3, packet.FrameNumber); Assert.True(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); Assert.Equal(4, packet.FrameNumber); Assert.False(jitterBuffer.TryRead(new FrameIndex(packet.FrameNumber) + 1, ref packet)); }