示例#1
0
        public int Input(int Port, int tact)
        {
            int returnvalue = 0xFF;

            if ((Port & 0xff) == 0x1f)
            {
                returnvalue = 0x0;

                this.Gamepad = Gamepads.FirstOrDefault();
                if (Gamepad == null)
                {
                    return(returnvalue);
                }
                //GamePadState currentState = GamePad.GetState(playerIndex);
                //000FUDLR
                if (Gamepad.Buttons.Count() > 0)
                {
                    if (Gamepad.Buttons[0].Pressed)
                    {
                        returnvalue |= 16;
                    }
                    if ((Gamepad.Buttons.Count >= 12 && Gamepad.Buttons[12].Pressed) || (Gamepad.Axes.Count > 1 && Gamepad.Axes[1] > 0.5))//up
                    {
                        returnvalue |= 8;
                    }
                    if ((Gamepad.Buttons.Count >= 13 && Gamepad.Buttons[13].Pressed) || (Gamepad.Axes.Count > 1 && Gamepad.Axes[1] < -0.5))//down
                    {
                        returnvalue |= 4;
                    }
                    if ((Gamepad.Buttons.Count >= 14 && Gamepad.Buttons[14].Pressed) || (Gamepad.Axes.Count > 0 && Gamepad.Axes[0] < -0.5))//left
                    {
                        returnvalue |= 2;
                    }
                    if ((Gamepad.Buttons.Count >= 15 && Gamepad.Buttons[15].Pressed) || (Gamepad.Axes.Count > 0 && Gamepad.Axes[0] > 0.5))//right
                    {
                        returnvalue |= 1;
                    }
                }
            }
            return(returnvalue);
        }
示例#2
0
        public void Update(float dt)
        {
            dt = Math.Min(dt, 0.1f);

            // Bind OpenGL
            m_window.MakeCurrent();

            // Update input
            m_keyboard.Update();
            m_mouse.Update();
            m_gamepads.Update();
            if (m_steamControllers != null)
            {
                m_steamControllers.Update();
            }

            if (m_steamControllers != null)
            {
                // Choose an active steampad
                if (ActiveSteamController == null || !ActiveSteamController.Connected)
                {
                    // No steampad connected
                    if (User.Settings.EnableSteamController && m_currentState.EnableGamepad)
                    {
                        ActiveSteamController = SteamControllers.FirstOrDefault(pad => pad.Connected);
                        if (ActiveSteamController != null && !(m_currentState is TestState))
                        {
                            Screen.InputMethod = InputMethod.SteamController;
                        }
                    }
                    else
                    {
                        ActiveSteamController = null;
                    }
                }
                else
                {
                    // Steampad connected
                    if (!User.Settings.EnableSteamController || !m_currentState.EnableGamepad)
                    {
                        // Disable pad if necessary
                        ActiveSteamController = null;
                    }
                    else
                    {
                        // Switch pad if Accept pressed
                        foreach (var steampad in SteamControllers)
                        {
                            if (steampad.Connected &&
                                steampad.Buttons[SteamControllerButton.MenuSelect.GetID()].Pressed)
                            {
                                ActiveSteamController = steampad;
                                Screen.InputMethod    = InputMethod.SteamController;
                                break;
                            }
                        }
                    }
                }
            }

            // Choose an active gamepad
            if (ActiveGamepad == null || !ActiveGamepad.Connected)
            {
                // No Pad connected
                if (User.Settings.EnableGamepad && m_currentState.EnableGamepad)
                {
                    ActiveGamepad = Gamepads.FirstOrDefault(pad => pad.Connected);
                    if (ActiveGamepad != null)
                    {
                        ActiveGamepad.EnableRumble = User.Settings.EnableGamepadRumble;
                        if (User.Settings.GamepadPromptType != GamepadType.Unknown)
                        {
                            ActiveGamepad.Type = User.Settings.GamepadPromptType;
                        }
                        if (!(m_currentState is TestState) && Screen.InputMethod != InputMethod.SteamController)
                        {
                            Screen.InputMethod = InputMethod.Gamepad;
                        }
                    }
                }
                else
                {
                    ActiveGamepad = null;
                }
            }
            else
            {
                // Pad connected
                if (!User.Settings.EnableGamepad || !m_currentState.EnableGamepad)
                {
                    // Disable pad if necessary
                    ActiveGamepad = null;
                }
                else
                {
                    // Switch pad if Start or A pressed
                    foreach (var gamepad in Gamepads)
                    {
                        if (gamepad.Connected &&
                            gamepad.Buttons[GamepadButton.Start].Pressed ||
                            gamepad.Buttons[GamepadButton.A].Pressed)
                        {
                            ActiveGamepad = gamepad;
                            ActiveGamepad.EnableRumble = User.Settings.EnableGamepadRumble;
                            if (User.Settings.GamepadPromptType != GamepadType.Unknown)
                            {
                                ActiveGamepad.Type = User.Settings.GamepadPromptType;
                            }
                            if (Screen.InputMethod != InputMethod.SteamController)
                            {
                                Screen.InputMethod = InputMethod.Gamepad;
                            }
                            break;
                        }
                    }
                }
            }

            // Update tasks
            for (int i = m_promiseTasks.Count - 1; i >= 0; --i)
            {
                var task = m_promiseTasks[i];
                if (task.Promise.Status != Status.Waiting)
                {
                    task.OnComplete.Invoke();
                    m_promiseTasks.RemoveAt(i);
                }
            }

            // Update sound
            if (m_audio is OpenALAudio)
            {
                ((OpenALAudio)m_audio).Update(dt);
            }

            // Toggle fullscreen
            if ((
                    (Keyboard.Keys[Key.LeftAlt].Held || Keyboard.Keys[Key.RightAlt].Held) &&
                    Keyboard.Keys[Key.Return].Pressed
                    ) ||
                (
                    App.Platform == Platform.OSX &&
                    (Keyboard.Keys[Key.LeftGUI].Held || Keyboard.Keys[Key.RightGUI].Held) &&
                    Keyboard.Keys[Key.W].Pressed
                ))
            {
                Window.Fullscreen        = !Window.Fullscreen;
                User.Settings.Fullscreen = Window.Fullscreen;
                User.Settings.Save();
            }

            // Update screen
            m_screen.Update(dt);

            // Update state
            if (m_pendingPendingState != null)
            {
                m_pendingState = m_pendingPendingState;
                m_pendingState.PreInit(m_currentState, m_pendingTransition);
                m_currentState.Shutdown();
                m_pendingPendingState = null;

                m_transition = m_pendingTransition;
                m_transition.Init(m_currentState, m_pendingState);
                m_pendingTransition = null;
            }

            if (m_transition != null)
            {
                if (m_transition.Complete)
                {
                    m_currentState.PostShutdown();
                    m_pendingState.Init();
                    m_transition.Shutdown();
                    m_currentState = m_pendingState;
                    m_pendingState = null;
                    m_transition   = null;
                }
                else
                {
                    m_currentState.PostUpdate(dt);
                    m_pendingState.PreUpdate(dt);
                    m_transition.Update(dt);
                }
            }

            if (m_transition == null)
            {
                m_currentState.Update(dt);
                m_currentState.PopulateCamera(Camera);
            }
            else
            {
                m_transition.PopulateCamera(Camera);
            }

            var cameraTransInv = Camera.Transform;

            MathUtils.FastInvert(ref cameraTransInv);
            Audio.Listener.Transform     = cameraTransInv;
            m_cameraAxisMarker.Transform = cameraTransInv;

            // Update sky
            if (m_sky != null)
            {
                m_sky.Animate();
            }

            // Update sound
            m_gameAudio.Update();

            // Update debug camera
            if (UseDebugCamera)
            {
                m_debugCameraController.Update(dt);
                m_debugCameraController.Populate(Camera);
            }
        }