Go to Page... |
|
Thread Tools | Display Modes |
|
06-22-19, 07:59 AM | #1 |
(Classic) Optimizing table search for auto dismount addon
Hi,
Been working on a new version of my Classic dismount addon; mostly, because it requires two button presses to activate an ability. In this version I register an OnKeyDown event and call for Dismount(). This works perfectly well in retail (BfA), but when my friend tries it out on the Classic Beta it requires two button presses for most abilities (excluding grenades, distract, and similar abilities that works fine). The only difference between the two of us is that I am working with a latency of 40 ms, and he around 120 ms. As such, I execute the OnKeyDown event in 1 ms and he around 3 ms. Disclaimer: to try this addon out for yourself on retail you need to disable auto dismount, and use a flying mount (and be in the air). Toc file: Code:
## Interface: 80100 ## Title: dashingDismount ## Notes: Dismount ## Author: DashingSplash dashingDismount.lua Code:
local dashingDismount = CreateFrame("Frame", nil, UIParent) local dashingSplash = CreateFrame("Frame", nil, UIParent) local table_1 = {t = {}, st = {}, ct = {}, at = {}} local table_2 = {t2 = {}, st2 = {}, ct2 = {}, at2 = {}} local key1, key2 local mod dashingDismount:SetScript("OnKeyDown", function(self, key, ...) local beginTime = debugprofilestop() if IsMounted() then if GetActionBarPage() ~= 2 then if not IsModifierKeyDown() and tContains(table_1.t, key) then Dismount() elseif IsShiftKeyDown() and tContains(table_1.st, key) then Dismount() elseif IsControlKeyDown() and tContains(table_1.ct, key) then Dismount() elseif IsAltKeyDown() and tContains(table_1.at, key) then Dismount() end else if not IsModifierKeyDown() and tContains(table_2.t2, key) then Dismount() elseif IsShiftKeyDown() and tContains(table_2.st2, key) then Dismount() elseif IsControlKeyDown() and tContains(table_2.ct2, key) then Dismount() elseif IsAltKeyDown() and tContains(table_2.at2, key) then Dismount() end end end local timeUsed = debugprofilestop() - beginTime print(timeUsed) end) local function dashingKey(key) if GetActionBarPage() ~= 2 then if string.find(key, "SHIFT-") ~= nil then table_1.st[#table_1.st+1] = string.sub(key, 7) elseif string.find(key1, "CTRL-") ~= nil then table_1.ct[#table_1.ct+1] = string.sub(key, 6) elseif string.find(key1, "ALT-") ~= nil then table_1.at[#table_1.at+1] = string.sub(key, 5) else table_1.t[#table_1.t+1] = key end else if string.find(key, "SHIFT-") ~= nil then table_2.st2[#table_2.st2+1] = string.sub(key, 7) elseif string.find(key1, "CTRL-") ~= nil then table_2.ct2[#table_2.ct2+1] = string.sub(key, 6) elseif string.find(key1, "ALT-") ~= nil then table_2.at2[#table_2.at2+1] = string.sub(key, 5) else table_2.t2[#table_2.t2+1] = key end end end local function dashingBindings() local button, buttonName local slot local actionName local actionType, id local ActionBars = {'Action', 'Action', 'Stance', 'MultiBarBottomLeft', 'MultiBarBottomRight', 'MultiBarRight', 'MultiBarLeft'} local ActionBarsBinding = {'ACTION', 'ACTION', 'SHAPESHIFT', 'MULTIACTIONBAR1', 'MULTIACTIONBAR2', 'MULTIACTIONBAR3', 'MULTIACTIONBAR4'} local protectedSkills = {"Alchemy", "Cooking", "Enchanting", "Engineering", "Blacksmithing", "Tailoring", "First Aid"} for page, barName in ipairs(ActionBars) do if page == 2 then ChangeActionBarPage(2) else ChangeActionBarPage(1) end for i = 1, 12 do button = _G[barName .. 'Button' .. i] buttonName = ActionBarsBinding[page] .. "BUTTON" .. i if button ~= nil then slot = ActionButton_GetPagedID(button) or ActionButton_CalculateAction(button) or button:GetAttribute('action') or 0 if HasAction(slot) then actionType, id = GetActionInfo(slot) key1, key2 = GetBindingKey(buttonName) actionName = GetSpellInfo(id) if not tContains(protectedSkills, actionName) then if key1 ~= nil then print(key1) dashingKey(key1) end if key2 ~= nil then print(key2) dashingKey(key2) end end end end end end end local function dashingUpdate(self, event, ...) for _, tableWipe in pairs(table_1) do wipe(tableWipe) end for _, tableWipe in pairs(table_2) do wipe(tableWipe) end dashingBindings() end dashingSplash:RegisterEvent("MODIFIER_STATE_CHANGED") dashingSplash:SetScript("OnEvent", function(self, event, key, state) if state == 1 then mod = string.sub(key, 2) print(mod) else mod = 'nil' print(mod) end end) dashingDismount:Show() dashingDismount:EnableKeyboard(true) dashingDismount:SetPropagateKeyboardInput(true) dashingDismount:RegisterEvent("PLAYER_LOGIN") dashingDismount:RegisterEvent("UPDATE_BINDINGS") --dashingDismount:RegisterEvent("ACTIONBAR_SLOT_CHANGED") dashingDismount:SetScript("OnEvent", dashingUpdate) My question is the following: how can I make the following code more efficient? If you have any input regarding the rest of the addon feel free to provide constructive criticism. Code:
dashingDismount:SetScript("OnKeyDown", function(self, key, ...) local beginTime = debugprofilestop() if IsMounted() then if GetActionBarPage() ~= 2 then if not IsModifierKeyDown() and tContains(table_1.t, key) then Dismount() elseif IsShiftKeyDown() and tContains(table_1.st, key) then Dismount() elseif IsControlKeyDown() and tContains(table_1.ct, key) then Dismount() elseif IsAltKeyDown() and tContains(table_1.at, key) then Dismount() end else if not IsModifierKeyDown() and tContains(table_2.t2, key) then Dismount() elseif IsShiftKeyDown() and tContains(table_2.st2, key) then Dismount() elseif IsControlKeyDown() and tContains(table_2.ct2, key) then Dismount() elseif IsAltKeyDown() and tContains(table_2.at2, key) then Dismount() end end end local timeUsed = debugprofilestop() - beginTime print(timeUsed) end) Last edited by DashingSplash : 06-22-19 at 08:01 AM. |
|
06-22-19, 10:52 AM | #2 |
It appears that the majority of time spent is due to Dismount().
I would assume that there is no way to make that faster since it is latency dependent? |
|
06-23-19, 07:25 PM | #3 |
Oh, boy.
Lua Code:
Last edited by MunkDev : 06-23-19 at 07:36 PM. |
|
06-24-19, 11:28 AM | #4 |
Wow! Now that's some clean and good-looking code. Thank you for the help.
Was really surprised to see that Lua Code:
was a thing. Although, I assume I'll get a better understanding of the API with some experience. The only thing that had to be included in your code was to allow companion, item, and macro functionality. See modified function below. Any input on that? Lua Code:
The only thing I am unsure about is how Lua Code:
works. When and how is the button state set to checked? frame:EnableKeyboard(true) seems moot. Can set it to false (or even remove it completely) and the addon will still work. In my first version I had to set the frame to inherit from UIParent, and then show the frame for EnableKeyboard to actually work. Safe to remove it, or does it actually have some hidden function? Last edited by DashingSplash : 06-24-19 at 11:48 AM. |
|
06-26-19, 08:05 AM | #5 | |||
Lua Code:
Lua Code:
Lua Code:
Casting the shapeshift form generates an event that updates the stance bar, which results in the current stance active having its button set to checked. Lua Code:
|
||||
06-28-19, 12:33 PM | #6 | |
Ended up exporting the Interface code and adding them to Visual Studio with the NPL/Lua language service. Works well enough, but could be better. Serves its purpose at the very least, and I can actually follow the execution path for most things. I am pleased with the dismount AddOn now, but the only downside with it is that it seems to be latency dependent (although, I haven't had an American try it on the beta yet). On retail at 40ms latency the Dismount() function seems to take about 1ms; on classic beta with 120ms latency the Dismount() function seems to take about 3ms. Which seems to cause most abilities to require two button presses, but could be due to other changes/differences between Classic and retail. The only thing I can see myself adding to this AddOn is if there is a way to make the Dismount() function execute faster. I am not entirely sure how a hooksecurefunc works, but I would assume that it would always be executing slower than the actual Dismount() function? Last edited by DashingSplash : 06-28-19 at 12:42 PM. |
||
WoWInterface » Developer Discussions » Lua/XML Help » (Classic) Optimizing table search for auto dismount addon |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|