Skip to content

Commit 6c287e0

Browse files
Fix #5252 & #5189 (#5367)
1 parent 6fdf215 commit 6c287e0

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

src/karts/ghost_kart.cpp

+57
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// along with this program; if not, write to the Free Software
1717
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1818

19+
#include "audio/sfx_manager.hpp"
20+
#include "audio/sfx_base.hpp"
1921
#include "items/attachment.hpp"
2022
#include "items/powerup.hpp"
2123
#include "karts/ghost_kart.hpp"
@@ -26,6 +28,7 @@
2628
#include "modes/linear_world.hpp"
2729
#include "modes/world.hpp"
2830
#include "replay/replay_recorder.hpp"
31+
#include "tracks/terrain_info.hpp"
2932
#include "tracks/track.hpp"
3033

3134
#include "LinearMath/btQuaternion.h"
@@ -99,6 +102,8 @@ void GhostKart::updateGraphics(float dt)
99102
Moveable::updateGraphics(center_shift, btQuaternion(0, 0, 0, 1));
100103
// Also update attachment's graphics
101104
m_attachment->updateGraphics(dt);
105+
106+
updateSound(dt);
102107
} // updateGraphics
103108

104109
// ----------------------------------------------------------------------------
@@ -219,6 +224,8 @@ void GhostKart::update(int ticks)
219224
m_all_replay_events[idx].m_red_skidding);
220225
getKartGFX()->update(dt);
221226

227+
m_speed = getSpeed();
228+
222229
Vec3 front(0, 0, getKartLength()*0.5f);
223230
m_xyz_front = getTrans()(front);
224231

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

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

247+
// ----------------------------------------------------------------------------
248+
void GhostKart::updateSound(float dt)
249+
{
250+
if (!getController()) return;
251+
252+
GhostController* gc = dynamic_cast<GhostController*>(getController());
253+
if (gc == NULL) return;
254+
255+
const unsigned int idx = gc->getCurrentReplayIndex();
256+
257+
updateEngineSFX(dt);
258+
259+
if (m_skid_sound)
260+
{
261+
if(m_all_replay_events[idx].m_skidding_effect)
262+
{
263+
if (m_skid_sound->getStatus()!=SFXBase::SFX_PLAYING)
264+
{
265+
m_skid_sound->play(getSmoothedXYZ());
266+
}
267+
}
268+
else if(m_skid_sound->getStatus()==SFXBase::SFX_PLAYING)
269+
{
270+
m_skid_sound->stop();
271+
}
272+
}
273+
274+
if (m_nitro_sound)
275+
{
276+
if(m_all_replay_events[idx].m_nitro_usage)
277+
{
278+
if (m_nitro_sound->getStatus()!=SFXBase::SFX_PLAYING)
279+
{
280+
m_nitro_sound->play(getSmoothedXYZ());
281+
}
282+
}
283+
else if(m_nitro_sound->getStatus()==SFXBase::SFX_PLAYING)
284+
{
285+
m_nitro_sound->stop();
286+
}
287+
}
288+
}
289+
238290
// ----------------------------------------------------------------------------
239291
/** Returns the speed of the kart in meters/second. */
240292
float GhostKart::getSpeed() const
241293
{
294+
if (!getController())
295+
{
296+
return 0.f;
297+
}
298+
242299
const GhostController* gc =
243300
dynamic_cast<const GhostController*>(getController());
244301

src/karts/ghost_kart.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ class GhostKart : public Kart
5555
// ----------------------------------------------------------------------------
5656
/** Compute the time at which the ghost finished the race */
5757
void computeFinishTime();
58+
// ----------------------------------------------------------------------------
59+
/** Update sound effect upon ghost replay data */
60+
void updateSound(float dt);
61+
5862
public:
5963
GhostKart(const std::string& ident, unsigned int world_kart_id,
6064
int position, float color_hue,
@@ -84,6 +88,9 @@ class GhostKart : public Kart
8488
/** Ghost can't be hunted. */
8589
virtual bool isInvulnerable() const OVERRIDE { return true; }
8690
// ------------------------------------------------------------------------
91+
/** Ghost are not on the ground if flying. */
92+
virtual bool isOnGround() const OVERRIDE { return !m_flying; }
93+
// ------------------------------------------------------------------------
8794
/** Returns the speed of the kart in meters/second. */
8895
virtual float getSpeed() const OVERRIDE;
8996
// ------------------------------------------------------------------------

src/karts/kart.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -2679,7 +2679,15 @@ void Kart::updateEngineSFX(float dt)
26792679
{
26802680
// Only update SFX during the last substep (otherwise too many SFX commands
26812681
// in one frame), and if sfx are enabled
2682-
if(!m_engine_sound || !SFXManager::get()->sfxAllowed() )
2682+
if(!SFXManager::get()->sfxAllowed())
2683+
return;
2684+
2685+
if (m_skid_sound)
2686+
m_skid_sound->setPosition(getSmoothedXYZ());
2687+
if (m_nitro_sound)
2688+
m_nitro_sound->setPosition(getSmoothedXYZ());
2689+
2690+
if (!m_engine_sound)
26832691
return;
26842692

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

32663274
for (int i = 0; i < EMITTER_COUNT; i++)
32673275
m_emitters[i]->setPosition(getXYZ());
3268-
if (m_skid_sound)
3269-
m_skid_sound->setPosition(getSmoothedXYZ());
3270-
m_nitro_sound->setPosition(getSmoothedXYZ());
32713276

32723277
m_attachment->updateGraphics(dt);
32733278

0 commit comments

Comments
 (0)