fixes to SoundManager external interface, clean up ifdef situation, and SoundGroup playin
This was SVN commit r13474.
This commit is contained in:
parent
b3653cfe16
commit
26dbac8d57
@ -304,10 +304,9 @@ bool CGame::Update(const double deltaRealTime, bool doInterpolate)
|
||||
if (doInterpolate)
|
||||
{
|
||||
m_TurnManager->Interpolate(deltaSimTime, deltaRealTime);
|
||||
#if CONFIG2_AUDIO
|
||||
|
||||
if ( g_SoundManager )
|
||||
g_SoundManager->IdleTask();
|
||||
#endif
|
||||
}
|
||||
|
||||
return ok;
|
||||
|
@ -106,23 +106,27 @@ static void LoadGlobals()
|
||||
CFG_GET_VAL("silhouettes", Bool, g_Silhouettes);
|
||||
CFG_GET_VAL("showsky", Bool, g_ShowSky);
|
||||
|
||||
#if CONFIG2_AUDIO
|
||||
float gain = 0.5f;
|
||||
float musicGain = 0.5f;
|
||||
float ambientGain = 0.5f;
|
||||
float actionGain = 0.5f;
|
||||
float uiGain = 0.5f;
|
||||
|
||||
CFG_GET_VAL("sound.mastergain", Float, gain);
|
||||
CFG_GET_VAL("sound.musicgain", Float, musicGain);
|
||||
CFG_GET_VAL("sound.ambientgain", Float, ambientGain);
|
||||
CFG_GET_VAL("sound.actiongain", Float, actionGain);
|
||||
CFG_GET_VAL("sound.uigain", Float, uiGain);
|
||||
|
||||
if (g_SoundManager)
|
||||
g_SoundManager->SetGains(gain, musicGain, ambientGain, actionGain, uiGain);
|
||||
{
|
||||
float gain = 0.5f;
|
||||
float musicGain = 0.5f;
|
||||
float ambientGain = 0.5f;
|
||||
float actionGain = 0.5f;
|
||||
float uiGain = 0.5f;
|
||||
|
||||
CFG_GET_VAL("sound.mastergain", Float, gain);
|
||||
CFG_GET_VAL("sound.musicgain", Float, musicGain);
|
||||
CFG_GET_VAL("sound.ambientgain", Float, ambientGain);
|
||||
CFG_GET_VAL("sound.actiongain", Float, actionGain);
|
||||
CFG_GET_VAL("sound.uigain", Float, uiGain);
|
||||
|
||||
g_SoundManager->SetMasterGain( gain );
|
||||
g_SoundManager->SetMusicGain( musicGain );
|
||||
g_SoundManager->SetAmbientGain( ambientGain );
|
||||
g_SoundManager->SetActionGain( actionGain );
|
||||
g_SoundManager->SetUIGain( uiGain );
|
||||
}
|
||||
|
||||
#endif // CONFIG2_AUDIO
|
||||
|
||||
CFG_GET_VAL("jsdebugger.enable", Bool, g_JSDebuggerEnabled);
|
||||
CFG_GET_VAL("profiler2.script.enable", Bool, g_ScriptProfilingEnabled);
|
||||
|
@ -193,10 +193,9 @@ void Render()
|
||||
{
|
||||
PROFILE3("render");
|
||||
|
||||
#if CONFIG2_AUDIO
|
||||
if (g_SoundManager)
|
||||
g_SoundManager->IdleTask();
|
||||
#endif
|
||||
|
||||
ogl_WarnIfError();
|
||||
|
||||
g_Profiler2.RecordGPUFrameStart();
|
||||
@ -732,10 +731,8 @@ void Shutdown(int UNUSED(flags))
|
||||
// resource
|
||||
// first shut down all resource owners, and then the handle manager.
|
||||
TIMER_BEGIN(L"resource modules");
|
||||
#if CONFIG2_AUDIO
|
||||
if (g_SoundManager)
|
||||
delete g_SoundManager;
|
||||
#endif
|
||||
|
||||
ISoundManager::SetEnabled(false);
|
||||
|
||||
g_VFS.reset();
|
||||
|
||||
@ -981,14 +978,7 @@ void InitGraphics(const CmdLineArgs& args, int flags)
|
||||
}
|
||||
|
||||
if(g_DisableAudio)
|
||||
{
|
||||
// speed up startup by disabling all sound
|
||||
// (OpenAL init will be skipped).
|
||||
// must be called before first snd_open.
|
||||
#if CONFIG2_AUDIO
|
||||
ISoundManager::SetEnabled(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
g_GUI = new CGUIManager(g_ScriptingHost.GetScriptInterface());
|
||||
|
||||
|
@ -72,18 +72,16 @@ InReaction GlobalsInputHandler(const SDL_Event_* ev)
|
||||
if(ev->ev.active.state & SDL_APPACTIVE)
|
||||
{
|
||||
g_app_minimized = (ev->ev.active.gain == 0); // negated
|
||||
#if CONFIG2_AUDIO
|
||||
|
||||
if ( g_SoundManager )
|
||||
g_SoundManager->Pause( g_app_minimized && g_PauseOnFocusLoss && !g_NetClient );
|
||||
#endif
|
||||
}
|
||||
if(ev->ev.active.state & SDL_APPINPUTFOCUS)
|
||||
{
|
||||
g_app_has_focus = (ev->ev.active.gain != 0);
|
||||
#if CONFIG2_AUDIO
|
||||
|
||||
if ( g_SoundManager )
|
||||
g_SoundManager->Pause( !g_app_has_focus && g_PauseOnFocusLoss && !g_NetClient );
|
||||
#endif
|
||||
}
|
||||
if(ev->ev.active.state & SDL_APPMOUSEFOCUS)
|
||||
g_mouse_active = (ev->ev.active.gain != 0);
|
||||
|
@ -341,10 +341,9 @@ JSBool SetPaused(JSContext* cx, uintN argc, jsval* vp)
|
||||
try
|
||||
{
|
||||
g_Game->m_Paused = ToPrimitive<bool> (JS_ARGV(cx, vp)[0]);
|
||||
#if CONFIG2_AUDIO
|
||||
|
||||
if ( g_SoundManager )
|
||||
g_SoundManager->Pause(g_Game->m_Paused);
|
||||
#endif
|
||||
}
|
||||
catch (PSERROR_Scripting_ConversionFailed&)
|
||||
{
|
||||
|
@ -20,12 +20,10 @@
|
||||
#include "simulation2/system/Component.h"
|
||||
#include "ICmpSoundManager.h"
|
||||
|
||||
#include "lib/config2.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "simulation2/MessageTypes.h"
|
||||
#include "simulation2/components/ICmpPosition.h"
|
||||
#include "simulation2/components/ICmpRangeManager.h"
|
||||
#include "soundmanager/scripting/SoundGroup.h"
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
class CCmpSoundManager : public ICmpSoundManager
|
||||
{
|
||||
@ -37,10 +35,6 @@ public:
|
||||
|
||||
DEFAULT_COMPONENT_ALLOCATOR(SoundManager)
|
||||
|
||||
#if CONFIG2_AUDIO
|
||||
std::map<std::wstring, CSoundGroup*> m_SoundGroups;
|
||||
#endif
|
||||
|
||||
static std::string GetSchema()
|
||||
{
|
||||
return "<a:component type='system'/><empty/>";
|
||||
@ -52,11 +46,6 @@ public:
|
||||
|
||||
virtual void Deinit()
|
||||
{
|
||||
#if CONFIG2_AUDIO
|
||||
for (std::map<std::wstring, CSoundGroup*>::iterator it = m_SoundGroups.begin(); it != m_SoundGroups.end(); ++it)
|
||||
delete it->second;
|
||||
m_SoundGroups.clear();
|
||||
#endif // CONFIG2_AUDIO
|
||||
}
|
||||
|
||||
virtual void Serialize(ISerializer& UNUSED(serialize))
|
||||
@ -74,73 +63,32 @@ public:
|
||||
{
|
||||
switch (msg.GetType())
|
||||
{
|
||||
case MT_Update:
|
||||
{
|
||||
#if CONFIG2_AUDIO
|
||||
// Update all the sound groups
|
||||
// TODO: is it sensible to do this once per simulation turn, not once per renderer frame
|
||||
// or on some other timer?
|
||||
const CMessageUpdate& msgData = static_cast<const CMessageUpdate&> (msg);
|
||||
float t = msgData.turnLength.ToFloat();
|
||||
for (std::map<std::wstring, CSoundGroup*>::iterator it = m_SoundGroups.begin(); it != m_SoundGroups.end(); ++it)
|
||||
if (it->second)
|
||||
it->second->Update(t);
|
||||
#else // !CONFIG2_AUDIO
|
||||
UNUSED2(msg);
|
||||
#endif // !CONFIG2_AUDIO
|
||||
break;
|
||||
}
|
||||
case MT_Update:
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void PlaySoundGroup(std::wstring name, entity_id_t source)
|
||||
{
|
||||
#if CONFIG2_AUDIO
|
||||
// Make sure the sound group is loaded
|
||||
CSoundGroup* group;
|
||||
if (m_SoundGroups.find(name) == m_SoundGroups.end())
|
||||
if ( g_SoundManager )
|
||||
{
|
||||
group = new CSoundGroup();
|
||||
if (!group->LoadSoundGroup(L"audio/" + name))
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(source, GetSimContext().GetCurrentDisplayedPlayer());
|
||||
|
||||
if (vis == ICmpRangeManager::VIS_VISIBLE)
|
||||
{
|
||||
LOGERROR(L"Failed to load sound group '%ls'", name.c_str());
|
||||
delete group;
|
||||
group = NULL;
|
||||
if (source != INVALID_ENTITY)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), source);
|
||||
if (cmpPosition && cmpPosition->IsInWorld())
|
||||
{
|
||||
CVector3D sourcePos = CVector3D(cmpPosition->GetPosition());
|
||||
g_SoundManager->PlayAsGroup(name, sourcePos, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Cache the sound group (or the null, if it failed)
|
||||
m_SoundGroups[name] = group;
|
||||
}
|
||||
else
|
||||
{
|
||||
group = m_SoundGroups[name];
|
||||
}
|
||||
|
||||
// Failed to load group -> do nothing
|
||||
if (!group)
|
||||
return;
|
||||
|
||||
// Only play the sound if the entity is visible
|
||||
CmpPtr<ICmpRangeManager> cmpRangeManager(GetSimContext(), SYSTEM_ENTITY);
|
||||
ICmpRangeManager::ELosVisibility vis = cmpRangeManager->GetLosVisibility(source, GetSimContext().GetCurrentDisplayedPlayer());
|
||||
|
||||
if (vis == ICmpRangeManager::VIS_VISIBLE)
|
||||
{
|
||||
// Find the source's position, if possible
|
||||
// (TODO: we should do something more sensible if there's no position available)
|
||||
CVector3D sourcePos(0, 0, 0);
|
||||
if (source != INVALID_ENTITY)
|
||||
{
|
||||
CmpPtr<ICmpPosition> cmpPosition(GetSimContext(), source);
|
||||
if (cmpPosition && cmpPosition->IsInWorld())
|
||||
sourcePos = CVector3D(cmpPosition->GetPosition());
|
||||
}
|
||||
|
||||
group->PlayNext(sourcePos, source);
|
||||
}
|
||||
#else // !CONFIG2_AUDIO
|
||||
UNUSED2(name);
|
||||
UNUSED2(source);
|
||||
#endif // !CONFIG2_AUDIO
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -20,8 +20,9 @@
|
||||
|
||||
#include "lib/config2.h"
|
||||
#include "lib/file/vfs/vfs_path.h"
|
||||
#include "simulation2/system/Entity.h"
|
||||
|
||||
#if CONFIG2_AUDIO
|
||||
class CVector3D;
|
||||
|
||||
class ISoundManager
|
||||
{
|
||||
@ -35,23 +36,20 @@ public:
|
||||
virtual void IdleTask() = 0;
|
||||
virtual void Pause(bool pauseIt) = 0;
|
||||
|
||||
virtual void SetGains(float masterG, float musicG, float ambientG, float actionG, float uiG ) = 0;
|
||||
virtual void SetMasterGain(float gain) = 0;
|
||||
virtual void SetMusicGain(float gain) = 0;
|
||||
virtual void SetAmbientGain(float gain) = 0;
|
||||
virtual void SetActionGain(float gain) = 0;
|
||||
virtual void SetUIGain(float gain) = 0;
|
||||
|
||||
virtual void PlayAsUI(const VfsPath& itemPath, bool looping) = 0;
|
||||
virtual void PlayAsMusic(const VfsPath& itemPath, bool looping) = 0;
|
||||
virtual void PlayAsAmbient(const VfsPath& itemPath, bool looping) = 0;
|
||||
|
||||
virtual void PlayAsGroup(const VfsPath& groupPath, CVector3D sourcePos, entity_id_t source) = 0;
|
||||
|
||||
virtual bool InDistress() = 0;
|
||||
};
|
||||
|
||||
#else // !CONFIG2_AUDIO
|
||||
|
||||
class ISoundManager {};
|
||||
|
||||
#endif // !CONFIG2_AUDIO
|
||||
|
||||
|
||||
extern ISoundManager* g_SoundManager;
|
||||
|
||||
#endif // INCLUDED_ISOUNDMANAGER_H
|
||||
|
@ -293,6 +293,10 @@ CSoundManager::~CSoundManager()
|
||||
}
|
||||
AL_CHECK
|
||||
|
||||
for (std::map<std::wstring, CSoundGroup*>::iterator it = m_SoundGroups.begin(); it != m_SoundGroups.end(); ++it)
|
||||
delete it->second;
|
||||
m_SoundGroups.clear();
|
||||
|
||||
if ( m_PlayListItems )
|
||||
delete m_PlayListItems;
|
||||
|
||||
@ -482,17 +486,6 @@ void CSoundManager::StartPlayList( bool doLoop )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CSoundManager::SetGains(float masterG, float musicG, float ambientG, float actionG, float uiG )
|
||||
{
|
||||
SetMasterGain( masterG );
|
||||
SetMusicGain( musicG );
|
||||
SetAmbientGain( ambientG );
|
||||
SetActionGain( actionG );
|
||||
SetUIGain( uiG );
|
||||
}
|
||||
|
||||
void CSoundManager::SetMasterGain(float gain)
|
||||
{
|
||||
if ( m_Enabled )
|
||||
@ -656,6 +649,32 @@ void CSoundManager::SetMusicEnabled (bool isEnabled)
|
||||
m_MusicEnabled = isEnabled;
|
||||
}
|
||||
|
||||
void CSoundManager::PlayAsGroup(const VfsPath& groupPath, CVector3D sourcePos, entity_id_t source)
|
||||
{
|
||||
// Make sure the sound group is loaded
|
||||
CSoundGroup* group;
|
||||
if (m_SoundGroups.find(groupPath.string()) == m_SoundGroups.end())
|
||||
{
|
||||
group = new CSoundGroup();
|
||||
if (!group->LoadSoundGroup(L"audio/" + groupPath.string() ))
|
||||
{
|
||||
LOGERROR(L"Failed to load sound group '%ls'", groupPath.string().c_str());
|
||||
delete group;
|
||||
group = NULL;
|
||||
}
|
||||
// Cache the sound group (or the null, if it failed)
|
||||
m_SoundGroups[groupPath.string()] = group;
|
||||
}
|
||||
else
|
||||
{
|
||||
group = m_SoundGroups[groupPath.string()];
|
||||
}
|
||||
|
||||
// Failed to load group -> do nothing
|
||||
if ( group )
|
||||
group->PlayNext(sourcePos, source);
|
||||
}
|
||||
|
||||
void CSoundManager::PlayAsMusic( const VfsPath& itemPath, bool looping )
|
||||
{
|
||||
UNUSED2( looping );
|
||||
@ -785,6 +804,10 @@ void CSoundManager::SetAmbientItem(ISoundItem* anItem)
|
||||
}
|
||||
AL_CHECK
|
||||
}
|
||||
#else // CONFIG2_AUDIO
|
||||
|
||||
void ISoundManager::CreateSoundManager(){}
|
||||
void ISoundManager::SetEnabled(bool UNUSED(doEnable)){}
|
||||
|
||||
#endif // CONFIG2_AUDIO
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "simulation2/system/Entity.h"
|
||||
#include "soundmanager/data/SoundData.h"
|
||||
#include "soundmanager/items/ISoundItem.h"
|
||||
#include "soundmanager/scripting/SoundGroup.h"
|
||||
#include "ps/Profiler2.h"
|
||||
|
||||
#include <vector>
|
||||
@ -48,6 +49,7 @@ struct ALSourceHolder
|
||||
typedef std::vector<VfsPath> PlayList;
|
||||
typedef std::vector<ISoundItem*> ItemsList;
|
||||
typedef std::map<entity_id_t, ISoundItem*> ItemsMap;
|
||||
typedef std::map<std::wstring, CSoundGroup*> SoundGroupMap;
|
||||
|
||||
class CSoundManagerWorker;
|
||||
|
||||
@ -66,6 +68,7 @@ protected:
|
||||
CSoundManagerWorker* m_Worker;
|
||||
CMutex m_DistressMutex;
|
||||
PlayList* m_PlayListItems;
|
||||
SoundGroupMap m_SoundGroups;
|
||||
|
||||
float m_Gain;
|
||||
float m_MusicGain;
|
||||
@ -131,9 +134,9 @@ public:
|
||||
void PlayAsMusic( const VfsPath& itemPath, bool looping );
|
||||
void PlayAsAmbient( const VfsPath& itemPath, bool looping );
|
||||
void PlayAsUI(const VfsPath& itemPath, bool looping);
|
||||
void PlayAsGroup(const VfsPath& groupPath, CVector3D sourcePos, entity_id_t source);
|
||||
|
||||
void PlayGroupItem(ISoundItem* anItem, ALfloat groupGain);
|
||||
void SetGains(float masterG, float musicG, float ambientG, float actionG, float uiG );
|
||||
|
||||
bool InDistress();
|
||||
void SetDistressThroughShortage();
|
||||
|
@ -87,7 +87,7 @@ namespace JSI_Sound
|
||||
|
||||
|
||||
#else
|
||||
bool MusicPlaying(void* UNUSED(cbdata) ){}
|
||||
bool MusicPlaying(void* UNUSED(cbdata) ){ return false; }
|
||||
void PlayAmbientSound(void* UNUSED(cbdata), std::wstring UNUSED(filename), bool UNUSED(looping) ){}
|
||||
void PlayUISound(void* UNUSED(cbdata), std::wstring UNUSED(filename), bool UNUSED(looping) ) {}
|
||||
void PlayMusic(void* UNUSED(cbdata), std::wstring UNUSED(filename), bool UNUSED(looping) ) {}
|
||||
|
Loading…
Reference in New Issue
Block a user