Prechádzať zdrojové kódy

Add a sleep to the thread example;

To avoid confusion
bjorn 4 mesiacov pred
rodič
commit
3cc19c3f43
1 zmenil súbory, kde vykonal 8 pridanie a 3 odobranie
  1. 8 3
      examples/Intro/Thread/main.lua

+ 8 - 3
examples/Intro/Thread/main.lua

@@ -2,12 +2,15 @@ function lovr.load()
   -- This holds the thread code
   -- This must be wrapped with [[]] or '' to allow the engine to run it as Lua
   threadCode = [[
-    local lovr = { thread = require 'lovr.thread' }
+    local lovr = {}
+    lovr.thread = require 'lovr.thread'
+    lovr.timer = require 'lovr.timer'
     local channel = lovr.thread.getChannel('test')
     local x = 0
     while true do
       x = x + 1
       channel:push(x)
+      lovr.timer.sleep(.1)
     end
   ]]
 
@@ -22,8 +25,10 @@ function lovr.load()
 end
 
 function lovr.update(dt)
-  -- Read and delete the message
-  message = channel:pop()
+  -- Read and delete any messages in the queue
+  while channel:peek() do
+    message = channel:pop()
+  end
 end
 
 function lovr.draw(pass)