Ejemplo n.º 1
0
        /// <summary>
        /// Gets the index of the first player which does not have an associated game pad.
        /// </summary>
        /// <returns>The index of the first player which does not have an associated game pad.</returns>
        private Int32 GetFirstAvailablePlayerIndex()
        {
            for (int i = 0; i < devicesByPlayer.Length; i++)
            {
                if (devicesByPlayer[i] == null)
                {
                    return(i);
                }
            }

            var devicesOld = devicesByPlayer;
            var devicesNew = new SDL2GamePadDevice[devicesOld.Length + 1];

            Array.Copy(devicesOld, devicesNew, devicesOld.Length);

            devicesByPlayer = devicesNew;

            return(devicesByPlayer.Length - 1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when a controller device is added.
        /// </summary>
        /// <param name="joystickIndex">The index of the device to add.</param>
        private void OnControllerDeviceAdded(Int32 joystickIndex)
        {
            var gamecontroller = SDL.GameControllerOpen(joystickIndex);
            var joystick       = SDL.GameControllerGetJoystick(gamecontroller);
            var joystickID     = SDL.JoystickInstanceID(joystick);

            for (int i = 0; i < devicesByPlayer.Length; i++)
            {
                if (devicesByPlayer[i] != null && devicesByPlayer[i].InstanceID == joystickID)
                {
                    return;
                }
            }

            var playerIndex = GetFirstAvailablePlayerIndex();
            var device      = new SDL2GamePadDevice(Ultraviolet, joystickIndex, playerIndex);

            devicesByPlayer[playerIndex] = device;
            count++;

            OnGamePadConnected(device, playerIndex);
        }