Quantcast

Hide snapshot reference-counting behind an API.

Johnny C. Lam [11-26-13 - 14:05]
Hide snapshot reference-counting behind an API.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1210 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleFuture.lua
OvalePaperDoll.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 8b2d2a0..00f0f0d 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -23,6 +23,7 @@ local OvalePoolRefCount = Ovale.OvalePoolRefCount
 local OvaleData = nil
 local OvaleFuture = nil
 local OvaleGUID = nil
+local OvalePaperDoll = nil
 local OvaleState = nil

 local ipairs = ipairs
@@ -41,7 +42,7 @@ do
 	self_pool.Clean = function(self, aura)
 		-- Release reference-counted snapshot before wiping.
 		if aura.snapshot then
-			aura.snapshot:ReleaseReference()
+			OvalePaperDoll:ReleaseSnapshot(aura.snapshot)
 		end
 	end
 end
@@ -337,6 +338,7 @@ function OvaleAura:OnInitialize()
 	OvaleData = Ovale.OvaleData
 	OvaleFuture = Ovale.OvaleFuture
 	OvaleGUID = Ovale.OvaleGUID
+	OvalePaperDoll = Ovale.OvalePaperDoll
 	OvaleState = Ovale.OvaleState
 end

diff --git a/OvaleFuture.lua b/OvaleFuture.lua
index a529320..3480f39 100644
--- a/OvaleFuture.lua
+++ b/OvaleFuture.lua
@@ -52,7 +52,7 @@ do
 	self_pool.Clean = function(self, spellcast)
 		-- Release reference-counted snapshot before wiping.
 		if spellcast.snapshot then
-			spellcast.snapshot:ReleaseReference()
+			OvalePaperDoll:ReleaseSnapshot(spellcast.snapshot)
 		end
 	end
 end
@@ -514,10 +514,10 @@ end

 function OvaleFuture:UpdateSnapshotFromSpellcast(dest, spellcast)
 	if dest.snapshot then
-		dest.snapshot:ReleaseReference()
+		OvalePaperDoll:ReleaseSnapshot(dest.snapshot)
 	end
 	if spellcast.snapshot then
-		dest.snapshot = spellcast.snapshot:GetReference()
+		dest.snapshot = OvalePaperDoll:GetSnapshot(spellcast.snapshot)
 	end
 	if spellcast.damageMultiplier then
 		dest.damageMultiplier = spellcast.damageMultiplier
diff --git a/OvalePaperDoll.lua b/OvalePaperDoll.lua
index aa2cbd7..502f0c8 100644
--- a/OvalePaperDoll.lua
+++ b/OvalePaperDoll.lua
@@ -436,15 +436,15 @@ function OvalePaperDoll:CurrentSnapshot()
 	return self.snapshot
 end

--- Get a new reference to the current snapshot.
-function OvalePaperDoll:GetSnapshot()
-	local snapshot = self:CurrentSnapshot()
-	return snapshot:GetReference()
+-- Get a new reference to a snapshot; if no snapshot is specified, use the current one.
+function OvalePaperDoll:GetSnapshot(snapshot)
+	snapshot = snapshot or self:CurrentSnapshot()
+	return self_pool:GetReference(snapshot)
 end

 -- Release a reference to the given snapshot.
 function OvalePaperDoll:ReleaseSnapshot(snapshot)
-	return snapshot:ReleaseReference()
+	return self_pool:ReleaseReference(snapshot)
 end

 function OvalePaperDoll:Debug(snapshot)
@@ -502,10 +502,10 @@ function OvalePaperDoll:ResetState(state)
 	state.specialization = self.specialization
 	local now = API_GetTime()
 	if state.snapshot and state.snapshot.snapshotTime < now then
-		state.snapshot:ReleaseReference()
+		self_pool:ReleaseReference(state.snapshot)
 		state.snapshot = nil
 	end
-	state.snapshot = state.snapshot or self.snapshot:GetReference()
+	state.snapshot = state.snapshot or self_pool:GetReference(self.snapshot)
 end
 --</public-static-methods>