public void Simple() { var gameInputs = new ConcurrentQueue <(ClientId, Packets.GameInput)>(); var g1 = new Packets.GameInput { Movement = 1 }; var g2 = new Packets.GameInput { Movement = 2 }; gameInputs.Enqueue((0, g1)); gameInputs.Enqueue((1, g2)); while (!gameInputs.IsEmpty) { (ClientId, Packets.GameInput)pair; if (gameInputs.TryDequeue(out pair)) { ClientId clientId = pair.Item1; Packets.GameInput gameInput = pair.Item2; System.Console.WriteLine("[DEBUG] Client ID: {0}", clientId); System.Console.WriteLine("[DEBUG] Movement: {0}", gameInput.Movement); } } }
public void Send(Packets.GameInput gameInput) { server.MatchSome(server => { packetProcessor.Send <Packets.GameInput>( server, gameInput, DeliveryMethod.ReliableOrdered ); }); }
private void Process(Queue <Input> inputs) { var gameInput = new Packets.GameInput(); while (inputs.Count > 0) { Input input = inputs.Dequeue(); switch (input) { case Input.Quit: Exit(); break; case Input.Connect: netClient.Connect(); sound.Play(Sound.Background.Dungeon); break; case Input.Disconnect: netClient.Disconnect(); sound.Stop(); break; case Input.MoveUp: case Input.MoveLeft: case Input.MoveDown: case Input.MoveRight: gameInput.Movement = (int)input.GetGameInputMovement(); break; case Input.UseSlotA: gameInput.UseSlotA = true; sound.Play(Sound.Effect.SwordSlash); break; case Input.UseSlotB: gameInput.UseSlotB = true; sound.Play(Sound.Effect.SwordSlash); break; case Input.NextItemSlotA: gameInput.NextItemSlotA = true; break; case Input.NextItemSlotB: gameInput.NextItemSlotB = true; break; case Input.PrevItemSlotA: gameInput.PrevItemSlotA = true; break; case Input.PrevItemSlotB: gameInput.PrevItemSlotB = true; break; case Input.DebugPrint: game.MatchSome(game => { game.world.ecsRegistry.DebugPrint(); // This is commented out because it's very slow // game.world.map.DebugPrint(); }); break; case Input.DebugRender: GameNS.WorldNS.MapsExt.Renderer.renderGameLayer = true; break; case Input.DebugUnRender: GameNS.WorldNS.MapsExt.Renderer.renderGameLayer = false; break; case Input.DebugDisconnect: netClient.DebugDisconnect = true; break; case Input.DebugUnDisconnect: netClient.DebugDisconnect = false; break; default: System.Console.WriteLine( "[WARN] Unhandled input: {0}", input ); break; } } // If `gameInput` has been modified to be different from its default // value, send it if (!gameInput.Equals(new Packets.GameInput())) { netClient.Send(gameInput); } }