Skip to content

Commit 5f3a17e

Browse files
sfan5nerzhul
authored andcommittedApr 11, 2020
Implement minetest.sound_fade()
1 parent 054c5df commit 5f3a17e

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed
 

Diff for: ‎doc/client_lua_api.txt

+7
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,13 @@ Call these functions only at load time!
734734
* `spec` is a `SimpleSoundSpec`
735735
* `parameters` is a sound parameter table
736736
* `minetest.sound_stop(handle)`
737+
* `handle` is a handle returned by `minetest.sound_play`
738+
* `minetest.sound_fade(handle, step, gain)`
739+
* `handle` is a handle returned by `minetest.sound_play`
740+
* `step` determines how fast a sound will fade.
741+
Negative step will lower the sound volume, positive step will increase
742+
the sound volume.
743+
* `gain` the target gain for the fade.
737744

738745
### Timing
739746
* `minetest.after(time, func, ...)`

Diff for: ‎src/script/lua_api/l_client.cpp

+19-3
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ int ModApiClient::l_gettext(lua_State *L)
209209
return 1;
210210
}
211211

212-
// get_node(pos)
212+
// get_node_or_nil(pos)
213213
// pos = {x=num, y=num, z=num}
214214
int ModApiClient::l_get_node_or_nil(lua_State *L)
215215
{
@@ -228,6 +228,7 @@ int ModApiClient::l_get_node_or_nil(lua_State *L)
228228
return 1;
229229
}
230230

231+
// get_langauge()
231232
int ModApiClient::l_get_language(lua_State *L)
232233
{
233234
#ifdef _WIN32
@@ -244,6 +245,7 @@ int ModApiClient::l_get_language(lua_State *L)
244245
return 2;
245246
}
246247

248+
// get_wielded_item()
247249
int ModApiClient::l_get_wielded_item(lua_State *L)
248250
{
249251
Client *client = getClient(L);
@@ -266,12 +268,14 @@ int ModApiClient::l_get_meta(lua_State *L)
266268
return 1;
267269
}
268270

271+
// sound_play(spec, parameters)
269272
int ModApiClient::l_sound_play(lua_State *L)
270273
{
271274
ISoundManager *sound = getClient(L)->getSoundManager();
272275

273276
SimpleSoundSpec spec;
274277
read_soundspec(L, 1, spec);
278+
275279
float gain = 1.0f;
276280
float pitch = 1.0f;
277281
bool looped = false;
@@ -293,21 +297,32 @@ int ModApiClient::l_sound_play(lua_State *L)
293297
}
294298
}
295299

296-
handle = sound->playSound(spec.name, looped, gain * spec.gain, 0.0f, pitch);
300+
handle = sound->playSound(spec.name, looped, gain * spec.gain, spec.fade, pitch);
297301
lua_pushinteger(L, handle);
298302

299303
return 1;
300304
}
301305

306+
// sound_stop(handle)
302307
int ModApiClient::l_sound_stop(lua_State *L)
303308
{
304-
u32 handle = luaL_checkinteger(L, 1);
309+
s32 handle = luaL_checkinteger(L, 1);
305310

306311
getClient(L)->getSoundManager()->stopSound(handle);
307312

308313
return 0;
309314
}
310315

316+
// sound_fade(handle, step, gain)
317+
int ModApiClient::l_sound_fade(lua_State *L)
318+
{
319+
s32 handle = luaL_checkinteger(L, 1);
320+
float step = readParam<float>(L, 2);
321+
float gain = readParam<float>(L, 3);
322+
getClient(L)->getSoundManager()->fadeSound(handle, step, gain);
323+
return 0;
324+
}
325+
311326
// get_server_info()
312327
int ModApiClient::l_get_server_info(lua_State *L)
313328
{
@@ -426,6 +441,7 @@ void ModApiClient::Initialize(lua_State *L, int top)
426441
API_FCT(get_meta);
427442
API_FCT(sound_play);
428443
API_FCT(sound_stop);
444+
API_FCT(sound_fade);
429445
API_FCT(get_server_info);
430446
API_FCT(get_item_def);
431447
API_FCT(get_node_def);

Diff for: ‎src/script/lua_api/l_client.h

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class ModApiClient : public ModApiBase
6969
// get_node(pos)
7070
static int l_get_node_or_nil(lua_State *L);
7171

72+
// get_language()
7273
static int l_get_language(lua_State *L);
7374

7475
// get_wielded_item()
@@ -77,10 +78,15 @@ class ModApiClient : public ModApiBase
7778
// get_meta(pos)
7879
static int l_get_meta(lua_State *L);
7980

81+
// sound_play(spec, parameters)
8082
static int l_sound_play(lua_State *L);
8183

84+
// sound_stop(handle)
8285
static int l_sound_stop(lua_State *L);
8386

87+
// sound_fade(handle, step, gain)
88+
static int l_sound_fade(lua_State *L);
89+
8490
// get_server_info()
8591
static int l_get_server_info(lua_State *L);
8692

Diff for: ‎src/script/lua_api/l_nodemeta.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ Metadata* NodeMetaRef::getmeta(bool auto_create)
5555

5656
void NodeMetaRef::clearMeta()
5757
{
58+
SANITY_CHECK(!m_is_local);
5859
m_env->getMap().removeNodeMetadata(m_p);
5960
}
6061

6162
void NodeMetaRef::reportMetadataChange(const std::string *name)
6263
{
64+
SANITY_CHECK(!m_is_local);
6365
// NOTE: This same code is in rollback_interface.cpp
6466
// Inform other things that the metadata has changed
6567
NodeMetadata *meta = dynamic_cast<NodeMetadata*>(m_meta);

0 commit comments

Comments
 (0)
Please sign in to comment.