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