summaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_client.cpp
diff options
context:
space:
mode:
authorred-001 <red-001@outlook.ie>2017-04-06 07:14:31 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-04-06 08:14:31 +0200
commit4ee6be856d435dff010244c910d5dafe2bfbeb1e (patch)
tree43557d528d75584851e199342827c320a57bee46 /src/script/lua_api/l_client.cpp
parent6da828c471768f2a9efadce7dd51c6cdc5cde6cc (diff)
downloadminetest-4ee6be856d435dff010244c910d5dafe2bfbeb1e.tar.gz
minetest-4ee6be856d435dff010244c910d5dafe2bfbeb1e.tar.bz2
minetest-4ee6be856d435dff010244c910d5dafe2bfbeb1e.zip
[CSM] Add support for positional audio. (#5516)
Fixes parts of #5389.
Diffstat (limited to 'src/script/lua_api/l_client.cpp')
-rw-r--r--src/script/lua_api/l_client.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 5a0cd5cc3..2d906985f 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -194,6 +194,45 @@ int ModApiClient::l_get_meta(lua_State *L)
return 1;
}
+int ModApiClient::l_sound_play(lua_State *L)
+{
+ ISoundManager *sound = getClient(L)->getSoundManager();
+
+ SimpleSoundSpec spec;
+ read_soundspec(L, 1, spec);
+ float gain = 1.0 ;
+ bool looped = false;
+ s32 handle;
+
+ if (lua_istable(L, 2)) {
+ getfloatfield(L, 2, "gain", gain);
+ getboolfield(L, 2, "loop", looped);
+
+ lua_getfield(L, 2, "pos");
+ if (!lua_isnil(L, -1)) {
+ v3f pos = read_v3f(L, -1) * BS;
+ lua_pop(L, 1);
+ handle = sound->playSoundAt(spec.name, looped, gain * spec.gain, pos);
+ lua_pushinteger(L, handle);
+ return 1;
+ }
+ }
+
+ handle = sound->playSound(spec.name, looped, gain * spec.gain);
+ lua_pushinteger(L, handle);
+
+ return 1;
+}
+
+int ModApiClient::l_sound_stop(lua_State *L)
+{
+ u32 handle = luaL_checkinteger(L, 1);
+
+ getClient(L)->getSoundManager()->stopSound(handle);
+
+ return 0;
+}
+
void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
@@ -209,4 +248,6 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(get_wielded_item);
API_FCT(disconnect);
API_FCT(get_meta);
+ API_FCT(sound_play);
+ API_FCT(sound_stop);
}