Poll for events before update/run and do a first timestep after window creation

Moving the event loop improves accuracy of various input functions, and thus decreases mouse lag for custom pointers, for instance.
Doing a timestep after window creation makes sure that engine initialization isn't in the first dt.
NOTE: A near-zero dt can occur.
This commit is contained in:
Bart van Strien
2011-11-19 15:38:51 +01:00
parent 0aae9684b3
commit 35cfb66bf7
2 changed files with 51 additions and 29 deletions
+18 -10
View File
@@ -315,6 +315,11 @@ function love.init()
love.graphics.setCaption(c.title)
end
-- Our first timestep, because screen creation can take some time
if love.timer then
love.timer.step()
end
if love.filesystem then
love.filesystem.setRelease(c.release and is_fused_game)
if c.identity then love.filesystem.setIdentity(c.identity) end
@@ -368,16 +373,6 @@ function love.run()
-- Main loop time.
while true do
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics then
love.graphics.clear()
if love.draw then love.draw() end
end
-- Process events.
if love.event then
for e,a,b,c in love.event.poll() do
@@ -393,6 +388,19 @@ function love.run()
end
end
-- Update dt, as we'll be passing it to update
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
-- Call update and draw
if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
if love.graphics then
love.graphics.clear()
if love.draw then love.draw() end
end
if love.timer then love.timer.sleep(0.001) end
if love.graphics then love.graphics.present() end