mirror of
https://codeberg.org/tenplus1/ambience.git
synced 2025-01-11 10:30:17 +01:00
fix timed stops and tweaked water sound gain
This commit is contained in:
parent
45b0e6b28e
commit
2b143286b7
27
init.lua
27
init.lua
@ -133,7 +133,6 @@ local get_ambience = function(player, tod, name)
|
||||
|
||||
pos.y = pos.y - 0.2 -- reset pos
|
||||
|
||||
|
||||
-- get all set nodes around player
|
||||
local ps, cn = minetest.find_nodes_in_area(
|
||||
{x = pos.x - radius, y = pos.y - radius, z = pos.z - radius},
|
||||
@ -189,7 +188,15 @@ minetest.register_globalstep(function(dtime)
|
||||
|
||||
--print(string.format("elapsed time: %.4f\n", os.clock() - t1))
|
||||
|
||||
if set_name then
|
||||
local ok = true
|
||||
|
||||
-- check set exists
|
||||
if set_name ~= nil and not sound_sets[set_name] then
|
||||
print("[ambience] sound set doesn't exist:", set_name)
|
||||
ok = false
|
||||
end
|
||||
|
||||
if ok and set_name then
|
||||
|
||||
-- stop sound if another set active
|
||||
if playing[player_name]
|
||||
@ -198,17 +205,19 @@ minetest.register_globalstep(function(dtime)
|
||||
if playing[player_name].sound ~= set_name
|
||||
or (playing[player_name].sound == set_name
|
||||
and playing[player_name].gain ~= MORE_GAIN) then
|
||||
|
||||
--print ("-- change stop")
|
||||
minetest.sound_stop(playing[player_name].handler)
|
||||
|
||||
playing[player_name].sound = nil
|
||||
playing[player_name].handler = nil
|
||||
playing[player_name].gain = nil
|
||||
else
|
||||
return
|
||||
-- return
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
|
||||
if ok then
|
||||
-- choose random sound from set selected
|
||||
number = random(1, #sound_sets[set_name].sounds)
|
||||
ambience = sound_sets[set_name].sounds[number]
|
||||
@ -233,6 +242,7 @@ minetest.register_globalstep(function(dtime)
|
||||
playing[player_name].handler = handler
|
||||
playing[player_name].sound = set_name
|
||||
playing[player_name].gain = MORE_GAIN
|
||||
playing[player_name].old_handler = handler
|
||||
|
||||
minetest.after(ambience.length, function(args)
|
||||
|
||||
@ -240,18 +250,23 @@ minetest.register_globalstep(function(dtime)
|
||||
|
||||
if playing[player_name]
|
||||
and playing[player_name].handler
|
||||
and playing[player_name].sound == set_name then
|
||||
|
||||
and playing[player_name].sound == set_name
|
||||
and handler == playing[player_name].old_handler then
|
||||
--print("-- timed stop")
|
||||
minetest.sound_stop(playing[player_name].handler)
|
||||
|
||||
playing[player_name].sound = nil
|
||||
playing[player_name].handler = nil
|
||||
playing[player_name].gain = nil
|
||||
playing[player_name].old_handler = handler
|
||||
end
|
||||
|
||||
end, {ambience, player_name})
|
||||
end
|
||||
end
|
||||
|
||||
end -- end ok
|
||||
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -44,7 +44,6 @@ ambience.add_set("splash", {
|
||||
})
|
||||
|
||||
-- check for env_sounds mod, if not found enable water flowing sounds
|
||||
|
||||
if not minetest.get_modpath("env_sounds") then
|
||||
|
||||
-- Water sound plays when near flowing water, will get louder if more than 50
|
||||
@ -58,12 +57,10 @@ ambience.add_set("flowing_water", {
|
||||
|
||||
local c = (def.totals["default:water_flowing"] or 0)
|
||||
|
||||
if c > 50 then
|
||||
return "flowing_water", 0.5
|
||||
|
||||
elseif c > 20 then
|
||||
return "flowing_water"
|
||||
if c > 5 then
|
||||
return "flowing_water", math.min(0.04 + c * 0.004, 0.6)
|
||||
end
|
||||
|
||||
end,
|
||||
nodes = {"default:water_flowing"}
|
||||
})
|
||||
@ -79,12 +76,10 @@ ambience.add_set("river", {
|
||||
|
||||
local c = (def.totals["default:river_water_flowing"] or 0)
|
||||
|
||||
if c > 20 then
|
||||
return "river", 0.4
|
||||
|
||||
elseif c > 5 then
|
||||
return "river"
|
||||
if c > 5 then
|
||||
return "river", math.min(0.04 + c * 0.004, 0.5)
|
||||
end
|
||||
|
||||
end,
|
||||
nodes = {"default:river_water_flowing"}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user