Guest User

Untitled

a guest
Jan 23rd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. -- main thread loop
  2. function love.run()
  3.     if love.load then love.load(arg) end
  4.  
  5.     local dt = 0
  6.  
  7.     -- Main loop time.
  8.     while true do
  9.         if love.timer then
  10.             love.timer.step()
  11.             dt = love.timer.getDelta()
  12.         end
  13.        
  14.         if love.update then love.update(dt) end -- will pass 0 if love.timer is disabled
  15.        
  16.         if love.graphics then
  17.             love.graphics.clear()
  18.             if love.draw then love.draw() end
  19.         end
  20.  
  21.         if love.timer then love.timer.sleep(0.001) end
  22.        
  23.         if love.graphics then love.graphics.present() end
  24.     end
  25. end
  26.  
  27.  
  28. -- update thread loop
  29. function sim:run()
  30.     local dt = self.thread:demand("fps")
  31.    
  32.     local accumulator = 0
  33.     local oldtime = love.timer.getMicroTime()
  34.    
  35.     while true do
  36.         local curtime = love.timer.getMicroTime()
  37.         local frametime = curtime-oldtime
  38.         oldtime = curtime
  39.        
  40.        
  41.         if frametime > 0.25 then print("crap", frametime) frametime = 0.25 end
  42.        
  43.         accumulator = accumulator + frametime
  44.        
  45.         while accumulator >= dt do
  46.             accumulator = accumulator - dt
  47.            
  48.             -- Process events.
  49.             for e,a,b,c in love.event.poll() do
  50.                 if e == "q" then
  51.                     if not love.quit or not love.quit() then
  52.                         if love.audio then
  53.                             love.audio.stop()
  54.                         end
  55.                         return
  56.                     end
  57.                 end
  58.                 self.handlers[e](a,b,c) -- made my own handlers based on ones in boot.lua
  59.             end
  60.            
  61.             self:update(dt, accumulator)
  62.             self:send()
  63.         end
  64.        
  65.         love.timer.sleep(0.001) -- keeps CPU usage way down
  66.        
  67.     end
  68. end
Add Comment
Please, Sign In to add comment