Thread Tools Display Modes
01/06/16, 02:47 PM   #1
dominoid
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 34
What's the most CPU economical for location "fence"

What is the most CPU friendly way to setup a location radius fence? I want to do something when a player comes within a certain radius of an in-world object or location. I know I can use OnUpdate, but that should be avoided if possible right? So . . . is there another way? If not, what is the best way to throttle OnUpdate so its not too intensive?

TIA
  Reply With Quote
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
01/06/16, 03:11 PM   #3
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Or EVENT_MANAGER:RegisterForUpdate("uniqueTag", intervalInMilliseconds, function(gameTimeMs) ... end)
  Reply With Quote
01/06/16, 04:31 PM   #4
dominoid
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 34
Originally Posted by merlight View Post
Or EVENT_MANAGER:RegisterForUpdate("uniqueTag", intervalInMilliseconds, function(gameTimeMs) ... end)
Thank you both for the timely answer. This solution appears to be the easiest at this time and appears to meet my requirements. Thanks again.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » What's the most CPU economical for location "fence"


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off