Thread: GetTime()
View Single Post
10-02-20, 05:57 AM   #12
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
If you don't mind use a lib, you may check the example for Continue() in the Scorpio - asynchronous framework, the async frame work is designed to smooth the operation of codes and make the fps stable.

The async framework is also designed based on the debugprofilestop. The lib can be used as an API lib, works like :

Lua Code:
  1. Scorpio.Continue(function()
  2.     -- The function is processed within in a coroutine
  3.     -- so, async API can be used
  4.     local testTable = {}
  5.     for i = 1, 100000 do
  6.         testTable[i] = i
  7.     end
  8.  
  9.     local startTime = GetTime()
  10.  
  11.     for k, v in pairs(testTable) do
  12.         -- The Continue API will yield the current coroutine
  13.         -- And then check if there is still enough time to resume it
  14.         -- So the fps can be protected
  15.         Scorpio.Continue()
  16.  
  17.         -- If the process is yield, it'll be resumed in the next phase(with OnUpdate)
  18.         -- So we can check how many the recycle processed in one phase
  19.         if GetTime() ~= startTime then
  20.             print(k)
  21.             startTime = GetTime()
  22.         end
  23.     end
  24. end)

I prefer the Lua's coroutine compares to the callback since the logic can be put together
  Reply With Quote