Add auto update hook

This commit is contained in:
Matthias Richter 2011-02-01 23:39:59 +01:00
parent 4a24422e54
commit ae58b7e822

View File

@ -149,23 +149,40 @@ local function share_group(shape, other)
return false return false
end end
-- update with a minimum time step local _love_update
local function update_min_step(dt, min_step) function setAutoUpdate(max_step)
assert(type(min_step) == "number") assert(_love_update == nil, "Auto update already enabled!")
while dt > min_step do
update(min_step) if max_step > 1 then -- assume it's a framerate
dt = dt - min_step max_step = 1 / max_step
end end
_love_update = love.update
love.update = function(dt)
_love_update(dt)
update(dt) update(dt)
end
if type(max_step) == "number" then
local combined_update = love.update
love.update = function(dt)
while dt > max_step do
combined_update(max_step)
dt = dt - max_step
end
combined_update(dt)
end
end
end
function setNoAutoUpdate()
love.update = _love_update
_love_update = nil
end end
-- check for collisions -- check for collisions
local colliding_last_frame = {} local colliding_last_frame = {}
function update(dt, min_step) function update(dt)
if min_step then
update_min_step(dt, min_step)
return
end
-- collect colliding shapes -- collect colliding shapes
local tested, colliding = {}, {} local tested, colliding = {}, {}
for _,shape in pairs(shapes) do for _,shape in pairs(shapes) do