diff --git a/MikScrollingBattleText/MikCombatEventHelper.lua b/MikScrollingBattleText/MikCombatEventHelper.lua index 465bb68..314f48e 100644 --- a/MikScrollingBattleText/MikCombatEventHelper.lua +++ b/MikScrollingBattleText/MikCombatEventHelper.lua @@ -4,18 +4,20 @@ -- Maintainer: Athene ------------------------------------------------------------------------------------- --- Create "namespace." -MikCEH = {}; +-- Create "namespace." It is private to MikScrollingBattleText and shared through the addon table. +local _, addonTable = ... +local MikCEH = {}; +addonTable.MikCEH = MikCEH; -- Upvalue caches for frequently called functions. local string_find, string_gsub = string.find, string.gsub local string_len, string_sub, string_gfind = string.len, string.sub, string.gfind -local table_insert, table_getn, table_setn = table.insert, table.getn, table.setn +local table_insert, table_getn, table_wipe = table.insert, table.getn, table.wipe local GetTime, UnitHealth, UnitHealthMax = GetTime, UnitHealth, UnitHealthMax local UnitMana, UnitManaMax, UnitName = UnitMana, UnitManaMax, UnitName local UnitIsPlayer, UnitIsFriend, UnitExists = UnitIsPlayer, UnitIsFriend, UnitExists local GetNumRaidMembers, GetNumPartyMembers = GetNumRaidMembers, GetNumPartyMembers -local pairs, tonumber, type, pcall = pairs, tonumber, type, pcall +local tonumber, type, pcall = tonumber, type, pcall ------------------------------------------------------------------------------------- -- Public constants. @@ -1152,10 +1154,7 @@ function MikCEH.SetupCombatLogEvents() -- Replace listenEvents with filtered list. -- Clear and repopulate to maintain the same table reference. - for i = table_getn(listenEvents), 1, -1 do - listenEvents[i] = nil - end - table_setn(listenEvents, 0) + table_wipe(listenEvents) for _, eventName in filteredEvents do table_insert(listenEvents, eventName) end @@ -4063,7 +4062,7 @@ function MikCEH.GetCapturedData(combatMessage, globalStringName, captureOrder) local stringFound = false; -- Erase old captured data. - MikCEH.EraseTable(orderedCaptureData); + table_wipe(orderedCaptureData); -- Get the unordered capture data. local tempCapturedData = MikCEH.GetUnorderedCaptureDataTable(string_gfind(combatMessage, globalStringInfo.Search)()); @@ -4108,7 +4107,7 @@ end -- parameters passed. -- ********************************************************************************** function MikCEH.GetUnorderedCaptureDataTable(c1, c2, c3, c4, c5, c6, c7, c8, c9) - -- Assign directly by index instead of EraseTable + table_insert. + -- Assign directly by index instead of table_wipe + table_insert. unorderedCaptureData[1] = c1; unorderedCaptureData[2] = c2; unorderedCaptureData[3] = c3; @@ -4190,7 +4189,7 @@ function MikCEH.GetDamageEventData(directionType, actionType, hitType, damageTyp local eventData = MikCEH.CombatEventData; -- Erase the combat event data table. - MikCEH.EraseTable(eventData); + table_wipe(eventData); -- Populate the event data fields. @@ -4216,7 +4215,7 @@ function MikCEH.GetHealEventData(directionType, healType, amount, effectName, na local eventData = MikCEH.CombatEventData; -- Erase the combat event data table. - MikCEH.EraseTable(eventData); + table_wipe(eventData); -- Populate the event data fields. eventData.EventType = MikCEH.EVENTTYPE_HEAL; @@ -4240,7 +4239,7 @@ function MikCEH.GetNotificationEventData(notificationType, amount, effectName, S local eventData = MikCEH.CombatEventData; -- Erase the combat event data table. - MikCEH.EraseTable(eventData); + table_wipe(eventData); -- Populate the event data fields. eventData.EventType = MikCEH.EVENTTYPE_NOTIFICATION; @@ -4336,21 +4335,6 @@ function MikCEH.SendEvent(eventData) end --- ********************************************************************************** --- Erases the passed table without losing the reference to the original memory. --- This helps prevent GC churn. --- ********************************************************************************** -function MikCEH.EraseTable(t) - -- Loop through all the keys in the table and clear it. - for key in pairs(t) do - t[key] = nil; - end - - -- Set the length of the table to 0. - table_setn(t, 0); -end - - ------------------------------------------------------------------------------------- -- Trigger utility functions. ------------------------------------------------------------------------------------- @@ -4396,7 +4380,7 @@ function MikCEH.GetSearchTriggerEventData(triggerKey, capturedData) local eventData = MikCEH.TriggerEventData; -- Erase the trigger event data table. - MikCEH.EraseTable(eventData); + table_wipe(eventData); -- Populate the trigger event data fields. eventData.TriggerKey = triggerKey; @@ -4421,7 +4405,7 @@ function MikCEH.GetThresholdTriggerEventData(triggerKey, triggerAmount) local eventData = MikCEH.TriggerEventData; -- Erase the trigger event data table. - MikCEH.EraseTable(eventData); + table_wipe(eventData); -- Populate the trigger event data fields. eventData.TriggerKey = triggerKey; @@ -4489,12 +4473,12 @@ end -- ********************************************************************************** function MikCEH.UnregisterAllTriggers() -- Erase the trigger arrays. - MikCEH.EraseTable(selfHealthTriggers); - MikCEH.EraseTable(selfManaTriggers); - MikCEH.EraseTable(petHealthTriggers); - MikCEH.EraseTable(enemyHealthTriggers); - MikCEH.EraseTable(friendlyHealthTriggers); - MikCEH.EraseTable(searchPatternTriggers); + table_wipe(selfHealthTriggers); + table_wipe(selfManaTriggers); + table_wipe(petHealthTriggers); + table_wipe(enemyHealthTriggers); + table_wipe(friendlyHealthTriggers); + table_wipe(searchPatternTriggers); end diff --git a/MikScrollingBattleText/MikScrollingBattleText.lua b/MikScrollingBattleText/MikScrollingBattleText.lua index fbf1157..c5e3dba 100644 --- a/MikScrollingBattleText/MikScrollingBattleText.lua +++ b/MikScrollingBattleText/MikScrollingBattleText.lua @@ -8,10 +8,16 @@ -- Public Constants. ------------------------------------------------------------------------------------- +-- The combat event helper, private to this addon. +local _, addonTable = ... +local MikCEH = addonTable.MikCEH; + +-- The search pattern trigger type, for the options addon. +MikSBT.TRIGGERTYPE_SEARCH_PATTERN = MikCEH.TRIGGERTYPE_SEARCH_PATTERN; + -- Upvalue caches for frequently called functions. local string_find, string_gsub = string.find, string.gsub -local table_insert, table_getn, table_remove = table.insert, table.getn, table.remove -local table_setn = table.setn +local table_insert, table_getn, table_wipe = table.insert, table.getn, table.wipe local math_ceil, math_floor, math_random = math.ceil, math.floor, math.random local GetTime = GetTime local getglobal = getglobal @@ -347,11 +353,7 @@ function MikSBT.OnUpdate() end -- Clear the merged animation events array. - local numMergedEvents = table_getn(mergeData.MergedEvents); - for i = 1, numMergedEvents do - mergeData.MergedEvents[i] = nil; - end - table_setn(mergeData.MergedEvents, 0); + table_wipe(mergeData.MergedEvents); -- Reset the last merged time. @@ -829,10 +831,8 @@ function MikSBT.MergeEvents(mergeData, numEvents) -- Release the animation event table to the events pool. eventsPool:Release(mergeData.UnmergedEvents[x]); end - - mergeData.UnmergedEvents[x] = nil; end - table_setn(mergeData.UnmergedEvents, 0); + table_wipe(mergeData.UnmergedEvents); end @@ -1951,10 +1951,7 @@ function MikSBT.RepositionAnimDisplayInfo(scrollArea) end -- Animation Style -- Clear the temp non stickies table. - for x = 1, numNonStickies do - activeNonStickies[x] = nil; - end - table_setn(activeNonStickies, 0); + table_wipe(activeNonStickies); end @@ -2034,10 +2031,7 @@ function MikSBT.RepositionStickyAnimDisplayInfo(scrollArea) end -- Animation Style -- Clear the temp stickies table. - for x = 1, numStickies do - activeStickies[x] = nil; - end - table_setn(activeStickies, 0); + table_wipe(activeStickies); end diff --git a/MikScrollingBattleTextOptions/MSBTOptions.lua b/MikScrollingBattleTextOptions/MSBTOptions.lua index cee546f..5f5ca99 100644 --- a/MikScrollingBattleTextOptions/MSBTOptions.lua +++ b/MikScrollingBattleTextOptions/MSBTOptions.lua @@ -554,7 +554,7 @@ function MikSBTOpt.TriggerTypeDropdownOnClick(frameName) UIDropDownMenu_SetSelectedValue(getglobal(frameName), this.value); -- Setup the trigger controls appropriately depending on the trigger type. - MikSBTOpt.SetupVariableTriggerControls(getglobal(frameName):GetParent().TriggerKey, this.value == MikCEH.TRIGGERTYPE_SEARCH_PATTERN); + MikSBTOpt.SetupVariableTriggerControls(getglobal(frameName):GetParent().TriggerKey, this.value == MikSBT.TRIGGERTYPE_SEARCH_PATTERN); end @@ -3345,7 +3345,7 @@ function MikSBTOpt.ShowTriggerConfig(triggerKey) MikSBTOpt.PopulateEditbox(TRIGGER_CONFIGURATION_FRAME_NAME .. "IconNameEditbox", texture); -- Setup the trigger controls appropriately depending on the trigger type. - MikSBTOpt.SetupVariableTriggerControls(triggerKey, triggerData.TriggerSettings.TriggerType == MikCEH.TRIGGERTYPE_SEARCH_PATTERN); + MikSBTOpt.SetupVariableTriggerControls(triggerKey, triggerData.TriggerSettings.TriggerType == MikSBT.TRIGGERTYPE_SEARCH_PATTERN); -- Show the trigger settings. triggerFrame:Show(); @@ -3389,7 +3389,7 @@ function MikSBTOpt.SetupVariableTriggerControls(triggerKey, showSearch) if (not triggerFrame.SelectedTriggerEvents) then triggerFrame.SelectedTriggerEvents = {}; else - MikCEH.EraseTable(triggerFrame.SelectedTriggerEvents); + table.wipe(triggerFrame.SelectedTriggerEvents); end -- Loop through all of the trigger events for the trigger. @@ -3525,7 +3525,7 @@ function MikSBTOpt.SaveTriggerConfig() end -- Check if the trigger type is search pattern. - if (triggerData.TriggerSettings.TriggerType == MikCEH.TRIGGERTYPE_SEARCH_PATTERN) then + if (triggerData.TriggerSettings.TriggerType == MikSBT.TRIGGERTYPE_SEARCH_PATTERN) then -- Clear the threshold field. triggerData.TriggerSettings.Threshold = nil; diff --git a/README.md b/README.md index f1090af..77d5e61 100644 --- a/README.md +++ b/README.md @@ -90,12 +90,12 @@ SuperWoW, UnitXP SP3 and Nampower integration has been removed in favor of Class ## Architecture -### Global Namespaces +### Namespaces | Namespace | Purpose | |---|---| -| `MikSBT` | Main addon: display, animation, profiles, event routing, slash commands | -| `MikCEH` | Combat Event Helper: parses combat events into structured data | +| `MikSBT` | Global. Main addon: display, animation, profiles, event routing, slash commands, and the API the options addon and other addons use | +| `MikCEH` | Private, shared through the addon table. Combat Event Helper: parses combat events into structured data | ### Event Processing Pipeline