love.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. function love.run()
  2. if love.math then love.math.setRandomSeed(os.time()) end
  3. tickRate = .02
  4. tickDelta = 0
  5. interp = .12
  6. love.load(arg)
  7. delta = 0
  8. while true do
  9. love.timer.step()
  10. delta = love.timer.getDelta()
  11. tickDelta = tickDelta + delta
  12. while tickDelta >= tickRate do
  13. tickDelta = tickDelta - tickRate
  14. love.event.pump()
  15. for e, a, b, c, d in love.event.poll() do
  16. if e == 'quit' then f.exe(love.quit) love.audio.stop() return
  17. else love.handlers[e](a, b, c, d) end
  18. end
  19. love.update()
  20. end
  21. love.graphics.clear()
  22. love.draw()
  23. love.graphics.present()
  24. love.timer.sleep(.001)
  25. end
  26. end
  27. function love.errhand(msg)
  28. msg = tostring(msg)
  29. print((debug.traceback('Error: ' .. tostring(msg), 1 + 2):gsub('\n[^\n]+$', '')))
  30. if not love.window or not love.graphics or not love.event then return end
  31. if not love.graphics.isCreated() or not love.window.isCreated() then
  32. if not pcall(love.window.setMode, 800, 600) then return end
  33. end
  34. -- Reset state.
  35. if love.mouse then
  36. love.mouse.setVisible(true)
  37. love.mouse.setGrabbed(false)
  38. end
  39. if love.joystick then
  40. for i,v in ipairs(love.joystick.getJoysticks()) do
  41. v:setVibration() -- Stop all joystick vibrations.
  42. end
  43. end
  44. if love.audio then love.audio.stop() end
  45. love.graphics.reset()
  46. love.graphics.setBackgroundColor(35, 35, 35)
  47. local font = love.graphics.setNewFont('data/media/fonts/pixel.ttf', 8)
  48. love.graphics.setColor(255, 255, 255, 255)
  49. local trace = debug.traceback()
  50. love.graphics.clear()
  51. love.graphics.origin()
  52. local err = {}
  53. for l in string.gmatch(trace, '(.-)\n') do
  54. if not string.match(l, 'boot.lua') then
  55. l = string.gsub(l, 'stack traceback:', 'more details:\n')
  56. table.insert(err, l)
  57. end
  58. end
  59. local p = table.concat(err, '\n')
  60. p = string.gsub(p, '\t', '')
  61. p = string.gsub(p, '%[string "(.-)"%]', '%1')
  62. if goregous then
  63. goregous:send({'error', msg .. '|' .. p:gsub('\n', '|')})
  64. end
  65. local _, lines = font:getWrap(msg, love.graphics.getWidth() - 140)
  66. local function draw()
  67. love.graphics.clear()
  68. love.graphics.setColor(255, 255, 255, 128)
  69. love.graphics.print('groupGore crashed =[\n\nhere\'s why:', 64, 64)
  70. love.graphics.setColor(192, 0, 0, 255)
  71. love.graphics.printf(msg, 64, 64 + font:getHeight() * 4, love.graphics.getWidth() - 64)
  72. love.graphics.setColor(255, 255, 255, 128)
  73. love.graphics.printf(p, 64, 64 + font:getHeight() * (5 + lines), love.graphics.getWidth() - 64)
  74. love.graphics.present()
  75. end
  76. while true do
  77. love.event.pump()
  78. for e, a, b, c in love.event.poll() do
  79. if e == 'quit' then return end
  80. if e == 'keypressed' and a == 'escape' then return end
  81. end
  82. draw()
  83. if love.timer then love.timer.sleep(0.1) end
  84. end
  85. end
  86. function love.graphics.rectangleCenter(style, x, y, w, h, pix)
  87. local ox, oy = math.round(x - (w / 2)), math.round(y - (h / 2))
  88. if pix then ox = ox + .5 oy = oy + .5 end
  89. love.graphics.rectangle(style, ox, oy, w, h)
  90. end
  91. function love.graphics.printCenter(str, x, y, h, v)
  92. local xx = x - ((h or (h == nil)) and (love.graphics.getFont():getWidth(str) / 2) or 0)
  93. local yy = y - ((v or (v == nil)) and (love.graphics.getFont():getHeight() / 2) or 0)
  94. love.graphics.print(str, xx, yy)
  95. end
  96. function love.graphics.width(x) x = x or 1 return love.graphics.getWidth() * x end
  97. function love.graphics.height(x) x = x or 1 return love.graphics.getHeight() * x end
  98. function love.graphics.minUnit(x) return math.min(love.graphics.width(x), love.graphics.height(x)) end
  99. timer = {}
  100. timer.rot = function(val, fn) if not val or val == 0 then return val end if val <= tickRate then f.exe(fn) return 0 end return val - tickRate end