Just to help anyone else out that is interested in this, I modified castbar.lua to calculate the latency. Basically, I added a function for UNIT_SPELLCAST_SENT that simply stores the send time:
Code:
local UNIT_SPELLCAST_SENT = function(self, event, unit, spell, spellrank)
if(self.unit ~= unit) then return end
self.Castbar.sentTime = GetTime()
end
Don't forget to register and unregister for the event in Enable and Disable:
Code:
object:RegisterEvent("UNIT_SPELLCAST_SENT", UNIT_SPELLCAST_SENT)
-- or --
object:UnregisterEvent("UNIT_SPELLCAST_SENT", UNIT_SPELLCAST_SENT)
Then I updated UNIT_SPELLCAST_START to calculate and store the latency:
Code:
if (castbar.sentTime) then
castbar.latency = GetTime() - castbar.sentTime
else
castbar.latency = 0
end
And finally, I modified onUpdate to use the latency value:
Code:
if self.SafeZone then
local width = self:GetWidth() * self.latency / self.max
if (width < 1) then width = 1 end
self.SafeZone:SetWidth(width);
end
This seems to be working for me but it's hardly extensively tested. Do with it as you will.
EDIT: I updated the code because I was getting errors some of the time when sentTime didn't get set. I'm not sure why this would happen so I just added a check around the latency calculation. Otherwise it worked fine for me while I played for a couple of hours.