Quantcast

Use GetTime() directly in modules instead of relying on Ovale.now.

Johnny C. Lam [09-26-13 - 05:34]
Use GetTime() directly in modules instead of relying on Ovale.now.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1030 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.lua
OvaleAura.lua
OvaleDamageTaken.lua
OvaleEnemies.lua
OvaleFrame.lua
OvaleFuture.lua
OvaleLatency.lua
OvalePaperDoll.lua
OvaleState.lua
OvaleSwing.lua
diff --git a/Ovale.lua b/Ovale.lua
index d52e132..ddd2041 100644
--- a/Ovale.lua
+++ b/Ovale.lua
@@ -38,8 +38,6 @@ local OVALE_TRUE_STRING = tostring(true)

 --<public-static-properties>
 Ovale.L = L
---The current time, updated once per frame refresh.
-Ovale.now = API_GetTime()
 -- The most recent spell cast.
 Ovale.lastSpellcast = {}
 --The table of check boxes definition
@@ -165,7 +163,7 @@ function Ovale:PLAYER_REGEN_DISABLED()
 	self.enCombat = true
 	self.score = 0
 	self.maxScore = 0
-	self.combatStartTime = Ovale.now
+	self.combatStartTime = API_GetTime()
 	self:UpdateVisibility()
 end

diff --git a/OvaleAura.lua b/OvaleAura.lua
index f5338fc..98dac63 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -28,6 +28,7 @@ local strfind = string.find
 local tinsert = table.insert
 local tsort = table.sort
 local wipe = table.wipe
+local API_GetTime = GetTime
 local API_UnitAura = UnitAura

 -- aura pool
@@ -89,12 +90,13 @@ local function UnitGainedAura(guid, spellId, filter, casterGUID, icon, count, de
 	casterGUID = casterGUID or OVALE_UNKNOWN_GUID
 	local mine = (casterGUID == self_player_guid)
 	local existingAura, aura
+	local now = API_GetTime()
 	existingAura = self_aura[guid][filter][spellId][casterGUID]
 	if existingAura then
 		aura = existingAura
 	else
 		aura = self_pool:Get()
-		aura.gain = Ovale.now
+		aura.gain = now
 		self_aura[guid][filter][spellId][casterGUID] = aura
 	end

@@ -116,7 +118,7 @@ local function UnitGainedAura(guid, spellId, filter, casterGUID, icon, count, de
 	local addAura = not existingAura or not auraIsUnchanged
 	if addAura then
 		Ovale:DebugPrintf(OVALE_AURA_DEBUG, "    Adding %s %s (%s) to %s at %f, aura.serial=%d",
-			filter, name, spellId, guid, Ovale.now, aura.serial)
+			filter, name, spellId, guid, now, aura.serial)
 		aura.icon = icon
 		aura.stacks = count
 		aura.debuffType = debuffType
@@ -149,7 +151,7 @@ local function UnitGainedAura(guid, spellId, filter, casterGUID, icon, count, de
 				local lastSpellId = lastSpellcast and lastSpellcast.spellId
 				if lastSpellId and OvaleData:NeedNewSnapshot(spellId, lastSpellId) then
 					Ovale:DebugPrintf(OVALE_AURA_DEBUG, "    Snapshot stats for %s %s (%s) on %s from %f, now=%f, aura.serial=%d",
-						filter, name, spellId, guid, lastSpellcast.snapshotTime, Ovale.now, aura.serial)
+						filter, name, spellId, guid, lastSpellcast.snapshotTime, now, aura.serial)
 					OvalePaperDoll:SnapshotStats(aura, Ovale.lastSpellcast)
 					-- TODO: This isn't correct if lastSpellId doesn't directly apply the DoT.
 					aura.damageMultiplier = Ovale.lastSpellcast.damageMultiplier
@@ -168,8 +170,9 @@ end
 local function RemoveAuraIfExpired(guid, spellId, filter, aura, serial)
 	local self = OvaleAura
 	if aura and serial and aura.serial ~= serial then
+		local now = API_GetTime()
 		Ovale:DebugPrintf(OVALE_AURA_DEBUG, "    Removing expired %s %s (%s) from %s at %f, serial=%d aura.serial=%d",
-			filter, aura.name, spellId, guid, Ovale.now, serial, aura.serial)
+			filter, aura.name, spellId, guid, now, serial, aura.serial)
 		self:SendMessage("Ovale_AuraRemoved", guid, spellId, aura.source)
 		self_pool:Release(aura)
 		return true
@@ -296,6 +299,7 @@ local function UpdateAuraTick(guid, spellId, timestamp)
 		end
 	end
 	if aura and aura.tick then
+		local now = API_GetTime()
 		local tick = aura.tick
 		local ticksSeen = aura.ticksSeen or 0
 		if not aura.lastTickTime then
@@ -313,7 +317,7 @@ local function UpdateAuraTick(guid, spellId, timestamp)
 		aura.lastTickTime = timestamp
 		aura.tick = tick
 		aura.ticksSeen = ticksSeen
-		Ovale:DebugPrintf(OVALE_AURA_DEBUG, "Updating %s %s (%s) on %s at %f, tick=%f", filter, aura.name, spellId, guid, Ovale.now, tick)
+		Ovale:DebugPrintf(OVALE_AURA_DEBUG, "Updating %s %s (%s) on %s at %f, tick=%f", filter, aura.name, spellId, guid, now, tick)
 	end
 end
 --</private-static-methods>
diff --git a/OvaleDamageTaken.lua b/OvaleDamageTaken.lua
index 652dde4..0ef528d 100644
--- a/OvaleDamageTaken.lua
+++ b/OvaleDamageTaken.lua
@@ -20,6 +20,7 @@ local OvalePool = Ovale.OvalePool
 local OvaleQueue = Ovale.OvaleQueue

 local select = select
+local API_GetTime = GetTime

 -- Player's GUID.
 local self_player_guid = nil
@@ -59,15 +60,16 @@ end
 function OvaleDamageTaken:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
 	local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = select(1, ...)
 	if destGUID == self_player_guid and event:find("_DAMAGE") then
+		local now = API_GetTime()
 		if event:find("SWING_") == 1 then
 			local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = select(12, ...)
 			Ovale:DebugPrintf(OVALE_DAMAGE_TAKEN_DEBUG, "%s caused %d damage.", event, amount)
-			AddDamageTaken(Ovale.now, amount)
+			AddDamageTaken(now, amount)
 		elseif event:find("RANGE_") == 1 or event:find("SPELL_") == 1 then
 			local spellId, spellName, spellSchool = select(12, ...)
 			local amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = select(15, ...)
 			Ovale:DebugPrintf(OVALE_DAMAGE_TAKEN_DEBUG, "%s (%s) caused %d damage.", event, spellName, amount)
-			AddDamageTaken(Ovale.now, amount)
+			AddDamageTaken(now, amount)
 		end
 	end
 end
@@ -78,7 +80,8 @@ end

 -- Return the total damage taken in the previous time interval (in seconds).
 function OvaleDamageTaken:GetRecentDamage(interval, lagCorrection)
-	local lowerBound = Ovale.now - interval
+	local now = API_GetTime()
+	local lowerBound = now - interval
 	if lagCorrection then
 		lowerBound = lowerBound - OvaleLatency:GetLatency()
 	end
@@ -95,7 +98,7 @@ function OvaleDamageTaken:GetRecentDamage(interval, lagCorrection)
 end

 function OvaleDamageTaken:RemoveExpiredEvents()
-	local now = Ovale.now
+	local now = API_GetTime()
 	while true do
 		local event = self_damageEvent:Back()
 		if not event then break end
diff --git a/OvaleEnemies.lua b/OvaleEnemies.lua
index 12f2453..64bbace 100644
--- a/OvaleEnemies.lua
+++ b/OvaleEnemies.lua
@@ -20,6 +20,7 @@ local pairs = pairs
 local select = select
 local tostring = tostring
 local wipe = table.wipe
+local API_GetTime = GetTime
 local COMBATLOG_OBJECT_AFFILIATION_OUTSIDER = COMBATLOG_OBJECT_AFFILIATION_OUTSIDER
 local COMBATLOG_OBJECT_REACTION_HOSTILE = COMBATLOG_OBJECT_REACTION_HOSTILE

@@ -93,17 +94,17 @@ end

 function OvaleEnemies:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
 	local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = select(1, ...)
-
+	local now = API_GetTime()
 	if event == "UNIT_DIED" then
 		RemoveEnemy(destGUID, true)
 	elseif sourceFlags and bit_band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) > 0
 			and bit_band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) > 0
 			and destFlags and bit_band(destFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0 then
-		AddEnemy(sourceGUID, sourceName, Ovale.now)
+		AddEnemy(sourceGUID, sourceName, now)
 	elseif destGUID and bit_band(destFlags, COMBATLOG_OBJECT_REACTION_HOSTILE) > 0
 			and bit_band(destFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) > 0
 			and sourceFlags and bit_band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0 then
-		AddEnemy(destGUID, destName, Ovale.now)
+		AddEnemy(destGUID, destName, now)
 	end
 end

@@ -118,8 +119,9 @@ end
 -- These enemies are not in combat with your group, out of range, or
 -- incapacitated and shouldn't count toward the number of active enemies.
 function OvaleEnemies:RemoveInactiveEnemies()
+	local now = API_GetTime()
 	for guid, timestamp in pairs(self_enemyLastSeen) do
-		if Ovale.now - timestamp > REAP_INTERVAL then
+		if now - timestamp > REAP_INTERVAL then
 			RemoveEnemy(guid)
 		end
 	end
diff --git a/OvaleFrame.lua b/OvaleFrame.lua
index 9542b7f..4926ffd 100644
--- a/OvaleFrame.lua
+++ b/OvaleFrame.lua
@@ -157,8 +157,7 @@ do

 	local function OnUpdate(self)
 		-- Update current time.
-		Ovale.now = API_GetTime()
-		local now = Ovale.now
+		local now = API_GetTime()

 		local profile = OvaleOptions:GetProfile()
 		local forceRefresh = not self.lastUpdate or (now > self.lastUpdate + profile.apparence.updateInterval)
diff --git a/OvaleFuture.lua b/OvaleFuture.lua
index 79e9749..528f0e7 100644
--- a/OvaleFuture.lua
+++ b/OvaleFuture.lua
@@ -28,6 +28,7 @@ local select = select
 local tinsert = table.insert
 local tostring = tostring
 local tremove = table.remove
+local API_GetTime = GetTime
 local API_UnitCastingInfo = UnitCastingInfo
 local API_UnitChannelInfo = UnitChannelInfo
 local API_UnitGUID = UnitGUID
@@ -135,8 +136,9 @@ local function AddSpellToQueue(spellId, lineId, startTime, endTime, channeled, a
 	else
 		spellcast.target = API_UnitGUID("target")
 	end
+	local now = API_GetTime()
 	TracePrintf(spellId, "    AddSpellToQueue: %f %s (%d), lineId=%d, startTime=%f, endTime=%f, target=%s",
-		Ovale.now, OvaleData:GetSpellName(spellId), spellId, lineId, startTime, endTime, spellcast.target)
+		now, OvaleData:GetSpellName(spellId), spellId, lineId, startTime, endTime, spellcast.target)

 	-- Snapshot the current stats for the spellcast.
 	OvalePaperDoll:SnapshotStats(spellcast)
@@ -192,9 +194,10 @@ end

 local function RemoveSpellFromQueue(spellId, lineId)
 	local self = OvaleFuture
+	local now = API_GetTime()
 	for index, spellcast in ipairs(self_activeSpellcast) do
 		if spellcast.lineId == lineId then
-			TracePrintf(spellId, "    RemoveSpellFromQueue: %f %s (%d)", Ovale.now, OvaleData:GetSpellName(spellId), spellId)
+			TracePrintf(spellId, "    RemoveSpellFromQueue: %f %s (%d)", now, OvaleData:GetSpellName(spellId), spellId)
 			tremove(self_activeSpellcast, index)
 			self_pool:Release(spellcast)
 			break
@@ -279,7 +282,7 @@ end

 function OvaleFuture:Ovale_AuraAdded(event, guid, spellId, caster)
 	if guid == OvaleGUID:GetGUID("player") then
-		self_timeAuraAdded = Ovale.now
+		self_timeAuraAdded = API_GetTime()
 	end
 end

@@ -298,15 +301,17 @@ end
 function OvaleFuture:UNIT_SPELLCAST_CHANNEL_START(event, unit, name, rank, lineId, spellId)
 	if unit == "player" then
 		local startTime, endTime = select(5, API_UnitChannelInfo("player"))
+		local now = API_GetTime()
 		TracePrintf(spellId, "%s: %f %d, lineId=%d, startTime=%f, endTime=%f",
-			event, Ovale.now, spellId, lineId, startTime, endTime)
+			event, now, spellId, lineId, startTime, endTime)
 		AddSpellToQueue(spellId, lineId, startTime/1000, endTime/1000, true, false)
 	end
 end

 function OvaleFuture:UNIT_SPELLCAST_CHANNEL_STOP(event, unit, name, rank, lineId, spellId)
 	if unit == "player" then
-		TracePrintf(spellId, "%s: %f %d, lineId=%d", event, Ovale.now, spellId, lineId)
+		local now = API_GetTime()
+		TracePrintf(spellId, "%s: %f %d, lineId=%d", event, now, spellId, lineId)
 		RemoveSpellFromQueue(spellId, lineId)
 	end
 end
@@ -315,8 +320,9 @@ end
 function OvaleFuture:UNIT_SPELLCAST_START(event, unit, name, rank, lineId, spellId)
 	if unit == "player" then
 		local startTime, endTime = select(5, API_UnitCastingInfo("player"))
+		local now = API_GetTime()
 		TracePrintf(spellId, "%s: %f %d, lineId=%d, startTime=%f, endTime=%f",
-			event, Ovale.now, spellId, lineId, startTime, endTime)
+			event, now, spellId, lineId, startTime, endTime)
 		AddSpellToQueue(spellId, lineId, startTime/1000, endTime/1000, false, false)
 	end
 end
@@ -324,7 +330,8 @@ end
 --Called if the player interrupted early his cast
 function OvaleFuture:UNIT_SPELLCAST_INTERRUPTED(event, unit, name, rank, lineId, spellId)
 	if unit == "player" then
-		TracePrintf(spellId, "%s: %f %d, lineId=%d", event, Ovale.now, spellId, lineId)
+		local now = API_GetTime()
+		TracePrintf(spellId, "%s: %f %d, lineId=%d", event, now, spellId, lineId)
 		RemoveSpellFromQueue(spellId, lineId)
 	end
 end
@@ -347,7 +354,8 @@ function OvaleFuture:UNIT_SPELLCAST_SENT(event, unit, spell, rank, target, lineI
 		else
 			self_lastTarget = OVALE_UNKNOWN_GUID
 		end
-		TracePrintf(spell, "%s: %f %s on %s, lineId=%d", event, Ovale.now, spell, self_lastTarget, lineId)
+		local now = API_GetTime()
+		TracePrintf(spell, "%s: %f %s on %s, lineId=%d", event, now, spell, self_lastTarget, lineId)
 	end
 end

@@ -363,7 +371,8 @@ end
 ]]--
 function OvaleFuture:UNIT_SPELLCAST_SUCCEEDED(event, unit, name, rank, lineId, spellId)
 	if unit == "player" then
-		TracePrintf(spellId, "%s: %f %d, lineId=%d", event, Ovale.now, spellId, lineId)
+		local now = API_GetTime()
+		TracePrintf(spellId, "%s: %f %d, lineId=%d", event, now, spellId, lineId)

 		-- Search for a cast-time spell matching this spellcast that was added by UNIT_SPELLCAST_START.
 		for _, spellcast in ipairs(self_activeSpellcast) do
@@ -384,7 +393,7 @@ function OvaleFuture:UNIT_SPELLCAST_SUCCEEDED(event, unit, name, rank, lineId, s
 			UNIT_SPELLCAST_CHANNEL_START and UNIT_SPELLCAST_CHANNEL_STOP.
 		]]--
 		if not API_UnitChannelInfo("player") then
-			AddSpellToQueue(spellId, lineId, Ovale.now, Ovale.now, false, true)
+			AddSpellToQueue(spellId, lineId, now, now, false, true)
 		end
 	end
 end
@@ -435,11 +444,12 @@ function OvaleFuture:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
 	if sourceGUID == OvaleGUID:GetGUID("player") then
 		if OVALE_CLEU_SPELLCAST_RESULTS[event] then
 			local spellId, spellName = select(12, ...)
-			TracePrintf(spellId, "%s: %f %s (%d)", event, Ovale.now, spellName, spellId)
+			local now = API_GetTime()
+			TracePrintf(spellId, "%s: %f %s (%d)", event, now, spellName, spellId)
 			for index, spellcast in ipairs(self_activeSpellcast) do
 				if spellcast.allowRemove and (spellcast.spellId == spellId or spellcast.auraSpellId == spellId) then
 					if not spellcast.channeled and (spellcast.removeOnSuccess or event ~= "SPELL_CAST_SUCCESS") then
-						TracePrintf(spellId, "    Spell finished: %f %s (%d)", Ovale.now, spellName, spellId)
+						TracePrintf(spellId, "    Spell finished: %f %s (%d)", now, spellName, spellId)
 						tremove(self_activeSpellcast, index)
 						UpdateLastSpellInfo(spellcast)
 						Ovale.refreshNeeded["player"] = true
diff --git a/OvaleLatency.lua b/OvaleLatency.lua
index fdb30c2..a6bdfec 100644
--- a/OvaleLatency.lua
+++ b/OvaleLatency.lua
@@ -14,6 +14,7 @@ Ovale.OvaleLatency = OvaleLatency
 --<private-static-properties>
 local select = select
 local API_GetNetStats = GetNetStats
+local API_GetTime = GetTime

 -- The spell requests that have been sent to the server and are awaiting a reply.
 -- self_sentSpellcast[lineId] = GetTime() timestamp
@@ -50,10 +51,11 @@ function OvaleLatency:UpdateLatency(event, unit, name, rank, lineId, spellId)
 			we are assuming that the processing time on the server is negligible compared to the
 			network latency.  As a result, this will always over-estimate the true latency.
 		]]--
-		local latency = Ovale.now - self_sentSpellcast[lineId]
+		local now = API_GetTime()
+		local latency = now - self_sentSpellcast[lineId]
 		if latency > 0 then
 			self_latency = latency
-			self_lastUpdateTime = Ovale.now
+			self_lastUpdateTime = now
 		end
 		self_sentSpellcast[lineId] = nil
 	end
@@ -62,14 +64,15 @@ end
 function OvaleLatency:UNIT_SPELLCAST_SENT(event, unit, spell, rank, target, lineId)
 	if unit == "player" then
 		-- Note starting time for latency calculation.
-		self_sentSpellcast[lineId] = Ovale.now
+		self_sentSpellcast[lineId] = API_GetTime()
 	end
 end

 function OvaleLatency:GetLatency()
 	-- If we haven't cast a spell in a while, then get the average world roundtrip latency
 	-- using GetNetStats().
-	if not self_latency or not self_lastUpdateTime or Ovale.now - self_lastUpdateTime > 10 then
+	local now = API_GetTime()
+	if not self_latency or not self_lastUpdateTime or now - self_lastUpdateTime > 10 then
 		self_latency = select(4, API_GetNetStats()) / 1000
 	end
 	return self_latency
diff --git a/OvalePaperDoll.lua b/OvalePaperDoll.lua
index 64ca40f..c341fc3 100644
--- a/OvalePaperDoll.lua
+++ b/OvalePaperDoll.lua
@@ -31,6 +31,7 @@ local API_GetSpecialization = GetSpecialization
 local API_GetSpellBonusDamage = GetSpellBonusDamage
 local API_GetSpellBonusHealing = GetSpellBonusHealing
 local API_GetSpellCritChance = GetSpellCritChance
+local API_GetTime = GetTime
 local API_UnitAttackPower = UnitAttackPower
 local API_UnitAttackSpeed = UnitAttackSpeed
 local API_UnitClass = UnitClass
@@ -126,6 +127,7 @@ local function GetSnapshot(t)
 	local self = OvalePaperDoll
 	self:RemoveOldSnapshots()
 	local stat = self_snapshot:Front()
+	local now = API_GetTime()
 	if not stat then
 		local newStat = self_pool:Get()
 		do
@@ -135,16 +137,16 @@ local function GetSnapshot(t)
 			end
 			newStat.baseDamageMultiplier = 1
 		end
-		newStat.snapshotTime = Ovale.now
+		newStat.snapshotTime = now
 		self_snapshot:InsertFront(newStat)
 		stat = self_snapshot:Front()
 	elseif stat.snapshotTime < t then
 		local newStat = self_pool:Get()
 		self:SnapshotStats(newStat, stat)
-		newStat.snapshotTime = Ovale.now
+		newStat.snapshotTime = now
 		self_snapshot:InsertFront(newStat)
 		stat = self_snapshot:Front()
-		Ovale:DebugPrintf(OVALE_SNAPSHOT_DEBUG, "New snapshot at %f.", Ovale.now)
+		Ovale:DebugPrintf(OVALE_SNAPSHOT_DEBUG, "New snapshot at %f.", now)
 	end
 	return stat
 end
@@ -172,7 +174,9 @@ function OvalePaperDoll:OnEnable()
 	self:RegisterEvent("UNIT_STATS")
 	self:RegisterMessage("Ovale_EquipmentChanged", "UpdateDamage")
 	self:RegisterMessage("Ovale_StanceChanged")
-	self.stat = GetSnapshot(Ovale.now)
+
+	local now = API_GetTime()
+	self.stat = GetSnapshot(now)
 end

 function OvalePaperDoll:OnDisable()
@@ -199,37 +203,41 @@ function OvalePaperDoll:OnDisable()
 end

 function OvalePaperDoll:COMBAT_RATING_UPDATE(event)
-	self.stat = GetSnapshot(Ovale.now)
+	local now = API_GetTime()
+	self.stat = GetSnapshot(now)
 	self.stat.meleeCrit = API_GetCritChance()
 	self.stat.rangedCrit = API_GetRangedCritChance()
 	self.stat.spellCrit = API_GetSpellCritChance(OVALE_SPELLDAMAGE_SCHOOL[self.class])
-	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, Ovale.now)
+	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, now)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f%%", OVALE_SNAPSHOT_STATS.meleeCrit, self.stat.meleeCrit)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f%%", OVALE_SNAPSHOT_STATS.rangedCrit, self.stat.rangedCrit)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f%%", OVALE_SNAPSHOT_STATS.spellCrit, self.stat.spellCrit)
 end

 function OvalePaperDoll:MASTERY_UPDATE(event)
-	self.stat = GetSnapshot(Ovale.now)
+	local now = API_GetTime()
+	self.stat = GetSnapshot(now)
 	if self.level < 80 then
 		self.stat.masteryEffect = 0
 	else
 		self.stat.masteryEffect = API_GetMasteryEffect()
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: %s = %f%%",
-			event, Ovale.now, OVALE_SNAPSHOT_STATS.masteryEffect, self.stat.masteryEffect)
+			event, now, OVALE_SNAPSHOT_STATS.masteryEffect, self.stat.masteryEffect)
 	end
 end

 function OvalePaperDoll:PLAYER_LEVEL_UP(event, level, ...)
 	self.level = tonumber(level) or API_UnitLevel("player")
-	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: level = %d", event, Ovale.now, self.level)
+	local now = API_GetTime()
+	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: level = %d", event, now, self.level)
 end

 function OvalePaperDoll:PLAYER_DAMAGE_DONE_MODS(event, unitId)
-	self.stat = GetSnapshot(Ovale.now)
+	local now = API_GetTime()
+	self.stat = GetSnapshot(now)
 	self.stat.spellBonusHealing = API_GetSpellBonusHealing()
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: %s = %d",
-		event, Ovale.now, OVALE_SNAPSHOT_STATS.spellBonusHealing, self.stat.spellBonusHealing)
+		event, now, OVALE_SNAPSHOT_STATS.spellBonusHealing, self.stat.spellBonusHealing)
 end

 function OvalePaperDoll:PLAYER_REGEN_ENABLED(event)
@@ -237,19 +245,21 @@ function OvalePaperDoll:PLAYER_REGEN_ENABLED(event)
 end

 function OvalePaperDoll:SPELL_POWER_CHANGED(event)
-	self.stat = GetSnapshot(Ovale.now)
+	local now = API_GetTime()
+	self.stat = GetSnapshot(now)
 	self.stat.spellBonusDamage = API_GetSpellBonusDamage(OVALE_SPELLDAMAGE_SCHOOL[self.class])
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: %s = %d",
-		event, Ovale.now, OVALE_SNAPSHOT_STATS.spellBonusDamage, self.stat.spellBonusDamage)
+		event, now, OVALE_SNAPSHOT_STATS.spellBonusDamage, self.stat.spellBonusDamage)
 end

 function OvalePaperDoll:UNIT_ATTACK_POWER(event, unitId)
 	if unitId == "player" then
-		self.stat = GetSnapshot(Ovale.now)
+		local now = API_GetTime()
+		self.stat = GetSnapshot(now)
 		local base, posBuff, negBuff = API_UnitAttackPower(unitId)
 		self.stat.attackPower = base + posBuff + negBuff
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: %s = %d",
-			event, Ovale.now, OVALE_SNAPSHOT_STATS.attackPower, self.stat.attackPower)
+			event, now, OVALE_SNAPSHOT_STATS.attackPower, self.stat.attackPower)
 		self:UpdateDamage(event)
 	end
 end
@@ -257,42 +267,47 @@ end
 function OvalePaperDoll:UNIT_DISPLAYPOWER(event, unitId)
 	if unitId == "player" then
 		self.powerType = API_UnitPowerType(unitId)
-		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: power type = %d", event, Ovale.now, self.powerType)
+		local now = API_GetTime()
+		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: power type = %d", event, now, self.powerType)
 	end
 end

 function OvalePaperDoll:UNIT_LEVEL(event, unitId)
 	if unitId == "player" then
 		self.level = API_UnitLevel(unitId)
-		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: level = %d", event, Ovale.now, self.level)
+		local now = API_GetTime()
+		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: level = %d", event, now, self.level)
 	end
 end

 function OvalePaperDoll:UNIT_RANGEDDAMAGE(event, unitId)
 	if unitId == "player" then
-		self.stat = GetSnapshot(Ovale.now)
+		local now = API_GetTime()
+		self.stat = GetSnapshot(now)
 		self.stat.rangedHaste = API_GetRangedHaste()
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: %s = %f%%",
-			event, Ovale.now, OVALE_SNAPSHOT_STATS.rangedHaste, self.stat.rangedHaste)
+			event, now, OVALE_SNAPSHOT_STATS.rangedHaste, self.stat.rangedHaste)
 	end
 end

 function OvalePaperDoll:UNIT_RANGED_ATTACK_POWER(event, unitId)
 	if unitId == "player" then
 		local base, posBuff, negBuff = API_UnitRangedAttackPower(unitId)
-		self.stat = GetSnapshot(Ovale.now)
+		local now = API_GetTime()
+		self.stat = GetSnapshot(now)
 		self.stat.rangedAttackPower = base + posBuff + negBuff
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f: %s = %d",
-			event, Ovale.now, OVALE_SNAPSHOT_STATS.rangedAttackPower, self.stat.rangedAttackPower)
+			event, now, OVALE_SNAPSHOT_STATS.rangedAttackPower, self.stat.rangedAttackPower)
 	end
 end

 function OvalePaperDoll:UNIT_SPELL_HASTE(event, unitId)
 	if unitId == "player" then
-		self.stat = GetSnapshot(Ovale.now)
+		local now = API_GetTime()
+		self.stat = GetSnapshot(now)
 		self.stat.meleeHaste = API_GetMeleeHaste()
 		self.stat.spellHaste = API_UnitSpellHaste(unitId)
-		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, Ovale.now)
+		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, now)
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f%%", OVALE_SNAPSHOT_STATS.meleeHaste, self.stat.meleeHaste)
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f%%", OVALE_SNAPSHOT_STATS.spellHaste, self.stat.spellHaste)
 		self:UpdateDamage(event)
@@ -302,13 +317,14 @@ end

 function OvalePaperDoll:UNIT_STATS(event, unitId)
 	if unitId == "player" then
-		self.stat = GetSnapshot(Ovale.now)
+		local now = API_GetTime()
+		self.stat = GetSnapshot(now)
 		self.stat.strength = API_UnitStat(unitId, 1)
 		self.stat.agility = API_UnitStat(unitId, 2)
 		self.stat.stamina = API_UnitStat(unitId, 3)
 		self.stat.intellect = API_UnitStat(unitId, 4)
 		self.stat.spirit = API_UnitStat(unitId, 5)
-		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, Ovale.now)
+		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, now)
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %d", OVALE_SNAPSHOT_STATS.agility, self.stat.agility)
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %d", OVALE_SNAPSHOT_STATS.intellect, self.stat.intellect)
 		Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %d", OVALE_SNAPSHOT_STATS.spirit, self.stat.spirit)
@@ -322,7 +338,8 @@ function OvalePaperDoll:UpdateDamage(event)
 	local minDamage, maxDamage, minOffHandDamage, maxOffHandDamage, _, _, damageMultiplier = API_UnitDamage("player")
 	local mainHandAttackSpeed, offHandAttackSpeed = API_UnitAttackSpeed("player")

-	self.stat = GetSnapshot(Ovale.now)
+	local now = API_GetTime()
+	self.stat = GetSnapshot(now)
 	self.stat.baseDamageMultiplier = damageMultiplier
 	if self.class == "DRUID" and OvaleStance:IsStance("druid_cat_form") then
 		-- Cat Form: 100% increased auto-attack damage.
@@ -368,7 +385,7 @@ function OvalePaperDoll:UpdateDamage(event)
 		self.stat.offHandWeaponDamage = 0
 	end

-	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, Ovale.now)
+	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "%s @ %f", event, now)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f", OVALE_SNAPSHOT_STATS.baseDamageMultiplier, self.stat.baseDamageMultiplier)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f", OVALE_SNAPSHOT_STATS.mainHandWeaponDamage, self.stat.mainHandWeaponDamage)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f", OVALE_SNAPSHOT_STATS.offHandWeaponDamage, self.stat.offHandWeaponDamage)
@@ -437,7 +454,7 @@ end

 -- Remove snapshots older than SNAPSHOT_WINDOW seconds from now, but always leave most recent snapshot.
 function OvalePaperDoll:RemoveOldSnapshots()
-	local now = Ovale.now
+	local now = API_GetTime()
 	while self_snapshot:Size() > 1 do
 		local stat = self_snapshot:Back()
 		if stat then
diff --git a/OvaleState.lua b/OvaleState.lua
index 59c23df..3674339 100644
--- a/OvaleState.lua
+++ b/OvaleState.lua
@@ -33,6 +33,7 @@ local API_GetEclipseDirection = GetEclipseDirection
 local API_GetRuneCooldown = GetRuneCooldown
 local API_GetRuneType = GetRuneType
 local API_GetSpellInfo = GetSpellInfo
+local API_GetTime = GetTime
 local API_UnitHealth = UnitHealth
 local API_UnitHealthMax = UnitHealthMax
 local API_UnitPower = UnitPower
@@ -89,7 +90,7 @@ end

 --<public-static-methods>
 function OvaleState:StartNewFrame()
-	self.maintenant = Ovale.now
+	self.maintenant = API_GetTime()
 	self.gcd = OvaleData:GetGCD()
 end

diff --git a/OvaleSwing.lua b/OvaleSwing.lua
index 5e39867..cc28c92 100644
--- a/OvaleSwing.lua
+++ b/OvaleSwing.lua
@@ -36,6 +36,7 @@ local OvalePaperDoll = Ovale.OvalePaperDoll
 local math_abs = math.abs
 local unpack = unpack
 local API_GetSpellInfo = GetSpellInfo
+local API_GetTime = GetTime
 local API_IsDualWielding = IsDualWielding
 local API_UnitAttackSpeed = UnitAttackSpeed
 local API_UnitRangedDamage = UnitRangedDamage
@@ -107,14 +108,15 @@ end
 function OvaleSwing:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventName, srcGUID, srcName, srcFlags, dstName, dstGUID, dstFlags, ...)
 	if srcGUID == OvaleGUID:GetGUID("player") then
 		if eventName == "SWING_DAMAGE" or eventName == "SWING_MISSED" then
-			self:MeleeSwing(Ovale.now)
+			local now = API_GetTime()
+			self:MeleeSwing(now)
 		end
 	end
 end

 function OvaleSwing:UNIT_SPELLCAST_START(event, unit, spell)
 	if OVALE_DELAY_SPELLS[spell] and unit=="player" then
-		self.startdelay = Ovale.now
+		self.startdelay = API_GetTime()
 		local name, rank, icon, cost, isFunnel, powerType, castTime, minRange, maxRange = API_GetSpellInfo(spell)
 		self.delay = castTime
 	end
@@ -122,17 +124,19 @@ end

 function OvaleSwing:UNIT_SPELLCAST_INTERRUPTED(event, unit, spell)
 	if unit == "player" and OVALE_DELAY_SPELLS[spell] and self.startdelay then
-		self.delay = Ovale.now - self.startdelay
+		local now = API_GetTime()
+		self.delay = now - self.startdelay
 	end
 end

 function OvaleSwing:UNIT_SPELLCAST_SUCCEEDED(event, unit, spell)
 	if unit == "player" then
+		local now = API_GetTime()
 		if OVALE_RESET_SPELLS[spell] then
-			self:MeleeSwing(Ovale.now)
+			self:MeleeSwing(now)
 		end
 		if OVALE_DELAY_SPELLS[spell] and self.startdelay then
-			self.delay = Ovale.now - self.startdelay
+			self.delay = now - self.startdelay
 		end
 		if spell == OVALE_AUTOSHOT_NAME then
 			self:Shoot()
@@ -187,7 +191,7 @@ function OvaleSwing:Shoot()
 		print("Prediction = " ..(self.duration+self.starttime))
 	end]]
 	self.duration = API_UnitRangedDamage('player')
-	self.starttime = Ovale.now
+	self.starttime = API_GetTime()
 	--print("Shoot " .. self.starttime)
 end