1
0
forked from 0ad/0ad

big SoundManager checkin,futureproof javascript interface, isolate external calls to remove OpenAL references

This was SVN commit r13455.
This commit is contained in:
stwf 2013-06-06 11:13:57 +00:00
parent 1341b88468
commit 71b25d5bd4
32 changed files with 318 additions and 1065 deletions

View File

@ -46,8 +46,6 @@ function Music()
this.currentState = 0;
this.oldState = 0;
this.currentMusic = null;
// timer for delay between tracks
this.timer = [];
this.time = Date.now();
@ -81,11 +79,7 @@ Music.prototype.updateState = function()
switch (this.currentState)
{
case this.states.OFF:
if (this.isPlaying())
{
var thePlayer = SoundPlayer();
thePlayer.stopMusic();
}
Engine.StopMusic();
break;
case this.states.MENU:
@ -152,50 +146,34 @@ Music.prototype.getRandomTrack = function(tracks)
Music.prototype.startPlayList = function(tracks, fadeInPeriod, isLooping)
{
this.currentMusicList = new MusicList;
Engine.ClearPlaylist();
for (var i in tracks)
{
this.currentMusicList.addItem( this.RELATIVE_MUSIC_PATH + tracks[i] )
Engine.AddPlaylistItem( this.RELATIVE_MUSIC_PATH + tracks[i] );
}
if (this.currentMusicList)
{
if (isLooping)
this.currentMusicList.loop();
else
this.currentMusicList.play();
}
if (isLooping)
Engine.LoopPlaylist();
else
Engine.PlayPlaylist();
};
Music.prototype.switchMusic = function(track, fadeInPeriod, isLooping)
{
this.currentMusic = new MusicSound(this.RELATIVE_MUSIC_PATH + track);
if (this.currentMusic)
{
if (isLooping)
this.currentMusic.loop();
else
this.currentMusic.play();
}
if (isLooping)
Engine.LoopMusic(this.RELATIVE_MUSIC_PATH + track);
else
Engine.PlayMusic(this.RELATIVE_MUSIC_PATH + track);
};
Music.prototype.isPlaying = function()
{
if (!this.currentMusic)
return false;
// should return whether there is a valid handle; gain and fade do this also
// However, if looping is not set, then it always returns false because the
// handle is immediately cleared out
// return this.currentMusic.isPlaying();
return true;
return Engine.MusicPlaying();
};
Music.prototype.start = function()
{
var thePlayer = SoundPlayer();
thePlayer.startMusic();
Engine.StartMusic();
this.setState(this.states.PEACE);
};
@ -204,31 +182,3 @@ Music.prototype.stop = function()
this.setState(this.states.OFF);
};
// =============================================================================
// This allows for delays between tracks
// =============================================================================
Music.prototype.setDelay = function(state, delay)
{
this.timer = [this.time + delay, state];
};
Music.prototype.stopTimer = function()
{
this.timer = null;
};
// Needs to be called in onTick() to work
Music.prototype.updateTimer = function()
{
this.time = Date.now();
if (this.timer && (this.timer[0] <= this.time))
{
// Setting to OFF first guarantees that a state
// change will take place even if the current
// state is the same as the new state
this.reference.setState(this.states.OFF);
this.reference.setState(this.timer[1]);
this.stopTimer();
}
};

View File

@ -6,7 +6,6 @@ const background = "hellenes1"; // Background type. Currently: 'hellenes1', 'per
function init(initData)
{
initMusic();
// Play main menu music
global.music.setState(global.music.states.MENU);
@ -156,9 +155,6 @@ function onTick()
// Animate submenu
updateMenuPosition(tickLength);
// Update music state
global.music.updateTimer();
if (Engine.IsUserReportEnabled())
{
getGUIObjectByName("userReportEnabledText").caption =

View File

@ -299,9 +299,6 @@ function onTick()
// Animate menu
updateMenuPosition(tickLength);
// Update music state
global.music.updateTimer();
// When training is blocked, flash population (alternates colour every 500msec)
if (g_IsTrainingBlocked && (Date.now() % 1000) < 500)
getGUIObjectByName("resourcePop").textcolor = POPULATION_ALERT_COLOR;
@ -639,12 +636,7 @@ function playRandomAmbient(type)
// currentAmbient = newRandomSound("ambient", "temperate_", "dayscape");
const AMBIENT = "audio/ambient/dayscape/day_temperate_gen_03.ogg";
currentAmbient = new AmbientSound(AMBIENT);
if (currentAmbient)
{
currentAmbient.loop();
}
Engine.LoopAmbientSound( AMBIENT );
break;
default:

View File

@ -308,6 +308,4 @@ function init(data)
function onTick()
{
// Update music state
global.music.updateTimer();
}

View File

@ -559,7 +559,7 @@ function setup_all_libs ()
"soundmanager",
"soundmanager/data",
"soundmanager/items",
"soundmanager/js",
"soundmanager/scripting",
"scripting",
"maths",
"maths/scripting",

View File

@ -46,7 +46,7 @@
#include "simulation2/Simulation2.h"
#include "simulation2/components/ICmpPlayer.h"
#include "simulation2/components/ICmpPlayerManager.h"
#include "soundmanager/SoundManager.h"
#include "soundmanager/ISoundManager.h"
extern bool g_GameRestarted;

View File

@ -24,7 +24,7 @@
#include "ps/CLogger.h"
#include "ps/GameSetup/CmdLineArgs.h"
#include "lib/timer.h"
#include "soundmanager/SoundManager.h"
#include "soundmanager/ISoundManager.h"
// (these variables are documented in the header.)

View File

@ -88,7 +88,8 @@
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/ScriptStats.h"
#include "simulation2/Simulation2.h"
#include "soundmanager/SoundManager.h"
#include "soundmanager/scripting/JSInterface_Sound.h"
#include "soundmanager/ISoundManager.h"
#include "tools/atlas/GameInterface/GameLoop.h"
#include "tools/atlas/GameInterface/View.h"
@ -321,9 +322,6 @@ static void RegisterJavascriptInterfaces()
// maths
JSI_Vector3D::init();
// sound
CSoundManager::ScriptingInit();
// graphics
CGameView::ScriptingInit();
@ -337,6 +335,7 @@ static void RegisterJavascriptInterfaces()
CGUI::ScriptingInit();
GuiScriptingInit(g_ScriptingHost.GetScriptInterface());
JSI_Sound::RegisterScriptFunctions(g_ScriptingHost.GetScriptInterface());
}
@ -885,7 +884,7 @@ void Init(const CmdLineArgs& args, int UNUSED(flags))
#if CONFIG2_AUDIO
CSoundManager::CreateSoundManager();
ISoundManager::CreateSoundManager();
#endif
// g_ConfigDB, command line args, globals
@ -957,7 +956,7 @@ void InitGraphics(const CmdLineArgs& args, int flags)
// (OpenAL init will be skipped).
// must be called before first snd_open.
#if CONFIG2_AUDIO
CSoundManager::SetEnabled(false);
ISoundManager::SetEnabled(false);
#endif
}

View File

@ -21,7 +21,7 @@
#include "lib/external_libraries/libsdl.h"
#include "network/NetClient.h"
#include "ps/GameSetup/Config.h"
#include "soundmanager/SoundManager.h"
#include "soundmanager/ISoundManager.h"
bool g_app_minimized = false;
bool g_app_has_focus = true;

View File

@ -53,7 +53,7 @@
#include "renderer/Renderer.h"
#include "scriptinterface/ScriptInterface.h"
#include "simulation2/Simulation2.h"
#include "soundmanager/SoundManager.h"
#include "soundmanager/ISoundManager.h"
// rationale: the function table is now at the end of the source file to
// avoid the need for forward declarations for every function.

View File

@ -25,7 +25,7 @@
#include "simulation2/MessageTypes.h"
#include "simulation2/components/ICmpPosition.h"
#include "simulation2/components/ICmpRangeManager.h"
#include "soundmanager/js/SoundGroup.h"
#include "soundmanager/scripting/SoundGroup.h"
class CCmpSoundManager : public ICmpSoundManager
{

View File

@ -0,0 +1,59 @@
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_ISOUNDMANAGER_H
#define INCLUDED_ISOUNDMANAGER_H
#include "lib/config2.h"
#if CONFIG2_AUDIO
class CSoundManagerWorker;
class ISoundManager
{
public:
virtual ~ISoundManager() {};
virtual void IdleTask() = 0;
virtual void Pause(bool pauseIt) = 0;
virtual void SetMemoryUsage(long bufferSize, int bufferCount) = 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;
static void CreateSoundManager();
static void SetEnabled(bool doEnable);
virtual bool InDistress() = 0;
virtual long GetBufferCount() = 0;
virtual long GetBufferSize() = 0;
};
#else // !CONFIG2_AUDIO
class ISoundManager {};
#endif // !CONFIG2_AUDIO
extern ISoundManager* g_SoundManager;
#endif // INCLUDED_ISOUNDMANAGER_H

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -17,23 +17,19 @@
#include "precompiled.h"
#include "ISoundManager.h"
#include "SoundManager.h"
#include "soundmanager/data/SoundData.h"
#include "soundmanager/items/CSoundItem.h"
#include "soundmanager/items/CBufferItem.h"
#include "soundmanager/items/CStreamItem.h"
#include "soundmanager/js/SoundPlayer.h"
#include "soundmanager/js/AmbientSound.h"
#include "soundmanager/js/MusicList.h"
#include "soundmanager/js/MusicSound.h"
#include "soundmanager/js/Sound.h"
#include "lib/external_libraries/libsdl.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "ps/Profiler2.h"
CSoundManager* g_SoundManager = NULL;
ISoundManager* g_SoundManager = NULL;
#define SOURCE_NUM 64
@ -207,29 +203,15 @@ private:
bool m_Enabled;
bool m_Shutdown;
CSoundManagerWorker(CSoundManager* UNUSED(other)){};
CSoundManagerWorker(ISoundManager* UNUSED(other)){};
};
#endif
void CSoundManager::ScriptingInit()
{
JAmbientSound::ScriptingInit();
JMusicSound::ScriptingInit();
JSound::ScriptingInit();
JSoundPlayer::ScriptingInit();
JMusicList::ScriptingInit();
}
#if CONFIG2_AUDIO
void CSoundManager::CreateSoundManager()
void ISoundManager::CreateSoundManager()
{
g_SoundManager = new CSoundManager();
}
void CSoundManager::SetEnabled(bool doEnable)
void ISoundManager::SetEnabled(bool doEnable)
{
if ( g_SoundManager && !doEnable )
{
@ -237,7 +219,7 @@ void CSoundManager::SetEnabled(bool doEnable)
}
else if ( ! g_SoundManager && doEnable )
{
CSoundManager::CreateSoundManager();
ISoundManager::CreateSoundManager();
}
}
@ -466,9 +448,9 @@ long CSoundManager::GetBufferSize()
return m_BufferSize;
}
void CSoundManager::AddPlayListItem( const VfsPath& itemPath)
void CSoundManager::AddPlayListItem( const VfsPath* itemPath)
{
m_PlayListItems->push_back( itemPath );
m_PlayListItems->push_back( *itemPath );
}
void CSoundManager::ClearPlayListItems()
@ -485,20 +467,23 @@ void CSoundManager::ClearPlayListItems()
void CSoundManager::StartPlayList( bool doLoop )
{
if ( !m_PlayListItems->empty() )
{
m_PlayingPlaylist = true;
m_LoopingPlaylist = doLoop;
m_RunningPlaylist = false;
ISoundItem* aSnd = g_SoundManager->LoadItem( (m_PlayListItems->at( 0 )) );
if ( aSnd )
SetMusicItem( aSnd );
else
{
SetMusicItem( NULL );
}
}
if ( m_MusicEnabled )
{
if ( m_PlayListItems->size() > 0 )
{
m_PlayingPlaylist = true;
m_LoopingPlaylist = doLoop;
m_RunningPlaylist = false;
ISoundItem* aSnd = LoadItem( (m_PlayListItems->at( 0 )) );
if ( aSnd )
SetMusicItem( aSnd );
else
{
SetMusicItem( NULL );
}
}
}
}
@ -598,7 +583,7 @@ void CSoundManager::IdleTask()
else
nextPath = *it;
ISoundItem* aSnd = g_SoundManager->LoadItem( nextPath );
ISoundItem* aSnd = LoadItem( nextPath );
if ( aSnd )
SetMusicItem( aSnd );
}
@ -746,7 +731,7 @@ void CSoundManager::PauseMusic (bool pauseIt)
{
m_CurrentTune->FadeAndPause( 1.0 );
}
else if ( m_CurrentTune && m_MusicPaused && !pauseIt )
else if ( m_CurrentTune && m_MusicPaused && !pauseIt && m_MusicEnabled )
{
m_CurrentTune->SetGain(0);
m_CurrentTune->Resume();

View File

@ -22,7 +22,11 @@
#if CONFIG2_AUDIO
#include "lib/external_libraries/openal.h"
#include "lib/file/vfs/vfs_path.h"
#include "soundmanager/ISoundManager.h"
#include "soundmanager/items/ISoundItem.h"
#include "simulation2/system/Entity.h"
#include "soundmanager/data/SoundData.h"
@ -34,13 +38,6 @@
#define AL_CHECK CSoundManager::al_check(__func__, __LINE__);
typedef std::vector<VfsPath> PlayList;
typedef std::vector<ISoundItem*> ItemsList;
typedef std::map<entity_id_t, ISoundItem*> ItemsMap;
class CSoundManagerWorker;
struct ALSourceHolder
{
/// Title of the column
@ -48,7 +45,14 @@ struct ALSourceHolder
ISoundItem* SourceItem;
};
class CSoundManager
typedef std::vector<VfsPath> PlayList;
typedef std::vector<ISoundItem*> ItemsList;
typedef std::map<entity_id_t, ISoundItem*> ItemsMap;
class CSoundManagerWorker;
class CSoundManager : public ISoundManager
{
NONCOPYABLE(CSoundManager);
@ -96,7 +100,7 @@ public:
void ClearPlayListItems();
void StartPlayList( bool doLoop );
void AddPlayListItem( const VfsPath& itemPath);
void AddPlayListItem( const VfsPath* itemPath);
static void ScriptingInit();
static void CreateSoundManager();
@ -153,15 +157,7 @@ private:
#define AL_CHECK
class CSoundManager
{
public:
static void ScriptingInit();
};
#endif // !CONFIG2_AUDIO
extern CSoundManager* g_SoundManager;
#endif // INCLUDED_SOUNDMANAGER_H

View File

@ -60,7 +60,7 @@ void CBufferItem::ReleaseOpenALBuffer()
delete[] al_buf;
}
alSourcei(m_ALSource, AL_BUFFER, NULL);
g_SoundManager->ReleaseALSource(m_ALSource);
((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource);
AL_CHECK
m_ALSource = 0;

View File

@ -46,7 +46,7 @@ void CSoundBase::ReleaseOpenAL()
AL_CHECK
alSourcei(m_ALSource, AL_BUFFER, NULL);
AL_CHECK
g_SoundManager->ReleaseALSource(m_ALSource);
((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource);
AL_CHECK
m_ALSource = 0;
}
@ -96,7 +96,7 @@ bool CSoundBase::Finished()
bool CSoundBase::InitOpenAL()
{
alGetError(); /* clear error */
m_ALSource = g_SoundManager->GetALSource( this );
m_ALSource = ((CSoundManager*)g_SoundManager)->GetALSource( this );
AL_CHECK
@ -288,9 +288,9 @@ void CSoundBase::Play()
if (err != AL_NO_ERROR)
{
if (err == AL_INVALID)
g_SoundManager->SetDistressThroughError();
((CSoundManager*)g_SoundManager)->SetDistressThroughError();
else
g_SoundManager->al_ReportError(err, __func__, __LINE__);
((CSoundManager*)g_SoundManager)->al_ReportError(err, __func__, __LINE__);
}
}
}
@ -348,12 +348,12 @@ void CSoundBase::FadeToIn(ALfloat newVolume, double fadeDuration)
void CSoundBase::PlayAsMusic()
{
g_SoundManager->SetMusicItem(this);
((CSoundManager*)g_SoundManager)->SetMusicItem(this);
}
void CSoundBase::PlayAsAmbient()
{
g_SoundManager->SetAmbientItem(this);
((CSoundManager*)g_SoundManager)->SetAmbientItem(this);
}
void CSoundBase::Stop()

View File

@ -57,7 +57,7 @@ void CStreamItem::ReleaseOpenALStream()
}
alSourcei(m_ALSource, AL_BUFFER, NULL);
AL_CHECK
g_SoundManager->ReleaseALSource(m_ALSource);
((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource);
AL_CHECK
m_ALSource = 0;
}

View File

@ -22,7 +22,6 @@
#if CONFIG2_AUDIO
#include "lib/external_libraries/openal.h"
#include "maths/Vector3D.h"
#include "ps/CStr.h"
#include "soundmanager/data/SoundData.h"
@ -53,16 +52,16 @@ public:
virtual void PlayAndDelete() = 0;
virtual void StopAndDelete() = 0;
virtual void FadeToIn(ALfloat newVolume, double fadeDuration) = 0;
virtual void FadeToIn(float newVolume, double fadeDuration) = 0;
virtual void FadeAndDelete(double fadeTime) = 0;
virtual void FadeAndPause(double fadeTime) = 0;
virtual void PlayLoop() = 0;
virtual void SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain) = 0;
virtual void SetPitch(ALfloat pitch) = 0;
virtual void SetGain(ALfloat gain) = 0;
virtual void SetCone(float innerCone, float outerCone, float coneGain) = 0;
virtual void SetPitch(float pitch) = 0;
virtual void SetGain(float gain) = 0;
virtual void SetLocation(const CVector3D& position) = 0;
virtual void SetRollOff(ALfloat gain) = 0;
virtual void SetRollOff(float gain) = 0;
virtual void Pause() = 0;
virtual void Resume() = 0;

View File

@ -1,109 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "AmbientSound.h"
#include "lib/config2.h"
#include "lib/utf8.h"
#include "maths/Vector3D.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "ps/Filesystem.h"
#include "soundmanager/SoundManager.h"
JAmbientSound::JAmbientSound(const VfsPath& pathname) : m_FileName(pathname)
{
}
// start playing the sound, all ambient sounds loop
bool JAmbientSound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager ) {
ISoundItem* aSnd = g_SoundManager->LoadItem(m_FileName);
if (aSnd)
aSnd->PlayAsAmbient();
}
#endif // CONFIG2_AUDIO
return true;
}
// start playing the sound, all ambient sounds loop
bool JAmbientSound::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager ) {
ISoundItem* aSnd = g_SoundManager->LoadItem(m_FileName);
if (aSnd)
aSnd->PlayAsAmbient();
}
#endif // CONFIG2_AUDIO
return true;
}
bool JAmbientSound::Free(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager )
g_SoundManager->SetAmbientItem(0L);
#endif // CONFIG2_AUDIO
return true;
}
// Script-bound functions
void JAmbientSound::ScriptingInit()
{
AddMethod<CStr, &JAmbientSound::ToString>("toString", 0);
AddMethod<bool, &JAmbientSound::Play>("play", 0);
AddMethod<bool, &JAmbientSound::Loop>("loop", 0);
AddMethod<bool, &JAmbientSound::Free>("free", 0);
CJSObject<JAmbientSound>::ScriptingInit("AmbientSound", &JAmbientSound::Construct, 1);
}
CStr JAmbientSound::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
std::ostringstream stringStream;
stringStream << "[object AmbientSound: ";
stringStream << m_FileName.string().c_str();
return stringStream.str();
}
JSBool JAmbientSound::Construct(JSContext* cx, uintN UNUSED(argc), jsval* vp)
{
// JSU_REQUIRE_MIN_PARAMS(1);
CStrW filename;
if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], filename))
return JS_FALSE;
JAmbientSound* newObject = new JAmbientSound(filename);
newObject->m_EngineOwned = false;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObject->GetScript()));
return JS_TRUE;
}

View File

@ -1,50 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_JAMBIENTSOUND
#define INCLUDED_JAMBIENTSOUND
#include "scripting/ScriptableObject.h"
#include "soundmanager/items/ISoundItem.h"
class JAmbientSound : public CJSObject<JAmbientSound>
{
public:
JAmbientSound(const VfsPath& pathname);
CStr ToString(JSContext* cx, uintN argc, jsval* argv);
bool Play(JSContext* cx, uintN argc, jsval* argv);
bool Loop(JSContext* cx, uintN argc, jsval* argv);
bool Free(JSContext* cx, uintN argc, jsval* argv);
bool SetGain(JSContext* cx, uintN argc, jsval* argv);
bool SetPitch(JSContext* cx, uintN argc, jsval* argv);
bool Fade(JSContext* cx, uintN argc, jsval* argv);
static JSBool Construct(JSContext* cx, uintN argc, jsval* vp);
void clearSoundItem();
static void ScriptingInit();
protected:
VfsPath m_FileName;
};
#endif // #ifndef INCLUDED_JAMBIENTSOUND

View File

@ -1,106 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "MusicList.h"
#include "lib/config2.h"
#include "lib/utf8.h"
#include "maths/Vector3D.h"
#include "ps/CStr.h"
#include "ps/Filesystem.h"
#include "ps/CLogger.h"
#include "soundmanager/SoundManager.h"
#include "gui/GUI.h"
#include <sstream>
JMusicList::JMusicList()
{
#if CONFIG2_AUDIO
if ( g_SoundManager )
g_SoundManager->ClearPlayListItems();
#endif
}
bool JMusicList::AddItem(JSContext* cx, uintN UNUSED(argc), jsval* vp)
{
CStrW filename;
if (! ToPrimitive<CStrW>(cx, vp[0], filename))
return false;
#if CONFIG2_AUDIO
if ( g_SoundManager )
g_SoundManager->AddPlayListItem( VfsPath( filename ) );
#endif
return true;
}
bool JMusicList::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager )
g_SoundManager->StartPlayList( false );
#endif // CONFIG2_AUDIO
return true;
}
// request the sound be played until free() is called. returns immediately.
bool JMusicList::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager )
g_SoundManager->StartPlayList( true );
#endif // CONFIG2_AUDIO
return true;
}
void JMusicList::ScriptingInit()
{
AddMethod<CStr, &JMusicList::ToString>("toString", 0);
AddMethod<bool, &JMusicList::Play>("play", 0);
AddMethod<bool, &JMusicList::Loop>("loop", 0);
AddMethod<bool, &JMusicList::AddItem>("addItem", 1);
CJSObject<JMusicList>::ScriptingInit("MusicList", &JMusicList::Construct, 0);
}
CStr JMusicList::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
std::ostringstream stringStream;
stringStream << "[object MusicList]";
return stringStream.str();
}
JSBool JMusicList::Construct(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* vp)
{
CStrW filename;
JMusicList* newObject = new JMusicList();
newObject->m_EngineOwned = false;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObject->GetScript()));
return JS_TRUE;
}

View File

@ -1,59 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
// JS sound binding
// interface rationale:
// - can't just expose fire and forget playSound to script code:
// we sometimes need to loop until a certain condition is met
// (e.g. building is complete) => need means of access (Handle) to sound.
//
// - the current 64-bit Handle can't be stored as-is by JS code;
// we could make it 32 bit, but that limits its usefulness
// (barely enough tag bits).
//
// - instead, we provide a thin class wrapper (using scriptableobject.h)
// on top of the snd API that encapsulates the Handle.
#ifndef INCLUDED_MUSICLIST_H
#define INCLUDED_MUSICLIST_H
#include "scripting/ScriptableObject.h"
#include "soundmanager/items/ISoundItem.h"
class JMusicList : public CJSObject<JMusicList>
{
public:
JMusicList();
// Script-bound functions
CStr ToString(JSContext* cx, uintN argc, jsval* argv);
bool Play(JSContext* cx, uintN argc, jsval* argv);
bool Loop(JSContext* cx, uintN argc, jsval* argv);
bool AddItem(JSContext* cx, uintN argc, jsval* vp);
static JSBool Construct(JSContext* cx, uintN argc, jsval* vp);
static void ScriptingInit();
protected:
};
#endif // #ifndef INCLUDED_MUSICLIST_H

View File

@ -1,91 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "MusicSound.h"
#include "lib/config2.h"
#include "lib/utf8.h"
#include "maths/Vector3D.h"
#include "ps/CStr.h"
#include "ps/Filesystem.h"
#include "soundmanager/SoundManager.h"
#include <sstream>
JMusicSound::JMusicSound(const VfsPath& pathname) : m_FileName(pathname)
{
}
bool JMusicSound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager ) {
ISoundItem* aSnd = g_SoundManager->LoadItem(m_FileName);
if (aSnd != NULL)
aSnd->PlayAsMusic();
}
#endif // CONFIG2_AUDIO
return true;
}
// request the sound be played until free() is called. returns immediately.
bool JMusicSound::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager ) {
ISoundItem* aSnd = g_SoundManager->LoadItem(m_FileName);
if (aSnd != NULL)
aSnd->PlayAsMusic();
}
#endif // CONFIG2_AUDIO
return true;
}
void JMusicSound::ScriptingInit()
{
AddMethod<CStr, &JMusicSound::ToString>("toString", 0);
AddMethod<bool, &JMusicSound::Play>("play", 0);
AddMethod<bool, &JMusicSound::Loop>("loop", 0);
CJSObject<JMusicSound>::ScriptingInit("MusicSound", &JMusicSound::Construct, 1);
}
CStr JMusicSound::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
std::ostringstream stringStream;
stringStream << "[object MusicSound: ";
stringStream << m_FileName.string().c_str();
return stringStream.str();
}
JSBool JMusicSound::Construct(JSContext* cx, uintN UNUSED(argc), jsval* vp)
{
CStrW filename;
if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], filename))
return JS_FALSE;
JMusicSound* newObject = new JMusicSound(filename);
newObject->m_EngineOwned = false;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObject->GetScript()));
return JS_TRUE;
}

View File

@ -1,58 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
// JS sound binding
// interface rationale:
// - can't just expose fire and forget playSound to script code:
// we sometimes need to loop until a certain condition is met
// (e.g. building is complete) => need means of access (Handle) to sound.
//
// - the current 64-bit Handle can't be stored as-is by JS code;
// we could make it 32 bit, but that limits its usefulness
// (barely enough tag bits).
//
// - instead, we provide a thin class wrapper (using scriptableobject.h)
// on top of the snd API that encapsulates the Handle.
#ifndef INCLUDED_MUSICSOUND_H
#define INCLUDED_MUSICSOUND_H
#include "scripting/ScriptableObject.h"
#include "soundmanager/items/ISoundItem.h"
class JMusicSound : public CJSObject<JMusicSound>
{
public:
JMusicSound(const VfsPath& pathname);
// Script-bound functions
CStr ToString(JSContext* cx, uintN argc, jsval* argv);
bool Play(JSContext* cx, uintN argc, jsval* argv);
bool Loop(JSContext* cx, uintN argc, jsval* argv);
static JSBool Construct(JSContext* cx, uintN argc, jsval* vp);
static void ScriptingInit();
protected:
VfsPath m_FileName;
};
#endif // #ifndef INCLUDED_MUSICSOUND_H

View File

@ -1,213 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "Sound.h"
#include "lib/config2.h"
#include "lib/utf8.h"
#include "maths/Vector3D.h"
#include "ps/CStr.h"
#include "ps/Filesystem.h"
#include "soundmanager/SoundManager.h"
JSound::JSound(const VfsPath& pathname)
{
#if CONFIG2_AUDIO
if ( g_SoundManager )
m_SndItem = g_SoundManager->LoadItem(pathname);
#else // !CONFIG2_AUDIO
UNUSED2(pathname);
#endif // !CONFIG2_AUDIO
}
JSound::~JSound()
{
#if CONFIG2_AUDIO
if (m_SndItem)
{
m_SndItem->FadeAndDelete(0.2);
m_SndItem = 0;
}
#endif // CONFIG2_AUDIO
}
bool JSound::ClearSoundItem()
{
#if CONFIG2_AUDIO
m_SndItem = 0L;
#endif
return true;
}
bool JSound::SetGain(JSContext* cx, uintN UNUSED(argc), jsval* argv)
{
#if CONFIG2_AUDIO
if (! m_SndItem)
return false;
float gain;
if (! ToPrimitive<float>(cx, argv[0], gain))
return false;
m_SndItem->SetGain(gain);
#else // !CONFIG2_AUDIO
UNUSED2(cx);
UNUSED2(argv);
#endif // !CONFIG2_AUDIO
return true;
}
bool JSound::SetPitch(JSContext* cx, uintN UNUSED(argc), jsval* argv)
{
#if CONFIG2_AUDIO
if (! m_SndItem)
return false;
float pitch;
if (! ToPrimitive<float>(cx, argv[0], pitch))
return false;
m_SndItem->SetPitch(pitch);
#else // !CONFIG2_AUDIO
UNUSED2(cx);
UNUSED2(argv);
#endif // CONFIG2_AUDIO
return true;
}
bool JSound::SetPosition(JSContext* cx, uintN argc, jsval* argv)
{
#if CONFIG2_AUDIO
if (! m_SndItem)
return false;
ENSURE(argc >= 1); // FIXME
CVector3D pos;
// absolute world coords
if (!ToPrimitive<CVector3D>(cx, argv[0], pos))
return false;
m_SndItem->SetLocation(pos);
#else // !CONFIG2_AUDIO
UNUSED2(cx);
UNUSED2(argc);
UNUSED2(argv);
#endif // !CONFIG2_AUDIO
return true;
}
bool JSound::Fade(JSContext* cx, uintN UNUSED(argc), jsval* argv)
{
#if CONFIG2_AUDIO
if (! m_SndItem)
return false;
// ENSURE(argc >= 3); // FIXME
float initial_gain, final_gain;
float length;
if (! (ToPrimitive<float>(cx, argv[0], initial_gain)
&& ToPrimitive<float>(cx, argv[1], final_gain)
&& ToPrimitive<float>(cx, argv[2], length)))
return false;
m_SndItem->SetGain(initial_gain);
m_SndItem->FadeToIn(final_gain, length);
#else // !CONFIG2_AUDIO
UNUSED2(cx);
UNUSED2(argv);
#endif // !CONFIG2_AUDIO
return true;
}
bool JSound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if (! m_SndItem)
return false;
m_SndItem->Play();
#endif // CONFIG2_AUDIO
return true;
}
bool JSound::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if (! m_SndItem)
return false;
m_SndItem->PlayLoop();
#endif // CONFIG2_AUDIO
return true;
}
bool JSound::Free(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if (m_SndItem)
{
m_SndItem->FadeAndDelete(0.2);
m_SndItem = 0;
}
#endif // CONFIG2_AUDIO
return true;
}
void JSound::ScriptingInit()
{
AddMethod<CStr, &JSound::ToString>("toString", 0);
AddMethod<bool, &JSound::Play>("play", 0);
AddMethod<bool, &JSound::Loop>("loop", 0);
AddMethod<bool, &JSound::Free>("free", 0);
AddMethod<bool, &JSound::SetGain>("setGain", 0);
AddMethod<bool, &JSound::SetPitch>("setPitch", 0);
AddMethod<bool, &JSound::SetPosition>("setPosition", 0);
AddMethod<bool, &JSound::Fade>("fade", 0);
CJSObject<JSound>::ScriptingInit("Sound", &JSound::Construct, 1);
}
CStr JSound::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
CStrW titleString( m_SndItem->GetName()->string() );
return "[object Sound: " + (m_SndItem ? titleString.ToUTF8() : "(null)") + "]";
#else // !CONFIG2_AUDIO
return "[object Sound: audio disabled]";
#endif // !CONFIG2_AUDIO
}
JSBool JSound::Construct(JSContext* cx, uintN UNUSED(argc), jsval* vp)
{
// JSU_REQUIRE_MIN_PARAMS(1);
CStrW filename;
if (! ToPrimitive<CStrW>(cx, JS_ARGV(cx, vp)[0], filename))
return JS_FALSE;
JSound* newObject = new JSound(filename);
newObject->m_EngineOwned = false;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObject->GetScript()));
return JS_TRUE;
}

View File

@ -1,71 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
// JS sound binding
// interface rationale:
// - can't just expose fire and forget playSound to script code:
// we sometimes need to loop until a certain condition is met
// (e.g. building is complete) => need means of access (Handle) to sound.
//
// - the current 64-bit Handle can't be stored as-is by JS code;
// we could make it 32 bit, but that limits its usefulness
// (barely enough tag bits).
//
// - instead, we provide a thin class wrapper (using scriptableobject.h)
// on top of the snd API that encapsulates the Handle.
#ifndef INCLUDED_JSOUND
#define INCLUDED_JSOUND
#include "lib/config2.h"
#include "scripting/ScriptableObject.h"
#include "soundmanager/items/ISoundItem.h"
class JSound : public CJSObject<JSound>
{
public:
// note: filename is stored by handle manager; no need to keep a copy here.
JSound(const VfsPath& pathname);
virtual ~JSound();
CStr ToString(JSContext* cx, uintN argc, jsval* argv);
bool Play(JSContext* cx, uintN argc, jsval* argv);
bool Loop(JSContext* cx, uintN argc, jsval* argv);
bool Free(JSContext* cx, uintN argc, jsval* argv);
bool SetGain(JSContext* cx, uintN argc, jsval* argv);
bool SetPitch(JSContext* cx, uintN argc, jsval* argv);
bool SetPosition(JSContext* cx, uintN argc, jsval* argv);
bool ClearSoundItem();
bool Fade(JSContext* cx, uintN argc, jsval* argv);
static JSBool Construct(JSContext* cx, uintN argc, jsval* vp);
static void ScriptingInit();
protected:
#if CONFIG2_AUDIO
ISoundItem* m_SndItem;
#endif
};
#endif // #ifndef INCLUDED_JSOUND

View File

@ -1,83 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "SoundPlayer.h"
#include "lib/config2.h"
#include "lib/utf8.h"
#include "maths/Vector3D.h"
#include "ps/Filesystem.h"
#include "soundmanager/SoundManager.h"
#include <sstream>
JSoundPlayer::JSoundPlayer()
{
}
JSoundPlayer::~JSoundPlayer()
{
}
bool JSoundPlayer::StartMusic(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager )
g_SoundManager->SetMusicEnabled(true);
#endif
return true;
}
// request the sound be played until free() is called. returns immediately.
bool JSoundPlayer::StopMusic(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
#if CONFIG2_AUDIO
if ( g_SoundManager )
g_SoundManager->SetMusicEnabled(false);
#endif
return true;
}
void JSoundPlayer::ScriptingInit()
{
AddMethod<CStr, &JSoundPlayer::ToString>("toString", 0);
AddMethod<bool, &JSoundPlayer::StartMusic>("startMusic", 0);
AddMethod<bool, &JSoundPlayer::StopMusic>("stopMusic", 0);
CJSObject<JSoundPlayer>::ScriptingInit("SoundPlayer", &JSoundPlayer::Construct, 1);
}
JSBool JSoundPlayer::Construct(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* vp)
{
JSoundPlayer* newObject = new JSoundPlayer();
newObject->m_EngineOwned = false;
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(newObject->GetScript()));
return JS_TRUE;
}
CStr JSoundPlayer::ToString(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
std::ostringstream stringStream;
stringStream << "[object MusicPlayer]";
return stringStream.str();
}

View File

@ -1,59 +0,0 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
// JS sound binding
// interface rationale:
// - can't just expose fire and forget playSound to script code:
// we sometimes need to loop until a certain condition is met
// (e.g. building is complete) => need means of access (Handle) to sound.
//
// - the current 64-bit Handle can't be stored as-is by JS code;
// we could make it 32 bit, but that limits its usefulness
// (barely enough tag bits).
//
// - instead, we provide a thin class wrapper (using scriptableobject.h)
// on top of the snd API that encapsulates the Handle.
#ifndef INCLUDED_JSOUNDPLAYER
#define INCLUDED_JSOUNDPLAYER
#include "scripting/ScriptableObject.h"
#include "soundmanager/items/ISoundItem.h"
class JSoundPlayer : public CJSObject<JSoundPlayer>
{
public:
JSoundPlayer();
virtual ~JSoundPlayer();
// Script-bound functions
CStr ToString(JSContext* cx, uintN argc, jsval* argv);
bool StartMusic(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv));
bool StopMusic(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv));
static JSBool Construct(JSContext* cx, uintN argc, jsval* vp);
static void ScriptingInit();
protected:
VfsPath m_FileName;
};
#endif // #ifndef INCLUDED_JSOUNDPLAYER

View File

@ -0,0 +1,149 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "scriptinterface/ScriptInterface.h"
#include "JSInterface_Sound.h"
#include "lib/config2.h"
#include "lib/utf8.h"
#include "maths/Vector3D.h"
#include "ps/Filesystem.h"
#include "soundmanager/SoundManager.h"
#include <sstream>
namespace JSI_Sound
{
void StartMusic(void* UNUSED(cbdata))
{
#if CONFIG2_AUDIO
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if ( sndManager )
sndManager->SetMusicEnabled(true);
#endif
}
void StopMusic(void* UNUSED(cbdata))
{
#if CONFIG2_AUDIO
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if ( sndManager )
sndManager->SetMusicEnabled(false);
#endif
}
void ClearPlaylist(void* UNUSED(cbdata))
{
#if CONFIG2_AUDIO
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if ( sndManager )
sndManager->ClearPlayListItems();
#endif
}
void AddPlaylistItem(void* UNUSED(cbdata), std::wstring filename)
{
#if CONFIG2_AUDIO
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if ( sndManager )
sndManager->AddPlayListItem( new VfsPath( filename ) );
#else
UNUSED2(filename);
#endif
}
void LoopPlaylist(void* UNUSED(cbdata))
{
#if CONFIG2_AUDIO
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if ( sndManager )
sndManager->StartPlayList( true );
#endif
}
void PlayPlaylist(void* UNUSED(cbdata))
{
#if CONFIG2_AUDIO
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if ( sndManager )
sndManager->StartPlayList( false );
#endif
}
void LoopMusic(void* UNUSED(cbdata), std::wstring filename)
{
#if CONFIG2_AUDIO
if ( g_SoundManager ) {
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
ISoundItem* aSnd = sndManager->LoadItem(filename);
if (aSnd != NULL)
aSnd->PlayAsMusic();
}
#else
UNUSED2(filename);
#endif // CONFIG2_AUDIO
}
void PlayMusic(void* UNUSED(cbdata), std::wstring filename)
{
#if CONFIG2_AUDIO
if ( g_SoundManager ) {
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
ISoundItem* aSnd = sndManager->LoadItem(filename);
if (aSnd != NULL)
aSnd->PlayAsMusic();
}
#else
UNUSED2(filename);
#endif // CONFIG2_AUDIO
}
void LoopAmbientSound(void* UNUSED(cbdata), std::wstring filename)
{
#if CONFIG2_AUDIO
if ( g_SoundManager ) {
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
ISoundItem* aSnd = sndManager->LoadItem(filename);
if (aSnd != NULL)
aSnd->PlayAsAmbient();
}
#else
UNUSED2(filename);
#endif // CONFIG2_AUDIO
}
bool MusicPlaying(void* UNUSED(cbdata))
{
#if CONFIG2_AUDIO
return true;
#else
return false;
#endif // CONFIG2_AUDIO
}
void RegisterScriptFunctions(ScriptInterface& scriptInterface)
{
scriptInterface.RegisterFunction<void, &StartMusic>("StartMusic");
scriptInterface.RegisterFunction<void, &StopMusic>("StopMusic");
scriptInterface.RegisterFunction<void, &ClearPlaylist>("ClearPlaylist");
scriptInterface.RegisterFunction<void, std::wstring, &AddPlaylistItem>("AddPlaylistItem");
scriptInterface.RegisterFunction<void, &LoopPlaylist>("LoopPlaylist");
scriptInterface.RegisterFunction<void, &PlayPlaylist>("PlayPlaylist");
scriptInterface.RegisterFunction<void, std::wstring, &LoopMusic>("LoopMusic");
scriptInterface.RegisterFunction<void, std::wstring, &PlayMusic>("PlayMusic");
scriptInterface.RegisterFunction<void, std::wstring, &LoopAmbientSound>("LoopAmbientSound");
scriptInterface.RegisterFunction<bool, &MusicPlaying>("MusicPlaying");
}
}

View File

@ -0,0 +1,29 @@
/* Copyright (C) 2012 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_SOUNDSCRIPTINTERFACE
#define INCLUDED_SOUNDSCRIPTINTERFACE
class ScriptInterface;
namespace JSI_Sound
{
void RegisterScriptFunctions(ScriptInterface& scriptInterface);
}
#endif // #ifndef INCLUDED_SOUNDSCRIPTINTERFACE

View File

@ -181,7 +181,7 @@ void CSoundGroup::UploadPropertiesAndPlay(size_t theIndex, const CVector3D& posi
if ( (sndDist * 2) < itemDist )
sndDist = itemDist;
ISoundItem* hSound = g_SoundManager->ItemForEntity( source, sndData);
ISoundItem* hSound = ((CSoundManager*)g_SoundManager)->ItemForEntity( source, sndData);
if ( hSound )
{
@ -208,7 +208,7 @@ void CSoundGroup::UploadPropertiesAndPlay(size_t theIndex, const CVector3D& posi
hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain);
g_SoundManager->PlayGroupItem(hSound, theGain);
((CSoundManager*)g_SoundManager)->PlayGroupItem(hSound, theGain);
}
}
}