internal UpdateContext(PayloadTime lastPayloadTime, PayloadData payload, InitializationData initializationData) { Time = lastPayloadTime == null ? new PayloadTime() : new PayloadTime(lastPayloadTime.At); Payload = payload; // TODO: Update map width and height on map resize. MapWidth = initializationData.Configuration.MapConfiguration.WIDTH; MapHeight = initializationData.Configuration.MapConfiguration.HEIGHT; YourShip = payload.Ships.Single(s => s.Id == initializationData.ShipID); OtherShips = payload.Ships.Where(s => s.Id != initializationData.ShipID); }
private async Task HandlePayloadAsync(JArray parameters) { await _payloadLock.WaitAsync(); try { var serverPayload = parameters; var payload = _payloadDecompressor.DecompressPayload(serverPayload); var context = new UpdateContext(_currentPayloadTime, payload, _initializationData); _currentPayloadTime = context.Time; await(OnUpdateAsync?.Invoke(context) ?? Task.CompletedTask); } finally { _payloadLock.Release(); } }