diff options
| author | Jeija <jeija@mesecons.net> | 2014-01-11 15:36:30 +0100 | 
|---|---|---|
| committer | Jeija <jeija@mesecons.net> | 2014-01-11 15:36:30 +0100 | 
| commit | ff5e3153257ae8789d43297d1c3739e6a22cd105 (patch) | |
| tree | c6b32ff9abcefc6ba1e25a4ad10a1e45acbf0c15 | |
| parent | f1211f7dae58ff4298b6bf4fcaa572e7995ab5e2 (diff) | |
Fix ActionQueue delays
| -rw-r--r-- | mesecons/actionqueue.lua | 21 | 
1 files changed, 13 insertions, 8 deletions
| diff --git a/mesecons/actionqueue.lua b/mesecons/actionqueue.lua index a00054a..1c02b46 100644 --- a/mesecons/actionqueue.lua +++ b/mesecons/actionqueue.lua @@ -63,19 +63,24 @@ minetest.register_globalstep(function (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  	local actions = mesecon:tablecopy(mesecon.queue.actions) +	local actions_now={} +  	mesecon.queue.actions = {} -	for i, action in ipairs(actions) do -		if action.time > 0 then -			action.time = action.time - dtime -			table.insert(mesecon.queue.actions, action) -- will be handled another time +	-- sort actions in execute now (actions_now) and for later (mesecon.queue.actions) +	for i, ac in ipairs(actions) do +		if ac.time > 0 then +			ac.time = ac.time - dtime -- executed later +			table.insert(mesecon.queue.actions, ac) +		else +			table.insert(actions_now, ac)  		end  	end -	while(#actions > 0) do -- execute highest priorities first, until all are executed -		local hp = get_highest_priority(actions) -		mesecon.queue:execute(actions[hp]) -		table.remove(actions, hp) +	while(#actions_now > 0) do -- execute highest priorities first, until all are executed +		local hp = get_highest_priority(actions_now) +		mesecon.queue:execute(actions_now[hp]) +		table.remove(actions_now, hp)  	end  end) | 
