aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp19
-rw-r--r--src/script/common/c_content.h4
-rw-r--r--src/script/lua_api/l_server.cpp9
-rw-r--r--src/script/lua_api/l_sound.cpp4
4 files changed, 19 insertions, 17 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 33f42cd4a..12a73d65e 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -1051,22 +1051,26 @@ void push_palette(lua_State *L, const std::vector<video::SColor> *palette)
/******************************************************************************/
void read_server_sound_params(lua_State *L, int index,
- ServerSoundParams &params)
+ ServerPlayingSound &params)
{
if(index < 0)
index = lua_gettop(L) + 1 + index;
- // Clear
- params = ServerSoundParams();
+
if(lua_istable(L, index)){
+ // Functional overlap: this may modify SimpleSoundSpec contents
+ getfloatfield(L, index, "fade", params.spec.fade);
+ getfloatfield(L, index, "pitch", params.spec.pitch);
+ getboolfield(L, index, "loop", params.spec.loop);
+
getfloatfield(L, index, "gain", params.gain);
+
+ // Handle positional information
getstringfield(L, index, "to_player", params.to_player);
- getfloatfield(L, index, "fade", params.fade);
- getfloatfield(L, index, "pitch", params.pitch);
lua_getfield(L, index, "pos");
if(!lua_isnil(L, -1)){
v3f p = read_v3f(L, -1)*BS;
params.pos = p;
- params.type = ServerSoundParams::SSP_POSITIONAL;
+ params.type = ServerPlayingSound::SSP_POSITIONAL;
}
lua_pop(L, 1);
lua_getfield(L, index, "object");
@@ -1075,13 +1079,12 @@ void read_server_sound_params(lua_State *L, int index,
ServerActiveObject *sao = ObjectRef::getobject(ref);
if(sao){
params.object = sao->getId();
- params.type = ServerSoundParams::SSP_OBJECT;
+ params.type = ServerPlayingSound::SSP_OBJECT;
}
}
lua_pop(L, 1);
params.max_hear_distance = BS*getfloatfield_default(L, index,
"max_hear_distance", params.max_hear_distance/BS);
- getboolfield(L, index, "loop", params.loop);
getstringfield(L, index, "exclude_player", params.exclude_player);
}
}
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index a7b8709c6..06f80328a 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -53,7 +53,7 @@ struct ItemDefinition;
struct ToolCapabilities;
struct ObjectProperties;
struct SimpleSoundSpec;
-struct ServerSoundParams;
+struct ServerPlayingSound;
class Inventory;
class InventoryList;
struct NodeBox;
@@ -91,7 +91,7 @@ void read_soundspec (lua_State *L, int index,
NodeBox read_nodebox (lua_State *L, int index);
void read_server_sound_params (lua_State *L, int index,
- ServerSoundParams &params);
+ ServerPlayingSound &params);
void push_dig_params (lua_State *L,
const DigParams &params);
diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp
index 4b0b45887..a5daae346 100644
--- a/src/script/lua_api/l_server.cpp
+++ b/src/script/lua_api/l_server.cpp
@@ -437,16 +437,15 @@ int ModApiServer::l_get_worldpath(lua_State *L)
int ModApiServer::l_sound_play(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
- SimpleSoundSpec spec;
- read_soundspec(L, 1, spec);
- ServerSoundParams params;
+ ServerPlayingSound params;
+ read_soundspec(L, 1, params.spec);
read_server_sound_params(L, 2, params);
bool ephemeral = lua_gettop(L) > 2 && readParam<bool>(L, 3);
if (ephemeral) {
- getServer(L)->playSound(spec, params, true);
+ getServer(L)->playSound(params, true);
lua_pushnil(L);
} else {
- s32 handle = getServer(L)->playSound(spec, params);
+ s32 handle = getServer(L)->playSound(params);
lua_pushinteger(L, handle);
}
return 1;
diff --git a/src/script/lua_api/l_sound.cpp b/src/script/lua_api/l_sound.cpp
index b86eda53e..934b4a07e 100644
--- a/src/script/lua_api/l_sound.cpp
+++ b/src/script/lua_api/l_sound.cpp
@@ -28,9 +28,9 @@ int ModApiSound::l_sound_play(lua_State *L)
{
SimpleSoundSpec spec;
read_soundspec(L, 1, spec);
- bool looped = readParam<bool>(L, 2);
+ spec.loop = readParam<bool>(L, 2);
- s32 handle = getGuiEngine(L)->playSound(spec, looped);
+ s32 handle = getGuiEngine(L)->playSound(spec);
lua_pushinteger(L, handle);