WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Function timing (https://www.wowinterface.com/forums/showthread.php?t=49566)

citrot 08-04-14 09:38 AM

Function timing
 
Hi!

I would like to execute timed functions. Only wow lua support i found until now: "OnUpdate" event. Is there something else what is not based on graphical engine?

Thank you,

Phanx 08-04-14 12:19 PM

Unless you're getting 2 FPS, and even then for most purposes, it doesn't really matter that OnUpdate is tied to your framerate:

Code:

local t = 5 -- do something 5 seconds from now
local f = CreateFrame("Frame")
f:SetScript("OnUpdate", function(self, elapsed)
    t = t - elapsed
    if t <= 0 then
          -- do something
    end
end)

Your other option would be to use the animation system:

Code:

local f = CreateFrame("Frame")
local g = f:CreateAnimationGroup()
local a = g:CreateAnimation()
a:SetDuration(5) -- do something in 5 seconds
g:SetScript("OnFinished", function()
    -- do something
end)

All existing timer libraries use one of the above methods.

In WoD the game will provide an actual timer mechanism, but the primary benefit to using it will likely be in reducing the amount of code that needs to be written to implement a timer, rather than offering any tangible performance boost:

Code:

C_Timer.After(5, function()
    -- do something
end)


p3lim 08-04-14 07:12 PM

C_Timer would most likely be better for performance too, but no benchmarks have been done yet.

SDPhantom 08-04-14 09:17 PM

I would think C_Timer.After() would be easier on resources since you won't have to create any UI objects to use. The only problem is you'll need to manage setting it up again if you want something to keep calling every so many seconds if you don't want to use Blizzard's Lua-defined Ticker factories (C_Timer.NewTicker() and C_Timer.NewTimer()). Note the Ticker factories return a table hooked into a metatable to control the ability to cancel a timer with entries for remaining iteration counts, a cancel flag, and a dynamicly-created callback function that is passed to C_Timer each iteration. This creates significantly more overhead than using C_Timer.After() yourself.

p3lim 08-04-14 11:51 PM

Quote:

Originally Posted by SDPhantom (Post 294751)
I would think C_Timer.After() would be easier on resources since you won't have to create any UI objects to use. The only problem is you'll need to manage setting it up again if you want something to keep calling every so many seconds if you don't want to use Blizzard's Lua-defined Ticker factories (C_Timer.NewTicker() and C_Timer.NewTimer()). Note the Ticker factories return a table hooked into a metatable to control the ability to cancel a timer with entries for remaining iteration counts, a cancel flag, and a dynamicly-created callback function that is passed to C_Timer each iteration. This creates significantly more overhead than using C_Timer.After() yourself.

Basically, unless you need to cancel it or need something that keeps repeating, use C_Timer.After.

citrot 08-05-14 03:54 PM

Thank you for tipps. I think, i keep OnUpdate.


All times are GMT -6. The time now is 09:23 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI