View Single Post
01/06/16, 02:59 PM   #2
coolmodi
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 47
Originally Posted by dominoid View Post
If not, what is the best way to throttle OnUpdate so its not too intensive?
Just use a buffer like that:

Lua Code:
  1. local BufferTable = {}
  2. local function BufferReached(key, buffer)
  3.     if key == nil then return end
  4.     if BufferTable[key] == nil then BufferTable[key] = {} end
  5.     BufferTable[key].buffer = buffer or 3
  6.     BufferTable[key].now = GetFrameTimeSeconds()
  7.     if BufferTable[key].last == nil then BufferTable[key].last = BufferTable[key].now end
  8.     BufferTable[key].diff = BufferTable[key].now - BufferTable[key].last
  9.     BufferTable[key].eval = BufferTable[key].diff >= BufferTable[key].buffer
  10.     if BufferTable[key].eval then BufferTable[key].last = BufferTable[key].now end
  11.     return BufferTable[key].eval
  12. end
  13.  
  14. function GroupDamage.onUpdateHandler()
  15.     if not BufferReached("general", 1) then return; end
  16.        
  17.     GroupDamage:updateCombatData()
  18.     GroupDamage:orderCurrentRanking()
  19.     GroupDamage:fillMainTarget()
  20.     GroupDamage:updateMissingGroupMembers()
  21.     GroupDamage:clearOldFights()
  22.     GroupDamage:updatePanel()
  23. end

And then use

Lua Code:
  1. self.control:SetHandler("OnUpdate", function() self.onUpdateHandler() end)

to set the handler, setting it in xml at least doesn't work for me. The second argument on BufferReached() sets the interval.

Last edited by coolmodi : 01/06/16 at 03:02 PM.
  Reply With Quote