Mercurial > wow > ouroloot
comparison core.lua @ 40:dc3a66688e50
More debug message tweaks. Put comm and loot caches on separate-but-related expirations; comm is now a bit shorter and loot is now a bit longer. Check cache expirations more often (possibly revert this).
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Fri, 30 Dec 2011 21:29:44 +0000 |
| parents | 8f7ec6ccf5e3 |
| children | d6b8858c1b64 |
comparison
equal
deleted
inserted
replaced
| 39:8f7ec6ccf5e3 | 40:dc3a66688e50 |
|---|---|
| 84 ['legendary'] = 5, ['orange'] = 5, | 84 ['legendary'] = 5, ['orange'] = 5, |
| 85 ['artifact'] = 6, | 85 ['artifact'] = 6, |
| 86 --['heirloom'] = 7, | 86 --['heirloom'] = 7, |
| 87 } | 87 } |
| 88 local my_name = UnitName('player') | 88 local my_name = UnitName('player') |
| 89 local comm_cleanup_ttl = 5 -- seconds in the cache | 89 local comm_cleanup_ttl = 4 -- seconds in the cache |
| 90 local revision_large = nil -- defaults to 1, possibly changed by revision | 90 local revision_large = nil -- defaults to 1, possibly changed by revision |
| 91 local g_LOOT_ITEM_ss, g_LOOT_ITEM_MULTIPLE_sss, g_LOOT_ITEM_SELF_s, g_LOOT_ITEM_SELF_MULTIPLE_ss | 91 local g_LOOT_ITEM_ss, g_LOOT_ITEM_MULTIPLE_sss, g_LOOT_ITEM_SELF_s, g_LOOT_ITEM_SELF_MULTIPLE_ss |
| 92 | 92 |
| 93 | 93 |
| 94 ------ Addon member data | 94 ------ Addon member data |
| 303 -- this is ass-ugly | 303 -- this is ass-ugly |
| 304 for name,c in pairs(caches) do | 304 for name,c in pairs(caches) do |
| 305 local fifo = c.fifo | 305 local fifo = c.fifo |
| 306 local active = #fifo > 0 | 306 local active = #fifo > 0 |
| 307 while (#fifo > 0) and (now - fifo[1].t > c.ttl) do | 307 while (#fifo > 0) and (now - fifo[1].t > c.ttl) do |
| 308 addon.dprint('cache', name, "cache removing",fifo[1].t, fifo[1].m) | 308 addon.dprint('cache', name, "cache removing", fifo[1].t, "<", fifo[1].m, ">") |
| 309 tremove(fifo,1) | 309 tremove(fifo,1) |
| 310 end | 310 end |
| 311 if active and #fifo == 0 and c.func then | 311 if active and #fifo == 0 and c.func then |
| 312 addon.dprint('cache', name, "empty, firing cleanup") | 312 addon.dprint('cache', name, "empty, firing cleanup") |
| 313 c:func() | 313 c:func() |
| 314 end | 314 end |
| 315 alldone = alldone and (#fifo == 0) | 315 alldone = alldone and (#fifo == 0) |
| 316 end | 316 end |
| 317 if alldone then | 317 if alldone then |
| 318 addon.dprint('cache',"OnLoop finishing animation group") | 318 addon.dprint('cache',"OnLoop FINISHING animation group") |
| 319 cleanup_group:Finish() | 319 cleanup_group:Finish() |
| 320 end | 320 else |
| 321 addon.dprint('cache',"OnLoop done") | 321 addon.dprint('cache',"OnLoop done, not yet finished") |
| 322 end | |
| 322 end) | 323 end) |
| 323 | 324 |
| 324 local function _add (cache, x) | 325 local function _add (cache, x) |
| 325 local datum = { t=time(), m=x } | 326 local datum = { t=time(), m=x } |
| 326 cache.hash[x] = datum | 327 cache.hash[x] = datum |
| 327 tinsert (cache.fifo, datum) | 328 tinsert (cache.fifo, datum) |
| 328 if not cleanup_group:IsPlaying() then | 329 if not cleanup_group:IsPlaying() then |
| 329 addon.dprint('cache', cache.name, "STARTING animation group") | 330 addon.dprint('cache', cache.name, "with entry", datum.t, "<", datum.x, "> STARTING animation group") |
| 330 cache.cleanup:SetDuration(2) -- hmmm | 331 cache.cleanup:SetDuration(1) -- hmmm |
| 331 cleanup_group:Play() | 332 cleanup_group:Play() |
| 332 end | 333 end |
| 333 end | 334 end |
| 334 local function _test (cache, x) | 335 local function _test (cache, x) |
| 336 -- FIXME This can return false positives, if called after the onloop | |
| 337 -- fifo has been removed but before the GC has removed the weak entry. | |
| 338 -- What to do, what to do... | |
| 335 return cache.hash[x] ~= nil | 339 return cache.hash[x] ~= nil |
| 336 --[[for _,v in ipairs(cache) do | |
| 337 if v.m == x then return true end | |
| 338 end]] | |
| 339 end | 340 end |
| 340 | 341 |
| 341 function create_new_cache (name, ttl, on_alldone) | 342 function create_new_cache (name, ttl, on_alldone) |
| 342 -- setting OnFinished for cleanup fires at the end of each inner loop, | 343 -- setting OnFinished for cleanup fires at the end of each inner loop, |
| 343 -- with no 'requested' argument to distinguish cases. thus, on_alldone. | 344 -- with no 'requested' argument to distinguish cases. thus, on_alldone. |
| 719 if addon.display then | 720 if addon.display then |
| 720 addon:redisplay() | 721 addon:redisplay() |
| 721 end | 722 end |
| 722 table.wipe(candidates) | 723 table.wipe(candidates) |
| 723 end | 724 end |
| 724 addon.recent_loot = create_new_cache ('loot', comm_cleanup_ttl, prefer_local_loots) | 725 addon.recent_loot = create_new_cache ('loot', comm_cleanup_ttl+3, prefer_local_loots) |
| 725 | 726 |
| 726 local GetItemInfo, GetItemIcon = GetItemInfo, GetItemIcon | 727 local GetItemInfo, GetItemIcon = GetItemInfo, GetItemIcon |
| 727 | 728 |
| 728 -- 'from' and onwards only present if this is triggered by a broadcast | 729 -- 'from' and onwards only present if this is triggered by a broadcast |
| 729 function addon:_do_loot (local_override, recipient, itemid, count, from, extratext) | 730 function addon:_do_loot (local_override, recipient, itemid, count, from, extratext) |
| 1956 if sender == my_name then return end | 1957 if sender == my_name then return end |
| 1957 end | 1958 end |
| 1958 self.dprint('comm', ":OCR from", sender, "message is", msg) | 1959 self.dprint('comm', ":OCR from", sender, "message is", msg) |
| 1959 | 1960 |
| 1960 if self.recent_messages:test(msg) then | 1961 if self.recent_messages:test(msg) then |
| 1961 return self.dprint('cache', "message <",msg,"> already in cache, skipping") | 1962 self.dprint('cache', "OCR message <",msg,"> already in cache, skipping") |
| 1963 return | |
| 1962 end | 1964 end |
| 1963 self.recent_messages:add(msg) | 1965 self.recent_messages:add(msg) |
| 1964 | 1966 |
| 1965 -- Nothing is actually returned, just (ab)using tail calls. | 1967 -- Nothing is actually returned, just (ab)using tail calls. |
| 1966 return dotdotdot(sender,strsplit('\a',msg)) | 1968 return dotdotdot(sender,strsplit('\a',msg)) |
