Browse Source

Update tick and tock;

bjorn 5 years ago
parent
commit
6c578f6f9d
3 changed files with 28 additions and 31 deletions
  1. 13 7
      api/init.lua
  2. 2 11
      api/lovr/graphics/tick.lua
  3. 13 13
      api/lovr/graphics/tock.lua

+ 13 - 7
api/init.lua

@@ -9714,14 +9714,14 @@ return {
           },
           related = {
             "lovr.graphics.tock",
-            "lovr.graphics.getStats"
+            "lovr.graphics.getFeatures"
           },
           examples = {
             {
-              code = "function lovr.draw()\n  lovr.graphics.tick('mytimer')\n\n  -- Draw a bunch of cubes\n  for x = -4, 4 do\n    for y = -4, 4 do\n      for z = -4, 4 do\n        lovr.graphics.cube('fill', x, y, z, .2)\n      end\n    end\n  end\n\n  lovr.graphics.tock('mytimer')\n\n  local stats = lovr.graphics.getStats()\n  if stats.timers.mytimer then\n    print('rendering took ' .. stats.timers.mytimer .. ' seconds')\n  end\nend"
+              code = "function lovr.draw()\n  lovr.graphics.tick('mytimer')\n\n  -- Draw a bunch of cubes\n  for x = -4, 4 do\n    for y = -4, 4 do\n      for z = -4, 4 do\n        lovr.graphics.cube('fill', x, y, z, .2)\n      end\n    end\n  end\n\n  print('rendering took ' .. (lovr.graphics.tock('mytimer') or 0) .. ' seconds')\nend"
             }
           },
-          notes = "The timer can be stopped by calling `lovr.graphics.tock` using the same name.  All drawing commands between the tick and the tock will be timed.  It is not possible to nest calls to tick and tock.\n\nThe amount of time elapsed can be accessed from the `timers` field of `lovr.graphics.getStats`. Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if they are unavailable.\n\nGPU timers are not supported on all systems.  Check the `timers` feature using `lovr.graphics.getFeatures` to see if it is supported on the current system."
+          notes = "The timer can be stopped by calling `lovr.graphics.tock` using the same name.  All drawing commands between the tick and the tock will be timed.  It is not possible to nest calls to tick and tock.\n\nGPU timers are not supported on all systems.  Check the `timers` feature using `lovr.graphics.getFeatures` to see if it is supported on the current system."
         },
         {
           name = "tock",
@@ -9739,19 +9739,25 @@ return {
                   description = "The name of the timer."
                 }
               },
-              returns = {}
+              returns = {
+                {
+                  name = "time",
+                  type = "number",
+                  description = "The number of seconds elapsed, or `nil` if the data isn't ready yet."
+                }
+              }
             }
           },
           related = {
             "lovr.graphics.tick",
-            "lovr.graphics.getStats"
+            "lovr.graphics.getFeatures"
           },
           examples = {
             {
-              code = "function lovr.draw()\n  lovr.graphics.tick('mytimer')\n\n  -- Draw a bunch of cubes\n  for x = -4, 4 do\n    for y = -4, 4 do\n      for z = -4, 4 do\n        lovr.graphics.cube('fill', x, y, z, .2)\n      end\n    end\n  end\n\n  lovr.graphics.tock('mytimer')\n\n  local stats = lovr.graphics.getStats()\n  if stats.timers.mytimer then\n    print('rendering took ' .. stats.timers.mytimer .. ' seconds')\n  end\nend"
+              code = "function lovr.draw()\n  lovr.graphics.tick('mytimer')\n\n  -- Draw a bunch of cubes\n  for x = -4, 4 do\n    for y = -4, 4 do\n      for z = -4, 4 do\n        lovr.graphics.cube('fill', x, y, z, .2)\n      end\n    end\n  end\n\n  print('rendering took ' .. (lovr.graphics.tock('mytimer') or 0) .. ' seconds')\nend"
             }
           },
-          notes = "All drawing commands between the tick and the tock will be timed.  It is not possible to nest calls to tick and tock.\n\nThe amount of time elapsed can be accessed from the `timers` field of `lovr.graphics.getStats`. Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if they are unavailable.\n\nGPU timers are not supported on all systems.  Check the `timers` feature using `lovr.graphics.getFeatures` to see if it is supported on the current system."
+          notes = "All drawing commands between tick and tock will be timed.  It is not possible to nest calls to tick and tock.\n\nThe results are delayed, and might be `nil` for the first few frames.  This function returns the most recent available timer value.\n\nGPU timers are not supported on all systems.  Check the `timers` feature using `lovr.graphics.getFeatures` to see if it is supported on the current system."
         },
         {
           name = "transform",

+ 2 - 11
api/lovr/graphics/tick.lua

@@ -15,10 +15,6 @@ return {
     commands between the tick and the tock will be timed.  It is not possible to nest calls to tick
     and tock.
 
-    The amount of time elapsed can be accessed from the `timers` field of `lovr.graphics.getStats`.
-    Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if
-    they are unavailable.
-
     GPU timers are not supported on all systems.  Check the `timers` feature using
     `lovr.graphics.getFeatures` to see if it is supported on the current system.
   ]],
@@ -35,16 +31,11 @@ return {
         end
       end
 
-      lovr.graphics.tock('mytimer')
-
-      local stats = lovr.graphics.getStats()
-      if stats.timers.mytimer then
-        print('rendering took ' .. stats.timers.mytimer .. ' seconds')
-      end
+      print('rendering took ' .. (lovr.graphics.tock('mytimer') or 0) .. ' seconds')
     end
   ]],
   related = {
     'lovr.graphics.tock',
-    'lovr.graphics.getStats'
+    'lovr.graphics.getFeatures'
   }
 }

+ 13 - 13
api/lovr/graphics/tock.lua

@@ -9,14 +9,19 @@ return {
       description = 'The name of the timer.'
     }
   },
-  returns = {},
+  returns = {
+    {
+      name = 'time',
+      type = 'number',
+      description = 'The number of seconds elapsed, or `nil` if the data isn\'t ready yet.'
+    }
+  },
   notes = [[
-    All drawing commands between the tick and the tock will be timed.  It is not possible to nest
-    calls to tick and tock.
+    All drawing commands between tick and tock will be timed.  It is not possible to nest calls to
+    tick and tock.
 
-    The amount of time elapsed can be accessed from the `timers` field of `lovr.graphics.getStats`.
-    Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if
-    they are unavailable.
+    The results are delayed, and might be `nil` for the first few frames.  This function returns
+    the most recent available timer value.
 
     GPU timers are not supported on all systems.  Check the `timers` feature using
     `lovr.graphics.getFeatures` to see if it is supported on the current system.
@@ -34,16 +39,11 @@ return {
         end
       end
 
-      lovr.graphics.tock('mytimer')
-
-      local stats = lovr.graphics.getStats()
-      if stats.timers.mytimer then
-        print('rendering took ' .. stats.timers.mytimer .. ' seconds')
-      end
+      print('rendering took ' .. (lovr.graphics.tock('mytimer') or 0) .. ' seconds')
     end
   ]],
   related = {
     'lovr.graphics.tick',
-    'lovr.graphics.getStats'
+    'lovr.graphics.getFeatures'
   }
 }