Skip to content

Commit

Permalink
added more ambient sound control
Browse files Browse the repository at this point in the history
  • Loading branch information
kaadmy committed Sep 2, 2016
1 parent b2a18e6 commit f01a005
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 35 deletions.
7 changes: 5 additions & 2 deletions minetest.conf
Expand Up @@ -75,8 +75,11 @@ headbars_scale = 1
# private messages
pm_enable_saving = true

# ambience noises
flowing_water_sounds = true
# ambience noises (uncomment the lines below to disable specific ambient sounds)
ambiance_volume = 1.0
#ambiance_disable_birds = true
#ambiance_disable_crickets = true
#ambiance_disable_flowing_water = true

# server(user stuff)
max_users = 16
Expand Down
68 changes: 35 additions & 33 deletions mods/ambiance/init.lua
Expand Up @@ -72,44 +72,46 @@ local function step(dtime)
local name = player:get_player_name()

for soundname, sound in pairs(ambiance.sounds) do
if lastsound[name][soundname] then
lastsound[name][soundname] = lastsound[name][soundname] + dtime
else
lastsound[name][soundname] = 0
end

if lastsound[name][soundname] > sound.length then
local sourcepos = ambient_node_near(sound, pos)

if sound.can_play and sourcepos ~= nil and (not sound.can_play(sourcepos)) then
sourcepos = nil
if not minetest.setting_getbool("ambiance_disable_" .. soundname) then
if lastsound[name][soundname] then
lastsound[name][soundname] = lastsound[name][soundname] + dtime
else
lastsound[name][soundname] = 0
end

if sourcepos == nil then
if soundspec[name][soundname] then
minetest.sound_stop(soundspec[name][soundname])

soundspec[name][soundname] = nil
lastsound[name][soundname] = 0
if lastsound[name][soundname] > sound.length then
local sourcepos = ambient_node_near(sound, pos)

if sound.can_play and sourcepos ~= nil and (not sound.can_play(sourcepos)) then
sourcepos = nil
end
else
local ok = true
for _, p in pairs(player_positions) do
if (p.x * pos.x) + (p.y * pos.y) + (p.z * pos.z) < sound.dist * sound.dist then
ok = false

if sourcepos == nil then
if soundspec[name][soundname] then
minetest.sound_stop(soundspec[name][soundname])

soundspec[name][soundname] = nil
lastsound[name][soundname] = 0
end
else
local ok = true
for _, p in pairs(player_positions) do
if (p.x * pos.x) + (p.y * pos.y) + (p.z * pos.z) < sound.dist * sound.dist then
ok = false
end
end
end

if ok then
soundspec[name][soundname] = minetest.sound_play(
sound.file,
{
pos = sourcepos,
max_hear_distance = sound.dist,
gain = ambiance_volume,
})

lastsound[name][soundname] = 0
if ok then
soundspec[name][soundname] = minetest.sound_play(
sound.file,
{
pos = sourcepos,
max_hear_distance = sound.dist,
gain = ambiance_volume,
})

lastsound[name][soundname] = 0
end
end
end
end
Expand Down

0 comments on commit f01a005

Please sign in to comment.