Implement setEnabled method for sound track objects, fixes warnings on terminal and fixes hiding objects containing sounds from scripting

This commit is contained in:
Marianne Gagnon 2015-08-07 18:26:37 -04:00
parent 5b353a8921
commit 43d5dbeb3e
2 changed files with 26 additions and 5 deletions

View File

@ -583,6 +583,7 @@ TrackObjectPresentationSound::TrackObjectPresentationSound(
{
// TODO: respect 'parent' if any
m_enabled = true;
m_sound = NULL;
m_xyz = m_init_xyz;
@ -642,7 +643,7 @@ TrackObjectPresentationSound::TrackObjectPresentationSound(
// ----------------------------------------------------------------------------
void TrackObjectPresentationSound::update(float dt)
{
if (m_sound != NULL)
if (m_sound != NULL && m_enabled)
{
// muting when too far is implemented manually since not supported by
// OpenAL so need to call this every frame to update the muting state
@ -654,7 +655,7 @@ void TrackObjectPresentationSound::update(float dt)
// ----------------------------------------------------------------------------
void TrackObjectPresentationSound::onTriggerItemApproached()
{
if (m_sound != NULL && m_sound->getStatus() != SFXBase::SFX_PLAYING)
if (m_sound != NULL && m_sound->getStatus() != SFXBase::SFX_PLAYING && m_enabled)
{
m_sound->play();
}
@ -663,7 +664,7 @@ void TrackObjectPresentationSound::onTriggerItemApproached()
// ----------------------------------------------------------------------------
void TrackObjectPresentationSound::triggerSound(bool loop)
{
if (m_sound != NULL)
if (m_sound != NULL && m_enabled)
{
m_sound->setLoop(loop);
m_sound->play();
@ -673,7 +674,8 @@ void TrackObjectPresentationSound::triggerSound(bool loop)
// ----------------------------------------------------------------------------
void TrackObjectPresentationSound::stopSound()
{
if (m_sound != NULL) m_sound->stop();
if (m_sound != NULL)
m_sound->stop();
} // stopSound
// ----------------------------------------------------------------------------
@ -692,9 +694,24 @@ void TrackObjectPresentationSound::move(const core::vector3df& xyz,
bool isAbsoluteCoord)
{
m_xyz = xyz;
if (m_sound != NULL) m_sound->setPosition(xyz);
if (m_sound != NULL && m_enabled)
m_sound->setPosition(xyz);
} // move
// ----------------------------------------------------------------------------
void TrackObjectPresentationSound::setEnable(bool enabled)
{
if (enabled != m_enabled)
{
m_enabled = enabled;
if (enabled)
triggerSound(true);
else
stopSound();
}
}
// ----------------------------------------------------------------------------
TrackObjectPresentationBillboard::TrackObjectPresentationBillboard(
const XMLNode& xml_node,

View File

@ -265,6 +265,8 @@ private:
core::vector3df m_xyz;
bool m_enabled;
public:
TrackObjectPresentationSound(const XMLNode& xml_node,
@ -277,6 +279,8 @@ public:
void triggerSound(bool loop);
void stopSound();
virtual void setEnable(bool enabled) OVERRIDE;
// ------------------------------------------------------------------------
/** Currently used for sound effects only, in cutscenes only atm */
const std::string& getTriggerCondition() const { return m_trigger_condition; }