Thread Tools Display Modes
01-10-10, 09:51 PM   #1
Victimize
A Murloc Raider
Join Date: Dec 2009
Posts: 5
Adding latency to cast bars, like Quartz?

I have P3lim's oUF layout, and I was wondering if there was I bit of code I could add to give my cast bar the latency function, like Quartz does.
  Reply With Quote
01-10-10, 10:53 PM   #2
zero-kill
A Firelord
 
zero-kill's Avatar
Join Date: Aug 2009
Posts: 497
Nope
...but then I'm lazy and haven't found it anywhere in the forums.
  Reply With Quote
01-11-10, 12:45 AM   #3
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
It does include it, though it may not be as exact.

The Castbar element supports the .SafeZone sub element, which can be added and will give an approximate "safe zone" based on current latency. I added it to my layout with this:

Code:
if(unit == 'player') then
	self.Castbar.SafeZone = self.Castbar:CreateTexture(nil,'OVERLAY')
	self.Castbar.SafeZone:SetTexture(texture)
	self.Castbar.SafeZone:SetVertexColor(.69,.31,.31)
end
It's not perfect, but it's close. Note that you don't have to set the positioning for the texture, as the element sets it when a spell is being cast.
  Reply With Quote
01-11-10, 01:08 AM   #4
Xuerian
A Fallenroot Satyr
 
Xuerian's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 27
You'll have to figure it out for yourself, the particulars anyway, but it's pretty simple.

Hook UNIT_SPELLCAST_START on your castbar and watch for player cast starts, then use the postCastStart hook to set a spark or something to the point at which you can start casting another spell, determined by measuring the time the spell of that id was sent and that point.

The safezone works alright for predictable latency, but for varying, it's worthless.

It might be helpful to check out Quartz's latency module for tips.

It may end up being simpler for you to use your own OnCastbarUpdate (based on the default one), I had to to add the latency-friendly things (Showing bar when cast actually starts, fading it out, showing instant casts, etc) to my layout that way.

Last edited by Xuerian : 01-11-10 at 01:10 AM.
  Reply With Quote
01-11-10, 01:12 AM   #5
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Do note that the latency average is only updated every 30 sec, as oUF uses GetNetStats() to fetch it. That being said; WoW does a much finer job at handling casting with high latency in 3.x than any human could be.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
01-11-10, 01:19 AM   #6
Xuerian
A Fallenroot Satyr
 
Xuerian's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 27
Originally Posted by haste View Post
Do note that the latency average is only updated every 30 sec, as oUF uses GetNetStats() to fetch it. That being said; WoW does a much finer job at handling casting with high latency in 3.x than any human could be.
Sure does. Mash the button and it'll continuously cast, more or less. Unless you run into the GCD or cooldowns your client doesn't think are up, anyway.

It still goes a bit to hell if your latency is hugely unpredictable. I regularly run with a baseline of 250ms with areas where it rides up to 600ms+.

Having a visual indicator can cut down on RSI a bit, when you're mashing chain heal repeatedly.
  Reply With Quote
01-11-10, 03:19 AM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Xuerian View Post
mashing chain heal repeatedly.
Don't get me started.

Also, the "real" latency code in Castbars is easier to read through than the code in Quartz, since it isn't full of checks for various options.

Oh, and Xuerian, when are you going to update oUF Smooth Update so I can quit embedding a fixed copy in my layout?
  Reply With Quote
01-11-10, 06:14 PM   #8
Xuerian
A Fallenroot Satyr
 
Xuerian's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 27
Originally Posted by Phanx View Post
Don't get me started.

Also, the "real" latency code in Castbars is easier to read through than the code in Quartz, since it isn't full of checks for various options.

Oh, and Xuerian, when are you going to update oUF Smooth Update so I can quit embedding a fixed copy in my layout?
What's broken? >_>
  Reply With Quote
01-12-10, 12:06 AM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Bars with smaller max-values (under 150-200ish) don't ever fill completely with it enabled, leaving a 5-10 pixel gap at the end. If you haven't leveled any characters recently and don't play a rogue, warrior, death knight, or feral druid, you probably wouldn't notice.

There's comment on the download page with a Pastey URL to a fixed version that alleviates the problem.
  Reply With Quote
01-22-10, 01:03 PM   #10
juyanith
A Kobold Labourer
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1
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.
Attached Files
File Type: lua castbar.lua (10.5 KB, 983 views)

Last edited by juyanith : 01-22-10 at 07:52 PM. Reason: Attached modified castbar.lua
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Adding latency to cast bars, like Quartz?

Thread Tools
Display Modes

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