Browse Source

Add tick and tock example;

bjorn 6 years ago
parent
commit
fb1271fffc
3 changed files with 54 additions and 2 deletions
  1. 12 2
      api/init.lua
  2. 21 0
      api/lovr/graphics/tick.lua
  3. 21 0
      api/lovr/graphics/tock.lua

+ 12 - 2
api/init.lua

@@ -10776,11 +10776,16 @@ return {
           description = "Starts a named timer on the GPU, which can be stopped using `lovr.graphics.tock`.",
           description = "Starts a named timer on the GPU, which can be stopped using `lovr.graphics.tock`.",
           key = "lovr.graphics.tick",
           key = "lovr.graphics.tick",
           module = "lovr.graphics",
           module = "lovr.graphics",
-          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.",
           related = {
           related = {
             "lovr.graphics.tock",
             "lovr.graphics.tock",
             "lovr.graphics.getStats"
             "lovr.graphics.getStats"
           },
           },
+          examples = {
+            {
+              code = "function lovr.graphics.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"
+            }
+          },
+          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.",
           variants = {
           variants = {
             {
             {
               arguments = {
               arguments = {
@@ -10801,11 +10806,16 @@ return {
           description = "Stops a named timer on the GPU, previously started with `lovr.graphics.tick`.",
           description = "Stops a named timer on the GPU, previously started with `lovr.graphics.tick`.",
           key = "lovr.graphics.tock",
           key = "lovr.graphics.tock",
           module = "lovr.graphics",
           module = "lovr.graphics",
-          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.",
           related = {
           related = {
             "lovr.graphics.tick",
             "lovr.graphics.tick",
             "lovr.graphics.getStats"
             "lovr.graphics.getStats"
           },
           },
+          examples = {
+            {
+              code = "function lovr.graphics.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"
+            }
+          },
+          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.",
           variants = {
           variants = {
             {
             {
               arguments = {
               arguments = {

+ 21 - 0
api/lovr/graphics/tick.lua

@@ -19,6 +19,27 @@ return {
     Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if
     Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if
     they are unavailable.
     they are unavailable.
   ]],
   ]],
+  example = [[
+    function lovr.graphics.draw()
+      lovr.graphics.tick('mytimer')
+
+      -- Draw a bunch of cubes
+      for x = -4, 4 do
+        for y = -4, 4 do
+          for z = -4, 4 do
+            lovr.graphics.cube('fill', x, y, z, .2)
+          end
+        end
+      end
+
+      lovr.graphics.tock('mytimer')
+
+      local stats = lovr.graphics.getStats()
+      if stats.timers.mytimer then
+        print('rendering took ' .. stats.timers.mytimer .. ' seconds')
+      end
+    end
+  ]],
   related = {
   related = {
     'lovr.graphics.tock',
     'lovr.graphics.tock',
     'lovr.graphics.getStats'
     'lovr.graphics.getStats'

+ 21 - 0
api/lovr/graphics/tock.lua

@@ -18,6 +18,27 @@ return {
     Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if
     Note that the results are delayed (because the GPU runs asynchronously), and may be `nil` if
     they are unavailable.
     they are unavailable.
   ]],
   ]],
+  example = [[
+    function lovr.graphics.draw()
+      lovr.graphics.tick('mytimer')
+
+      -- Draw a bunch of cubes
+      for x = -4, 4 do
+        for y = -4, 4 do
+          for z = -4, 4 do
+            lovr.graphics.cube('fill', x, y, z, .2)
+          end
+        end
+      end
+
+      lovr.graphics.tock('mytimer')
+
+      local stats = lovr.graphics.getStats()
+      if stats.timers.mytimer then
+        print('rendering took ' .. stats.timers.mytimer .. ' seconds')
+      end
+    end
+  ]],
   related = {
   related = {
     'lovr.graphics.tick',
     'lovr.graphics.tick',
     'lovr.graphics.getStats'
     'lovr.graphics.getStats'