Browse Source

lovr.system.pollEvents;

bjorn 1 year ago
parent
commit
dab988e616

File diff suppressed because it is too large
+ 0 - 1
api/init.lua


+ 42 - 24
api/lovr/callbacks/errhand.lua

@@ -44,11 +44,12 @@ return {
     code = [[
     code = [[
       function lovr.errhand(message)
       function lovr.errhand(message)
         local function formatTraceback(s)
         local function formatTraceback(s)
-          return s:gsub('\n[^\n]+$', ''):gsub('\t', ''):gsub('stack traceback', '\nStack')
+          return s:gsub('\n[^\n]+$', ''):gsub('\t', ''):gsub('stack traceback:', '\nStack:\n')
         end
         end
 
 
-        message = tostring(message) .. formatTraceback(debug.traceback('', 4))
-        print('Error:\n' .. message)
+        message = 'Error:\n\n' .. tostring(message) .. formatTraceback(debug.traceback('', 4))
+
+        print(message)
 
 
         if not lovr.graphics or not lovr.graphics.isInitialized() then
         if not lovr.graphics or not lovr.graphics.isInitialized() then
           return function() return 1 end
           return function() return 1 end
@@ -56,39 +57,43 @@ return {
 
 
         if lovr.audio then lovr.audio.stop() end
         if lovr.audio then lovr.audio.stop() end
 
 
-        local scale = .35
-        local font = lovr.graphics.getDefaultFont()
-        local wrap = .7 * font:getPixelDensity()
-        local lines = font:getLines(message, wrap)
-        local width = math.min(font:getWidth(message), wrap) * scale
-        local height = .8 + #lines * font:getHeight() * scale
-        local x = -width / 2
-        local y = math.min(height / 2, 10)
-        local z = -10
-
-        lovr.graphics.setBackgroundColor(.11, .10, .14)
-        font:setPixelDensity()
-
-        local function render(pass)
-          pass:setColor(.95, .95, .95)
-          pass:text('Error', x, y, z, scale * 1.6, 0, 0, 0, 0, nil, 'left', 'top')
-          pass:text(message, x, y - .8, z, scale, 0, 0, 0, 0, wrap, 'left', 'top')
+        if not lovr.headset or lovr.headset.getPassthrough() == 'opaque' then
+          lovr.graphics.setBackgroundColor(.11, .10, .14)
+        else
+          lovr.graphics.setBackgroundColor(0, 0, 0, 0)
         end
         end
 
 
+        local font = lovr.graphics.getDefaultFont()
+
         return function()
         return function()
-          lovr.event.pump()
+          lovr.system.pollEvents()
 
 
           for name, a in lovr.event.poll() do
           for name, a in lovr.event.poll() do
             if name == 'quit' then return a or 1
             if name == 'quit' then return a or 1
             elseif name == 'restart' then return 'restart', lovr.restart and lovr.restart()
             elseif name == 'restart' then return 'restart', lovr.restart and lovr.restart()
-            elseif name == 'keypressed' and a == 'f5' then lovr.event.restart() end
+            elseif name == 'keypressed' and a == 'f5' then lovr.event.restart()
+            elseif name == 'keypressed' and a == 'escape' then lovr.event.quit() end
           end
           end
 
 
           if lovr.headset and lovr.headset.getDriver() ~= 'desktop' then
           if lovr.headset and lovr.headset.getDriver() ~= 'desktop' then
             lovr.headset.update()
             lovr.headset.update()
             local pass = lovr.headset.getPass()
             local pass = lovr.headset.getPass()
             if pass then
             if pass then
-              render(pass)
+              font:setPixelDensity()
+
+              local scale = .35
+              local font = lovr.graphics.getDefaultFont()
+              local wrap = .7 * font:getPixelDensity()
+              local lines = font:getLines(message, wrap)
+              local width = math.min(font:getWidth(message), wrap) * scale
+              local height = .8 + #lines * font:getHeight() * scale
+              local x = -width / 2
+              local y = math.min(height / 2, 10)
+              local z = -10
+
+              pass:setColor(.95, .95, .95)
+              pass:text(message, x, y, z, scale, 0, 0, 0, 0, wrap, 'left', 'top')
+
               lovr.graphics.submit(pass)
               lovr.graphics.submit(pass)
               lovr.headset.submit()
               lovr.headset.submit()
             end
             end
@@ -97,11 +102,24 @@ return {
           if lovr.system.isWindowOpen() then
           if lovr.system.isWindowOpen() then
             local pass = lovr.graphics.getWindowPass()
             local pass = lovr.graphics.getWindowPass()
             if pass then
             if pass then
-              render(pass)
+              local w, h = lovr.system.getWindowDimensions()
+              pass:setProjection(1, lovr.math.mat4():orthographic(0, w, 0, h, -1, 1))
+              font:setPixelDensity(1)
+
+              local scale = .6
+              local wrap = w * .8 / scale
+              local width = math.min(font:getWidth(message), wrap) * scale
+              local x = w / 2 - width / 2
+
+              pass:setColor(.95, .95, .95)
+              pass:text(message, x, h / 2, 0, scale, 0, 0, 0, 0, wrap, 'left', 'middle')
+
               lovr.graphics.submit(pass)
               lovr.graphics.submit(pass)
               lovr.graphics.present()
               lovr.graphics.present()
             end
             end
           end
           end
+
+          lovr.math.drain()
         end
         end
       end
       end
     ]]
     ]]

+ 9 - 18
api/lovr/callbacks/run.lua

@@ -29,8 +29,8 @@ return {
     - Returning a number will exit LÖVR using the number as the exit code (0 means success).
     - Returning a number will exit LÖVR using the number as the exit code (0 means success).
 
 
     Care should be taken when overriding this callback.  For example, if the main loop does not call
     Care should be taken when overriding this callback.  For example, if the main loop does not call
-    `lovr.event.pump` then the OS will think LÖVR is unresponsive, and if the quit event is not
-    handled then closing the window won't work.
+    `lovr.system.pollEvents` then the OS will think LÖVR is unresponsive, or if the quit event is
+    not handled then closing the window won't work.
   ]],
   ]],
   example = {
   example = {
     description = 'The default `lovr.run`:',
     description = 'The default `lovr.run`:',
@@ -39,8 +39,8 @@ return {
         if lovr.timer then lovr.timer.step() end
         if lovr.timer then lovr.timer.step() end
         if lovr.load then lovr.load(arg) end
         if lovr.load then lovr.load(arg) end
         return function()
         return function()
+          if lovr.system then lovr.system.pollEvents() end
           if lovr.event then
           if lovr.event then
-            lovr.event.pump()
             for name, a, b, c, d in lovr.event.poll() do
             for name, a, b, c, d in lovr.event.poll() do
               if name == 'restart' then
               if name == 'restart' then
                 local cookie = lovr.restart and lovr.restart()
                 local cookie = lovr.restart and lovr.restart()
@@ -56,21 +56,12 @@ return {
           if lovr.headset then dt = lovr.headset.update() end
           if lovr.headset then dt = lovr.headset.update() end
           if lovr.update then lovr.update(dt) end
           if lovr.update then lovr.update(dt) end
           if lovr.graphics then
           if lovr.graphics then
-            if lovr.headset then
-              local pass = lovr.headset.getPass()
-              if pass then
-                local skip = lovr.draw and lovr.draw(pass)
-                if not skip then lovr.graphics.submit(pass) end
-              end
-            end
-            if lovr.system.isWindowOpen() then
-              if lovr.mirror then
-                local pass = lovr.graphics.getWindowPass()
-                local skip = lovr.mirror(pass)
-                if not skip then lovr.graphics.submit(pass) end
-              end
-              lovr.graphics.present()
-            end
+            local headset = lovr.headset and lovr.headset.getPass()
+            if headset and (not lovr.draw or lovr.draw(headset)) then headset = nil end
+            local window = lovr.graphics.getWindowPass()
+            if window and (not lovr.mirror or lovr.mirror(window)) then window = nil end
+            lovr.graphics.submit(headset, window)
+            lovr.graphics.present()
           end
           end
           if lovr.headset then lovr.headset.submit() end
           if lovr.headset then lovr.headset.submit() end
           if lovr.math then lovr.math.drain() end
           if lovr.math then lovr.math.drain() end

+ 1 - 1
api/lovr/event/pump.lua → api/lovr/system/pollEvents.lua

@@ -1,5 +1,5 @@
 return {
 return {
-  summary = 'Pump new events into the queue for processing.',
+  summary = 'Poll the OS for new window events.',
   description = [[
   description = [[
     Fills the event queue with unprocessed events from the operating system.  This function should
     Fills the event queue with unprocessed events from the operating system.  This function should
     be called often, otherwise the operating system will consider the application unresponsive.
     be called often, otherwise the operating system will consider the application unresponsive.

+ 1 - 1
api/lovr/thread/init.lua

@@ -21,7 +21,7 @@ return {
     - The graphics module (or any functions that perform rendering) cannot be used in a thread.
     - The graphics module (or any functions that perform rendering) cannot be used in a thread.
       Note that this includes creating graphics objects like Models and Textures.  There are "data"
       Note that this includes creating graphics objects like Models and Textures.  There are "data"
       equivalent `ModelData` and `Image` objects that can be used in threads though.
       equivalent `ModelData` and `Image` objects that can be used in threads though.
-    - `lovr.event.pump` cannot be called from a thread.
+    - `lovr.system.pollEvents` cannot be called from a thread.
     - Crashes or problems can happen if two threads access the same object at the same time, so
     - Crashes or problems can happen if two threads access the same object at the same time, so
       special care must be taken to coordinate access to objects from multiple threads.
       special care must be taken to coordinate access to objects from multiple threads.
   ]],
   ]],

Some files were not shown because too many files changed in this diff