public SteeringStep Update()
        {
            try {
                if (_keyboard.Acquire().IsFailure)
                {
                    return(null);
                }

                if (_keyboard.Poll().IsFailure)
                {
                    return(null);
                }

                var state = _keyboard.GetCurrentState();
                if (!IsKeyboardUpdateRequired(state))
                {
                    return(null);
                }

                var step = new SteeringStep {
                    DirectionPercentage = VALOCITY, CamDirectionPercentage = VALOCITY
                };
                step.WithDirection(SteeringStep.MovingDirection.Left, state.PressedKeys.Contains(Key.A) && !state.PressedKeys.Contains(Key.D));
                step.WithDirection(SteeringStep.MovingDirection.Right, !state.PressedKeys.Contains(Key.A) && state.PressedKeys.Contains(Key.D));
                step.SpeedPercentage = state.PressedKeys.Contains(Key.W) ? VALOCITY : state.PressedKeys.Contains(Key.S) ? -VALOCITY : 0.0;
                step.WithCamDirection(SteeringStep.CameraDirection.Up, state.PressedKeys.Contains(Key.UpArrow) && !state.PressedKeys.Contains(Key.DownArrow));
                step.WithCamDirection(SteeringStep.CameraDirection.Down, state.PressedKeys.Contains(Key.DownArrow) && !state.PressedKeys.Contains(Key.UpArrow));
                step.WithCamDirection(SteeringStep.CameraDirection.Left, state.PressedKeys.Contains(Key.LeftArrow) && !state.PressedKeys.Contains(Key.RightArrow));
                step.WithCamDirection(SteeringStep.CameraDirection.Right, state.PressedKeys.Contains(Key.RightArrow) && !state.PressedKeys.Contains(Key.LeftArrow));
                return(step);
            } catch (Exception ex) {
                Trace.TraceError("Could not poll keyboard event(s): {0}", ex.StackTrace);
                return(null);
            } finally { }
        }
Example #2
0
        public void ExecuteStep(SteeringStep step)
        {
            var ip    = new IPEndPoint(IPAddress.Broadcast, 1338);
            var data  = step.Serialize();
            var crc   = new Crc32();
            var value = crc.ComputeChecksum(data);

            step.Crc = value;

            data = step.Serialize();
            _socket.Send(data, data.Length, ip);
        }
Example #3
0
        private void HandleStep(SteeringStep step)
        {
            Car.IsTopActive    = step.SpeedPercentage > 0;
            Car.IsBottomActive = step.SpeedPercentage < 0;
            Car.IsRightActive  = (step.Direction & SteeringStep.MovingDirection.Right) == SteeringStep.MovingDirection.Right;
            Car.IsLeftActive   = (step.Direction & SteeringStep.MovingDirection.Left) == SteeringStep.MovingDirection.Left;

            Camera.IsTopActive    = (step.CamDirection & SteeringStep.CameraDirection.Up) == SteeringStep.CameraDirection.Up;
            Camera.IsBottomActive = (step.CamDirection & SteeringStep.CameraDirection.Down) == SteeringStep.CameraDirection.Down;
            Camera.IsRightActive  = (step.CamDirection & SteeringStep.CameraDirection.Right) == SteeringStep.CameraDirection.Right;
            Camera.IsLeftActive   = (step.CamDirection & SteeringStep.CameraDirection.Left) == SteeringStep.CameraDirection.Left;

            _engine.ExecuteStep(step);
        }
        public SteeringStep Update()
        {
            var pad = GetCachedOrRetry();

            if (pad == null)
            {
                return(null);
            }

            if (pad.Acquire().IsFailure)
            {
                return(null);
            }

            if (pad.Poll().IsFailure)
            {
                return(null);
            }

            var state = pad.GetCurrentState();

            if (Result.Last.IsFailure)
            {
                return(null);
            }

            if (!IsGamepadUpdateRequired(state))
            {
                return(null);
            }

            var step = new SteeringStep();

            step.SpeedPercentage = Percentage(state.RotationY, 65535, 0);

            return(step);
        }