Code: Select all
if love.timer then love.timer.sleep(1) end
Code: Select all
if love.timer then love.timer.sleep(1) end
Wouldn't the OS handle this? Either way, most games that use default love.run eat as much CPU as they can (unless they use VSync), so it doesn't seem to help much.Robin wrote:Nope. It's there so people can have really simple love.updates, not change love.run and still don't have CPU monopoly.
Code: Select all
function love.run ()
-- these don't change, so we can make them local for faster access
local audio, graphics = love.audio, love.graphics
local event, timer = love.event, love.timer
-- Prepare stuff
if love.load then love.load(arg) end
local dt = 0
if timer then
-- Set a reasonable FPS limit
local FPS = 60
dt = 1/FPS
end
-- Main loop
while true do
-- Update the timer
if timer then timer.step() end
-- Process events
if event then
for e, a, b, c in event.poll() do
if e == "q" then
if not love.quit or not love.quit() then
if audio then audio.stop() end
end
return
end
love.handlers[e](a, b, c)
end
end
-- Do the game mechanic
if love.update then love.update(dt) end
-- Draw the graphics
if graphics then
graphics.clear()
if love.draw then love.draw() end
end
-- Wait for the end of this frame
if timer then
timer.step()
local time_work = timer.getDelta()
if time_work < dt then
timer.sleep((dt - time_work) * 1000)
end
end
-- Show the frame
if graphics then
graphics.present()
end
end
end
You need to read this.Rad3k wrote:The dt is actually constant, which may be a good thing if you use love.physics - according to Box2D manual, it doesn't like variable timestep.
Yes, I considered doing something like this in case it proved necessary. I will look into it.genericdave wrote:You need to read this.
Users browsing this forum: Semrush [Bot], snibo and 4 guests