internal void PlayerInputs(PlayerInputs item) { recieved .GetOrAdd(item.Id, new ConcurrentLinkedList <PlayerInputs>()) .Add(item); if (Interlocked.CompareExchange(ref going, 1, 0) == 0) { while (recieved.Sum(x => x.Value.Count) >= game2.gameState.players.Count) { var inputs = new Dictionary <Guid, PlayerInputs>(); foreach (var pair in recieved) { if (pair.Value.TryGetFirst(out var first)) { // TODO TryGetFirst and RemoveStart should be combined pair.Value.RemoveStart(); inputs[pair.Key] = first; } } game2.ApplyInputs(inputs); } var update = new Node(game2.gameState.GetGameStateUpdate()); lastUpdate.next.SetResult(update); lastUpdate = update; going = 0; } }