diff core.lua @ 82:ae17128ef3f2

Cosmetic cleanup. Minor tweaks to fixup_unique_replacements to aid in debugging.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Sun, 17 Jun 2012 20:55:11 +0000
parents 0f6355bcfe68
children 940e53dd18c3
line wrap: on
line diff
--- a/core.lua	Fri Jun 15 20:04:05 2012 +0000
+++ b/core.lua	Sun Jun 17 20:55:11 2012 +0000
@@ -1311,9 +1311,7 @@
 	local candidates = {}
 	local sigmap = {}
 	local function preempt_older_signature (oldersig, newersig)
---pprint("preempt", oldersig, "::", newersig)
 		local origin = candidates[oldersig] and candidates[oldersig].bcast_from
---pprint("preempt", "candidate", candidates[oldersig], "bcast:", origin)
 		if origin and g_seeing_oldsigs[origin] then
 			-- replace entry from older client with this newer one
 			candidates[oldersig] = nil
@@ -1409,9 +1407,7 @@
 			if #unique > 0 then
 				-- newer case
 				signature = unique .. oldersig
---pprint("newer", "mapping older <", oldersig, "> to newer <", signature, ">")
 				sigmap[oldersig] = signature
---pprint("newer", "testing recent for", signature, "yields", recent_loot:test(signature))
 				seenit = (from and recent_loot:test(signature))
 					-- The following clause is what handles older 'casts arriving
 					-- earlier.  All this is tested inside-out to maximize short
@@ -1422,7 +1418,6 @@
 				-- older case, only remote
 				assert(from)
 				signature = sigmap[oldersig] or oldersig
---pprint("older", "testing signature will be", signature)
 				seenit = recent_loot:test(signature)
 			end
 
@@ -2008,7 +2003,6 @@
 		-- FIXME printed could be too large if entries were deleted, how much do we care?
 		self.sharder = opts.autoshard
 	else
-		--g_loot = { printed = {}, raiders = {} }
 		g_loot = {}
 	end
 	if type(g_loot.raiders) ~= 'table' then
@@ -2355,8 +2349,7 @@
 	-- Solution:  We need to shuffle the boss entry above any of the loot
 	-- from that boss.
 	function addon._adjustBossOrder (is, should_be)
-		--pprint('loot', is, should_be)
-		if is == should_be then --pprint('loot', "equal, yay")
+		if is == should_be then
 			return
 		end
 		if (type(is)~='number') or (type(should_be)~='number') or (is < should_be) then
@@ -2366,14 +2359,12 @@
 		if g_loot[should_be].kind == 'time' then
 			should_be = should_be + 1
 			if is == should_be then
-				--pprint('loot', "needed to mark day entry, otherwise equal, yay")
 				return
 			end
 		end
 
 		assert(g_loot[is].kind == 'boss')
 		local boss = tremove (g_loot, is)
-		--pprint('loot', "MOVING", boss.bossname)
 		tinsert (g_loot, should_be, boss)
 		return should_be
 	end
@@ -2433,15 +2424,13 @@
 	-- doing them as a group.  But, if there're more than one of these per
 	-- boss, something else is funky anyhow and certainly not a hurry.
 	local function fixup_unique_replacements()
---print("replacements fixup happening!")
---tabledump(g_unique_replace.replacements)
---_G.GRR = g_unique_replace.replacements
 		for exist,info in pairs(gur.replacements) do
 			local winning_index = 1
 			local winner = info[1]
 			info[1] = nil
-			pprint('improv', "fixup for", exist, "starting with", winner[1],
-				"with", winner[2], "out of", #info, "total entries")
+			pprint('improv', "fixup for", exist, "starting with guid",
+				winner[1], "with tag", winner[2], "out of", #info,
+				"total entries")
 			-- Lowest player GUID wins.  Seniority gotta count for something.
 			for i = 2, #info do
 				if winner[1] <= info[i][1] then
@@ -2456,26 +2445,42 @@
 				info[i] = nil
 			end
 			pprint('improv', "final:", winner[1], winner[2])
+			--@debug@
+			-- purely a sanity check
+			if winning_index == 1 then
+				if winner[2] ~= info.LOCAL then
+					pprint('improv',
+						"things locally generated are not locally generated?",
+						info.LOCAL, winner[2])
+				end
+			end
+			--@end-debug@
 			--[[
 			A:  winner was generated locally
+			   >winning_index == 1
 			   >g_loot and history already has the replacement value
-			   >winning_index == 1
 			B:  winner was generated remotely
 			   >need to scan and replace
+			Detecting A is strictly an optimization.  We should be able to do
+			this code safely in all cases.
 			]]
 			if winning_index ~= 1 then
---XXX still needs to be debugged:
-				local cache = g_uniques[exist]
-				local looti = assert(cache.loot)  -- can't possibly be missing...
-				if g_loot[looti].unique ~= exist then
-					pprint('improv', "WTF. entry", looti,
-						"does not match original unique tag! instead",
-						g_loot[looti].unique)
-				else
+				--XXX this branch still needs to be tested with live data
+				local cache = g_uniques:SEARCH(exist)
+				local looti,hi,ui = cache.loot, cache.history, cache.history_may
+
+				-- Active loot
+				if looti and g_loot[looti].unique == exist then
 					pprint('improv', "found and replaced loot entry", looti)
 					g_loot[looti].unique = winner[2]
+				else
+					-- If winning_index == 1, the "previous" unique would not
+					-- have made it into the tables to begin with.  So don't
+					-- flag an error.  Still should be looked at.
+					pprint('improv', "Um.", looti, g_loot[looti].unique, winning_index)
 				end
-				local hi,ui = cache.history, cache.history_may
+
+				-- History
 				if hi ~= g_uniques.NOTFOUND then
 					local hist = addon.history[hi]
 					if ui and hist.unique[ui] == exist then
@@ -2492,6 +2497,7 @@
 					if ui then
 						pprint('improv', "found and replacing history entry", hi,
 							ui, hist.name)
+						assert(exist ~= winner[2])
 						hist.when[winner[2]] = hist.when[exist]
 						hist.id[winner[2]] = hist.id[exist]
 						hist.count[winner[2]] = hist.count[exist]
@@ -2577,13 +2583,6 @@
 		addon.NOLOAD = nil
 	end
 end
---function DOTEST()
---	local err = unique_collision:format (
---		"Codpiece of the Grimacing Lunatic",
---		'n3183021', 'Farmbuyer', '14', '78')
---	_unavoidable_collision (err)
---	pprint('ohfuck', "COLLISION", err)
---end
 
 
 ------ Saved texts
@@ -2783,18 +2782,16 @@
 			if e.unique and e.unique ~= "" then
 				local hmmm = _G.rawget(g_uniques,e.unique)
 				if hmmm then
-					hmmm.loot = i --;print("Active loot", i, "found with tag", e.unique)
+					hmmm.loot = i
 				elseif e.disposition == 'shard' or e.disposition == 'gvault' then
 					g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND }
 					count = count + 1
-					--print("Active loot", i, "INSERTED with tag", e.unique, "as", e.disposition)
 				else
 					hmmm = "active data not found in history ("..i.."/"..tostring(e.unique)
 						..") in precache loop!  trying to fixup for this session"
 					pprint(hmmm)  -- more?
 					-- try to simply fix up errors as we go
 					g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND }
-					--trouble = true
 				end
 			else
 				trouble = true
@@ -3089,7 +3086,6 @@
 		self.loot_clean = nil
 
 		if how == "local" then
-			--self:Print("Reassigned entry %d/%s from '%s' to '%s'.", index, e.itemlink, from_name, to_name)
 			_notify_about_change (_G.DEFAULT_CHAT_FRAME, _G.UNIT_YOU, index,
 				nil, from_name, from_person_class)
 			self:vbroadcast('reassign', unique, id, from_name, to_name)