View Single Post
03-17-13, 04:07 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You can also use the vararg (...) only for the arguments that change based on the event type:

Code:
f:SetScript("OnEvent", function(self, event, _, eventType, _, sourceGUID, _, sourceFlags, _, destGUID, _, destFlags, _, ...)
     local maskedTypeBit = tonumber(strsub(sourceGUID, 5, 5), 16) % 8
     if maskedTypeBit == "NPC" then
          if eventType == "SWING_DAMAGE" then
               if destGUID == playerGUID and 
                    local amount = ...
                    damageTable[time()] = amount
               end
          elseif eventType == "SOME_EVENT" then
               -- etc
          end
     end
end)
Also, the new damageTable format you're using is going to generate a large amount of garbage, since creating new tables is relatively costly in terms of memory. Since there is no advantage in your case to using an indexed table (sequential integer keys) over a hash table (keys can be anything) -- especially since you are nil-ing out keys, which puts holes in the table and prevents the use of any index-related functions like ipairs or table.sort on the table -- you should just use your original damageTable[time()] = amount format instead.

Also, the way you're detecting NPCs seems rather inefficient, with two function calls, a string creation, and a modulus operation. Why not use a single bit.band comparison on the sourceFlags argument instead? It'll be much faster, especially if you upvalue bit.band and the specific flag value constants you're interested in.

Code:
if bit.band(sourceFlags, COMBATLOG_OBJECT_TYPE_NPC) > 0 then
    -- source is an NPC
end
More info about unit flags here:
http://www.wowpedia.org/UnitFlag
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote