Fix ActionQueue delays

This commit is contained in:
Jeija 2014-01-11 15:36:30 +01:00
parent f1211f7dae
commit ff5e315325
1 changed files with 13 additions and 8 deletions

View File

@ -63,19 +63,24 @@ minetest.register_globalstep(function (dtime)
m_time = m_time + dtime m_time = m_time + dtime
if (m_time < 5) then return end -- don't even try if server has not been running for 2 seconds if (m_time < 5) then return end -- don't even try if server has not been running for 2 seconds
local actions = mesecon:tablecopy(mesecon.queue.actions) local actions = mesecon:tablecopy(mesecon.queue.actions)
local actions_now={}
mesecon.queue.actions = {} mesecon.queue.actions = {}
for i, action in ipairs(actions) do -- sort actions in execute now (actions_now) and for later (mesecon.queue.actions)
if action.time > 0 then for i, ac in ipairs(actions) do
action.time = action.time - dtime if ac.time > 0 then
table.insert(mesecon.queue.actions, action) -- will be handled another time ac.time = ac.time - dtime -- executed later
table.insert(mesecon.queue.actions, ac)
else
table.insert(actions_now, ac)
end end
end end
while(#actions > 0) do -- execute highest priorities first, until all are executed while(#actions_now > 0) do -- execute highest priorities first, until all are executed
local hp = get_highest_priority(actions) local hp = get_highest_priority(actions_now)
mesecon.queue:execute(actions[hp]) mesecon.queue:execute(actions_now[hp])
table.remove(actions, hp) table.remove(actions_now, hp)
end end
end) end)