Mercurial > wow > buffalo2
comparison ObjectiveEvents.lua @ 19:605e8f0e46db
ObjectiveCore / Style / Events / Frame
- polishing the execution path for better performance
- make use of the Blizzard_ObjectiveTracker bitfield values to ensure compatibility in possible secure hooks
- avoid full updates when possible (using said bitfield values to indicate targeted sections)
- extreme streamlining of event handling layout: specific reason updates are invoked from API hooks; broader updates are invoked by when the event listener catches something vague like 'QUEST_LOG_UPDATE'
author | Nenue |
---|---|
date | Wed, 06 Apr 2016 07:38:35 -0400 |
parents | 880828018bf4 |
children | 6bd2102d340b |
comparison
equal
deleted
inserted
replaced
18:d1812fb10ae6 | 19:605e8f0e46db |
---|---|
3 -- @project-revision@ @project-hash@ | 3 -- @project-revision@ @project-hash@ |
4 -- @file-revision@ @file-hash@ | 4 -- @file-revision@ @file-hash@ |
5 -- Created: 3/30/2016 1:23 AM | 5 -- Created: 3/30/2016 1:23 AM |
6 local B = select(2,...).frame | 6 local B = select(2,...).frame |
7 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') | 7 local mod = B:RegisterModule("ObjectiveTracker", _G.VeneerObjectiveWrapper, 'BuffFrame') |
8 local print = B.print('ObjectiveEvent') | 8 local print = B.print('Objectives') |
9 | |
10 local isHooked | |
11 local SmallEvents = { | |
12 QUEST_ACCEPTED = 'OnQuestAccepted', | |
13 QUEST_REMOVED = 'OnQuestRemoved' | |
14 } | |
15 | |
16 --- Using the same values as Blizzard_ObjectiveTracker for use in securehook | |
17 local OBJECTIVE_TRACKER_UPDATE_QUEST = 0x0001; | |
18 local OBJECTIVE_TRACKER_UPDATE_QUEST_ADDED = 0x0002; | |
19 local OBJECTIVE_TRACKER_UPDATE_TASK_ADDED = 0x0004; | |
20 local OBJECTIVE_TRACKER_UPDATE_SCENARIO = 0x0008; | |
21 local OBJECTIVE_TRACKER_UPDATE_SCENARIO_NEW_STAGE = 0x0010; | |
22 local OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT = 0x0020; | |
23 local OBJECTIVE_TRACKER_UPDATE_ACHIEVEMENT_ADDED = 0x0040; | |
24 local OBJECTIVE_TRACKER_UPDATE_SCENARIO_BONUS_DELAYED = 0x0080; | |
25 | |
26 local OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST = 0x0100; | |
27 local OBJECTIVE_TRACKER_UPDATE_MODULE_AUTO_QUEST_POPUP = 0x0200; | |
28 local OBJECTIVE_TRACKER_UPDATE_MODULE_BONUS_OBJECTIVE = 0x0400; | |
29 local OBJECTIVE_TRACKER_UPDATE_MODULE_SCENARIO = 0x0800; | |
30 local OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT = 0x1000; | |
31 | |
32 local OBJECTIVE_TRACKER_UPDATE_STATIC = 0x0000; | |
33 local OBJECTIVE_TRACKER_UPDATE_ALL = 0xFFFF; | |
34 | |
35 local OBJECTIVE_TRACKER_UPDATE_REASON = OBJECTIVE_TRACKER_UPDATE_ALL; -- default | |
36 local OBJECTIVE_TRACKER_UPDATE_ID = 0; | |
37 | |
38 local HandlerEvents = { | |
39 QUEST_ACCEPTED = 0x0003, | |
40 QUEST_WATCH_LIST_CHANGED = 0x0003, | |
41 SUPER_TRACKED_QUEST_CHANGED = mod.Quest, | |
42 QUEST_LOG_UPDATE = mod.Quest, | |
43 TRACKED_ACHIEVEMENT_LIST_CHANGED = mod.Cheevs, | |
44 TRACKED_ACHIEVEMENT_UPDATE = mod.Cheevs | |
45 } | |
46 | |
47 local BlizzHooks = { | |
48 ['AddQuestWatch'] = 'AddQuestWatch', | |
49 ['RemoveQuestWatch'] = 'RemoveQuestWatch', | |
50 ['AbandonQuest'] = 'AbandonQuest', | |
51 ['AcknowledgeAutoAcceptQuest'] = 'AcknowledgeAutoAcceptQuest', | |
52 ['AddAutoQuestPopUp'] = 'AddAutoQuestPopUp', | |
53 ['RemoveAutoQuestPopUp'] = 'RemoveAutoQuestPopUp', | |
54 ['RemoveTrackedAchievement'] = 'RemoveTrackedAchievement' | |
55 } | |
56 | |
57 mod.SetEvents = function() | |
58 | |
59 for event, _ in pairs(SmallEvents) do | |
60 mod:RegisterEvent(event) | |
61 end | |
62 | |
63 for event, _ in pairs(HandlerEvents) do | |
64 mod:RegisterEvent(event) | |
65 end | |
66 mod:SetScript('OnEvent', mod.OnEvent) | |
67 | |
68 | |
69 if not isHooked then | |
70 VeneerData.CallLog = {} | |
71 isHooked = true | |
72 for blizzFunc, veneerFunc in pairs(BlizzHooks) do | |
73 if mod[veneerFunc] then | |
74 hooksecurefunc(blizzFunc, mod[veneerFunc]) | |
75 else | |
76 hooksecurefunc(blizzFunc, function(...) | |
77 print('catching', blizzFunc, ...) | |
78 tinsert(VeneerData.CallLog, {blizzFunc, ...}) | |
79 end) | |
80 end | |
81 end | |
82 | |
83 end | |
84 end | |
85 | |
86 function mod:OnEvent (event, ...) | |
87 local isHandled | |
88 if SmallEvents[event] then | |
89 print('|cFF00FF00'..SmallEvents[event]..'(' ..event..'|r', ...) | |
90 mod[SmallEvents[event]](event, ...) | |
91 isHandled = true | |
92 end | |
93 if HandlerEvents[event] then | |
94 print('|cFF0088FF'..event..'|r wrapper update') | |
95 mod.UpdateWrapper(event) | |
96 isHandled = true | |
97 end | |
98 if not isHandled then | |
99 print('|cFFFF4400'..event..'|r', ...) | |
100 end | |
101 end | |
102 | 9 |
103 -------------------------------------------------------------------- | 10 -------------------------------------------------------------------- |
104 --- Events that are handled by Blizzard_ObjectiveTracker | 11 --- Events that are handled by Blizzard_ObjectiveTracker |
105 -------------------------------------------------------------------- | 12 -------------------------------------------------------------------- |
106 print(mod:GetName()) | |
107 mod.OnQuestAccepted = function(_, questLogIndex, questID) | |
108 AddQuestWatch(questLogIndex) | |
109 SetSuperTrackedQuestID(questID) | |
110 end | |
111 | |
112 mod.OnQuestComplete = function(_, questLogIndex, questID) | |
113 QuestPOIUpdateIcons() | |
114 end | |
115 | |
116 mod.OnQuestFinished = function(_, questLogIndex, questID) | |
117 mod.TrackClosest() | |
118 RemoveQuestWatch(questLogIndex) | |
119 end | |
120 | |
121 | |
122 mod.OnQuestRemoved = function(_, questLogIndex, questID) | |
123 | |
124 mod.UpdateWrapper(0x00000003) | |
125 | |
126 end | |
127 | |
128 mod.OnQuestFromLocation = function(event) end | |
129 | 13 |
130 ------------------------------------------------------------------- | 14 ------------------------------------------------------------------- |
131 --- Function hooks for BlizzUI compatibility | 15 --- Function hooks for BlizzUI compatibility |
132 ------------------------------------------------------------------- | 16 ------------------------------------------------------------------- |
133 mod.AddQuestWatch = function(questID) | 17 mod.AddQuestWatch = function(questID) |
134 mod.UpdateWrapper(0x00000003) | 18 mod:Update(0x00000003) |
135 end | 19 end |
136 | 20 |
137 mod.RemoveQuestWatch = function(questIndex, ...) | 21 mod.RemoveQuestWatch = function(questIndex, ...) |
138 print('|cFFFF8800RemoveQuestWatch', questIndex, ...) | 22 print('|cFFFF8800RemoveQuestWatch', questIndex, ...) |
139 local info = mod.Quest.LogInfo[questIndex] | 23 local info = mod.Quest.LogInfo[questIndex] |
145 -- remove if they still match | 29 -- remove if they still match |
146 if mod.Quest.WatchInfo[info.watchIndex] == info then | 30 if mod.Quest.WatchInfo[info.watchIndex] == info then |
147 print('cleaning dead WatchInfo entry') | 31 print('cleaning dead WatchInfo entry') |
148 mod.Quest.WatchInfo[info.watchIndex] = nil | 32 mod.Quest.WatchInfo[info.watchIndex] = nil |
149 end | 33 end |
34 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST) | |
35 end | |
150 | 36 |
151 mod.UpdateWrapper('RemovedQuestWatch' .. tostring(questIndex)) | 37 mod.AddTrackedAchievement = function(cheevID) |
152 QuestPOIUpdateIcons() | 38 mod.CleanWidgets() |
39 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT) | |
153 end | 40 end |
41 | |
154 | 42 |
155 mod.RemoveTrackedAchievement = function(cheevID) | 43 mod.RemoveTrackedAchievement = function(cheevID) |
156 print('|cFFFF8800UntrackAchievement', cheevID) | 44 print('|cFFFF8800UntrackAchievement', cheevID) |
157 mod.CleanWidgets() | 45 mod.CleanWidgets() |
46 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_ACHIEVEMENT) | |
158 end | 47 end |
159 | 48 |
160 mod.AcceptQuest = function() | 49 mod.AcceptQuest = function() |
50 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST_ADDED) | |
161 end | 51 end |
162 | 52 |
163 mod.AbandonQuest = function() | 53 mod.AbandonQuest = function() |
164 | |
165 QuestPOIUpdateIcons() | 54 QuestPOIUpdateIcons() |
55 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST) | |
56 end | |
57 mod.TurnInQuest = function() | |
58 QuestPOIUpdateIcons() | |
59 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_QUEST) | |
60 end | |
61 mod.AddAutoQuestPopUp = function(...) | |
62 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_AUTO_QUEST_POPUP) | |
63 end | |
64 mod.RemoveAutoQuestPopUp = function(...) | |
65 mod:Update(OBJECTIVE_TRACKER_UPDATE_MODULE_AUTO_QUEST_POPUP) | |
166 end | 66 end |
167 | 67 |
168 mod.TurnInQuest = function() | 68 mod.SetSuperTrackedQuestID = function(questID) |
169 | 69 mod:Update() |
170 QuestPOIUpdateIcons() | |
171 end | 70 end |
172 | |
173 mod.AddAutoQuestPopUp = function(...) | |
174 print('|cFFFF8800AddAutoQuestPopUp|r', ...) | |
175 mod.UpdateWrapper(OBJECTIVE_TRACKER_UPDATE_MODULE_AUTO_QUEST_POPUP) | |
176 end | |
177 mod.RemoveAutoQuestPopUp = function(...) | |
178 print('|cFFFF8800RemoveAutoQuestPopUp|r', ...) | |
179 mod.UpdateWrapper(OBJECTIVE_TRACKER_UPDATE_MODULE_AUTO_QUEST_POPUP) | |
180 end |