--- a/main.lua +++ b/main.lua @@ -209,12 +209,11 @@ math.random() math.random() if love.load then love.load(arg) end - local dt = 0 local acc = 0 - -- Main loop time. - while true do - local frame_start = love.timer.getTime() + -- One iteration per call: the browser build (love.js) calls the returned + -- function once per frame instead of running a blocking "while true" loop. + return function() -- Process events. if love.event then love.event.pump() @@ -224,7 +223,7 @@ if love.audio then love.audio.stop() end - return + return a or 0 end end love.handlers[e](a,b,c,d) @@ -232,8 +231,7 @@ end love.timer.step() - dt = love.timer.getDelta() - dt = math.min(dt, MAX_FRAMETIME) + local dt = math.min(love.timer.getDelta(), MAX_FRAMETIME) acc = acc + dt while acc >= MIN_FRAMETIME do @@ -246,7 +244,6 @@ love.draw() love.graphics.present() - love.timer.sleep(0.001) end end