Advertisement
wolfboyft

My love.run

Jan 6th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. -- The following function is based on the MIT licensed code here: https://gist.github.com/Positive07/5e80f03cabd069087930d569c148241c
  2. -- Copyright (c) 2018 Arvid Gerstmann, Jake Besworth, Max, Pablo Mayobre, LÖVE Developers, Henry Fleminger Thomson
  3.  
  4. function love.run()
  5.     love.load(love.arg.parseGameArguments(arg))
  6.     love.timer.step()
  7.     local delta, lag = 0, 0
  8.    
  9.     return function()
  10.         do -- Events
  11.             love.event.pump()
  12.             for name, a,b,c,d,e,f in love.event.poll() do
  13.                 if name == "quit" then
  14.                     if not love.quit() then
  15.                         return a or 0
  16.                     end
  17.                 end
  18.                 love.handles[name](a,b,c,d,e,f)
  19.             end
  20.         end
  21.        
  22.         do -- Update
  23.             local start = love.timer.getTime()
  24.             delta = love.timer.step()
  25.             lag = math.min(lag + delta, constants.core.tickRate * constants.core.maxFrameSkip)
  26.             local frames = math.floor(lag / constants.core.tickRate)
  27.             lag = lag % constants.core.tickRate
  28.             for _=1, frames do
  29.                 love.update(constants.core.tickRate)
  30.             end
  31.         end
  32.        
  33.         if love.graphics.isActive() then -- Rendering
  34.             love.graphics.origin()
  35.             love.graphics.clear(love.graphics.getBackgroundColor())
  36.             love.draw()
  37.             love.graphics.present()
  38.         end
  39.        
  40.         if not settings.current.manualGarbageCollection.disable then -- Garbage collection
  41.             local start = love.timer.getTime()
  42.             for _=1, settings.current.manualGarbageCollection.steps do
  43.                 if love.timer.getTime() - start > settings.current.manualGarbageCollection.timeLimit then break end
  44.                 collectgarbage("step", 1)
  45.             end
  46.            
  47.             if collectgarbage("count") / 1024 > settings.current.manualGarbageCollection.safetyMargin then
  48.                 collectgarbage("collect")
  49.             end
  50.            
  51.             collectgarbage("stop")
  52.         end
  53.        
  54.         love.timer.sleep(0.001)
  55.     end
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement