Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5252 & #5189 #5367

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/karts/ghost_kart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#include "audio/sfx_manager.hpp"
#include "audio/sfx_base.hpp"
#include "items/attachment.hpp"
#include "items/powerup.hpp"
#include "karts/ghost_kart.hpp"
Expand All @@ -26,6 +28,7 @@
#include "modes/linear_world.hpp"
#include "modes/world.hpp"
#include "replay/replay_recorder.hpp"
#include "tracks/terrain_info.hpp"
#include "tracks/track.hpp"

#include "LinearMath/btQuaternion.h"
Expand Down Expand Up @@ -99,6 +102,8 @@ void GhostKart::updateGraphics(float dt)
Moveable::updateGraphics(center_shift, btQuaternion(0, 0, 0, 1));
// Also update attachment's graphics
m_attachment->updateGraphics(dt);

updateSound(dt);
} // updateGraphics

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -219,6 +224,8 @@ void GhostKart::update(int ticks)
m_all_replay_events[idx].m_red_skidding);
getKartGFX()->update(dt);

m_speed = getSpeed();

Vec3 front(0, 0, getKartLength()*0.5f);
m_xyz_front = getTrans()(front);

Expand All @@ -233,12 +240,62 @@ void GhostKart::update(int ticks)
getKartModel()->setAnimation(KartModel::AF_DEFAULT);
}

m_terrain_info->update(getTrans().getBasis(),
getXYZ() + getTrans().getBasis().getColumn(1) * 0.1f);
} // update

// ----------------------------------------------------------------------------
void GhostKart::updateSound(float dt)
{
if (!getController()) return;

GhostController* gc = dynamic_cast<GhostController*>(getController());
if (gc == NULL) return;

const unsigned int idx = gc->getCurrentReplayIndex();

updateEngineSFX(dt);

if (m_skid_sound)
{
if(m_all_replay_events[idx].m_skidding_effect)
{
if (m_skid_sound->getStatus()!=SFXBase::SFX_PLAYING)
{
m_skid_sound->play(getSmoothedXYZ());
}
}
else if(m_skid_sound->getStatus()==SFXBase::SFX_PLAYING)
{
m_skid_sound->stop();
}
}

if (m_nitro_sound)
{
if(m_all_replay_events[idx].m_nitro_usage)
{
if (m_nitro_sound->getStatus()!=SFXBase::SFX_PLAYING)
{
m_nitro_sound->play(getSmoothedXYZ());
}
}
else if(m_nitro_sound->getStatus()==SFXBase::SFX_PLAYING)
{
m_nitro_sound->stop();
}
}
}

// ----------------------------------------------------------------------------
/** Returns the speed of the kart in meters/second. */
float GhostKart::getSpeed() const
{
if (!getController())
{
return 0.f;
}

const GhostController* gc =
dynamic_cast<const GhostController*>(getController());

Expand Down
7 changes: 7 additions & 0 deletions src/karts/ghost_kart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ class GhostKart : public Kart
// ----------------------------------------------------------------------------
/** Compute the time at which the ghost finished the race */
void computeFinishTime();
// ----------------------------------------------------------------------------
/** Update sound effect upon ghost replay data */
void updateSound(float dt);

public:
GhostKart(const std::string& ident, unsigned int world_kart_id,
int position, float color_hue,
Expand Down Expand Up @@ -84,6 +88,9 @@ class GhostKart : public Kart
/** Ghost can't be hunted. */
virtual bool isInvulnerable() const OVERRIDE { return true; }
// ------------------------------------------------------------------------
/** Ghost are not on the ground if flying. */
virtual bool isOnGround() const OVERRIDE { return !m_flying; }
// ------------------------------------------------------------------------
/** Returns the speed of the kart in meters/second. */
virtual float getSpeed() const OVERRIDE;
// ------------------------------------------------------------------------
Expand Down
13 changes: 9 additions & 4 deletions src/karts/kart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,15 @@ void Kart::updateEngineSFX(float dt)
{
// Only update SFX during the last substep (otherwise too many SFX commands
// in one frame), and if sfx are enabled
if(!m_engine_sound || !SFXManager::get()->sfxAllowed() )
if(!SFXManager::get()->sfxAllowed())
return;

if (m_skid_sound)
m_skid_sound->setPosition(getSmoothedXYZ());
if (m_nitro_sound)
m_nitro_sound->setPosition(getSmoothedXYZ());

if (!m_engine_sound)
return;

// when going faster, use higher pitch for engine
Expand Down Expand Up @@ -3265,9 +3273,6 @@ void Kart::updateGraphics(float dt)

for (int i = 0; i < EMITTER_COUNT; i++)
m_emitters[i]->setPosition(getXYZ());
if (m_skid_sound)
m_skid_sound->setPosition(getSmoothedXYZ());
m_nitro_sound->setPosition(getSmoothedXYZ());

m_attachment->updateGraphics(dt);

Expand Down
Loading