ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   What's the most CPU economical for location "fence" (https://www.esoui.com/forums/showthread.php?t=5574)

dominoid 01/06/16 02:47 PM

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

coolmodi 01/06/16 02:59 PM

Quote:

Originally Posted by dominoid (Post 24949)
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.

merlight 01/06/16 03:11 PM

Or EVENT_MANAGER:RegisterForUpdate("uniqueTag", intervalInMilliseconds, function(gameTimeMs) ... end)

dominoid 01/06/16 04:31 PM

Quote:

Originally Posted by merlight (Post 24951)
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.


All times are GMT -6. The time now is 10:11 PM.

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