summaryrefslogtreecommitdiff
path: root/src/script/common/c_content.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2022-06-20 21:56:12 +0200
committerGitHub <noreply@github.com>2022-06-20 21:56:12 +0200
commita463620edbe57071a7101297d33226507567ca73 (patch)
tree342d433ca55f4e3d1826508c303f2e6229d503f1 /src/script/common/c_content.cpp
parent0b41533763bc9f104a2da2e4191f4654b8d8dab4 (diff)
downloadminetest-a463620edbe57071a7101297d33226507567ca73.tar.gz
minetest-a463620edbe57071a7101297d33226507567ca73.tar.bz2
minetest-a463620edbe57071a7101297d33226507567ca73.zip
Re-order sound-related code (#12382)
Dropped ServerSoundParams -> moved to ServerPlayingSound. This gets rid of the duplicated 'fade' and 'pitch' values on server-side where only one was used anyway. SimpleSoundSpec is the basic sound without positional information, hence 'loop' is included. Recursively added PROTOCOL_VERSION to most functions to reduce the versioning mess in the future. Per-type version numbers are kept for now as a safety rope in a special case.
Diffstat (limited to 'src/script/common/c_content.cpp')
-rw-r--r--src/script/common/c_content.cpp19
1 files changed, 11 insertions, 8 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);
}
}