Work around particle emission issues.

Seems like minetest doesn't behave very well on trying to spawn
more than 1 particlespawner during a single tick.

Work around this so smoke comes out correctly...
This commit is contained in:
Aaron Suen 2019-03-10 03:32:59 -04:00
parent 65d9400115
commit 78f1b2971a
3 changed files with 49 additions and 22 deletions

View File

@ -1,34 +1,54 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore
= minetest, nodecore
local math, minetest, nodecore
= math, minetest, nodecore
local math_random
= math.random
-- LUALOCALS > ---------------------------------------------------------
local smoking = {}
local queue = {}
local qtotal = 0
local batch
function nodecore.smoke(pos, time)
local now = minetest.get_us_time() / 1000000
local key = minetest.hash_node_position(pos)
local old = smoking[key]
if old and now < old.exp then minetest.delete_particlespawner(old.id) end
if (not time) or (time <= 0) then
smoking[key] = nil
return
end
smoking[key] = {
id = minetest.add_particlespawner({
minetest.register_globalstep(function()
if not batch then
if qtotal < 1 then return end
batch = queue
queue = {}
qtotal = 0
end
if #batch < 1 then
batch = nil
return
end
local t = batch[#batch]
batch[#batch] = nil
minetest.add_particlespawner({
texture = "nc_api_smoke.png",
collisiondetection = true,
amount = 4 * time,
time = time,
minpos = {x = pos.x - 0.4, y = pos.y - 0.4, z = pos.z - 0.4},
maxpos = {x = pos.x + 0.4, y = pos.y + 0.4, z = pos.z + 0.4},
amount = 4 * t.time,
time = t.time,
minpos = {x = t.pos.x - 0.4, y = t.pos.y - 0.4, z = t.pos.z - 0.4},
maxpos = {x = t.pos.x + 0.4, y = t.pos.y + 0.4, z = t.pos.z + 0.4},
minvel = {x = -0.1, y = 0.3, z = -0.1},
maxvel = {x = 0.1, y = 0.7, z = 0.1},
minexptime = 1,
maxexptime = 5,
minsize = 1,
maxsize = 3
}),
exp = now + time
}
})
end)
local qmax = 10
function nodecore.smoke(pos, time)
if (not time) or (time <= 0) then return end
if qtotal < qmax then
queue[#queue + 1] = {pos = pos, time = time}
else
local r = math_random(1, qtotal + 1)
if r <= qmax then queue[r] = {pos = pos, time = time} end
end
qtotal = qtotal + 1
end

View File

@ -61,3 +61,11 @@ minetest.register_node(modname .. ":ash", {
},
crush_damage = 0.25
})
nodecore.register_limited_abm({
label = "TEST",
interval = 1,
chance = 1,
nodenames = {modname .. ":ash"},
action = function(pos) return nodecore.smoke(pos, 1) end
})

View File

@ -77,7 +77,6 @@ nodecore.register_limited_abm({
if nodecore.cooking(minetest.get_meta(pos), "time", 120,
not heated(pos), pos) then
minetest.get_meta(pos):from_table({})
return minetest.set_node(pos, {name = modname .. ":glass"})
end
end})