void Ship::DoThrusterSounds() const { // XXX any ship being the current camera body should emit sounds // also, ship sounds could be split to internal and external sounds // XXX sound logic could be part of a bigger class (ship internal sounds) /* Ship engine noise. less loud inside */ float v_env = (Pi::game->GetWorldView()->GetCameraController()->IsExternal() ? 1.0f : 0.5f) * Sound::GetSfxVolume(); static Sound::Event sndev; float volBoth = 0.0f; volBoth += 0.5f*fabs(GetThrusterState().y); volBoth += 0.5f*fabs(GetThrusterState().z); float targetVol[2] = { volBoth, volBoth }; if (GetThrusterState().x > 0.0) targetVol[0] += 0.5f*float(GetThrusterState().x); else targetVol[1] += -0.5f*float(GetThrusterState().x); targetVol[0] = v_env * Clamp(targetVol[0], 0.0f, 1.0f); targetVol[1] = v_env * Clamp(targetVol[1], 0.0f, 1.0f); float dv_dt[2] = { 4.0f, 4.0f }; if (!sndev.VolumeAnimate(targetVol, dv_dt)) { sndev.Play("Thruster_large", 0.0f, 0.0f, Sound::OP_REPEAT); sndev.VolumeAnimate(targetVol, dv_dt); } float angthrust = 0.1f * v_env * float(GetAngThrusterState().Length()); static Sound::Event angThrustSnd; if (!angThrustSnd.VolumeAnimate(angthrust, angthrust, 5.0f, 5.0f)) { angThrustSnd.Play("Thruster_Small", 0.0f, 0.0f, Sound::OP_REPEAT); angThrustSnd.VolumeAnimate(angthrust, angthrust, 5.0f, 5.0f); } }
void Player::StaticUpdate(const float timeStep) { Body *b; vector3d v; matrix4x4d m; if (GetFlightState() == Ship::FLYING) { switch (m_flightControlState) { case CONTROL_FIXSPEED: if (Pi::GetView() == Pi::worldView) PollControls(timeStep); b = (GetCombatTarget() ? GetCombatTarget() : GetNavTarget()); GetRotMatrix(m); v = m * vector3d(0, 0, -m_setSpeed); if (b) v += b->GetVelocityRelativeTo(this->GetFrame()); AIMatchVel(v); break; case CONTROL_MANUAL: if (Pi::GetView() == Pi::worldView) PollControls(timeStep); break; case CONTROL_AUTOPILOT: break; } } Ship::StaticUpdate(timeStep); // also calls autopilot AI if (m_flightControlState == CONTROL_AUTOPILOT && !AIIsActive()) { Pi::RequestTimeAccel(1); SetFlightControlState(CONTROL_MANUAL); //FIXSPEED); // m_setSpeed = 0; } /* This wank probably shouldn't be in Player... */ /* Ship engine noise. less loud inside */ float v_env = (Pi::worldView->GetCamType() == WorldView::CAM_EXTERNAL ? 1.0f : 0.5f); static Sound::Event sndev; float volBoth = 0.0f; volBoth += 0.5f*fabs(GetThrusterState().y); volBoth += 0.5f*fabs(GetThrusterState().z); float targetVol[2] = { volBoth, volBoth }; if (GetThrusterState().x > 0.0) targetVol[0] += 0.5f*(float)GetThrusterState().x; else targetVol[1] += -0.5f*(float)GetThrusterState().x; targetVol[0] = v_env * Clamp(targetVol[0], 0.0f, 1.0f); targetVol[1] = v_env * Clamp(targetVol[1], 0.0f, 1.0f); float dv_dt[2] = { 4.0f, 4.0f }; if (!sndev.VolumeAnimate(targetVol, dv_dt)) { sndev.Play("Thruster_large", 0.0f, 0.0f, Sound::OP_REPEAT); sndev.VolumeAnimate(targetVol, dv_dt); } float angthrust = 0.1f * v_env * (float)Pi::player->GetAngThrusterState().Length(); static Sound::Event angThrustSnd; if (!angThrustSnd.VolumeAnimate(angthrust, angthrust, 5.0f, 5.0f)) { angThrustSnd.Play("Thruster_Small", 0.0f, 0.0f, Sound::OP_REPEAT); angThrustSnd.VolumeAnimate(angthrust, angthrust, 5.0f, 5.0f); } }
void Missile::StaticUpdate(const float timeStep) { // Note: direct call to AI->TimeStepUpdate if (m_curAICmd!=nullptr) m_curAICmd->TimeStepUpdate(); //Add smoke trails for missiles on thruster state static double s_timeAccum = 0.0; s_timeAccum += timeStep; if (!is_equal_exact(GetThrusterState().LengthSqr(), 0.0) && (s_timeAccum > 4 || 0.1*Pi::rng.Double() < timeStep)) { s_timeAccum = 0.0; const vector3d pos = GetOrient() * vector3d(0, 0 , 5); const float speed = std::min(10.0*GetVelocity().Length()*std::max(1.0,fabs(GetThrusterState().z)),100.0); SfxManager::AddThrustSmoke(this, speed, pos); } }
// position in ship's frame vector3d Ship::AIGetNextFramePos() { vector3d thrusters = GetThrusterState(); vector3d maxThrust = GetMaxThrust(thrusters); vector3d thrust = vector3d(maxThrust.x*thrusters.x, maxThrust.y*thrusters.y, maxThrust.z*thrusters.z); matrix4x4d rot; GetRotMatrix(rot); vector3d vel = GetVelocity() + rot * thrust * Pi::GetTimeStep() / GetMass(); vector3d pos = GetPosition() + vel * Pi::GetTimeStep(); return pos; }
void Player::StaticUpdate(const float timeStep) { vector3d v; matrix4x4d m; Ship::StaticUpdate(timeStep); // also calls autopilot AI if (GetFlightState() == Ship::FLYING) { switch (m_flightControlState) { case CONTROL_FIXSPEED: if (Pi::GetView() == Pi::worldView) PollControls(timeStep); if (IsAnyThrusterKeyDown()) break; GetRotMatrix(m); v = m * vector3d(0, 0, -m_setSpeed); if (m_setSpeedTarget) { v += m_setSpeedTarget->GetVelocityRelTo(GetFrame()); } AIMatchVel(v); break; case CONTROL_MANUAL: if (Pi::GetView() == Pi::worldView) PollControls(timeStep); break; case CONTROL_AUTOPILOT: if (AIIsActive()) break; Pi::game->RequestTimeAccel(Game::TIMEACCEL_1X); // AIMatchVel(vector3d(0.0)); // just in case autopilot doesn't... // actually this breaks last timestep slightly in non-relative target cases AIMatchAngVelObjSpace(vector3d(0.0)); if (GetFrame()->IsRotatingFrame()) SetFlightControlState(CONTROL_FIXSPEED); else SetFlightControlState(CONTROL_MANUAL); m_setSpeed = 0.0; break; } } else SetFlightControlState(CONTROL_MANUAL); /* This wank probably shouldn't be in Player... */ /* Ship engine noise. less loud inside */ float v_env = (Pi::worldView->GetCamType() == WorldView::CAM_EXTERNAL ? 1.0f : 0.5f) * Sound::GetSfxVolume(); static Sound::Event sndev; float volBoth = 0.0f; volBoth += 0.5f*fabs(GetThrusterState().y); volBoth += 0.5f*fabs(GetThrusterState().z); float targetVol[2] = { volBoth, volBoth }; if (GetThrusterState().x > 0.0) targetVol[0] += 0.5f*float(GetThrusterState().x); else targetVol[1] += -0.5f*float(GetThrusterState().x); targetVol[0] = v_env * Clamp(targetVol[0], 0.0f, 1.0f); targetVol[1] = v_env * Clamp(targetVol[1], 0.0f, 1.0f); float dv_dt[2] = { 4.0f, 4.0f }; if (!sndev.VolumeAnimate(targetVol, dv_dt)) { sndev.Play("Thruster_large", 0.0f, 0.0f, Sound::OP_REPEAT); sndev.VolumeAnimate(targetVol, dv_dt); } float angthrust = 0.1f * v_env * float(Pi::player->GetAngThrusterState().Length()); static Sound::Event angThrustSnd; if (!angThrustSnd.VolumeAnimate(angthrust, angthrust, 5.0f, 5.0f)) { angThrustSnd.Play("Thruster_Small", 0.0f, 0.0f, Sound::OP_REPEAT); angThrustSnd.VolumeAnimate(angthrust, angthrust, 5.0f, 5.0f); } }