mirror of
https://github.com/love2d/love.git
synced 2026-08-13 17:10:54 +02:00
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:
+18
-10
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user