Exemplo n.º 1
0
        /// <inheritdoc />
        public Joystick GetJoystick(int id)
        {
            // Check if cached.
            if (_loadedJoysticks.ContainsKey(id))
            {
                return(_loadedJoysticks[id]);
            }

            //// Check if the joystick exists.
            //if(Glfw.JoystickPresent(id) == 0) return null;

            //Glfw.GetVersion(out int major, out int minor, out int _);
            //if (major < 3 && minor < 3)
            //{
            //    Engine.Log.Warning("Cannot use Joystick API. Glfw native library must be at least version 3.3", MessageSource.Input);
            //    return null;
            //}

            //if(!Glfw.JoystickIsGamepad(id)) return null;

            //// Load and cache.
            //IntPtr name = Glfw.GetGamepadName(id);
            //List<byte> bytes = new List<byte>();
            //unsafe
            //{
            //    char* nptr = (char*) name;
            //    while (*nptr != 0)
            //    {
            //        bytes.Add((byte)*nptr);
            //        nptr++;
            //    }
            //}
            //GlfwJoystick joystick = new GlfwJoystick(id, System.Text.Encoding.UTF8.GetString(bytes.ToArray()));
            GlfwJoystick joystick = new GlfwJoystick(id, Glfw.GetJoystickName(id));

            // Update twice to fill both current frame and last frame values.
            joystick.Update();
            joystick.Update();
            _loadedJoysticks.Add(id, joystick);

            return(joystick);
        }
Exemplo n.º 2
0
        static void JoystickCallback(Glfw.Joystick joy, Glfw.ConnectionEvent evt)
        {
            if (evt == Glfw.ConnectionEvent.Connected)
            {
                var axes    = Glfw.GetJoystickAxes(joy);
                var buttons = Glfw.GetJoystickButtons(joy);

                Log("{0} at {1}: Joystick {2} ({3}) was connected with {4} axes and {5} buttons",
                    m_Counter++, Glfw.GetTime(),
                    joy,
                    Glfw.GetJoystickName(joy),
                    axes.Length,
                    buttons.Length);
            }
            else
            {
                Log("{0} at {1}: Joystick {2} was disconnected",
                    m_Counter++, Glfw.GetTime(), joy);
            }
        }
Exemplo n.º 3
0
        static void JoystickCallback(Glfw.Joystick joy, Glfw.ConnectionEvent evt)
        {
            if (evt == Glfw.ConnectionEvent.Connected)
            {
                var axisCount   = Glfw.GetJoystickAxes(joy).Length;
                var buttonCount = Glfw.GetJoystickButtons(joy).Length;

                Log("Found joystick {0} named \'{1}\' with {2} axes, {3} buttons\n",
                    (int)joy + 1,
                    Glfw.GetJoystickName(joy),
                    axisCount,
                    buttonCount);

                m_Joysticks.Add(joy);
            }
            else if (evt == Glfw.ConnectionEvent.Disconnected)
            {
                m_Joysticks.Remove(joy);
                Log("Lost joystick {0}", (int)joy + 1);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initialize the device.
 /// </summary>
 public void Initialize()
 {
     Name = Glfw.GetJoystickName((Glfw.Joystick)Index);
 }