From b5280dff600ff64407278faa3bb32c4964b380c4 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Fri, 19 Jul 2013 05:33:52 +0000 Subject: [PATCH] Improve latency measurement by using the correct events for timestamps. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@981 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleFuture.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/OvaleFuture.lua b/OvaleFuture.lua index 7128c42..0af0bbe 100644 --- a/OvaleFuture.lua +++ b/OvaleFuture.lua @@ -166,6 +166,21 @@ local function AddSpellToQueue(spellId, lineId, startTime, endTime, channeled, a tinsert(self_activeSpellcast, spellcast) + -- Update latency measurement. API_GetTime() only updates on frame refresh (OnUpdate) so + -- this latency measurement has a lower bound of the 1/FPS, where FPS is the current frame + -- rate. + if self_sentSpellcast[lineId] then + local latency = Ovale.now - self_sentSpellcast[lineId] + local castTime = endTime - startTime + if castTime > 0 and latency > castTime then + latency = castTime + end + if latency > 0 then + self.latency = latency + end + self_sentSpellcast[lineId] = nil + end + ScoreSpell(spellId) Ovale.refreshNeeded["player"] = true end @@ -328,6 +343,8 @@ function OvaleFuture:UNIT_SPELLCAST_SENT(event, unit, spell, rank, target, lineI self_lastTarget = OVALE_UNKNOWN_GUID end TracePrintf(spell, "%s: %f %s on %s, lineId=%d", event, Ovale.now, spell, self_lastTarget, lineId) + + -- Note starting time for latency calculation. self_sentSpellcast[lineId] = Ovale.now end end @@ -367,17 +384,6 @@ function OvaleFuture:UNIT_SPELLCAST_SUCCEEDED(event, unit, name, rank, lineId, s if not API_UnitChannelInfo("player") then AddSpellToQueue(spellId, lineId, Ovale.now, Ovale.now, false, true) end - - -- Update latency measurement. API_GetTime() only updates on frame refresh (OnUpdate) so - -- this latency measurement has a lower bound of the 1/FPS, where FPS is the current frame - -- rate. - if self_sentSpellcast[lineId] then - local latency = Ovale.now - self_sentSpellcast[lineId] - if latency > 0 then - self.latency = latency - end - self_sentSpellcast[lineId] = nil - end end end -- 1.7.9.5