Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action queue may reorder actions #551

Open
numberZero opened this issue Jan 21, 2021 · 0 comments
Open

Action queue may reorder actions #551

numberZero opened this issue Jan 21, 2021 · 0 comments
Labels

Comments

@numberZero
Copy link
Contributor

According to this code, all expired actions are sorted by priority, then by original order. So if actions with different time happen to expire in the same globalstep, the time difference is ignored and addition order takes precedence.

for _, ac in ipairs(actions) do
if ac.time > 0 then
-- action ac is to be executed later
-- ~> insert into queue.actions
ac.time = ac.time - dtime
table.insert(queue.actions, ac)
else
-- action ac is to be executed now
-- ~> insert into actions_now
table.insert(actions_now, ac)
end
end
-- stable-sort the executed actions after their priority
-- some constructions might depend on the execution order, hence we first
-- execute the actions that had a lower index in actions_now
local old_action_order = {}
for i, ac in ipairs(actions_now) do
old_action_order[ac] = i
end
table.sort(actions_now, function(ac1, ac2)
if ac1.priority ~= ac2.priority then
return ac1.priority > ac2.priority
else
return old_action_order[ac1] < old_action_order[ac2]
end
end)

This affects LuaC interrupts, delayers, whatever devices use non-zero time in queue:add_action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant