aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2022-07-09 22:32:24 +0200
committerGitHub <noreply@github.com>2022-07-09 22:32:24 +0200
commite51f474613c5d4bd53a8d213785bcb51f5cf447f (patch)
tree1278a6dbf5e9507ed97a4ed66afcbcb71da3639d /src/script/lua_api
parent051181fa6ee00d8379e8a7dc7442b58342d4352b (diff)
downloadminetest-e51f474613c5d4bd53a8d213785bcb51f5cf447f.tar.gz
minetest-e51f474613c5d4bd53a8d213785bcb51f5cf447f.tar.bz2
minetest-e51f474613c5d4bd53a8d213785bcb51f5cf447f.zip
Sounds: Various little improvements (#12486)
Use SimpleSoundSpec where reasonable (OpenAL) Ensure the sound IDs do not underflow or get overwritten -> loop in u16 Proper use of an enum.
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_client.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index aaced7cd0..05ac53cbb 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -268,30 +268,32 @@ int ModApiClient::l_sound_play(lua_State *L)
SimpleSoundSpec spec;
read_soundspec(L, 1, spec);
+ SoundLocation type = SoundLocation::Local;
float gain = 1.0f;
- float pitch = 1.0f;
- bool looped = false;
- s32 handle;
+ v3f position;
if (lua_istable(L, 2)) {
getfloatfield(L, 2, "gain", gain);
- getfloatfield(L, 2, "pitch", pitch);
- getboolfield(L, 2, "loop", looped);
+ getfloatfield(L, 2, "pitch", spec.pitch);
+ getboolfield(L, 2, "loop", spec.loop);
lua_getfield(L, 2, "pos");
if (!lua_isnil(L, -1)) {
- v3f pos = read_v3f(L, -1) * BS;
+ position = read_v3f(L, -1) * BS;
+ type = SoundLocation::Position;
lua_pop(L, 1);
- handle = sound->playSoundAt(
- spec.name, looped, gain * spec.gain, pos, pitch);
- lua_pushinteger(L, handle);
- return 1;
}
}
- handle = sound->playSound(spec.name, looped, gain * spec.gain, spec.fade, pitch);
- lua_pushinteger(L, handle);
+ spec.gain *= gain;
+ s32 handle;
+ if (type == SoundLocation::Local)
+ handle = sound->playSound(spec);
+ else
+ handle = sound->playSoundAt(spec, position);
+
+ lua_pushinteger(L, handle);
return 1;
}