示例#1
0
        public override void Update(float motorRpmPercent, GearboxAction action)
        {
            if (_motor.Rpm < 2 && (_currentGear == GEAR_NEUTRAL || _currentGear == GEAR_1) && action == GearboxAction.GearDown)
            {
                GearDown();
            }
            if ((_currentGear == GEAR_REVERSE || _currentGear == GEAR_NEUTRAL) && action == GearboxAction.GearUp)
            {
                GearUp();
            }

            if (!_motor.WheelsSpinning)
            {
                if (_currentGear == GEAR_REVERSE || _currentGear == GEAR_NEUTRAL)
                {
                }
                else
                {
                    if (motorRpmPercent > ChangeUpPoint && _currentGear < Ratios.Count - 1)
                    {
                        GearUp();
                    }
                    if (motorRpmPercent < ChangeDownPoint && CurrentGear > 1 && GearEngaged && !_motor.IsAccelerating && _motor.CanChangeDown)
                    {
                        GearDown();
                    }
                }
            }

            base.Update(motorRpmPercent, action);
        }
示例#2
0
        public override void Update(float motorRpmPercent, GearboxAction action)
        {
            if (_motor.Rpm < 2 && (_currentGear == GEAR_NEUTRAL || _currentGear == GEAR_1) && action == GearboxAction.GearDown)
            {
                GearDown();
            }
            if ((_currentGear == GEAR_REVERSE || _currentGear == GEAR_NEUTRAL) && action == GearboxAction.GearUp)
            {
                GearUp();
            }

            if (!_motor.WheelsSpinning)
            {

                if (_currentGear == GEAR_REVERSE || _currentGear == GEAR_NEUTRAL)
                {

                }
                else
                {
                    if (motorRpmPercent > ChangeUpPoint && _currentGear < Ratios.Count - 1)
                        GearUp();
                    if (motorRpmPercent < ChangeDownPoint && CurrentGear > 1 && GearEngaged && !_motor.IsAccelerating && _motor.CanChangeDown)
                        GearDown();
                }
            }

            base.Update(motorRpmPercent, action);
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="motorRpmPercent">0..1 where 1 is max rpms</param>
        /// <param name="gameTime"></param>
        public virtual void Update(float motorRpmPercent, GearboxAction action)
        {
            if (_gearChange != null)
            {
                _gearChange.TimeTillEngaged -= Engine.Instance.FrameTime;

                if (_gearChange.TimeTillEngaged <= 0)
                {
                    if (_gearChange.Change > 0)
                    {
                        if (_currentGear < _ratios.Count - 1)
                        {
                            _currentGear++;
                        }
                    }
                    else
                    {
                        if (_currentGear > -1)
                        {
                            _currentGear--;
                        }
                    }
                    _clutch     = 1.0f;
                    _gearChange = null;
                    if (GearChangeCompleted != null)
                    {
                        GearChangeCompleted(this, null);
                    }
                }
                else
                {
                    _clutch = (_changeTime - _gearChange.TimeTillEngaged) / _changeTime;
                }
            }
        }
示例#4
0
        public void Update(float carSpeed, GearboxAction action)
        {
            _prevRpm      = _rpm;
            _lastCarSpeed = carSpeed;

            if (_rpm >= _redlineRpm)
            {
                _rpm = _redlineRpm;
            }

            if (_rpmLimiter > 0)
            {
                if (!WheelsSpinning)
                {
                    _currentPowerOutput = 0;
                }
                //_throttle = 0;
                _rpmLimiter -= Engine.Instance.FrameTime;
            }
            else
            {
                _currentPowerOutput = _maxPower * MathHelper.Lerp(_powerCurve[(int)_rpm], _powerCurve[(int)_rpm + 1], _rpm - (int)_rpm);
            }

            if (_gearbox.GearEngaged)
            {
                if (_gearbox.CurrentGear == 0 || WheelsSpinning)
                {
                    HandleRpmNoLoad();
                }
                else
                {
                    _rpm = carSpeed * _gearbox.CurrentRatio / DRIVETRAIN_MULTIPLIER;
                    if (_rpm < 0.8f)
                    {
                        _rpm = 0.8f;  //idle speed
                    }
                }
                _prevEngagedRpm = _rpm;
            }
            else
            {
                _rpm = MathHelper.Lerp(_prevEngagedRpm /*Math.Abs(carSpeed) * _gearbox.CurrentRatio / DRIVETRAIN_MULTIPLIER*/,
                                       carSpeed * _gearbox.NextRatio / DRIVETRAIN_MULTIPLIER, _gearbox.Clutch);
            }

            if (_rpm < 0.8f)
            {
                _rpm = 0.8f;
            }

            if (_rpm >= _redlineRpm)
            {
                _rpmLimiter = 0.2f;
                _rpm        = _redlineRpm;
            }

            _gearbox.Update(_rpm / _redlineRpm, action);
        }
示例#5
0
        public override void Update(float motorRpmPercent, GearboxAction action)
        {
            if (action == GearboxAction.GearUp && _currentGear < Ratios.Count - 1)
                GearUp();
            if (action == GearboxAction.GearDown && CurrentGear > -1 && _motor.CanChangeDown)
                GearDown();

            base.Update(motorRpmPercent, action);
        }
示例#6
0
        public override void Update(float motorRpmPercent, GearboxAction action)
        {
            if (action == GearboxAction.GearUp && _currentGear < Ratios.Count - 1)
            {
                GearUp();
            }
            if (action == GearboxAction.GearDown && CurrentGear > -1 && _motor.CanChangeDown)
            {
                GearDown();
            }

            base.Update(motorRpmPercent, action);
        }
示例#7
0
        private void UpdateEngineForce()
        {
            _previousSpeed = Speed;

            float newAccelerationForce = 0.0f;

            Motor.Throttle        = ThrottlePedalInput;
            newAccelerationForce += Motor.CurrentPowerOutput * 0.4f;

            if (Motor.Gearbox.GearEngaged && Motor.Gearbox.CurrentGear > 0)
            {
                float tractionFactor = Math.Min(1, (_traction + Speed) / newAccelerationForce);
                Motor.WheelsSpinning = tractionFactor < 1 || (Motor.Rpm > 0.7f && Speed < 10 && Motor.Throttle > 0);
                if (Motor.WheelsSpinning)
                {
                    _audioProvider.PlaySkid(true);
                    Wheels[2].IsSkidding = Wheels[3].IsSkidding = true;
                }
                else if (!_isOnGround)
                {
                    Motor.WheelsSpinning = true;
                }
            }

            GearboxAction action = GearboxAction.None;

            if (GearUpInput)
            {
                action = GearboxAction.GearUp;
            }
            else if (GearDownInput)
            {
                action = GearboxAction.GearDown;
            }
            Motor.Update(Speed, action);

            if (Motor.AtRedline && !Motor.WheelsSpinning)
            {
                _force *= 0.2f;
            }

            if (Motor.Throttle == 0 && Math.Abs(Speed) < 1)
            {
                Speed = 0;
            }

            if (_isOnGround)
            {
                _force += Direction * newAccelerationForce * Engine.Instance.FrameTime * 2.5f;
            }
        }
示例#8
0
文件: Motor.cs 项目: STPKITT/OpenNFS1
        public void Update(float carSpeed, GearboxAction action)
        {
            _prevRpm = _rpm;
            _lastCarSpeed = carSpeed;

            if (_rpm >= _redlineRpm)
            {
                _rpm = _redlineRpm;
            }

            if (_rpmLimiter > 0)
            {
                if (!WheelsSpinning) _currentPowerOutput = 0;
                //_throttle = 0;
                _rpmLimiter -= Engine.Instance.FrameTime;
            }
            else
                _currentPowerOutput = _maxPower * MathHelper.Lerp(_powerCurve[(int)_rpm], _powerCurve[(int)_rpm + 1], _rpm - (int)_rpm);

            if (_gearbox.GearEngaged)
            {
                if (_gearbox.CurrentGear == 0 || WheelsSpinning)
                {
                    HandleRpmNoLoad();
                }
                else
                {
                    _rpm = carSpeed * _gearbox.CurrentRatio / DRIVETRAIN_MULTIPLIER;
                    if (_rpm < 0.8f)
                        _rpm = 0.8f;  //idle speed
                }
                _prevEngagedRpm = _rpm;
            }
            else
            {
                _rpm = MathHelper.Lerp(_prevEngagedRpm /*Math.Abs(carSpeed) * _gearbox.CurrentRatio / DRIVETRAIN_MULTIPLIER*/,
                    carSpeed * _gearbox.NextRatio / DRIVETRAIN_MULTIPLIER, _gearbox.Clutch);
            }

            if (_rpm < 0.8f)
                _rpm = 0.8f;

            if (_rpm >= _redlineRpm)
            {
                _rpmLimiter = 0.2f;
                _rpm = _redlineRpm;
            }

            _gearbox.Update(_rpm / _redlineRpm, action);
        }
示例#9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="motorRpmPercent">0..1 where 1 is max rpms</param>
        /// <param name="gameTime"></param>
        public virtual void Update(float motorRpmPercent, GearboxAction action)
        {
            if (_gearChange != null)
            {
                _gearChange.TimeTillEngaged -= Engine.Instance.FrameTime;

                if (_gearChange.TimeTillEngaged <= 0)
                {
                    if (_gearChange.Change > 0)
                    {
                        if (_currentGear < _ratios.Count - 1)
                            _currentGear++;
                    }
                    else
                    {
                        if (_currentGear > -1)
                            _currentGear--;
                    }
                    _clutch = 1.0f;
                    _gearChange = null;
                    if (GearChangeCompleted != null) GearChangeCompleted(this, null);
                }
                else
                {
                    _clutch = (_changeTime - _gearChange.TimeTillEngaged) / _changeTime;
                }
            }
        }