Esempio n. 1
1
        private static void RunManager(InputConfig config)
        {
            try
            {
                var input = new DirectInput();
                var devices = new List<DeviceInstance>(input.GetDevices(DeviceType.Gamepad, DeviceEnumerationFlags.AllDevices));
                devices.AddRange(input.GetDevices(DeviceType.Joystick, DeviceEnumerationFlags.AllDevices));

                var registeredDevices = new List<Tuple<Config.Input, Joystick>>();

                foreach (var inp in config.Inputs)
                {
                    var device = devices.SingleOrDefault(di => di.ProductGuid == new Guid(inp.Guid));
                    if (device == null)
                    {
                        throw new Exception($"Device \"{inp.Nickname}\" not found");
                    }

                    var joy = new Joystick(input, device.InstanceGuid);

                    registeredDevices.Add(Tuple.Create(inp, joy));
                }

                while (true)
                {
                    var frame = new InputFrame();
                    frame.GenerationTime = DateTime.Now;

                    foreach (var registeredDevice in registeredDevices)
                    {
                        var state = registeredDevice.Item2.GetCurrentState();

                        switch (registeredDevice.Item1.Type.ToUpper())
                        {
                            case "JOYSTICK":
                                frame.SubFrames.Add(new JoystickSubFrame(state));
                                break;
                            case "GAMEPAD":
                                frame.SubFrames.Add(new GamepadSubFrame(state));
                                break;
                        }
                    }

                    FrameCaptured?.Invoke(frame);
                }

            }
            catch (ThreadAbortException)
            {
                Console.Error.WriteLine("Input Manager Stopped at " + DateTime.Now.ToString("G"));
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}\n\nInput Manager cannot continue", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }
Esempio n. 2
0
 public static void StartManager(InputConfig config)
 {
     _managerThread = new Thread(() => RunManager(config));
     _managerThread.Start();
 }