Пример #1
0
//------------------------------------------------------------------------
void CVehicleMovementStdBoat::UpdateRunSound(const float deltaTime)
{
	Vec3 localAccel(ZERO);
	m_measureSpeedTimer+=deltaTime;

	if (m_measureSpeedTimer > 0.25f)
	{
		const Vec3& v = m_physStatus[k_mainThread].v;
		Vec3 accel = (v - m_lastMeasuredVel) * (1.f/m_measureSpeedTimer);
		localAccel = accel * m_physStatus[k_mainThread].q;

		m_lastMeasuredVel = v;
		m_measureSpeedTimer = 0.f;
	}

	if (m_pVehicle->IsProbablyDistant())
		return;

  // rpm dropdown for waves
  if (m_rpmPitchDir != 0)    
  { 
    float speed = (m_rpmPitchDir > 0) ? 0.1f : -0.8f; // quick down, slow up
    m_waveSoundPitch += deltaTime * speed;

    if (m_waveSoundPitch < -m_waveSoundAmount) // dropdown amount
    {
      m_waveSoundPitch = -m_waveSoundAmount;
      m_rpmPitchDir = 1;
    }      
    else if (m_waveSoundPitch > 0.f)
    {
      m_waveSoundPitch = 0.f;
      m_rpmPitchDir = 0;
    }
  }

  if (m_rpmPitchSpeed>0.f)
  {    
    const float maxPedal = (!m_inWater) ? 1.f : Boosting() ? 0.8f : 0.7f;

    // pitch rpm with pedal          
    float pedal = GetEnginePedal();
    pedal = sgnnz(pedal)*max(ms_engineSoundIdleRatio, min(maxPedal, abs(pedal))); // clamp "pedal" to [0.2..0.7] range

    float delta = pedal - m_rpmScaleSgn;
    m_rpmScaleSgn = max(-1.f, min(1.f, m_rpmScaleSgn + sgn(delta)*min(abs(delta), m_rpmPitchSpeed*deltaTime)));

    // skip transition around 0 when on pedal (sounds more realistic)
    if (abs(GetEnginePedal()) > 0.001f && abs(delta) > 0.001f && sgn(m_rpmScaleSgn) != sgn(delta) && abs(m_rpmScaleSgn) <= 0.3f)
      m_rpmScaleSgn = sgn(delta)*0.3f;

    // for normal driving, rpm is clamped at max defined by sound dept
    m_rpmScale = abs(m_rpmScaleSgn);
    m_rpmScale = min(1.f, max(ms_engineSoundIdleRatio, m_rpmScale + m_waveSoundPitch));

		m_pIEntityAudioProxy->SetRtpcValue(m_audioControlIDs[eSID_VehicleRPM], m_rpmScale);
  }
}
//------------------------------------------------------------------------
void CVehicleMovementStdBoat::UpdateRunSound(const float deltaTime)
{
	Vec3 localAccel(ZERO);
	m_measureSpeedTimer+=deltaTime;

	if(m_measureSpeedTimer > 0.25f)
	{
		Vec3 accel = (m_statusDyn.v - m_lastMeasuredVel) * (1.f/m_measureSpeedTimer);
		Matrix33 worldTM(!m_statusPos.q);
		localAccel = worldTM * accel;

		m_lastMeasuredVel = m_statusDyn.v;
		m_measureSpeedTimer = 0.f;
	}

	if(m_pVehicle->IsProbablyDistant())
		return;

	float soundSpeedRatio = ms_engineSoundIdleRatio + (1.f-ms_engineSoundIdleRatio) * m_speedRatio;

	SetSoundParam(eSID_Run, "speed", soundSpeedRatio);
	SetSoundParam(eSID_Ambience, "speed", soundSpeedRatio);
	//SetSoundParam(eSID_Run, "boost", Boosting() ? 1.f : 0.f);

	float acceleration = min(1.f, abs(localAccel.y) / m_accel*max(1.f, m_accelCoeff));

	if(acceleration > 0.5f)
	{
		if(ISound *pSound = GetOrPlaySound(eSID_Acceleration, 2.f))
			SetSoundParam(pSound, "acceleration", acceleration);
	}

	float damage = GetSoundDamage();

	if(damage > 0.1f)
	{
		if(ISound *pSound = GetOrPlaySound(eSID_Damage, 5.f, m_enginePos))
			SetSoundParam(pSound, "damage", damage);
	}

	// rpm dropdown for waves
	if(m_rpmPitchDir != 0)
	{
		float speed = (m_rpmPitchDir > 0) ? 0.1f : -0.8f; // quick down, slow up
		m_waveSoundPitch += deltaTime * speed;

		if(m_waveSoundPitch < -m_waveSoundAmount)  // dropdown amount
		{
			m_waveSoundPitch = -m_waveSoundAmount;
			m_rpmPitchDir = 1;
		}
		else if(m_waveSoundPitch > 0.f)
		{
			m_waveSoundPitch = 0.f;
			m_rpmPitchDir = 0;
		}
	}

	if(m_rpmPitchSpeed>0.f)
	{
		const float maxPedal = (!m_inWater) ? 1.f : Boosting() ? 0.8f : 0.7f;

		// pitch rpm with pedal
		float pedal = GetEnginePedal();
		pedal = sgnnz(pedal)*max(ms_engineSoundIdleRatio, min(maxPedal, abs(pedal))); // clamp "pedal" to [0.2..0.7] range

		float delta = pedal - m_rpmScaleSgn;
		m_rpmScaleSgn = max(-1.f, min(1.f, m_rpmScaleSgn + sgn(delta)*min(abs(delta), m_rpmPitchSpeed*deltaTime)));

		// skip transition around 0 when on pedal (sounds more realistic)
		if(abs(GetEnginePedal()) > 0.001f && abs(delta) > 0.001f && sgn(m_rpmScaleSgn) != sgn(delta) && abs(m_rpmScaleSgn) <= 0.3f)
			m_rpmScaleSgn = sgn(delta)*0.3f;

		// for normal driving, rpm is clamped at max defined by sound dept
		m_rpmScale = abs(m_rpmScaleSgn);
		m_rpmScale = min(1.f, max(ms_engineSoundIdleRatio, m_rpmScale + m_waveSoundPitch));

		SetSoundParam(eSID_Run, "rpm_scale", m_rpmScale);
		SetSoundParam(eSID_Ambience, "rpm_scale", m_rpmScale);
	}
}