Desynchronize node ambient sounds

- Removes repeating patterns, creates a richer and
  fuller sound experience
- Larger areas fill sound volume out better instead of
  just repeating more loudly
- Spread network traffic across multiple ticks better
  to reduce packet spikes

Each node position has a set delay, between 0 and 1
second, that's fixed for that pos but varies more or
less randomly between positions.  This ensures that
sounds loop with the same frequency and alignment
for a given single node, but desync across nodes.
This commit is contained in:
Aaron Suen 2021-12-07 00:57:33 -05:00
parent ffadef37fc
commit 25e0219ad8

View File

@ -32,7 +32,9 @@ local function ambiance_core(def, getpos)
opts.name = opts.name or def.sound_name
opts.gain = opts.gain or def.sound_gain
nodecore.sound_play(opts.name, opts)
minetest.after(opts.delay, function()
nodecore.sound_play(opts.name, opts)
end)
time = time - rate
end
@ -51,6 +53,7 @@ local function ambiance_core(def, getpos)
opts = {}
end
opts.pos = pos
opts.delay = (hash % 1000) / 1000
if #queue < max then
queue[#queue + 1] = opts
else