WoWInterface - View Single Post - (Classic) Optimizing table search for auto dismount addon
View Single Post
06-28-19, 12:33 PM   #6
A Murloc Raider
Join Date: Jun 2019
Posts: 7
Originally Posted by MunkDev View Post
I didn't really know this either, but given a copy of the UI source code, there's a method to finding what you're looking for by going to the source of something you want to modify and looking at how it works. If you haven't already, get a copy of the source code and use an editor that allows you to search in the code for the things you're interested in. In this case, it seems likely that Blizzard would at some point implement a utility function that returns the current modifier chain, because it's useful in a lot of cases.

I would actually use a table for this, partly for code clarity, and also because it's easier to modify on a whim.
Lua Code:
  1. local dismountTypes = {
  2.     spell = true,
  3.     item = true,
  4.     companion = true,
  5.     macro = false,
  6. }
Lua Code:
  1. if HasAction(action) then
  2.     local actionType, spellID = GetActionInfo(action)
  4.     if dismountTypes[actionType] and not protectedSkills[spellID] then
  5.         Dismount()
  6.     elseif actionType == "macro" then
  7.         spellID, _ = GetMacroSpell(spellID)
  8.         if spellID ~= nil and not protectedSkills[spellID] then
  9.             Dismount()
  10.         end
  11.     end
  12. end
  13. return

I'll give you an example of how to track execution path in this case, which I don't think any tutorial brings up. If you look in Bindings.xml, you'll find that e.g. SHAPESHIFTBUTTON1 is calling StanceBar_Select(1). A quick search for this function gives you this result:
Lua Code:
  1. -- Searching 1364 files for "function StanceBar_Select" (case sensitive)
  2. -- UISourceCode\StanceBar.lua:
  3. function StanceBar_Select (id)
  4.     StanceBarFrame.lastSelected = id;
  5.     CastShapeshiftForm(id);
  6. end

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:
  1. function StanceBar_OnEvent(self, event)
  2.     if(event == "UPDATE_SHAPESHIFT_COOLDOWN") then
  3.         StanceBar_UpdateState();
  4.     end
  5. end
  7. function StanceBar_UpdateState ()
  8.     ...
  9.     if ( isActive ) then
  10.         StanceBarFrame.lastSelected = button:GetID();
  11.         button:SetChecked(true);
  12.     else
  13.         button:SetChecked(false);
  14.     end
  15.     ...
  16. end
Tack så mycket!

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.
  Reply With Quote