ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Updating values using RegisterForUpdate() (https://www.esoui.com/forums/showthread.php?t=7693)

Letho 03/30/18 09:51 AM

Updating values using RegisterForUpdate()
 
Hey,

I have to update duration values (represented by a label) of ~10 objects. Each object contains a control (Top level window) and it's data:

Code:

object.control = #userData
object.data = {
    ['durationInfo'] = {
        ['startTime'] = 0100.00000
        ['endTime'] = 120.12345,
    },
    ['someOtherData'] = {
        -- ...
    },
    ['evenMoreData'] = {
        -- ...
    }
}

All objects show the display duration, taken from self.data.durationInfo, as a label that gets updated ten times per second (= needed for a display that has a precision of one digit after the dot). Let's say our GetGameTimeSeconds() is 114.2, the displayed remaining duration would be 5.92345 seconds, rounded to and displayed as 5.9s.


Now the question: There is two ways of achieving it:

1) Registering one updater that iterates through all objects and sets their displayed durations

Code:

Addon:RegisterForUpdate("GenericUpdater", 100, OnUpdateHandler)

function Addon.OnUpdateHandler()
    local curTime = GetGameTimeSeconds()
    for objName, objData in pairs(Addon.objects) do
        local durationDisplay = objData.durationInfo.endTime - curTime
        Addon.objects[objName]:SetDuration(durationDisplay)
    end

    -- some other stuff that needs to be checked onRegisteredUpdate, too, there are ~4-5 other tables that are iterated here
end

2) Registering an updater for every single object that updates it
Code:


-- genericObj is the class that all objects inherit their methods from
function genericObj:New(controlName)
    -- setting up the metatable, controls, etc.
    -- ...
    -- ...
    -- ...

    genericObj:RegisterForUpdate(controlName, 100, genericObj.OnUpdate)
end

function genericObj.OnUpdate()
    local durationDisplay = self.data['endTime'] - curTime -- (curTime being defined somewhere and stored
    'globally' in the addon class)
end

-- create an instance of the class genericObj
local testObject = genericObj:New("SuperDuperTestObject")


In short words: Should I register an updater for every object, that only handles itself, or should I register a 'monster updater' for the whole addon that updates every object that is part of the addon by iterating through it using a loop?

Rhyono 03/30/18 07:34 PM

Since the goal appears to be to update them simultaneously any way: I don't know of any benefit to making them all independently do the same thing when you could just have the parent refreshing function handle all of them at once.

Letho 03/31/18 03:05 AM

Yes, Chip helped with this on gitter, yesterday and he told us the same. Using as few updaters as possible is mostly the best solution.


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

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