comparison 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
comparison
equal deleted inserted replaced
81:0f6355bcfe68 82:ae17128ef3f2
1309 1309
1310 -- Recent loot cache 1310 -- Recent loot cache
1311 local candidates = {} 1311 local candidates = {}
1312 local sigmap = {} 1312 local sigmap = {}
1313 local function preempt_older_signature (oldersig, newersig) 1313 local function preempt_older_signature (oldersig, newersig)
1314 --pprint("preempt", oldersig, "::", newersig)
1315 local origin = candidates[oldersig] and candidates[oldersig].bcast_from 1314 local origin = candidates[oldersig] and candidates[oldersig].bcast_from
1316 --pprint("preempt", "candidate", candidates[oldersig], "bcast:", origin)
1317 if origin and g_seeing_oldsigs[origin] then 1315 if origin and g_seeing_oldsigs[origin] then
1318 -- replace entry from older client with this newer one 1316 -- replace entry from older client with this newer one
1319 candidates[oldersig] = nil 1317 candidates[oldersig] = nil
1320 addon.dprint('loot', "preempting signature <", oldersig, "> from", origin) 1318 addon.dprint('loot', "preempting signature <", oldersig, "> from", origin)
1321 end 1319 end
1407 local oldersig = recipient .. iname .. (count or "") 1405 local oldersig = recipient .. iname .. (count or "")
1408 local signature, seenit 1406 local signature, seenit
1409 if #unique > 0 then 1407 if #unique > 0 then
1410 -- newer case 1408 -- newer case
1411 signature = unique .. oldersig 1409 signature = unique .. oldersig
1412 --pprint("newer", "mapping older <", oldersig, "> to newer <", signature, ">")
1413 sigmap[oldersig] = signature 1410 sigmap[oldersig] = signature
1414 --pprint("newer", "testing recent for", signature, "yields", recent_loot:test(signature))
1415 seenit = (from and recent_loot:test(signature)) 1411 seenit = (from and recent_loot:test(signature))
1416 -- The following clause is what handles older 'casts arriving 1412 -- The following clause is what handles older 'casts arriving
1417 -- earlier. All this is tested inside-out to maximize short 1413 -- earlier. All this is tested inside-out to maximize short
1418 -- circuit evaluation; the preempt function always returns 1414 -- circuit evaluation; the preempt function always returns
1419 -- false to force seenit off. 1415 -- false to force seenit off.
1420 or (g_seeing_oldsigs and preempt_older_signature(oldersig,signature)) 1416 or (g_seeing_oldsigs and preempt_older_signature(oldersig,signature))
1421 else 1417 else
1422 -- older case, only remote 1418 -- older case, only remote
1423 assert(from) 1419 assert(from)
1424 signature = sigmap[oldersig] or oldersig 1420 signature = sigmap[oldersig] or oldersig
1425 --pprint("older", "testing signature will be", signature)
1426 seenit = recent_loot:test(signature) 1421 seenit = recent_loot:test(signature)
1427 end 1422 end
1428 1423
1429 if seenit then 1424 if seenit then
1430 self.dprint('loot', "remote", prefix, "<", signature, 1425 self.dprint('loot', "remote", prefix, "<", signature,
2006 self.dprint('flow', "restoring", #g_loot, "entries") 2001 self.dprint('flow', "restoring", #g_loot, "entries")
2007 self:ScheduleTimer("Activate", 12, opts.threshold) 2002 self:ScheduleTimer("Activate", 12, opts.threshold)
2008 -- FIXME printed could be too large if entries were deleted, how much do we care? 2003 -- FIXME printed could be too large if entries were deleted, how much do we care?
2009 self.sharder = opts.autoshard 2004 self.sharder = opts.autoshard
2010 else 2005 else
2011 --g_loot = { printed = {}, raiders = {} }
2012 g_loot = {} 2006 g_loot = {}
2013 end 2007 end
2014 if type(g_loot.raiders) ~= 'table' then 2008 if type(g_loot.raiders) ~= 'table' then
2015 g_loot.raiders = {} 2009 g_loot.raiders = {}
2016 end 2010 end
2353 -- Problem: (1) boss kill happens, (2) fast looting happens, (3) boss 2347 -- Problem: (1) boss kill happens, (2) fast looting happens, (3) boss
2354 -- cache cleanup fires. Result: loot shows up before boss kill entry. 2348 -- cache cleanup fires. Result: loot shows up before boss kill entry.
2355 -- Solution: We need to shuffle the boss entry above any of the loot 2349 -- Solution: We need to shuffle the boss entry above any of the loot
2356 -- from that boss. 2350 -- from that boss.
2357 function addon._adjustBossOrder (is, should_be) 2351 function addon._adjustBossOrder (is, should_be)
2358 --pprint('loot', is, should_be) 2352 if is == should_be then
2359 if is == should_be then --pprint('loot', "equal, yay")
2360 return 2353 return
2361 end 2354 end
2362 if (type(is)~='number') or (type(should_be)~='number') or (is < should_be) then 2355 if (type(is)~='number') or (type(should_be)~='number') or (is < should_be) then
2363 pprint('loot', is, should_be, "...the hell? bailing") 2356 pprint('loot', is, should_be, "...the hell? bailing")
2364 return 2357 return
2365 end 2358 end
2366 if g_loot[should_be].kind == 'time' then 2359 if g_loot[should_be].kind == 'time' then
2367 should_be = should_be + 1 2360 should_be = should_be + 1
2368 if is == should_be then 2361 if is == should_be then
2369 --pprint('loot', "needed to mark day entry, otherwise equal, yay")
2370 return 2362 return
2371 end 2363 end
2372 end 2364 end
2373 2365
2374 assert(g_loot[is].kind == 'boss') 2366 assert(g_loot[is].kind == 'boss')
2375 local boss = tremove (g_loot, is) 2367 local boss = tremove (g_loot, is)
2376 --pprint('loot', "MOVING", boss.bossname)
2377 tinsert (g_loot, should_be, boss) 2368 tinsert (g_loot, should_be, boss)
2378 return should_be 2369 return should_be
2379 end 2370 end
2380 end 2371 end
2381 2372
2431 -- Strictly speaking, we'd want to handle individual 'exist' entries 2422 -- Strictly speaking, we'd want to handle individual 'exist' entries
2432 -- as they expire, rather then waiting for all of them to expire and then 2423 -- as they expire, rather then waiting for all of them to expire and then
2433 -- doing them as a group. But, if there're more than one of these per 2424 -- doing them as a group. But, if there're more than one of these per
2434 -- boss, something else is funky anyhow and certainly not a hurry. 2425 -- boss, something else is funky anyhow and certainly not a hurry.
2435 local function fixup_unique_replacements() 2426 local function fixup_unique_replacements()
2436 --print("replacements fixup happening!")
2437 --tabledump(g_unique_replace.replacements)
2438 --_G.GRR = g_unique_replace.replacements
2439 for exist,info in pairs(gur.replacements) do 2427 for exist,info in pairs(gur.replacements) do
2440 local winning_index = 1 2428 local winning_index = 1
2441 local winner = info[1] 2429 local winner = info[1]
2442 info[1] = nil 2430 info[1] = nil
2443 pprint('improv', "fixup for", exist, "starting with", winner[1], 2431 pprint('improv', "fixup for", exist, "starting with guid",
2444 "with", winner[2], "out of", #info, "total entries") 2432 winner[1], "with tag", winner[2], "out of", #info,
2433 "total entries")
2445 -- Lowest player GUID wins. Seniority gotta count for something. 2434 -- Lowest player GUID wins. Seniority gotta count for something.
2446 for i = 2, #info do 2435 for i = 2, #info do
2447 if winner[1] <= info[i][1] then 2436 if winner[1] <= info[i][1] then
2448 pprint('improv', "champ wins against", i, info[i][1]) 2437 pprint('improv', "champ wins against", i, info[i][1])
2449 flib.del(info[i]) 2438 flib.del(info[i])
2454 winning_index = i 2443 winning_index = i
2455 end 2444 end
2456 info[i] = nil 2445 info[i] = nil
2457 end 2446 end
2458 pprint('improv', "final:", winner[1], winner[2]) 2447 pprint('improv', "final:", winner[1], winner[2])
2448 --@debug@
2449 -- purely a sanity check
2450 if winning_index == 1 then
2451 if winner[2] ~= info.LOCAL then
2452 pprint('improv',
2453 "things locally generated are not locally generated?",
2454 info.LOCAL, winner[2])
2455 end
2456 end
2457 --@end-debug@
2459 --[[ 2458 --[[
2460 A: winner was generated locally 2459 A: winner was generated locally
2460 >winning_index == 1
2461 >g_loot and history already has the replacement value 2461 >g_loot and history already has the replacement value
2462 >winning_index == 1
2463 B: winner was generated remotely 2462 B: winner was generated remotely
2464 >need to scan and replace 2463 >need to scan and replace
2464 Detecting A is strictly an optimization. We should be able to do
2465 this code safely in all cases.
2465 ]] 2466 ]]
2466 if winning_index ~= 1 then 2467 if winning_index ~= 1 then
2467 --XXX still needs to be debugged: 2468 --XXX this branch still needs to be tested with live data
2468 local cache = g_uniques[exist] 2469 local cache = g_uniques:SEARCH(exist)
2469 local looti = assert(cache.loot) -- can't possibly be missing... 2470 local looti,hi,ui = cache.loot, cache.history, cache.history_may
2470 if g_loot[looti].unique ~= exist then 2471
2471 pprint('improv', "WTF. entry", looti, 2472 -- Active loot
2472 "does not match original unique tag! instead", 2473 if looti and g_loot[looti].unique == exist then
2473 g_loot[looti].unique)
2474 else
2475 pprint('improv', "found and replaced loot entry", looti) 2474 pprint('improv', "found and replaced loot entry", looti)
2476 g_loot[looti].unique = winner[2] 2475 g_loot[looti].unique = winner[2]
2477 end 2476 else
2478 local hi,ui = cache.history, cache.history_may 2477 -- If winning_index == 1, the "previous" unique would not
2478 -- have made it into the tables to begin with. So don't
2479 -- flag an error. Still should be looked at.
2480 pprint('improv', "Um.", looti, g_loot[looti].unique, winning_index)
2481 end
2482
2483 -- History
2479 if hi ~= g_uniques.NOTFOUND then 2484 if hi ~= g_uniques.NOTFOUND then
2480 local hist = addon.history[hi] 2485 local hist = addon.history[hi]
2481 if ui and hist.unique[ui] == exist then 2486 if ui and hist.unique[ui] == exist then
2482 -- ui is valid 2487 -- ui is valid
2483 else 2488 else
2490 end 2495 end
2491 end 2496 end
2492 if ui then 2497 if ui then
2493 pprint('improv', "found and replacing history entry", hi, 2498 pprint('improv', "found and replacing history entry", hi,
2494 ui, hist.name) 2499 ui, hist.name)
2500 assert(exist ~= winner[2])
2495 hist.when[winner[2]] = hist.when[exist] 2501 hist.when[winner[2]] = hist.when[exist]
2496 hist.id[winner[2]] = hist.id[exist] 2502 hist.id[winner[2]] = hist.id[exist]
2497 hist.count[winner[2]] = hist.count[exist] 2503 hist.count[winner[2]] = hist.count[exist]
2498 hist.unique[ui] = winner[2] 2504 hist.unique[ui] = winner[2]
2499 hist.when[exist] = nil 2505 hist.when[exist] = nil
2575 addon:horrible_horrible_error (err) 2581 addon:horrible_horrible_error (err)
2576 -- we don't actually need to kill the GUI in this case 2582 -- we don't actually need to kill the GUI in this case
2577 addon.NOLOAD = nil 2583 addon.NOLOAD = nil
2578 end 2584 end
2579 end 2585 end
2580 --function DOTEST()
2581 -- local err = unique_collision:format (
2582 -- "Codpiece of the Grimacing Lunatic",
2583 -- 'n3183021', 'Farmbuyer', '14', '78')
2584 -- _unavoidable_collision (err)
2585 -- pprint('ohfuck', "COLLISION", err)
2586 --end
2587 2586
2588 2587
2589 ------ Saved texts 2588 ------ Saved texts
2590 function addon:check_saved_table(silent_p) 2589 function addon:check_saved_table(silent_p)
2591 local s = _G.OuroLootSV_saved 2590 local s = _G.OuroLootSV_saved
2781 end 2780 end
2782 for i,e in self:filtered_loot_iter('loot') do 2781 for i,e in self:filtered_loot_iter('loot') do
2783 if e.unique and e.unique ~= "" then 2782 if e.unique and e.unique ~= "" then
2784 local hmmm = _G.rawget(g_uniques,e.unique) 2783 local hmmm = _G.rawget(g_uniques,e.unique)
2785 if hmmm then 2784 if hmmm then
2786 hmmm.loot = i --;print("Active loot", i, "found with tag", e.unique) 2785 hmmm.loot = i
2787 elseif e.disposition == 'shard' or e.disposition == 'gvault' then 2786 elseif e.disposition == 'shard' or e.disposition == 'gvault' then
2788 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND } 2787 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND }
2789 count = count + 1 2788 count = count + 1
2790 --print("Active loot", i, "INSERTED with tag", e.unique, "as", e.disposition)
2791 else 2789 else
2792 hmmm = "active data not found in history ("..i.."/"..tostring(e.unique) 2790 hmmm = "active data not found in history ("..i.."/"..tostring(e.unique)
2793 ..") in precache loop! trying to fixup for this session" 2791 ..") in precache loop! trying to fixup for this session"
2794 pprint(hmmm) -- more? 2792 pprint(hmmm) -- more?
2795 -- try to simply fix up errors as we go 2793 -- try to simply fix up errors as we go
2796 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND } 2794 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND }
2797 --trouble = true
2798 end 2795 end
2799 else 2796 else
2800 trouble = true 2797 trouble = true
2801 pprint('loot', "ERROR precache loop found bad unique tag!", 2798 pprint('loot', "ERROR precache loop found bad unique tag!",
2802 i, "tag", tostring(e.unique), "from?", tostring(e.bcast_from)) 2799 i, "tag", tostring(e.unique), "from?", tostring(e.bcast_from))
3087 or select(2,_G.UnitClass(to_name)) 3084 or select(2,_G.UnitClass(to_name))
3088 self.hist_clean = nil 3085 self.hist_clean = nil
3089 self.loot_clean = nil 3086 self.loot_clean = nil
3090 3087
3091 if how == "local" then 3088 if how == "local" then
3092 --self:Print("Reassigned entry %d/%s from '%s' to '%s'.", index, e.itemlink, from_name, to_name)
3093 _notify_about_change (_G.DEFAULT_CHAT_FRAME, _G.UNIT_YOU, index, 3089 _notify_about_change (_G.DEFAULT_CHAT_FRAME, _G.UNIT_YOU, index,
3094 nil, from_name, from_person_class) 3090 nil, from_name, from_person_class)
3095 self:vbroadcast('reassign', unique, id, from_name, to_name) 3091 self:vbroadcast('reassign', unique, id, from_name, to_name)
3096 elseif opts.chatty_on_remote_changes then 3092 elseif opts.chatty_on_remote_changes then
3097 _notify_about_remote (sender, index, nil, from_name, from_person_class) 3093 _notify_about_remote (sender, index, nil, from_name, from_person_class)