void PlayFrame(float pSpeed, InputFrame pInputFrame)
    {
        // Here we provide an implementation on how we want our GameObject to move based on input.
        transform.position += MoveDelta(pSpeed, pInputFrame);
        if (!pInputFrame.HasActions)
        {
            return;
        }

        // Here we provide an implementation for actions.
        for (int i = 0; i < pInputFrame.actions.Length; i++)
        {
            switch (pInputFrame.actions[i].actionId)
            {
            case 1:
                byte jumpStep = pInputFrame.actions[i].data[0];
                transform.position += JumpDelta(jumpStep);
                if (_isJumping && jumpStep < byte.MaxValue)
                {
                    _listener.RecordAction(1, ++jumpStep);
                }

                break;

            default:
                break;
            }
        }
    }
 /// <summary>
 /// <para xml:lang="en">Send recognition request. The lowest available request interval is 300ms</para>
 /// <para xml:lang="zh">发送云识别请求。最低可用请求间隔是300ms。</para>
 /// </summary>
 public void Resolve(InputFrame iFrame, Action <CloudRecognizationResult> callback)
 {
     if (CloudRecognizer != null)
     {
         CloudRecognizer.resolve(iFrame, EasyARController.Scheduler, callback);
     }
 }
Example #3
0
        private void OnRightPressed(InputFrame obj)
        {
            if (!areControlsEnabled)
            {
                return;
            }
            NonPositionalAudio.PlaySound("Audio/MenuActionSound");

            switch (state)
            {
            case MenuState.ChoosePlayerMode:
                if (playerMode == PlayerMode.TwoVsTwo)
                {
                    SwitchPlayerMode();
                }
                break;

            case MenuState.ChooseGameMode:
                if (gameMode == GameMode.Waves)
                {
                    SwitchGameMode();
                }
                break;

            case MenuState.ChooseRuntime:
                SelectedRuntimeMode(selectedRuntimeMode + 1);
                break;
            }
        }
            public bool EquivalentButtons(InputFrame other)
            {
                if (keyboard != other.keyboard || mouse != other.mouse ||
                    (pads == null && other.pads != null) || (pads != null && other.pads == null))
                {
                    return(false);
                }

                if (pads == null && other.pads == null)
                {
                    return(true);
                }

                if (pads.Length != other.pads.Length)
                {
                    return(false);
                }

                for (int i = 0; i < pads.Length; i++)
                {
                    if (pads[i] != other.pads[i])
                    {
                        return(false);
                    }
                }

                return(true);
            }
 public void ResetInputs()
 {
     FramesToPlay.Clear();
     FramesToReconcile.Clear();
     inputFrame  = InputFrame.Empty;
     frameNumber = 0;
 }
        private static void SerializeInput()
        {
            InputFrame frame = default;

            frame.keyboard = Keyboard.GetState().RemoveHotkeys();
            frame.mouse    = Mouse.GetState();
            frame.pads     = new XINPUT_GAMEPAD[4];
            for (int i = 0; i < 4; i++)
            {
                frame.pads[i] = _pads[i];
            }

            if (frame.EquivalentButtons(_lastFrame))
            {
                _lastFrame.frames++;
            }
            else
            {
                if (_lastFrame.frames > 0)
                {
                    SerializeFrame(_lastFrame);
                }

                frame.frames = 1;
                _lastFrame   = frame;
            }
        }
 private static void SkipNextInput()
 {
     if (exporting)
     {
         skipInputFrame = Manager.Controller.Current;
     }
 }
Example #8
0
        protected override void StateUpdate()
        {
            if (!Initialized)
            {
                return;
            }

            if (ConnectedToServer)
            {
                m_lastInput = InputController.CurrentFrame();
            }
            else
            {
                // if not connected : try to reconnect every x second with ID message
                m_reconnectTryTimer += Time.deltaTime;
                if (m_reconnectTryTimer > m_reconnectTryDelayMS)
                {
#if DEBUG_LOG
                    Debug.Log("Trying to reconnect to server...");
#endif //DEBUG_LOG
                    m_TCPClient.Reconnect();
                    m_reconnectTryTimer = 0;
                }
            }
        }
Example #9
0
        /// <summary>
        /// Pass input data to the decoder. You must not modify the specified region of the buffer until the returned task completes.
        /// </summary>
        /// <param name="buffer">The buffer containing the input data.</param>
        /// <param name="offset">The offset at which the input data begins.</param>
        /// <param name="length">The length of the input data.</param>
        /// <returns>A task which tells you when the input data has been completely read and the buffer can be reused.</returns>
        public Task WriteInputAsync(byte[] buffer, int offset, int length)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }

            if (length < 0 || length > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            var frame = new InputFrame();

            frame.mBuffer = buffer;
            frame.mOrigin = offset;
            frame.mOffset = offset;
            frame.mEnding = offset + length;
            PushInputFrame(frame);
            return(frame.mCompletion.Task);
        }
Example #10
0
        void MCheckBox(object sender, EventArgs e)
        {
            CheckBox checkbox = sender as CheckBox;
            string   id1      = checkbox.Name.Substring(8); //what index

            if (checkbox == circleTestCheck)
            {
                timer3.Enabled = !timer3.Enabled;
                sink.Update(InputFrame.ParseInputString("RX=128"));
                sink.Update(InputFrame.ParseInputString("RY=128"));
                return;
            }

            if (checkbox.Checked)
            {
                (tabPage3.Controls["mTrackBarY" + (id1)] as NoFocusTrackBar).Enabled = false;
                (tabPage3.Controls["mValueY" + (id1)] as NumericUpDown).Enabled      = false;

                //update to maintain ratio
                var temp = (tabPage3.Controls["mTrackBarX" + (id1)] as NoFocusTrackBar).Value;
                (tabPage3.Controls["mTrackBarX" + (id1)] as NoFocusTrackBar).Value = 0;
                (tabPage3.Controls["mTrackBarX" + (id1)] as NoFocusTrackBar).Value = temp;
            }
            else
            {
                (tabPage3.Controls["mTrackBarY" + (id1)] as NoFocusTrackBar).Enabled = true;
                (tabPage3.Controls["mValueY" + (id1)] as NumericUpDown).Enabled      = true;
            }
        }
 public virtual void RaisePlayFrame(float pSpeed, InputFrame pFrame)
 {
     if (OnPlayFrame != null)
     {
         OnPlayFrame(pSpeed, pFrame);
     }
 }
Example #12
0
        private static void SetFeather(InputFrame input, ref GamePadDPad pad, ref GamePadThumbSticks sticks)
        {
            pad = new GamePadDPad(ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released);
            Vector2 aim = AnalogHelper.GetFeather(input);

            sticks = new GamePadThumbSticks(aim, new Vector2(0, 0));
        }
Example #13
0
        public override void OnFrame(InputFrame frame)
        {
            DateTime frameTime = DateTimeHelper.FromTimestampMicroseconds(frame.CreatedTimestamp, ReferenceTimestamp);

            SendAsync(new InputFrameAck(frame.FrameId)).Wait();
            _fireInputFrameEvent(new InputFrameEventArgs(frameTime, frame));
        }
Example #14
0
        private void OnNextPressed(InputFrame obj)
        {
            if (!areControlsEnabled)
            {
                return;
            }
            NonPositionalAudio.PlaySound("Audio/MenuActionSound");
            switch (state)
            {
            case MenuState.ChoosePlayerMode:
                GoToMenuState(MenuState.ChooseGameMode);
                break;

            case MenuState.ChooseGameMode:
                GoToMenuState(MenuState.ChooseRuntime);
                break;

            case MenuState.ChooseRuntime:
                GoToMenuState(MenuState.PressStart);
                break;

            case MenuState.PressStart:
                Game.CurrentGameMode.GameMode    = gameMode;
                Game.CurrentGameMode.PlayerMode  = playerMode;
                Game.CurrentGameMode.RuntimeInfo = selectedRuntimeMode;
                this.TransitionOutAndSwitchScene(new JoinScene(Game));
                break;
            }
        }
Example #15
0
        private void OnBackPressed(InputFrame obj)
        {
            if (!areControlsEnabled)
            {
                return;
            }
            NonPositionalAudio.PlaySound("Audio/MenuActionSound");

            switch (state)
            {
            case MenuState.PressStart:
                GoToMenuState(MenuState.ChooseRuntime);
                break;

            case MenuState.ChooseRuntime:
                GoToMenuState(MenuState.ChooseGameMode);
                break;

            case MenuState.ChooseGameMode:
                GoToMenuState(MenuState.ChoosePlayerMode);
                break;

            case MenuState.ChoosePlayerMode:
                this.TransitionOutAndSwitchScene(new MainMenuScene(Game));
                break;
            }
        }
 public static void SkipNextInput()
 {
     if (ExportLibTas)
     {
         skipInputFrame = Manager.Controller.Current;
     }
 }
        private void MovementFromKeyboard(InputFrame obj)
        {
            inputMovementDirection = Vector2.Zero;
            if (obj.CurrentKeyboardFrame.IsKeyDown(Keys.A))
            {
                inputMovementDirection.X = -1;
            }

            if (obj.CurrentKeyboardFrame.IsKeyDown(Keys.D))
            {
                inputMovementDirection.X = 1;
            }

            if (obj.CurrentKeyboardFrame.IsKeyDown(Keys.W))
            {
                inputMovementDirection.Y = -1;
            }

            if (obj.CurrentKeyboardFrame.IsKeyDown(Keys.S))
            {
                inputMovementDirection.Y = 1;
            }

            if (inputMovementDirection.LengthSquared() > 0)
            {
                inputMovementDirection.Normalize();
            }
        }
Example #18
0
 public void AddFrame(InputFrame frame)
 {
     if (frameInputs.Count == capacity)
     {
         frameInputs.Dequeue();
     }
     frameInputs.Enqueue(frame);
 }
    private void Move(InputFrame input)
    {
        // Move the player, clamping the movement so diagonals aren't faster
        Vector3 translation = Vector3.ClampMagnitude(new Vector3(input.horizontal, 0, input.vertical), speed);

        rigidbody.position = Vector3.MoveTowards(rigidbody.position, rigidbody.position + translation, speed * Time.fixedDeltaTime);
        rigidbody.velocity = translation + Vector3.up * rigidbody.velocity.y;
    }
 public static void EndExport()
 {
     streamWriter?.Flush();
     streamWriter?.Dispose();
     streamWriter   = null;
     skipInputFrame = null;
     ExportLibTas   = false;
 }
Example #21
0
 private void OnStartPressed(InputFrame obj)
 {
     if (!areControlsEnabled)
     {
         return;
     }
     NonPositionalAudio.PlaySound("Audio/MenuActionSound");
 }
 private static void StartExport(string path)
 {
     FinishExport();
     streamWriter   = new StreamWriter(path, false, Encoding.ASCII, 1 << 20);
     fileName       = path;
     skipInputFrame = null;
     exporting      = true;
 }
 public static void FinishExport()
 {
     streamWriter?.Flush();
     streamWriter?.Dispose();
     streamWriter   = null;
     skipInputFrame = null;
     exporting      = false;
 }
 public static void BeginExport(string path)
 {
     if (!ExportLibTas)
     {
         streamWriter   = new StreamWriter(path, false, Encoding.ASCII, 1 << 20);
         skipInputFrame = null;
         ExportLibTas   = true;
     }
 }
 private void PlayerUpdate(InputFrame input)
 {
     // Set the velocity to zero, move the player based on the next input, then detect & resolve collisions
     rigidbody.velocity = new Vector3(0f, rigidbody.velocity.y, 0f);
     if (input != null && input.HasInput)
     {
         Move(input);
     }
 }
        private static InputFrame DeserializeFrame(BinaryReader reader)
        {
            int frames = reader.ReadInt32();

            // Keyboard
            byte keyLength = reader.ReadByte();

            Keys[] keys = new Keys[keyLength];
            for (int i = 0; i < keyLength; i++)
            {
                keys[i] = (Keys)reader.ReadByte();
            }

            KeyboardState keyboard = new KeyboardState(keys);

            // Mouse
            int  mouseX       = reader.ReadInt32();
            int  mouseY       = reader.ReadInt32();
            int  mouseScroll  = reader.ReadInt32();
            byte mouseButtons = reader.ReadByte();

            ButtonState leftButton   = ((mouseButtons & 0b00001) == 0) ? ButtonState.Released : ButtonState.Pressed;
            ButtonState middleButton = ((mouseButtons & 0b00010) == 0) ? ButtonState.Released : ButtonState.Pressed;
            ButtonState rightButton  = ((mouseButtons & 0b00100) == 0) ? ButtonState.Released : ButtonState.Pressed;
            ButtonState xButton1     = ((mouseButtons & 0b01000) == 0) ? ButtonState.Released : ButtonState.Pressed;
            ButtonState xButton2     = ((mouseButtons & 0b10000) == 0) ? ButtonState.Released : ButtonState.Pressed;

            MouseState mouse = new MouseState(mouseX, mouseY, mouseScroll, leftButton, middleButton, rightButton, xButton1, xButton2);

            // Gamepads
            XINPUT_GAMEPAD[] pads = new XINPUT_GAMEPAD[4];
            for (int i = 0; i < 4; i++)
            {
                pads[i].Connected = reader.ReadBoolean();
                if (!pads[i].Connected)
                {
                    continue;
                }

                pads[i].Buttons      = reader.ReadUInt16();
                pads[i].LeftTrigger  = reader.ReadByte();
                pads[i].RightTrigger = reader.ReadByte();
                pads[i].ThumbLX      = reader.ReadInt16();
                pads[i].ThumbLY      = reader.ReadInt16();
                pads[i].ThumbRX      = reader.ReadInt16();
                pads[i].ThumbRY      = reader.ReadInt16();
            }

            // Create frame
            InputFrame frame = default;

            frame.frames   = frames;
            frame.keyboard = keyboard;
            frame.mouse    = mouse;
            frame.pads     = pads;
            return(frame);
        }
Example #27
0
 void Update()
 {
     //collect the next input to send
     nextInputFrame = new InputFrame()
     {
         horizontalInput = Input.GetAxis("Horizontal"),
         verticalInput   = Input.GetAxis("Vertical")
     };
 }
Example #28
0
 static public Vector2 GetFeather(InputFrame input)
 {
     if (input == LastQuery)
     {
         return(LastDirection);
     }
     LastQuery = input;
     return(ComputeFeather(input.GetX(), input.GetY(), input.Precision));
 }
 public override void OnInput(RpcArgs args)
 {
     if (networkObject.IsServer)
     {
         Byte[]     bytes  = args.GetNext <Byte[]>();
         InputFrame newest = (InputFrame)ByteArray.Deserialize(bytes);
         FramesToPlay.Add(newest);
     }
 }
Example #30
0
 public void SetFrozen(bool frozen)
 {
     _canMove = !frozen;
     if (frozen)
     {
         _playerController.SetVelocity(Vector2.zero);
         _inputFrame = InputFrame.Empty;
     }
 }
Example #31
0
    public void AddFrameData(int frame, Vector3 pos)
    {
        // Only add if it differs from the last frame
        InputFrame lastFrame = GetFrameData(frame);
#if UNITY_EDITOR
        if(lastFrame != null && lastFrame.Frame == frame)
        {
            throw new System.ArgumentException("Frame data already present", "frame");
        }
#endif

        if(lastFrame == null
            || lastFrame.pos != pos)
        {
            InputFrame thisFrame = new InputFrame();
            thisFrame.Frame = frame;
            thisFrame.pos = pos;
            FrameData.Add(thisFrame);
            FrameData.Sort((x, y) => x.Frame.CompareTo(y.Frame));
        }
    }
Example #32
0
        private void PushInputFrame(InputFrame frame)
        {
            lock (mSyncObject)
            {
                if (mDisposeTask != null)
                    throw new ObjectDisposedException(null);

                if (mFlushed)
                    throw new InvalidOperationException();

                mInputQueue.Enqueue(frame);
                TryStartDecoding();
            }
        }
Example #33
0
        /// <summary>
        /// Pass input data to the decoder. You must not modify the specified region of the buffer until the returned task completes.
        /// </summary>
        /// <param name="buffer">The buffer containing the input data.</param>
        /// <param name="offset">The offset at which the input data begins.</param>
        /// <param name="length">The length of the input data.</param>
        /// <returns>A task which tells you when the input data has been completely read and the buffer can be reused.</returns>
        public Task WriteInputAsync(byte[] buffer, int offset, int length)
        {
            if (buffer == null)
                throw new ArgumentNullException(nameof(buffer));

            if (offset < 0 || offset > buffer.Length)
                throw new ArgumentOutOfRangeException(nameof(offset));

            if (length < 0 || length > buffer.Length - offset)
                throw new ArgumentOutOfRangeException(nameof(length));

            var frame = new InputFrame();
            frame.mBuffer = buffer;
            frame.mOrigin = offset;
            frame.mOffset = offset;
            frame.mEnding = offset + length;
            PushInputFrame(frame);
            return frame.mCompletion.Task;
        }