Thread: GetTime()
View Single Post
09-30-20, 02:40 PM   #8
KL1SK
A Murloc Raider
Join Date: Sep 2020
Posts: 9
There is such code:
Lua Code:
  1. local EM = CreateFrame('Frame')
  2.  
  3. testTable = {}
  4. for i = 1, 100000 do
  5.     testTable[i] = i
  6. end
  7.  
  8. function DefPairs()
  9.     local startTime = GetTime()
  10.     for k, v in pairs(testTable) do
  11.         print(k)
  12.     end
  13.     print("LeadTime: " .. GetTime() - startTime)
  14. end
  15.  
  16. function SmoothPairs(table, mult, callback)
  17.     EM:SetScript("OnUpdate", nil)
  18.  
  19.     local prevFrameTime     = 0
  20.     local startTime         = GetTime()
  21.     local index, var        = nil, nil
  22.  
  23.     EM:SetScript("OnUpdate", function(self, elapsed)
  24.         if prevFrameTime == 0 then
  25.             prevFrameTime = GetTime()
  26.         else
  27.             local startFrameTime    = GetTime()
  28.             local frameDeltaTime    = startFrameTime - prevFrameTime
  29.             prevFrameTime           = startFrameTime
  30.  
  31.             local timeForWork       = ( 0.0001 / frameDeltaTime ) * mult
  32.             local stopTaskTime      = startFrameTime + timeForWork
  33.  
  34.             while GetTime() < stopTaskTime do
  35.                 index, var = next(table, index)
  36.                 if not index then
  37.                     EM:SetScript("OnUpdate", nil)
  38.                     print("LeadTime: " .. GetTime() - startTime)
  39.                     return
  40.                 else
  41.                     callback(index, var)
  42.                 end
  43.             end
  44.         end
  45.     end)
  46. end
  47.  
  48. function StopSmoothPairs()
  49.     EM:SetScript("OnUpdate", nil)
  50. end
  51.  
  52. -- /run SmoothPairs(testTable, 1, function(k, v) print(k) end)
  53. -- /run StopSmoothPairs()
  54. -- /run DefPairs()

But it does not work as expected. Assault GetTime() returns always the same value inside the frame.
Later try to check using "anim:SetScript("OnLoop", ...)", he seems to have no such restrictions.

Last edited by KL1SK : 09-30-20 at 04:02 PM.
  Reply With Quote