Handle the setting of the listener position in the sfx thread.
This commit is contained in:
parent
7e4e857b41
commit
bba7156aff
@ -74,7 +74,10 @@ SFXManager::SFXManager()
|
||||
m_initialized = music_manager->initialized();
|
||||
m_master_gain = UserConfigParams::m_sfx_volume;
|
||||
// Init position, since it can be used before positionListener is called.
|
||||
m_position = Vec3(0,0,0);
|
||||
// No need to use lock here, since the thread will be created later.
|
||||
m_listener_position.getData() = Vec3(0, 0, 0);
|
||||
m_listener_front = Vec3(0, 0, 1);
|
||||
m_listener_up = Vec3(0, 1, 0);
|
||||
|
||||
loadSfx();
|
||||
|
||||
@ -261,21 +264,21 @@ void* SFXManager::mainLoop(void *obj)
|
||||
me->m_sfx_commands.unlock();
|
||||
switch(current->m_command)
|
||||
{
|
||||
case SFX_PLAY: current->m_sfx->reallyPlayNow(); break;
|
||||
case SFX_STOP: current->m_sfx->reallyStopNow(); break;
|
||||
case SFX_PAUSE: current->m_sfx->reallyPauseNow(); break;
|
||||
case SFX_RESUME: current->m_sfx->reallyResumeNow(); break;
|
||||
case SFX_SPEED: current->m_sfx->reallySetSpeed(
|
||||
case SFX_PLAY: current->m_sfx->reallyPlayNow(); break;
|
||||
case SFX_STOP: current->m_sfx->reallyStopNow(); break;
|
||||
case SFX_PAUSE: current->m_sfx->reallyPauseNow(); break;
|
||||
case SFX_RESUME: current->m_sfx->reallyResumeNow(); break;
|
||||
case SFX_SPEED: current->m_sfx->reallySetSpeed(
|
||||
current->m_parameter.getX()); break;
|
||||
case SFX_POSITION: current->m_sfx->reallySetPosition(
|
||||
current->m_parameter); break;
|
||||
case SFX_VOLUME: current->m_sfx->reallySetVolume(
|
||||
case SFX_VOLUME: current->m_sfx->reallySetVolume(
|
||||
current->m_parameter.getX()); break;
|
||||
case SFX_DELETE: {
|
||||
current->m_sfx->reallyStopNow();
|
||||
me->deleteSFX(current->m_sfx);
|
||||
break;
|
||||
}
|
||||
case SFX_DELETE: {
|
||||
current->m_sfx->reallyStopNow();
|
||||
me->deleteSFX(current->m_sfx); break;
|
||||
}
|
||||
case SFX_LISTENER: me->reallyPositionListenerNow(); break;
|
||||
default: assert("Not yet supported.");
|
||||
}
|
||||
delete current;
|
||||
@ -702,28 +705,51 @@ const std::string SFXManager::getErrorString(int err)
|
||||
/** Sets the position and orientation of the listener.
|
||||
* \param position Position of the listener.
|
||||
* \param front Which way the listener is facing.
|
||||
* \param up The up direction of the listener.
|
||||
*/
|
||||
void SFXManager::positionListener(const Vec3 &position, const Vec3 &front)
|
||||
void SFXManager::positionListener(const Vec3 &position, const Vec3 &front,
|
||||
const Vec3 &up)
|
||||
{
|
||||
m_listener_position.lock();
|
||||
m_listener_position.getData() = position;
|
||||
m_listener_front = front;
|
||||
m_listener_up = up;
|
||||
m_listener_position.unlock();
|
||||
queue(SFX_LISTENER, NULL);
|
||||
} // positionListener
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Sets the position and orientation of the listener.
|
||||
* \param position Position of the listener.
|
||||
* \param front Which way the listener is facing.
|
||||
*/
|
||||
void SFXManager::reallyPositionListenerNow()
|
||||
{
|
||||
#if HAVE_OGGVORBIS
|
||||
if (!UserConfigParams::m_sfx || !m_initialized) return;
|
||||
|
||||
m_position = position;
|
||||
m_listener_position.lock();
|
||||
{
|
||||
|
||||
//forward vector
|
||||
m_listenerVec[0] = front.getX();
|
||||
m_listenerVec[1] = front.getY();
|
||||
m_listenerVec[2] = front.getZ();
|
||||
//forward vector
|
||||
float orientation[6];
|
||||
orientation[0] = m_listener_front.getX();
|
||||
orientation[1] = m_listener_front.getY();
|
||||
orientation[2] = m_listener_front.getZ();
|
||||
|
||||
//up vector
|
||||
m_listenerVec[3] = 0;
|
||||
m_listenerVec[4] = 0;
|
||||
m_listenerVec[5] = 1;
|
||||
//up vector
|
||||
orientation[3] = m_listener_up.getX();
|
||||
orientation[4] = m_listener_up.getY();
|
||||
orientation[5] = m_listener_up.getZ();
|
||||
|
||||
const Vec3 &pos = m_listener_position.getData();
|
||||
alListener3f(AL_POSITION, pos.getX(), pos.getY(), pos.getZ());
|
||||
alListenerfv(AL_ORIENTATION, orientation);
|
||||
}
|
||||
m_listener_position.unlock();
|
||||
|
||||
alListener3f(AL_POSITION, position.getX(), position.getY(), position.getZ());
|
||||
alListenerfv(AL_ORIENTATION, m_listenerVec);
|
||||
#endif
|
||||
}
|
||||
} // reallyPositionListenerNow
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Positional sound is cool, but creating a new object just to play a simple
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
SFX_SPEED,
|
||||
SFX_POSITION,
|
||||
SFX_VOLUME,
|
||||
SFX_LISTENER,
|
||||
SFX_EXIT,
|
||||
}; // SFXCommands
|
||||
|
||||
@ -129,8 +130,17 @@ private:
|
||||
} // SFXCommand(Vec3)
|
||||
}; // SFXCommand
|
||||
// ========================================================================
|
||||
/** Listener position */
|
||||
Vec3 m_position;
|
||||
|
||||
/** The position of the listener. Its lock will be used to
|
||||
* access m_listener_{position,front, up}. */
|
||||
Synchronised<Vec3> m_listener_position;
|
||||
|
||||
/** The direction the listener is facing. */
|
||||
Vec3 m_listener_front;
|
||||
|
||||
/** Up vector of the listener. */
|
||||
Vec3 m_listener_up;
|
||||
|
||||
|
||||
/** The buffers and info for all sound effects. These are shared among all
|
||||
* instances of SFXOpenal. */
|
||||
@ -145,9 +155,6 @@ private:
|
||||
/** To play non-positional sounds without having to create a new object for each */
|
||||
std::map<std::string, SFXBase*> m_quick_sounds;
|
||||
|
||||
/** listener vector (position vector + up vector) */
|
||||
float m_listenerVec[6];
|
||||
|
||||
/** If the sfx manager has been initialised. */
|
||||
bool m_initialized;
|
||||
|
||||
@ -167,6 +174,8 @@ private:
|
||||
static void* mainLoop(void *obj);
|
||||
void deleteSFX(SFXBase *sfx);
|
||||
void queueCommand(SFXCommand *command);
|
||||
void reallyPositionListenerNow();
|
||||
|
||||
public:
|
||||
static void create();
|
||||
static void destroy();
|
||||
@ -211,7 +220,8 @@ public:
|
||||
static bool checkError(const std::string &context);
|
||||
static const std::string getErrorString(int err);
|
||||
|
||||
void positionListener(const Vec3 &position, const Vec3 &front);
|
||||
void positionListener(const Vec3 &position,
|
||||
const Vec3 &front, const Vec3 &up);
|
||||
SFXBase* quickSound(const std::string &soundName);
|
||||
|
||||
/** Called when sound was muted/unmuted */
|
||||
@ -224,7 +234,7 @@ public:
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the current position of the listener. */
|
||||
Vec3 getListenerPos() const { return m_position; }
|
||||
Vec3 getListenerPos() const { return m_listener_position.getData(); }
|
||||
|
||||
};
|
||||
|
||||
|
@ -372,7 +372,9 @@ void Camera::smoothMoveCamera(float dt)
|
||||
|
||||
if (race_manager->getNumLocalPlayers() < 2)
|
||||
{
|
||||
SFXManager::get()->positionListener(current_position, current_target - current_position);
|
||||
SFXManager::get()->positionListener(current_position,
|
||||
current_target - current_position,
|
||||
Vec3(0,1,0));
|
||||
}
|
||||
} // smoothMoveCamera
|
||||
|
||||
@ -578,7 +580,8 @@ void Camera::positionCamera(float dt, float above_kart, float cam_angle,
|
||||
if (race_manager->getNumLocalPlayers() < 2)
|
||||
{
|
||||
SFXManager::get()->positionListener(m_camera->getPosition(),
|
||||
wanted_target - m_camera->getPosition());
|
||||
wanted_target - m_camera->getPosition(),
|
||||
Vec3(0, 1, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,8 @@ void CutsceneWorld::update(float dt)
|
||||
|
||||
SFXManager::get()->positionListener(m_camera->getAbsolutePosition(),
|
||||
m_camera->getTarget() -
|
||||
m_camera->getAbsolutePosition());
|
||||
m_camera->getAbsolutePosition(),
|
||||
Vec3(0,1,0));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ void StateManager::onGameStateChange(GameState new_state)
|
||||
{
|
||||
irr_driver->showPointer();
|
||||
input_manager->setMode(InputManager::MENU);
|
||||
SFXManager::get()->positionListener( Vec3(0,0,0), Vec3(0,1,0) );
|
||||
SFXManager::get()->positionListener( Vec3(0,0,0), Vec3(0,1,0), Vec3(0, 1, 0) );
|
||||
|
||||
if (new_state == MENU)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user