2013-09-14 17:26:43 +09:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 yvt
|
|
|
|
|
|
|
|
This file is part of OpenSpades.
|
|
|
|
|
|
|
|
OpenSpades 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.
|
|
|
|
|
|
|
|
OpenSpades 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 OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ScriptManager.h"
|
|
|
|
#include <Client/IAudioDevice.h>
|
2013-11-17 00:26:05 +09:00
|
|
|
#include <Client/IAudioChunk.h>
|
2013-09-14 17:26:43 +09:00
|
|
|
|
|
|
|
namespace spades {
|
|
|
|
namespace client{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class AudioDeviceRegistrar: public ScriptObjectRegistrar {
|
|
|
|
static void AudioParamFactory(AudioParam *p) {
|
|
|
|
new(p) AudioParam();
|
|
|
|
}
|
2013-09-21 04:17:34 +09:00
|
|
|
static IAudioChunk *RegisterSound(const std::string& name, IAudioDevice *dev) {
|
|
|
|
try{
|
2013-11-17 00:26:05 +09:00
|
|
|
IAudioChunk *c = dev->RegisterSound(name.c_str());
|
|
|
|
c->AddRef();
|
|
|
|
return c;
|
2013-09-21 04:17:34 +09:00
|
|
|
}catch(const std::exception& ex) {
|
|
|
|
ScriptContextUtils().SetNativeException(ex);
|
2017-12-15 23:05:08 +09:00
|
|
|
return nullptr;
|
2013-09-21 04:17:34 +09:00
|
|
|
}
|
|
|
|
}
|
2013-09-14 17:26:43 +09:00
|
|
|
public:
|
|
|
|
AudioDeviceRegistrar():
|
|
|
|
ScriptObjectRegistrar("AudioDevice"){
|
|
|
|
|
|
|
|
}
|
|
|
|
virtual void Register(ScriptManager *manager, Phase phase) {
|
|
|
|
asIScriptEngine *eng = manager->GetEngine();
|
|
|
|
int r;
|
|
|
|
eng->SetDefaultNamespace("spades");
|
|
|
|
switch(phase){
|
|
|
|
case PhaseObjectType:
|
|
|
|
r = eng->RegisterObjectType("AudioDevice",
|
|
|
|
0, asOBJ_REF);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectType("AudioParam",
|
|
|
|
sizeof(AudioParam), asOBJ_VALUE|asOBJ_POD|asOBJ_APP_CLASS_CDAK);
|
|
|
|
manager->CheckError(r);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case PhaseObjectMember:
|
|
|
|
r = eng->RegisterObjectBehaviour("AudioDevice",
|
|
|
|
asBEHAVE_ADDREF, "void f()",
|
|
|
|
asMETHOD(IAudioDevice, AddRef),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectBehaviour("AudioDevice",
|
|
|
|
asBEHAVE_RELEASE, "void f()",
|
|
|
|
asMETHOD(IAudioDevice, Release),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectMethod("AudioDevice",
|
|
|
|
"AudioChunk@ RegisterSound(const string& in)",
|
2013-09-21 04:17:34 +09:00
|
|
|
asFUNCTION(RegisterSound),
|
|
|
|
asCALL_CDECL_OBJLAST);
|
2013-09-14 17:26:43 +09:00
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectMethod("AudioDevice",
|
2017-12-15 22:31:39 +09:00
|
|
|
"void set_GameMap(GameMap@+)",
|
2013-09-14 17:26:43 +09:00
|
|
|
asMETHOD(IAudioDevice, SetGameMap),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectMethod("AudioDevice",
|
2017-12-15 22:31:39 +09:00
|
|
|
"void Play(AudioChunk@+, const Vector3& in, const AudioParam& in)",
|
2013-09-14 17:26:43 +09:00
|
|
|
asMETHOD(IAudioDevice, Play),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectMethod("AudioDevice",
|
2017-12-15 22:31:39 +09:00
|
|
|
"void PlayLocal(AudioChunk@+, const Vector3& in, const AudioParam& in)",
|
2013-09-14 17:26:43 +09:00
|
|
|
asMETHODPR(IAudioDevice, PlayLocal, (IAudioChunk*, const Vector3&, const AudioParam&), void),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectMethod("AudioDevice",
|
2017-12-15 22:31:39 +09:00
|
|
|
"void PlayLocal(AudioChunk@+, const AudioParam& in)",
|
2013-09-14 17:26:43 +09:00
|
|
|
asMETHODPR(IAudioDevice, PlayLocal, (IAudioChunk*, const AudioParam&), void),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectMethod("AudioDevice",
|
|
|
|
"void Respatialize(const Vector3& in, const Vector3& in, const Vector3& in)",
|
|
|
|
asMETHOD(IAudioDevice, Respatialize),
|
|
|
|
asCALL_THISCALL);
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectBehaviour("AudioParam", asBEHAVE_CONSTRUCT,
|
|
|
|
"void f()",
|
|
|
|
asFUNCTION(AudioParamFactory),
|
|
|
|
asCALL_CDECL_OBJLAST);
|
|
|
|
manager->CheckError(r);
|
2013-09-14 23:10:04 +09:00
|
|
|
r = eng->RegisterObjectProperty("AudioParam",
|
|
|
|
"float volume",
|
|
|
|
asOFFSET(AudioParam, volume));
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectProperty("AudioParam",
|
|
|
|
"float pitch",
|
|
|
|
asOFFSET(AudioParam, pitch));
|
|
|
|
manager->CheckError(r);
|
|
|
|
r = eng->RegisterObjectProperty("AudioParam",
|
|
|
|
"float referenceDistance",
|
|
|
|
asOFFSET(AudioParam, referenceDistance));
|
|
|
|
manager->CheckError(r);
|
2013-09-14 17:26:43 +09:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static AudioDeviceRegistrar registrar;
|
|
|
|
}
|
|
|
|
}
|