Pölygamy is quite invasive in this regard since it inserts and swaps callbacks on the fly on state change...
To that end, I've written a custom love.run loop that allows to do it without pain, and it may be useful to extract it and use it as a common base for the various libs.
The main loop is simplified, at the expense of a long preamble :
Code: Select all
while running do
love.timer.step()
delta = love.timer.getDelta()
manageCallbacks()
-- love.update, love.draw, and more if you want
for _,cb in ipairs( callbacks ) do
cb( delta )
end
-- Process events.
for e,a,b,c in love.event.poll() do
love.handlers[e](a,b,c)
end
love.timer.sleep( 1 )
love.graphics.present()
end
e.g.: callbackOrder={"polykeyheld", "polytimer", "update", "clear", "draw"}
Callbacks not referenced in the list are inserted before everything else.
The API is:
Polygamy.setCallback(name,callback) -- inserts or swaps a given callback
Polygamy.removeCallback(name)
Polygamy.setTransition(function,parameters enclosed in a tuple) -- see below.
These function don't act immediately, they queue the instructions, that are executed at the beginning of the main loop by manageCallbacks(). the setTransition allows to execute functions at that point too, I use them to run the before and after callbacks in Polygamy.state at a "clean" point in the loop.
The full loop is in the init file of Polygamy 0.4.0, in the Polygamy post in the Project forum
What do you think?
Edit, I just realised that there was a bug in the current implementation, I'll have to use double buffering in the queue.