Quantcast

Treat the current time in the simulator as part of the state.

Johnny C. Lam [11-15-13 - 19:56]
Treat the current time in the simulator as part of the state.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1169 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleBestAction.lua
OvaleCooldown.lua
OvaleFrame.lua
OvaleRunes.lua
OvaleState.lua
conditions/ManaPercent.lua
conditions/NextTick.lua
conditions/Power.lua
conditions/Runes.lua
conditions/TimeToMaxEnergy.lua
conditions/TimeToPowerFor.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index cc40838..bbd7cac 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -691,7 +691,7 @@ do
 				end

 				local start, ending, currentStacks, tick = state:GetAuraByGUID(guid, auraId, filter, true, target)
-				local newAura = state:NewAura(guid, auraId, filter, OvaleState.currentTime)
+				local newAura = state:NewAura(guid, auraId, filter, state.currentTime)
 				newAura.mine = true

 				--[[
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index 2f81bb9..185def4 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -80,6 +80,7 @@ end

 local function ComputeAction(element)
 	local self = OvaleBestAction
+	local state = OvaleState.state
 	local action = element.params[1]
 	local actionTexture, actionInRange, actionCooldownStart, actionCooldownDuration,
 		actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId = self:GetActionInfo(element)
@@ -119,7 +120,7 @@ local function ComputeAction(element)
 	if actionCooldownDuration and actionCooldownStart and actionCooldownStart > 0 then
 		start = actionCooldownDuration + actionCooldownStart
 	else
-		start = OvaleState.currentTime
+		start = state.currentTime
 	end

 	Ovale:Logf("start=%f nextCast=%s [%d]", start, OvaleState.nextCast, element.nodeId)
@@ -166,7 +167,7 @@ local function ComputeAction(element)
 	--]]
 	local value
 	if element.params.asValue and element.params.asValue == 1 then
-		local atTime = OvaleState.currentTime
+		local atTime = state.currentTime
 		if HasTime(timeSpan, atTime) then
 			value = 1
 		else
@@ -204,6 +205,7 @@ end

 local function ComputeArithmetic(element)
 	local self = OvaleBestAction
+	local state = OvaleState.state
 	local timeSpanA, _, elementA = self:Compute(element.a)
 	local timeSpanB, _, elementB = self:Compute(element.b)
 	local timeSpan = element.timeSpan
@@ -228,7 +230,7 @@ local function ComputeArithmetic(element)
 	local x = elementB and elementB.value or 0
 	local y = elementB and elementB.origin or 0
 	local z = elementB and elementB.rate or 0
-	local atTime = OvaleState.currentTime
+	local atTime = state.currentTime

 	Ovale:Logf("%f+(t-%f)*%f %s %f+(t-%f)*%f [%d]", a, b, c, element.operator, x, y, z, element.nodeId)

@@ -382,6 +384,7 @@ end
 local function ComputeCustomFunction(element)
 	Ovale:Logf("custom function %s", element.name)
 	local self = OvaleBestAction
+	local state = OvaleState.state
 	if not element.serial or element.serial < self_serial then
 		-- Cache new values in element.
 		element.timeSpanA, element.priorityA, element.elementA = self:Compute(element.a)
@@ -408,7 +411,7 @@ local function ComputeCustomFunction(element)
 			If the return value is an action, then return 1 if the action is off of cooldown, or
 			0 if it is on cooldown.
 		--]]
-		local atTime = OvaleState.currentTime
+		local atTime = state.currentTime
 		local value = 0
 		if HasTime(timeSpanA, atTime) then
 			if not elementA then	-- boolean
@@ -429,6 +432,7 @@ end

 local function ComputeFunction(element)
 	local self = OvaleBestAction
+	local state = OvaleState.state
 	local timeSpan = element.timeSpan
 	timeSpan:Reset()

@@ -463,7 +467,7 @@ local function ComputeFunction(element)
 		time, or 0 otherwise.
 	--]]
 	if element.params.asValue and element.params.asValue == 1 then
-		local atTime = OvaleState.currentTime
+		local atTime = state.currentTime
 		if HasTime(timeSpan, atTime) then
 			if value then
 				value = value + (atTime - origin) * rate
@@ -486,6 +490,7 @@ end

 local function ComputeGroup(element)
 	local self = OvaleBestAction
+	local state = OvaleState.state
 	local bestTimeSpan, bestPriority, bestElement, bestCastTime
 	local timeSpan = element.timeSpan
 	timeSpan:Reset()
@@ -501,9 +506,9 @@ local function ComputeGroup(element)

 	for k, v in ipairs(element.nodes) do
 		local currentTimeSpan, currentPriority, currentElement = self:Compute(v)
-		-- We only care about actions that are available at time t > OvaleState.currentTime.
+		-- We only care about actions that are available at time t > state.currentTime.
 		current:Reset()
-		IntersectInterval(currentTimeSpan, OvaleState.currentTime, math.huge, current)
+		IntersectInterval(currentTimeSpan, state.currentTime, math.huge, current)
 		if Measure(current) > 0 then
 			Ovale:Logf("    group checking %s [%d]", tostring(current), element.nodeId)
 			local currentCastTime
@@ -580,6 +585,7 @@ end
 local function ComputeIf(element)
 	Ovale:Logf("%s [%d]", element.type, element.nodeId)
 	local self = OvaleBestAction
+	local state = OvaleState.state

 	local timeSpanA = self:ComputeBool(element.a)
 	local timeSpan = element.timeSpan
@@ -602,7 +608,7 @@ local function ComputeIf(element)

 	local timeSpanB, priorityB, elementB = self:Compute(element.b)
 	-- If the "then" clause is a "wait" node, then only wait if the conditions are true.
-	if elementB and elementB.wait and not HasTime(conditionTimeSpan, OvaleState.currentTime) then
+	if elementB and elementB.wait and not HasTime(conditionTimeSpan, state.currentTime) then
 		elementB.wait = nil
 	end
 	-- Take intersection of the condition and B.
diff --git a/OvaleCooldown.lua b/OvaleCooldown.lua
index 79fba2e..cf65cbc 100644
--- a/OvaleCooldown.lua
+++ b/OvaleCooldown.lua
@@ -198,10 +198,10 @@ do
 	-- Force the cooldown of a spell to reset at the specified time.
 	function statePrototype:ResetSpellCooldown(spellId, atTime)
 		local state = self
-		if atTime >= OvaleState.currentTime then
+		if atTime >= state.currentTime then
 			local cd = state:GetCD(spellId)
-			cd.start = OvaleState.currentTime
-			cd.duration = atTime - OvaleState.currentTime
+			cd.start = state.currentTime
+			cd.duration = atTime - state.currentTime
 			cd.enable = 1
 		end
 	end
diff --git a/OvaleFrame.lua b/OvaleFrame.lua
index 992e6bb..68585f0 100644
--- a/OvaleFrame.lua
+++ b/OvaleFrame.lua
@@ -172,6 +172,7 @@ do
 		self.lastUpdate = now

 		OvaleState:StartNewFrame()
+		local state = OvaleState.state
 		for k,node in pairs(OvaleCompile.masterNodes) do
 			local target
 			if node.params and node.params.target then
@@ -214,8 +215,8 @@ do
 							actionUsable, actionShortcut, actionIsCurrent, actionEnable, spellId, actionTarget, noRed = OvaleBestAction:GetActionInfo(element)
 					if noRed then
 						start = actionCooldownStart + actionCooldownDuration
-						if start < OvaleState.currentTime then
-							start = OvaleState.currentTime
+						if start < state.currentTime then
+							start = state.currentTime
 						end
 					end
 						-- Dans le cas de canStopChannelling, on risque de demander d'interrompre le channelling courant, ce qui est stupide
diff --git a/OvaleRunes.lua b/OvaleRunes.lua
index 64c2f10..dbe8ef7 100644
--- a/OvaleRunes.lua
+++ b/OvaleRunes.lua
@@ -216,7 +216,7 @@ do
 	local statePrototype = OvaleRunes.statePrototype

 	function statePrototype:DebugRunes()
-		local now = OvaleState.currentTime
+		local now = state.currentTime
 		for slot = 1, 6 do
 			local rune = self.rune[slot]
 			if rune.active then
@@ -421,7 +421,7 @@ do
 				end
 			end
 			if maxEndCooldown > 0 then
-				return maxEndCooldown - OvaleState.currentTime
+				return maxEndCooldown - state.currentTime
 			end
 			return 0
 		end
diff --git a/OvaleState.lua b/OvaleState.lua
index a098fbc..7d8f5f9 100644
--- a/OvaleState.lua
+++ b/OvaleState.lua
@@ -31,16 +31,18 @@ local self_stateIsInitialized = false
 --</private-static-properties>

 --<public-static-properties>
--- The state for the simulator.
-OvaleState.state = {}
 -- The spell being cast.
 OvaleState.currentSpellId = nil
 OvaleState.now = nil
-OvaleState.currentTime = nil
 OvaleState.nextCast = nil
 OvaleState.startCast = nil
 OvaleState.endCast = nil
 OvaleState.lastSpellId = nil
+
+-- The state for the simulator.
+OvaleState.state = {
+	currentTime = nil,
+}
 --</public-static-properties>

 --<private-static-methods>
@@ -96,8 +98,9 @@ function OvaleState:InitializeState()
 end

 function OvaleState:Reset()
-	self.currentTime = self.now
-	Ovale:Logf("Reset state with current time = %f", self.currentTime)
+	local state = self.state
+	state.currentTime = self.now
+	Ovale:Logf("Reset state with current time = %f", state.currentTime)

 	self.lastSpellId = Ovale.lastSpellcast and Ovale.lastSpellcast.spellId
 	self.currentSpellId = nil
@@ -124,22 +127,22 @@ function OvaleState:ApplySpell(spellId, startCast, endCast, nextCast, nocd, targ
 	end

 	-- Update the latest spell cast in the simulator.
+	local state = self.state
 	self.nextCast = nextCast
 	self.currentSpellId = spellId
 	self.startCast = startCast
 	self.endCast = endCast
-
 	self.lastSpellId = spellId

 	-- Set the current time in the simulator to a little after the start of the current cast,
 	-- or to now if in the past.
 	if startCast >= self.now then
-		self.currentTime = startCast + 0.1
+		state.currentTime = startCast + 0.1
 	else
-		self.currentTime = self.now
+		state.currentTime = self.now
 	end

-	Ovale:Logf("Apply spell %d at %f currentTime=%f nextCast=%f endCast=%f targetGUID=%s", spellId, startCast, self.currentTime, self.nextCast, endCast, targetGUID)
+	Ovale:Logf("Apply spell %d at %f currentTime=%f nextCast=%f endCast=%f targetGUID=%s", spellId, startCast, state.currentTime, self.nextCast, endCast, targetGUID)

 	--[[
 		Apply the effects of the spellcast in three phases.
diff --git a/conditions/ManaPercent.lua b/conditions/ManaPercent.lua
index 4979931..9e4d8d0 100644
--- a/conditions/ManaPercent.lua
+++ b/conditions/ManaPercent.lua
@@ -42,8 +42,8 @@ do
 			local powerMax = OvalePower.maxPower.mana or 0
 			if powerMax > 0 then
 				local conversion = 100 / powerMax
-				local value, origin, rate = state.mana * conversion, OvaleState.currentTime, state.powerRate.mana * conversion
-				local start, ending = OvaleState.currentTime, math.huge
+				local value, origin, rate = state.mana * conversion, state.currentTime, state.powerRate.mana * conversion
+				local start, ending = state.currentTime, math.huge
 				return TestValue(start, ending, value, origin, rate, comparator, limit)
 			end
 		else
diff --git a/conditions/NextTick.lua b/conditions/NextTick.lua
index 6bb28d0..4e83761 100644
--- a/conditions/NextTick.lua
+++ b/conditions/NextTick.lua
@@ -42,7 +42,7 @@ do
 		local start, ending = state:GetAura(target, auraId, filter, mine, auraFound)
 		local tick = auraFound.tick
 		if ending and ending < math.huge and tick then
-			while ending - tick > OvaleState.currentTime do
+			while ending - tick > state.currentTime do
 				ending = ending - tick
 			end
 			return TestValue(0, ending, 0, ending, -1, comparator, limit)
diff --git a/conditions/Power.lua b/conditions/Power.lua
index aab2a61..8172acc 100644
--- a/conditions/Power.lua
+++ b/conditions/Power.lua
@@ -40,8 +40,8 @@ do
 		local target = ParseCondition(condition)
 		local state = OvaleState.state
 		if target == "player" then
-			local value, origin, rate = state[powerType], OvaleState.currentTime, state.powerRate[powerType]
-			local start, ending = OvaleState.currentTime, math.huge
+			local value, origin, rate = state[powerType], state.currentTime, state.powerRate[powerType]
+			local start, ending = state.currentTime, math.huge
 			return TestValue(start, ending, value, origin, rate, comparator, limit)
 		else
 			local powerInfo = OvalePower.POWER_INFO[powerType]
diff --git a/conditions/Runes.lua b/conditions/Runes.lua
index f7e9063..eaddd5b 100644
--- a/conditions/Runes.lua
+++ b/conditions/Runes.lua
@@ -71,7 +71,7 @@ do
 		local blood, unholy, frost, death, deathCondition = ParseRuneCondition(condition)
 		local state = OvaleState.state
 		local seconds = state:GetRunesCooldown(blood, unholy, frost, death, deathCondition)
-		return OvaleState.currentTime + seconds, math.huge
+		return state.currentTime + seconds, math.huge
 	end

 	--- Get the number of seconds before the rune conditions are met.
@@ -96,7 +96,7 @@ do
 		local blood, unholy, frost, death, deathCondition = ParseRuneCondition(condition)
 		local state = OvaleState.state
 		local seconds = state:GetRunesCooldown(blood, unholy, frost, death, deathCondition)
-		return 0, OvaleState.currentTime + seconds, seconds, OvaleState.currentTime, -1
+		return 0, state.currentTime + seconds, seconds, state.currentTime, -1
 	end

 	OvaleCondition:RegisterCondition("runes", false, Runes)
diff --git a/conditions/TimeToMaxEnergy.lua b/conditions/TimeToMaxEnergy.lua
index c8c8618..d3e588a 100644
--- a/conditions/TimeToMaxEnergy.lua
+++ b/conditions/TimeToMaxEnergy.lua
@@ -36,7 +36,7 @@ do
 		local energyRegen = state.powerRate.energy or 10
 		local t = (maxEnergy - energy) / energyRegen
 		if t > 0 then
-			return TestValue(0, OvaleState.currentTime + t, t, OvaleState.currentTime, -1, comparator, limit)
+			return TestValue(0, state.currentTime + t, t, state.currentTime, -1, comparator, limit)
 		end
 		return Compare(0, comparator, limit)
 	end
diff --git a/conditions/TimeToPowerFor.lua b/conditions/TimeToPowerFor.lua
index b35120f..5968432 100644
--- a/conditions/TimeToPowerFor.lua
+++ b/conditions/TimeToPowerFor.lua
@@ -40,7 +40,7 @@ do
 		if currentPower < cost then
 			if powerRate > 0 then
 				local t = (cost - currentPower)/powerRate
-				return TestValue(0, OvaleState.currentTime + t, t, OvaleState.currentTime, -1, comparator, limit)
+				return TestValue(0, state.currentTime + t, t, state.currentTime, -1, comparator, limit)
 			else
 				return Compare(math.huge, comparator, limit)
 			end