Start adding an audio scripting API, and also fix a deadlock in sfx_manager due to improper release of locks
This commit is contained in:
parent
789384a7bf
commit
90cf3176d1
@ -939,7 +939,7 @@ SFXBase* SFXManager::quickSound(const std::string &sound_type)
|
|||||||
{
|
{
|
||||||
if (!sfxAllowed()) return NULL;
|
if (!sfxAllowed()) return NULL;
|
||||||
|
|
||||||
m_quick_sounds.lock();
|
MutexLockerHelper lock(m_quick_sounds);
|
||||||
std::map<std::string, SFXBase*>::iterator sound =
|
std::map<std::string, SFXBase*>::iterator sound =
|
||||||
m_quick_sounds.getData().find(sound_type);
|
m_quick_sounds.getData().find(sound_type);
|
||||||
|
|
||||||
@ -950,14 +950,12 @@ SFXBase* SFXManager::quickSound(const std::string &sound_type)
|
|||||||
if (new_sound == NULL) return NULL;
|
if (new_sound == NULL) return NULL;
|
||||||
new_sound->play();
|
new_sound->play();
|
||||||
m_quick_sounds.getData()[sound_type] = new_sound;
|
m_quick_sounds.getData()[sound_type] = new_sound;
|
||||||
m_quick_sounds.unlock();
|
|
||||||
return new_sound;
|
return new_sound;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SFXBase *base_sound = sound->second;
|
SFXBase *base_sound = sound->second;
|
||||||
base_sound->play();
|
base_sound->play();
|
||||||
m_quick_sounds.unlock();
|
|
||||||
return base_sound;
|
return base_sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
55
src/scriptengine/script_audio.cpp
Normal file
55
src/scriptengine/script_audio.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
//
|
||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
// Copyright (C) 2014-2015 SuperTuxKart Team
|
||||||
|
//
|
||||||
|
// This program 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 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program 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 this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
#include "script_audio.hpp"
|
||||||
|
#include "audio/sfx_manager.hpp"
|
||||||
|
|
||||||
|
#include <angelscript.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
/** \cond DOXYGEN_IGNORE */
|
||||||
|
namespace Scripting
|
||||||
|
{
|
||||||
|
/** \endcond */
|
||||||
|
|
||||||
|
namespace Audio
|
||||||
|
{
|
||||||
|
/** \addtogroup Scripting
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/** \addtogroup Audio
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
void playSound(const std::string* sound_name)
|
||||||
|
{
|
||||||
|
SFXManager::get()->quickSound(*sound_name);
|
||||||
|
}
|
||||||
|
/** @}*/
|
||||||
|
/** @}*/
|
||||||
|
|
||||||
|
void registerScriptFunctions(asIScriptEngine *engine)
|
||||||
|
{
|
||||||
|
int r; // of type asERetCodes
|
||||||
|
engine->SetDefaultNamespace("Audio");
|
||||||
|
r = engine->RegisterGlobalFunction("void playSound(const string &in)", asFUNCTION(playSound), asCALL_CDECL); assert(r >= 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** \cond DOXYGEN_IGNORE */
|
||||||
|
}
|
||||||
|
/** \endcond */
|
33
src/scriptengine/script_audio.hpp
Normal file
33
src/scriptengine/script_audio.hpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//
|
||||||
|
// SuperTuxKart - a fun racing game with go-kart
|
||||||
|
// Copyright (C) 2014-2015 SuperTuxKart Team
|
||||||
|
//
|
||||||
|
// This program 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 3
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program 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 this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
#ifndef HEADER_SCRIPT_AUDIO_HPP
|
||||||
|
#define HEADER_SCRIPT_AUDIO_HPP
|
||||||
|
|
||||||
|
#include <angelscript.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Scripting
|
||||||
|
{
|
||||||
|
namespace Audio
|
||||||
|
{
|
||||||
|
void registerScriptFunctions(asIScriptEngine *engine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
@ -21,6 +21,7 @@
|
|||||||
#include "io/file_manager.hpp"
|
#include "io/file_manager.hpp"
|
||||||
#include "karts/kart.hpp"
|
#include "karts/kart.hpp"
|
||||||
#include "modes/world.hpp"
|
#include "modes/world.hpp"
|
||||||
|
#include "scriptengine/script_audio.hpp"
|
||||||
#include "scriptengine/script_challenges.hpp"
|
#include "scriptengine/script_challenges.hpp"
|
||||||
#include "scriptengine/script_kart.hpp"
|
#include "scriptengine/script_kart.hpp"
|
||||||
#include "scriptengine/script_engine.hpp"
|
#include "scriptengine/script_engine.hpp"
|
||||||
@ -336,6 +337,7 @@ namespace Scripting
|
|||||||
Scripting::Utils::registerScriptFunctions(m_engine);
|
Scripting::Utils::registerScriptFunctions(m_engine);
|
||||||
Scripting::GUI::registerScriptFunctions(m_engine);
|
Scripting::GUI::registerScriptFunctions(m_engine);
|
||||||
Scripting::GUI::registerScriptEnums(m_engine);
|
Scripting::GUI::registerScriptEnums(m_engine);
|
||||||
|
Scripting::Audio::registerScriptFunctions(m_engine);
|
||||||
|
|
||||||
// It is possible to register the functions, properties, and types in
|
// It is possible to register the functions, properties, and types in
|
||||||
// configuration groups as well. When compiling the scripts it can then
|
// configuration groups as well. When compiling the scripts it can then
|
||||||
|
Loading…
Reference in New Issue
Block a user