flickerstreak@1
|
1 --[[
|
flickerstreak@1
|
2 Name: AceEvent-2.0
|
flickerstreak@1
|
3 Revision: $Rev: 19845 $
|
flickerstreak@1
|
4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
|
flickerstreak@1
|
5 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
|
flickerstreak@1
|
6 Website: http://www.wowace.com/
|
flickerstreak@1
|
7 Documentation: http://www.wowace.com/index.php/AceEvent-2.0
|
flickerstreak@1
|
8 SVN: http://svn.wowace.com/root/trunk/Ace2/AceEvent-2.0
|
flickerstreak@1
|
9 Description: Mixin to allow for event handling, scheduling, and inter-addon
|
flickerstreak@1
|
10 communication.
|
flickerstreak@1
|
11 Dependencies: AceLibrary, AceOO-2.0
|
flickerstreak@1
|
12 ]]
|
flickerstreak@1
|
13
|
flickerstreak@1
|
14 local MAJOR_VERSION = "AceEvent-2.0"
|
flickerstreak@1
|
15 local MINOR_VERSION = "$Revision: 19845 $"
|
flickerstreak@1
|
16
|
flickerstreak@1
|
17 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
|
flickerstreak@1
|
18 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
|
flickerstreak@1
|
19
|
flickerstreak@1
|
20 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
|
flickerstreak@1
|
21
|
flickerstreak@1
|
22 local AceOO = AceLibrary:GetInstance("AceOO-2.0")
|
flickerstreak@1
|
23 local Mixin = AceOO.Mixin
|
flickerstreak@1
|
24 local AceEvent = Mixin {
|
flickerstreak@1
|
25 "RegisterEvent",
|
flickerstreak@1
|
26 "RegisterAllEvents",
|
flickerstreak@1
|
27 "UnregisterEvent",
|
flickerstreak@1
|
28 "UnregisterAllEvents",
|
flickerstreak@1
|
29 "TriggerEvent",
|
flickerstreak@1
|
30 "ScheduleEvent",
|
flickerstreak@1
|
31 "ScheduleRepeatingEvent",
|
flickerstreak@1
|
32 "CancelScheduledEvent",
|
flickerstreak@1
|
33 "CancelAllScheduledEvents",
|
flickerstreak@1
|
34 "IsEventRegistered",
|
flickerstreak@1
|
35 "IsEventScheduled",
|
flickerstreak@1
|
36 "RegisterBucketEvent",
|
flickerstreak@1
|
37 "UnregisterBucketEvent",
|
flickerstreak@1
|
38 "UnregisterAllBucketEvents",
|
flickerstreak@1
|
39 "IsBucketEventRegistered",
|
flickerstreak@1
|
40 }
|
flickerstreak@1
|
41
|
flickerstreak@1
|
42 local weakKey = {__mode="k"}
|
flickerstreak@1
|
43
|
flickerstreak@1
|
44 local FAKE_NIL
|
flickerstreak@1
|
45 local RATE
|
flickerstreak@1
|
46
|
flickerstreak@1
|
47 local eventsWhichHappenOnce = {
|
flickerstreak@1
|
48 PLAYER_LOGIN = true,
|
flickerstreak@1
|
49 AceEvent_FullyInitialized = true,
|
flickerstreak@1
|
50 VARIABLES_LOADED = true,
|
flickerstreak@1
|
51 PLAYER_LOGOUT = true,
|
flickerstreak@1
|
52 }
|
flickerstreak@1
|
53 local next = next
|
flickerstreak@1
|
54 local pairs = pairs
|
flickerstreak@1
|
55 local pcall = pcall
|
flickerstreak@1
|
56 local type = type
|
flickerstreak@1
|
57 local GetTime = GetTime
|
flickerstreak@1
|
58 local gcinfo = gcinfo
|
flickerstreak@1
|
59 local unpack = unpack
|
flickerstreak@1
|
60 local geterrorhandler = geterrorhandler
|
flickerstreak@1
|
61
|
flickerstreak@1
|
62 local registeringFromAceEvent
|
flickerstreak@1
|
63 function AceEvent:RegisterEvent(event, method, once)
|
flickerstreak@1
|
64 AceEvent:argCheck(event, 2, "string")
|
flickerstreak@1
|
65 if self == AceEvent and not registeringFromAceEvent then
|
flickerstreak@1
|
66 AceEvent:argCheck(method, 3, "function")
|
flickerstreak@1
|
67 self = method
|
flickerstreak@1
|
68 else
|
flickerstreak@1
|
69 AceEvent:argCheck(method, 3, "string", "function", "nil", "boolean", "number")
|
flickerstreak@1
|
70 if type(method) == "boolean" or type(method) == "number" then
|
flickerstreak@1
|
71 AceEvent:argCheck(once, 4, "nil")
|
flickerstreak@1
|
72 once, method = method, event
|
flickerstreak@1
|
73 end
|
flickerstreak@1
|
74 end
|
flickerstreak@1
|
75 AceEvent:argCheck(once, 4, "number", "boolean", "nil")
|
flickerstreak@1
|
76 if eventsWhichHappenOnce[event] then
|
flickerstreak@1
|
77 once = true
|
flickerstreak@1
|
78 end
|
flickerstreak@1
|
79 local throttleRate
|
flickerstreak@1
|
80 if type(once) == "number" then
|
flickerstreak@1
|
81 throttleRate, once = once
|
flickerstreak@1
|
82 end
|
flickerstreak@1
|
83 if not method then
|
flickerstreak@1
|
84 method = event
|
flickerstreak@1
|
85 end
|
flickerstreak@1
|
86 if type(method) == "string" and type(self[method]) ~= "function" then
|
flickerstreak@1
|
87 AceEvent:error("Cannot register event %q to method %q, it does not exist", event, method)
|
flickerstreak@1
|
88 else
|
flickerstreak@1
|
89 assert(type(method) == "function" or type(method) == "string")
|
flickerstreak@1
|
90 end
|
flickerstreak@1
|
91
|
flickerstreak@1
|
92 local AceEvent_registry = AceEvent.registry
|
flickerstreak@1
|
93 if not AceEvent_registry[event] then
|
flickerstreak@1
|
94 AceEvent_registry[event] = {}
|
flickerstreak@1
|
95 AceEvent.frame:RegisterEvent(event)
|
flickerstreak@1
|
96 end
|
flickerstreak@1
|
97
|
flickerstreak@1
|
98 local remember = true
|
flickerstreak@1
|
99 if AceEvent_registry[event][self] then
|
flickerstreak@1
|
100 remember = false
|
flickerstreak@1
|
101 end
|
flickerstreak@1
|
102 AceEvent_registry[event][self] = method
|
flickerstreak@1
|
103
|
flickerstreak@1
|
104 local AceEvent_onceRegistry = AceEvent.onceRegistry
|
flickerstreak@1
|
105 if once then
|
flickerstreak@1
|
106 if not AceEvent_onceRegistry then
|
flickerstreak@1
|
107 AceEvent.onceRegistry = {}
|
flickerstreak@1
|
108 AceEvent_onceRegistry = AceEvent.onceRegistry
|
flickerstreak@1
|
109 end
|
flickerstreak@1
|
110 if not AceEvent_onceRegistry[event] then
|
flickerstreak@1
|
111 AceEvent_onceRegistry[event] = {}
|
flickerstreak@1
|
112 end
|
flickerstreak@1
|
113 AceEvent_onceRegistry[event][self] = true
|
flickerstreak@1
|
114 else
|
flickerstreak@1
|
115 if AceEvent_onceRegistry and AceEvent_onceRegistry[event] then
|
flickerstreak@1
|
116 AceEvent_onceRegistry[event][self] = nil
|
flickerstreak@1
|
117 if not next(AceEvent_onceRegistry[event]) then
|
flickerstreak@1
|
118 AceEvent_onceRegistry[event] = nil
|
flickerstreak@1
|
119 end
|
flickerstreak@1
|
120 end
|
flickerstreak@1
|
121 end
|
flickerstreak@1
|
122
|
flickerstreak@1
|
123 local AceEvent_throttleRegistry = AceEvent.throttleRegistry
|
flickerstreak@1
|
124 if throttleRate then
|
flickerstreak@1
|
125 if not AceEvent_throttleRegistry then
|
flickerstreak@1
|
126 AceEvent.throttleRegistry = {}
|
flickerstreak@1
|
127 AceEvent_throttleRegistry = AceEvent.throttleRegistry
|
flickerstreak@1
|
128 end
|
flickerstreak@1
|
129 if not AceEvent_throttleRegistry[event] then
|
flickerstreak@1
|
130 AceEvent_throttleRegistry[event] = {}
|
flickerstreak@1
|
131 end
|
flickerstreak@1
|
132 if AceEvent_throttleRegistry[event][self] then
|
flickerstreak@1
|
133 AceEvent_throttleRegistry[event][self] = nil
|
flickerstreak@1
|
134 end
|
flickerstreak@1
|
135 AceEvent_throttleRegistry[event][self] = setmetatable({}, weakKey)
|
flickerstreak@1
|
136 local t = AceEvent_throttleRegistry[event][self]
|
flickerstreak@1
|
137 t[RATE] = throttleRate
|
flickerstreak@1
|
138 else
|
flickerstreak@1
|
139 if AceEvent_throttleRegistry and AceEvent_throttleRegistry[event] then
|
flickerstreak@1
|
140 if AceEvent_throttleRegistry[event][self] then
|
flickerstreak@1
|
141 AceEvent_throttleRegistry[event][self] = nil
|
flickerstreak@1
|
142 end
|
flickerstreak@1
|
143 if not next(AceEvent_throttleRegistry[event]) then
|
flickerstreak@1
|
144 AceEvent_throttleRegistry[event] = nil
|
flickerstreak@1
|
145 end
|
flickerstreak@1
|
146 end
|
flickerstreak@1
|
147 end
|
flickerstreak@1
|
148
|
flickerstreak@1
|
149 if remember then
|
flickerstreak@1
|
150 AceEvent:TriggerEvent("AceEvent_EventRegistered", self, event)
|
flickerstreak@1
|
151 end
|
flickerstreak@1
|
152 end
|
flickerstreak@1
|
153
|
flickerstreak@1
|
154 local ALL_EVENTS
|
flickerstreak@1
|
155
|
flickerstreak@1
|
156 function AceEvent:RegisterAllEvents(method)
|
flickerstreak@1
|
157 if self == AceEvent then
|
flickerstreak@1
|
158 AceEvent:argCheck(method, 1, "function")
|
flickerstreak@1
|
159 self = method
|
flickerstreak@1
|
160 else
|
flickerstreak@1
|
161 AceEvent:argCheck(method, 1, "string", "function")
|
flickerstreak@1
|
162 if type(method) == "string" and type(self[method]) ~= "function" then
|
flickerstreak@1
|
163 AceEvent:error("Cannot register all events to method %q, it does not exist", method)
|
flickerstreak@1
|
164 end
|
flickerstreak@1
|
165 end
|
flickerstreak@1
|
166
|
flickerstreak@1
|
167 local AceEvent_registry = AceEvent.registry
|
flickerstreak@1
|
168 if not AceEvent_registry[ALL_EVENTS] then
|
flickerstreak@1
|
169 AceEvent_registry[ALL_EVENTS] = {}
|
flickerstreak@1
|
170 AceEvent.frame:RegisterAllEvents()
|
flickerstreak@1
|
171 end
|
flickerstreak@1
|
172
|
flickerstreak@1
|
173 AceEvent_registry[ALL_EVENTS][self] = method
|
flickerstreak@1
|
174 end
|
flickerstreak@1
|
175
|
flickerstreak@1
|
176 local memstack, timestack = {}, {}
|
flickerstreak@1
|
177 local memdiff, timediff
|
flickerstreak@1
|
178
|
flickerstreak@1
|
179 local stack = setmetatable({}, {__mode='k'})
|
flickerstreak@1
|
180 function AceEvent:TriggerEvent(event, ...)
|
flickerstreak@1
|
181 local tmp = next(stack) or {}
|
flickerstreak@1
|
182 stack[tmp] = nil
|
flickerstreak@1
|
183 if type(event) ~= "string" then
|
flickerstreak@1
|
184 DEFAULT_CHAT_FRAME:AddMessage(debugstack())
|
flickerstreak@1
|
185 end
|
flickerstreak@1
|
186 AceEvent:argCheck(event, 2, "string")
|
flickerstreak@1
|
187 local AceEvent_registry = AceEvent.registry
|
flickerstreak@1
|
188 if (not AceEvent_registry[event] or not next(AceEvent_registry[event])) and (not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS])) then
|
flickerstreak@1
|
189 return
|
flickerstreak@1
|
190 end
|
flickerstreak@1
|
191 local lastEvent = AceEvent.currentEvent
|
flickerstreak@1
|
192 AceEvent.currentEvent = event
|
flickerstreak@1
|
193
|
flickerstreak@1
|
194 local AceEvent_onceRegistry = AceEvent.onceRegistry
|
flickerstreak@1
|
195 local AceEvent_debugTable = AceEvent.debugTable
|
flickerstreak@1
|
196 if AceEvent_onceRegistry and AceEvent_onceRegistry[event] then
|
flickerstreak@1
|
197 for obj, method in pairs(AceEvent_onceRegistry[event]) do
|
flickerstreak@1
|
198 tmp[obj] = AceEvent_registry[event] and AceEvent_registry[event][obj] or nil
|
flickerstreak@1
|
199 end
|
flickerstreak@1
|
200 local obj = next(tmp)
|
flickerstreak@1
|
201 while obj do
|
flickerstreak@1
|
202 local mem, time
|
flickerstreak@1
|
203 if AceEvent_debugTable then
|
flickerstreak@1
|
204 if not AceEvent_debugTable[event] then
|
flickerstreak@1
|
205 AceEvent_debugTable[event] = {}
|
flickerstreak@1
|
206 end
|
flickerstreak@1
|
207 if not AceEvent_debugTable[event][obj] then
|
flickerstreak@1
|
208 AceEvent_debugTable[event][obj] = {
|
flickerstreak@1
|
209 mem = 0,
|
flickerstreak@1
|
210 time = 0,
|
flickerstreak@1
|
211 count = 0,
|
flickerstreak@1
|
212 }
|
flickerstreak@1
|
213 end
|
flickerstreak@1
|
214 if memdiff then
|
flickerstreak@1
|
215 table.insert(memstack, memdiff)
|
flickerstreak@1
|
216 table.insert(timestack, timediff)
|
flickerstreak@1
|
217 end
|
flickerstreak@1
|
218 memdiff, timediff = 0, 0
|
flickerstreak@1
|
219 mem, time = gcinfo(), GetTime()
|
flickerstreak@1
|
220 end
|
flickerstreak@1
|
221 local method = tmp[obj]
|
flickerstreak@1
|
222 AceEvent.UnregisterEvent(obj, event)
|
flickerstreak@1
|
223 if type(method) == "string" then
|
flickerstreak@1
|
224 local obj_method = obj[method]
|
flickerstreak@1
|
225 if obj_method then
|
flickerstreak@1
|
226 local success, err = pcall(obj_method, obj, ...)
|
flickerstreak@1
|
227 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
228 end
|
flickerstreak@1
|
229 elseif method then -- function
|
flickerstreak@1
|
230 local success, err = pcall(method, ...)
|
flickerstreak@1
|
231 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
232 end
|
flickerstreak@1
|
233 if AceEvent_debugTable then
|
flickerstreak@1
|
234 local dmem, dtime = memdiff, timediff
|
flickerstreak@1
|
235 mem, time = gcinfo() - mem - memdiff, GetTime() - time - timediff
|
flickerstreak@1
|
236 AceEvent_debugTable[event][obj].mem = AceEvent_debugTable[event][obj].mem + mem
|
flickerstreak@1
|
237 AceEvent_debugTable[event][obj].time = AceEvent_debugTable[event][obj].time + time
|
flickerstreak@1
|
238 AceEvent_debugTable[event][obj].count = AceEvent_debugTable[event][obj].count + 1
|
flickerstreak@1
|
239
|
flickerstreak@1
|
240 memdiff, timediff = table.remove(memstack), table.remove(timestack)
|
flickerstreak@1
|
241 if memdiff then
|
flickerstreak@1
|
242 memdiff = memdiff + mem + dmem
|
flickerstreak@1
|
243 timediff = timediff + time + dtime
|
flickerstreak@1
|
244 end
|
flickerstreak@1
|
245 end
|
flickerstreak@1
|
246 tmp[obj] = nil
|
flickerstreak@1
|
247 obj = next(tmp)
|
flickerstreak@1
|
248 end
|
flickerstreak@1
|
249 end
|
flickerstreak@1
|
250
|
flickerstreak@1
|
251 local AceEvent_throttleRegistry = AceEvent.throttleRegistry
|
flickerstreak@1
|
252 local throttleTable = AceEvent_throttleRegistry and AceEvent_throttleRegistry[event]
|
flickerstreak@1
|
253 if AceEvent_registry[event] then
|
flickerstreak@1
|
254 for obj, method in pairs(AceEvent_registry[event]) do
|
flickerstreak@1
|
255 tmp[obj] = method
|
flickerstreak@1
|
256 end
|
flickerstreak@1
|
257 local obj = next(tmp)
|
flickerstreak@1
|
258 while obj do
|
flickerstreak@1
|
259 local method = tmp[obj]
|
flickerstreak@1
|
260 local continue = false
|
flickerstreak@1
|
261 if throttleTable and throttleTable[obj] then
|
flickerstreak@1
|
262 local a1 = ...
|
flickerstreak@1
|
263 if a1 == nil then
|
flickerstreak@1
|
264 a1 = FAKE_NIL
|
flickerstreak@1
|
265 end
|
flickerstreak@1
|
266 if not throttleTable[obj][a1] or GetTime() - throttleTable[obj][a1] >= throttleTable[obj][RATE] then
|
flickerstreak@1
|
267 throttleTable[obj][a1] = GetTime()
|
flickerstreak@1
|
268 else
|
flickerstreak@1
|
269 continue = true
|
flickerstreak@1
|
270 end
|
flickerstreak@1
|
271 end
|
flickerstreak@1
|
272 if not continue then
|
flickerstreak@1
|
273 local mem, time
|
flickerstreak@1
|
274 if AceEvent_debugTable then
|
flickerstreak@1
|
275 if not AceEvent_debugTable[event] then
|
flickerstreak@1
|
276 AceEvent_debugTable[event] = {}
|
flickerstreak@1
|
277 end
|
flickerstreak@1
|
278 if not AceEvent_debugTable[event][obj] then
|
flickerstreak@1
|
279 AceEvent_debugTable[event][obj] = {
|
flickerstreak@1
|
280 mem = 0,
|
flickerstreak@1
|
281 time = 0,
|
flickerstreak@1
|
282 count = 0,
|
flickerstreak@1
|
283 }
|
flickerstreak@1
|
284 end
|
flickerstreak@1
|
285 if memdiff then
|
flickerstreak@1
|
286 table.insert(memstack, memdiff)
|
flickerstreak@1
|
287 table.insert(timestack, timediff)
|
flickerstreak@1
|
288 end
|
flickerstreak@1
|
289 memdiff, timediff = 0, 0
|
flickerstreak@1
|
290 mem, time = gcinfo(), GetTime()
|
flickerstreak@1
|
291 end
|
flickerstreak@1
|
292 if type(method) == "string" then
|
flickerstreak@1
|
293 local obj_method = obj[method]
|
flickerstreak@1
|
294 if obj_method then
|
flickerstreak@1
|
295 local success, err = pcall(obj_method, obj, ...)
|
flickerstreak@1
|
296 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
297 end
|
flickerstreak@1
|
298 elseif method then -- function
|
flickerstreak@1
|
299 local success, err = pcall(method, ...)
|
flickerstreak@1
|
300 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
301 end
|
flickerstreak@1
|
302 if AceEvent_debugTable then
|
flickerstreak@1
|
303 local dmem, dtime = memdiff, timediff
|
flickerstreak@1
|
304 mem, time = gcinfo() - mem - memdiff, GetTime() - time - timediff
|
flickerstreak@1
|
305 AceEvent_debugTable[event][obj].mem = AceEvent_debugTable[event][obj].mem + mem
|
flickerstreak@1
|
306 AceEvent_debugTable[event][obj].time = AceEvent_debugTable[event][obj].time + time
|
flickerstreak@1
|
307 AceEvent_debugTable[event][obj].count = AceEvent_debugTable[event][obj].count + 1
|
flickerstreak@1
|
308
|
flickerstreak@1
|
309 memdiff, timediff = table.remove(memstack), table.remove(timestack)
|
flickerstreak@1
|
310 if memdiff then
|
flickerstreak@1
|
311 memdiff = memdiff + mem + dmem
|
flickerstreak@1
|
312 timediff = timediff + time + dtime
|
flickerstreak@1
|
313 end
|
flickerstreak@1
|
314 end
|
flickerstreak@1
|
315 end
|
flickerstreak@1
|
316 tmp[obj] = nil
|
flickerstreak@1
|
317 obj = next(tmp)
|
flickerstreak@1
|
318 end
|
flickerstreak@1
|
319 end
|
flickerstreak@1
|
320 if AceEvent_registry[ALL_EVENTS] then
|
flickerstreak@1
|
321 for obj, method in pairs(AceEvent_registry[ALL_EVENTS]) do
|
flickerstreak@1
|
322 tmp[obj] = method
|
flickerstreak@1
|
323 end
|
flickerstreak@1
|
324 local obj = next(tmp)
|
flickerstreak@1
|
325 while obj do
|
flickerstreak@1
|
326 local method = tmp[obj]
|
flickerstreak@1
|
327 local mem, time
|
flickerstreak@1
|
328 if AceEvent_debugTable then
|
flickerstreak@1
|
329 if not AceEvent_debugTable[event] then
|
flickerstreak@1
|
330 AceEvent_debugTable[event] = {}
|
flickerstreak@1
|
331 end
|
flickerstreak@1
|
332 if not AceEvent_debugTable[event][obj] then
|
flickerstreak@1
|
333 AceEvent_debugTable[event][obj] = {}
|
flickerstreak@1
|
334 AceEvent_debugTable[event][obj].mem = 0
|
flickerstreak@1
|
335 AceEvent_debugTable[event][obj].time = 0
|
flickerstreak@1
|
336 AceEvent_debugTable[event][obj].count = 0
|
flickerstreak@1
|
337 end
|
flickerstreak@1
|
338 if memdiff then
|
flickerstreak@1
|
339 table.insert(memstack, memdiff)
|
flickerstreak@1
|
340 table.insert(timestack, timediff)
|
flickerstreak@1
|
341 end
|
flickerstreak@1
|
342 memdiff, timediff = 0, 0
|
flickerstreak@1
|
343 mem, time = gcinfo(), GetTime()
|
flickerstreak@1
|
344 end
|
flickerstreak@1
|
345 if type(method) == "string" then
|
flickerstreak@1
|
346 local obj_method = obj[method]
|
flickerstreak@1
|
347 if obj_method then
|
flickerstreak@1
|
348 obj_method(obj, ...)
|
flickerstreak@1
|
349 local success, err = pcall(obj_method, obj, ...)
|
flickerstreak@1
|
350 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
351 end
|
flickerstreak@1
|
352 elseif method then -- function
|
flickerstreak@1
|
353 local success, err = pcall(method, ...)
|
flickerstreak@1
|
354 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
355 end
|
flickerstreak@1
|
356 if AceEvent_debugTable then
|
flickerstreak@1
|
357 local dmem, dtime = memdiff, timediff
|
flickerstreak@1
|
358 mem, time = gcinfo() - mem - memdiff, GetTime() - time - timediff
|
flickerstreak@1
|
359 AceEvent_debugTable[event][obj].mem = AceEvent_debugTable[event][obj].mem + mem
|
flickerstreak@1
|
360 AceEvent_debugTable[event][obj].time = AceEvent_debugTable[event][obj].time + time
|
flickerstreak@1
|
361 AceEvent_debugTable[event][obj].count = AceEvent_debugTable[event][obj].count + 1
|
flickerstreak@1
|
362
|
flickerstreak@1
|
363 memdiff, timediff = table.remove(memstack), table.remove(timestack)
|
flickerstreak@1
|
364 if memdiff then
|
flickerstreak@1
|
365 memdiff = memdiff + mem + dmem
|
flickerstreak@1
|
366 timediff = timediff + time + dtime
|
flickerstreak@1
|
367 end
|
flickerstreak@1
|
368 end
|
flickerstreak@1
|
369 tmp[obj] = nil
|
flickerstreak@1
|
370 obj = next(tmp)
|
flickerstreak@1
|
371 end
|
flickerstreak@1
|
372 end
|
flickerstreak@1
|
373 stack[tmp] = true
|
flickerstreak@1
|
374 AceEvent.currentEvent = lastEvent
|
flickerstreak@1
|
375 end
|
flickerstreak@1
|
376
|
flickerstreak@1
|
377 local delayRegistry
|
flickerstreak@1
|
378 local tmp = {}
|
flickerstreak@1
|
379 local function OnUpdate()
|
flickerstreak@1
|
380 local t = GetTime()
|
flickerstreak@1
|
381 for k,v in pairs(delayRegistry) do
|
flickerstreak@1
|
382 tmp[k] = true
|
flickerstreak@1
|
383 end
|
flickerstreak@1
|
384 for k in pairs(tmp) do
|
flickerstreak@1
|
385 local v = delayRegistry[k]
|
flickerstreak@1
|
386 if v then
|
flickerstreak@1
|
387 local v_time = v.time
|
flickerstreak@1
|
388 if not v_time then
|
flickerstreak@1
|
389 delayRegistry[k] = nil
|
flickerstreak@1
|
390 elseif v_time <= t then
|
flickerstreak@1
|
391 local v_repeatDelay = v.repeatDelay
|
flickerstreak@1
|
392 if v_repeatDelay then
|
flickerstreak@1
|
393 -- use the event time, not the current time, else timing inaccuracies add up over time
|
flickerstreak@1
|
394 v.time = v_time + v_repeatDelay
|
flickerstreak@1
|
395 end
|
flickerstreak@1
|
396 local event = v.event
|
flickerstreak@1
|
397 local mem, time
|
flickerstreak@1
|
398 if AceEvent_debugTable then
|
flickerstreak@1
|
399 mem, time = gcinfo(), GetTime()
|
flickerstreak@1
|
400 end
|
flickerstreak@1
|
401 if type(event) == "function" then
|
flickerstreak@1
|
402 local success, err = pcall(event, unpack(v))
|
flickerstreak@1
|
403 if not success then geterrorhandler()(err) end
|
flickerstreak@1
|
404 else
|
flickerstreak@1
|
405 AceEvent:TriggerEvent(event, unpack(v))
|
flickerstreak@1
|
406 end
|
flickerstreak@1
|
407 if AceEvent_debugTable then
|
flickerstreak@1
|
408 mem, time = gcinfo() - mem, GetTime() - time
|
flickerstreak@1
|
409 v.mem = v.mem + mem
|
flickerstreak@1
|
410 v.timeSpent = v.timeSpent + time
|
flickerstreak@1
|
411 v.count = v.count + 1
|
flickerstreak@1
|
412 end
|
flickerstreak@1
|
413 if not v_repeatDelay then
|
flickerstreak@1
|
414 local x = delayRegistry[k]
|
flickerstreak@1
|
415 if x and x.time == v_time then -- check if it was manually reset
|
flickerstreak@1
|
416 delayRegistry[k] = nil
|
flickerstreak@1
|
417 end
|
flickerstreak@1
|
418 end
|
flickerstreak@1
|
419 end
|
flickerstreak@1
|
420 end
|
flickerstreak@1
|
421 end
|
flickerstreak@1
|
422 for k in pairs(tmp) do
|
flickerstreak@1
|
423 tmp[k] = nil
|
flickerstreak@1
|
424 end
|
flickerstreak@1
|
425 if not next(delayRegistry) then
|
flickerstreak@1
|
426 AceEvent.frame:Hide()
|
flickerstreak@1
|
427 end
|
flickerstreak@1
|
428 end
|
flickerstreak@1
|
429
|
flickerstreak@1
|
430 local function ScheduleEvent(self, repeating, event, delay, ...)
|
flickerstreak@1
|
431 local id
|
flickerstreak@1
|
432 if type(event) == "string" or type(event) == "table" then
|
flickerstreak@1
|
433 if type(event) == "table" then
|
flickerstreak@1
|
434 if not delayRegistry or not delayRegistry[event] then
|
flickerstreak@1
|
435 AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
|
flickerstreak@1
|
436 end
|
flickerstreak@1
|
437 end
|
flickerstreak@1
|
438 if type(delay) ~= "number" then
|
flickerstreak@1
|
439 id, event, delay = event, delay, ...
|
flickerstreak@1
|
440 AceEvent:argCheck(event, 3, "string", "function", --[[ so message is right ]] "number")
|
flickerstreak@1
|
441 AceEvent:argCheck(delay, 4, "number")
|
flickerstreak@1
|
442 self:CancelScheduledEvent(id)
|
flickerstreak@1
|
443 end
|
flickerstreak@1
|
444 else
|
flickerstreak@1
|
445 AceEvent:argCheck(event, 2, "string", "function")
|
flickerstreak@1
|
446 AceEvent:argCheck(delay, 3, "number")
|
flickerstreak@1
|
447 end
|
flickerstreak@1
|
448
|
flickerstreak@1
|
449 if not delayRegistry then
|
flickerstreak@1
|
450 AceEvent.delayRegistry = {}
|
flickerstreak@1
|
451 delayRegistry = AceEvent.delayRegistry
|
flickerstreak@1
|
452 AceEvent.frame:SetScript("OnUpdate", OnUpdate)
|
flickerstreak@1
|
453 end
|
flickerstreak@1
|
454 local t
|
flickerstreak@1
|
455 if type(id) == "table" then
|
flickerstreak@1
|
456 for k in pairs(id) do
|
flickerstreak@1
|
457 id[k] = nil
|
flickerstreak@1
|
458 end
|
flickerstreak@1
|
459 t = id
|
flickerstreak@1
|
460 for i = 2, select('#', ...) do
|
flickerstreak@1
|
461 t[i-1] = select(i, ...)
|
flickerstreak@1
|
462 end
|
flickerstreak@1
|
463 elseif id then
|
flickerstreak@1
|
464 t = { select(2, ...) }
|
flickerstreak@1
|
465 else
|
flickerstreak@1
|
466 t = { ... }
|
flickerstreak@1
|
467 end
|
flickerstreak@1
|
468 t.event = event
|
flickerstreak@1
|
469 t.time = GetTime() + delay
|
flickerstreak@1
|
470 t.self = self
|
flickerstreak@1
|
471 t.id = id or t
|
flickerstreak@1
|
472 t.repeatDelay = repeating and delay
|
flickerstreak@1
|
473 if AceEvent_debugTable then
|
flickerstreak@1
|
474 t.mem = 0
|
flickerstreak@1
|
475 t.count = 0
|
flickerstreak@1
|
476 t.timeSpent = 0
|
flickerstreak@1
|
477 end
|
flickerstreak@1
|
478 delayRegistry[t.id] = t
|
flickerstreak@1
|
479 AceEvent.frame:Show()
|
flickerstreak@1
|
480 return t.id
|
flickerstreak@1
|
481 end
|
flickerstreak@1
|
482
|
flickerstreak@1
|
483 function AceEvent:ScheduleEvent(event, delay, ...)
|
flickerstreak@1
|
484 if type(event) == "string" or type(event) == "table" then
|
flickerstreak@1
|
485 if type(event) == "table" then
|
flickerstreak@1
|
486 if not delayRegistry or not delayRegistry[event] then
|
flickerstreak@1
|
487 AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
|
flickerstreak@1
|
488 end
|
flickerstreak@1
|
489 end
|
flickerstreak@1
|
490 if type(delay) ~= "number" then
|
flickerstreak@1
|
491 AceEvent:argCheck(delay, 3, "string", "function", --[[ so message is right ]] "number")
|
flickerstreak@1
|
492 AceEvent:argCheck(..., 4, "number")
|
flickerstreak@1
|
493 end
|
flickerstreak@1
|
494 else
|
flickerstreak@1
|
495 AceEvent:argCheck(event, 2, "string", "function")
|
flickerstreak@1
|
496 AceEvent:argCheck(delay, 3, "number")
|
flickerstreak@1
|
497 end
|
flickerstreak@1
|
498
|
flickerstreak@1
|
499 return ScheduleEvent(self, false, event, delay, ...)
|
flickerstreak@1
|
500 end
|
flickerstreak@1
|
501
|
flickerstreak@1
|
502 function AceEvent:ScheduleRepeatingEvent(event, delay, ...)
|
flickerstreak@1
|
503 if type(event) == "string" or type(event) == "table" then
|
flickerstreak@1
|
504 if type(event) == "table" then
|
flickerstreak@1
|
505 if not delayRegistry or not delayRegistry[event] then
|
flickerstreak@1
|
506 AceEvent:error("Bad argument #2 to `ScheduleEvent'. Improper id table fed in.")
|
flickerstreak@1
|
507 end
|
flickerstreak@1
|
508 end
|
flickerstreak@1
|
509 if type(delay) ~= "number" then
|
flickerstreak@1
|
510 AceEvent:argCheck(delay, 3, "string", "function", --[[ so message is right ]] "number")
|
flickerstreak@1
|
511 AceEvent:argCheck(..., 4, "number")
|
flickerstreak@1
|
512 end
|
flickerstreak@1
|
513 else
|
flickerstreak@1
|
514 AceEvent:argCheck(event, 2, "string", "function")
|
flickerstreak@1
|
515 AceEvent:argCheck(delay, 3, "number")
|
flickerstreak@1
|
516 end
|
flickerstreak@1
|
517
|
flickerstreak@1
|
518 return ScheduleEvent(self, true, event, delay, ...)
|
flickerstreak@1
|
519 end
|
flickerstreak@1
|
520
|
flickerstreak@1
|
521 function AceEvent:CancelScheduledEvent(t)
|
flickerstreak@1
|
522 AceEvent:argCheck(t, 2, "string", "table")
|
flickerstreak@1
|
523 if delayRegistry then
|
flickerstreak@1
|
524 local v = delayRegistry[t]
|
flickerstreak@1
|
525 if v then
|
flickerstreak@1
|
526 delayRegistry[t] = nil
|
flickerstreak@1
|
527 if not next(delayRegistry) then
|
flickerstreak@1
|
528 AceEvent.frame:Hide()
|
flickerstreak@1
|
529 end
|
flickerstreak@1
|
530 return true
|
flickerstreak@1
|
531 end
|
flickerstreak@1
|
532 end
|
flickerstreak@1
|
533 return false
|
flickerstreak@1
|
534 end
|
flickerstreak@1
|
535
|
flickerstreak@1
|
536 function AceEvent:IsEventScheduled(t)
|
flickerstreak@1
|
537 AceEvent:argCheck(t, 2, "string", "table")
|
flickerstreak@1
|
538 if delayRegistry then
|
flickerstreak@1
|
539 local v = delayRegistry[t]
|
flickerstreak@1
|
540 if v then
|
flickerstreak@1
|
541 return true, v.time - GetTime()
|
flickerstreak@1
|
542 end
|
flickerstreak@1
|
543 end
|
flickerstreak@1
|
544 return false, nil
|
flickerstreak@1
|
545 end
|
flickerstreak@1
|
546
|
flickerstreak@1
|
547 function AceEvent:UnregisterEvent(event)
|
flickerstreak@1
|
548 AceEvent:argCheck(event, 2, "string")
|
flickerstreak@1
|
549 local AceEvent_registry = AceEvent.registry
|
flickerstreak@1
|
550 if AceEvent_registry[event] and AceEvent_registry[event][self] then
|
flickerstreak@1
|
551 AceEvent_registry[event][self] = nil
|
flickerstreak@1
|
552 local AceEvent_onceRegistry = AceEvent.onceRegistry
|
flickerstreak@1
|
553 if AceEvent_onceRegistry and AceEvent_onceRegistry[event] and AceEvent_onceRegistry[event][self] then
|
flickerstreak@1
|
554 AceEvent_onceRegistry[event][self] = nil
|
flickerstreak@1
|
555 if not next(AceEvent_onceRegistry[event]) then
|
flickerstreak@1
|
556 AceEvent_onceRegistry[event] = nil
|
flickerstreak@1
|
557 end
|
flickerstreak@1
|
558 end
|
flickerstreak@1
|
559 local AceEvent_throttleRegistry = AceEvent.throttleRegistry
|
flickerstreak@1
|
560 if AceEvent_throttleRegistry and AceEvent_throttleRegistry[event] and AceEvent_throttleRegistry[event][self] then
|
flickerstreak@1
|
561 AceEvent_throttleRegistry[event][self] = nil
|
flickerstreak@1
|
562 if not next(AceEvent_throttleRegistry[event]) then
|
flickerstreak@1
|
563 AceEvent_throttleRegistry[event] = nil
|
flickerstreak@1
|
564 end
|
flickerstreak@1
|
565 end
|
flickerstreak@1
|
566 if not next(AceEvent_registry[event]) then
|
flickerstreak@1
|
567 AceEvent_registry[event] = nil
|
flickerstreak@1
|
568 if not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS]) then
|
flickerstreak@1
|
569 AceEvent.frame:UnregisterEvent(event)
|
flickerstreak@1
|
570 end
|
flickerstreak@1
|
571 end
|
flickerstreak@1
|
572 else
|
flickerstreak@1
|
573 if self == AceEvent then
|
flickerstreak@1
|
574 error(string.format("Cannot unregister event %q. Improperly unregistering from AceEvent-2.0.", event), 2)
|
flickerstreak@1
|
575 else
|
flickerstreak@1
|
576 AceEvent:error("Cannot unregister event %q. %q is not registered with it.", event, self)
|
flickerstreak@1
|
577 end
|
flickerstreak@1
|
578 end
|
flickerstreak@1
|
579 AceEvent:TriggerEvent("AceEvent_EventUnregistered", self, event)
|
flickerstreak@1
|
580 end
|
flickerstreak@1
|
581
|
flickerstreak@1
|
582 function AceEvent:UnregisterAllEvents()
|
flickerstreak@1
|
583 local AceEvent_registry = AceEvent.registry
|
flickerstreak@1
|
584 if AceEvent_registry[ALL_EVENTS] and AceEvent_registry[ALL_EVENTS][self] then
|
flickerstreak@1
|
585 AceEvent_registry[ALL_EVENTS][self] = nil
|
flickerstreak@1
|
586 if not next(AceEvent_registry[ALL_EVENTS]) then
|
flickerstreak@1
|
587 AceEvent.frame:UnregisterAllEvents()
|
flickerstreak@1
|
588 for k,v in pairs(AceEvent_registry) do
|
flickerstreak@1
|
589 if k ~= ALL_EVENTS then
|
flickerstreak@1
|
590 AceEvent.frame:RegisterEvent(k)
|
flickerstreak@1
|
591 end
|
flickerstreak@1
|
592 end
|
flickerstreak@1
|
593 AceEvent_registry[ALL_EVENTS] = nil
|
flickerstreak@1
|
594 end
|
flickerstreak@1
|
595 end
|
flickerstreak@1
|
596 local first = true
|
flickerstreak@1
|
597 for event, data in pairs(AceEvent_registry) do
|
flickerstreak@1
|
598 if first then
|
flickerstreak@1
|
599 if AceEvent_registry.AceEvent_EventUnregistered then
|
flickerstreak@1
|
600 event = "AceEvent_EventUnregistered"
|
flickerstreak@1
|
601 else
|
flickerstreak@1
|
602 first = false
|
flickerstreak@1
|
603 end
|
flickerstreak@1
|
604 end
|
flickerstreak@1
|
605 local x = data[self]
|
flickerstreak@1
|
606 data[self] = nil
|
flickerstreak@1
|
607 if x and event ~= ALL_EVENTS then
|
flickerstreak@1
|
608 if not next(data) then
|
flickerstreak@1
|
609 if not AceEvent_registry[ALL_EVENTS] or not next(AceEvent_registry[ALL_EVENTS]) then
|
flickerstreak@1
|
610 AceEvent.frame:UnregisterEvent(event)
|
flickerstreak@1
|
611 end
|
flickerstreak@1
|
612 AceEvent_registry[event] = nil
|
flickerstreak@1
|
613 end
|
flickerstreak@1
|
614 AceEvent:TriggerEvent("AceEvent_EventUnregistered", self, event)
|
flickerstreak@1
|
615 end
|
flickerstreak@1
|
616 if first then
|
flickerstreak@1
|
617 event = nil
|
flickerstreak@1
|
618 end
|
flickerstreak@1
|
619 end
|
flickerstreak@1
|
620 if AceEvent.onceRegistry then
|
flickerstreak@1
|
621 for event, data in pairs(AceEvent.onceRegistry) do
|
flickerstreak@1
|
622 data[self] = nil
|
flickerstreak@1
|
623 end
|
flickerstreak@1
|
624 end
|
flickerstreak@1
|
625 end
|
flickerstreak@1
|
626
|
flickerstreak@1
|
627 function AceEvent:CancelAllScheduledEvents()
|
flickerstreak@1
|
628 if delayRegistry then
|
flickerstreak@1
|
629 for k,v in pairs(delayRegistry) do
|
flickerstreak@1
|
630 if v.self == self then
|
flickerstreak@1
|
631 delayRegistry[k] = nil
|
flickerstreak@1
|
632 end
|
flickerstreak@1
|
633 end
|
flickerstreak@1
|
634 if not next(delayRegistry) then
|
flickerstreak@1
|
635 AceEvent.frame:Hide()
|
flickerstreak@1
|
636 end
|
flickerstreak@1
|
637 end
|
flickerstreak@1
|
638 end
|
flickerstreak@1
|
639
|
flickerstreak@1
|
640 function AceEvent:IsEventRegistered(event)
|
flickerstreak@1
|
641 AceEvent:argCheck(event, 2, "string")
|
flickerstreak@1
|
642 local AceEvent_registry = AceEvent.registry
|
flickerstreak@1
|
643 if self == AceEvent then
|
flickerstreak@1
|
644 return AceEvent_registry[event] and next(AceEvent_registry[event]) and true or false
|
flickerstreak@1
|
645 end
|
flickerstreak@1
|
646 if AceEvent_registry[event] and AceEvent_registry[event][self] then
|
flickerstreak@1
|
647 return true, AceEvent_registry[event][self]
|
flickerstreak@1
|
648 end
|
flickerstreak@1
|
649 return false, nil
|
flickerstreak@1
|
650 end
|
flickerstreak@1
|
651
|
flickerstreak@1
|
652 local bucketfunc
|
flickerstreak@1
|
653 function AceEvent:RegisterBucketEvent(event, delay, method)
|
flickerstreak@1
|
654 AceEvent:argCheck(event, 2, "string", "table")
|
flickerstreak@1
|
655 if type(event) == "table" then
|
flickerstreak@1
|
656 for k,v in pairs(event) do
|
flickerstreak@1
|
657 if type(k) ~= "number" then
|
flickerstreak@1
|
658 AceEvent:error("All keys to argument #2 to `RegisterBucketEvent' must be numbers.")
|
flickerstreak@1
|
659 elseif type(v) ~= "string" then
|
flickerstreak@1
|
660 AceEvent:error("All values to argument #2 to `RegisterBucketEvent' must be strings.")
|
flickerstreak@1
|
661 end
|
flickerstreak@1
|
662 end
|
flickerstreak@1
|
663 end
|
flickerstreak@1
|
664 AceEvent:argCheck(delay, 3, "number")
|
flickerstreak@1
|
665 if AceEvent == self then
|
flickerstreak@1
|
666 AceEvent:argCheck(method, 4, "function")
|
flickerstreak@1
|
667 self = method
|
flickerstreak@1
|
668 else
|
flickerstreak@1
|
669 if type(event) == "string" then
|
flickerstreak@1
|
670 AceEvent:argCheck(method, 4, "string", "function", "nil")
|
flickerstreak@1
|
671 if not method then
|
flickerstreak@1
|
672 method = event
|
flickerstreak@1
|
673 end
|
flickerstreak@1
|
674 else
|
flickerstreak@1
|
675 AceEvent:argCheck(method, 4, "string", "function")
|
flickerstreak@1
|
676 end
|
flickerstreak@1
|
677
|
flickerstreak@1
|
678 if type(method) == "string" and type(self[method]) ~= "function" then
|
flickerstreak@1
|
679 AceEvent:error("Cannot register event %q to method %q, it does not exist", event, method)
|
flickerstreak@1
|
680 end
|
flickerstreak@1
|
681 end
|
flickerstreak@1
|
682 if not AceEvent.buckets then
|
flickerstreak@1
|
683 AceEvent.buckets = {}
|
flickerstreak@1
|
684 end
|
flickerstreak@1
|
685 if not AceEvent.buckets[event] then
|
flickerstreak@1
|
686 AceEvent.buckets[event] = {}
|
flickerstreak@1
|
687 end
|
flickerstreak@1
|
688 if not AceEvent.buckets[event][self] then
|
flickerstreak@1
|
689 AceEvent.buckets[event][self] = {
|
flickerstreak@1
|
690 current = {},
|
flickerstreak@1
|
691 self = self
|
flickerstreak@1
|
692 }
|
flickerstreak@1
|
693 else
|
flickerstreak@1
|
694 AceEvent.CancelScheduledEvent(self, AceEvent.buckets[event][self].id)
|
flickerstreak@1
|
695 end
|
flickerstreak@1
|
696 local bucket = AceEvent.buckets[event][self]
|
flickerstreak@1
|
697 bucket.method = method
|
flickerstreak@1
|
698
|
flickerstreak@1
|
699 local func = function(arg1)
|
flickerstreak@1
|
700 bucket.run = true
|
flickerstreak@1
|
701 if arg1 then
|
flickerstreak@1
|
702 bucket.current[arg1] = true
|
flickerstreak@1
|
703 end
|
flickerstreak@1
|
704 end
|
flickerstreak@1
|
705 AceEvent.buckets[event][self].func = func
|
flickerstreak@1
|
706 if type(event) == "string" then
|
flickerstreak@1
|
707 AceEvent.RegisterEvent(self, event, func)
|
flickerstreak@1
|
708 else
|
flickerstreak@1
|
709 for _,v in ipairs(event) do
|
flickerstreak@1
|
710 AceEvent.RegisterEvent(self, v, func)
|
flickerstreak@1
|
711 end
|
flickerstreak@1
|
712 end
|
flickerstreak@1
|
713 if not bucketfunc then
|
flickerstreak@1
|
714 bucketfunc = function(bucket)
|
flickerstreak@1
|
715 local current = bucket.current
|
flickerstreak@1
|
716 local method = bucket.method
|
flickerstreak@1
|
717 local self = bucket.self
|
flickerstreak@1
|
718 if bucket.run then
|
flickerstreak@1
|
719 if type(method) == "string" then
|
flickerstreak@1
|
720 self[method](self, current)
|
flickerstreak@1
|
721 elseif method then -- function
|
flickerstreak@1
|
722 method(current)
|
flickerstreak@1
|
723 end
|
flickerstreak@1
|
724 for k in pairs(current) do
|
flickerstreak@1
|
725 current[k] = nil
|
flickerstreak@1
|
726 k = nil
|
flickerstreak@1
|
727 end
|
flickerstreak@1
|
728 bucket.run = false
|
flickerstreak@1
|
729 end
|
flickerstreak@1
|
730 end
|
flickerstreak@1
|
731 end
|
flickerstreak@1
|
732 bucket.id = AceEvent.ScheduleRepeatingEvent(self, bucketfunc, delay, bucket)
|
flickerstreak@1
|
733 end
|
flickerstreak@1
|
734
|
flickerstreak@1
|
735 function AceEvent:IsBucketEventRegistered(event)
|
flickerstreak@1
|
736 AceEvent:argCheck(event, 2, "string", "table")
|
flickerstreak@1
|
737 return AceEvent.buckets and AceEvent.buckets[event] and AceEvent.buckets[event][self]
|
flickerstreak@1
|
738 end
|
flickerstreak@1
|
739
|
flickerstreak@1
|
740 function AceEvent:UnregisterBucketEvent(event)
|
flickerstreak@1
|
741 AceEvent:argCheck(event, 2, "string", "table")
|
flickerstreak@1
|
742 if not AceEvent.buckets or not AceEvent.buckets[event] or not AceEvent.buckets[event][self] then
|
flickerstreak@1
|
743 AceEvent:error("Cannot unregister bucket event %q. %q is not registered with it.", event, self)
|
flickerstreak@1
|
744 end
|
flickerstreak@1
|
745
|
flickerstreak@1
|
746 local bucket = AceEvent.buckets[event][self]
|
flickerstreak@1
|
747
|
flickerstreak@1
|
748 if type(event) == "string" then
|
flickerstreak@1
|
749 AceEvent.UnregisterEvent(self, event)
|
flickerstreak@1
|
750 else
|
flickerstreak@1
|
751 for _,v in ipairs(event) do
|
flickerstreak@1
|
752 AceEvent.UnregisterEvent(self, v)
|
flickerstreak@1
|
753 end
|
flickerstreak@1
|
754 end
|
flickerstreak@1
|
755 AceEvent:CancelScheduledEvent(bucket.id)
|
flickerstreak@1
|
756
|
flickerstreak@1
|
757 AceEvent.buckets[event][self] = nil
|
flickerstreak@1
|
758 if not next(AceEvent.buckets[event]) then
|
flickerstreak@1
|
759 AceEvent.buckets[event] = nil
|
flickerstreak@1
|
760 end
|
flickerstreak@1
|
761 end
|
flickerstreak@1
|
762
|
flickerstreak@1
|
763 function AceEvent:UnregisterAllBucketEvents()
|
flickerstreak@1
|
764 if not AceEvent.buckets or not next(AceEvent.buckets) then
|
flickerstreak@1
|
765 return
|
flickerstreak@1
|
766 end
|
flickerstreak@1
|
767 for k,v in pairs(AceEvent.buckets) do
|
flickerstreak@1
|
768 if v == self then
|
flickerstreak@1
|
769 AceEvent.UnregisterBucketEvent(self, k)
|
flickerstreak@1
|
770 k = nil
|
flickerstreak@1
|
771 end
|
flickerstreak@1
|
772 end
|
flickerstreak@1
|
773 end
|
flickerstreak@1
|
774
|
flickerstreak@1
|
775 function AceEvent:OnEmbedDisable(target)
|
flickerstreak@1
|
776 self.UnregisterAllEvents(target)
|
flickerstreak@1
|
777
|
flickerstreak@1
|
778 self.CancelAllScheduledEvents(target)
|
flickerstreak@1
|
779
|
flickerstreak@1
|
780 self.UnregisterAllBucketEvents(target)
|
flickerstreak@1
|
781 end
|
flickerstreak@1
|
782
|
flickerstreak@1
|
783 function AceEvent:EnableDebugging()
|
flickerstreak@1
|
784 if not self.debugTable then
|
flickerstreak@1
|
785 self.debugTable = {}
|
flickerstreak@1
|
786
|
flickerstreak@1
|
787 if delayRegistry then
|
flickerstreak@1
|
788 for k,v in pairs(self.delayRegistry) do
|
flickerstreak@1
|
789 if not v.mem then
|
flickerstreak@1
|
790 v.mem = 0
|
flickerstreak@1
|
791 v.count = 0
|
flickerstreak@1
|
792 v.timeSpent = 0
|
flickerstreak@1
|
793 end
|
flickerstreak@1
|
794 end
|
flickerstreak@1
|
795 end
|
flickerstreak@1
|
796 end
|
flickerstreak@1
|
797 end
|
flickerstreak@1
|
798
|
flickerstreak@1
|
799 function AceEvent:IsFullyInitialized()
|
flickerstreak@1
|
800 return self.postInit or false
|
flickerstreak@1
|
801 end
|
flickerstreak@1
|
802
|
flickerstreak@1
|
803 function AceEvent:IsPostPlayerLogin()
|
flickerstreak@1
|
804 return self.playerLogin or false
|
flickerstreak@1
|
805 end
|
flickerstreak@1
|
806
|
flickerstreak@1
|
807 local function activate(self, oldLib, oldDeactivate)
|
flickerstreak@1
|
808 AceEvent = self
|
flickerstreak@1
|
809
|
flickerstreak@1
|
810 if oldLib then
|
flickerstreak@1
|
811 self.onceRegistry = oldLib.onceRegistry
|
flickerstreak@1
|
812 self.throttleRegistry = oldLib.throttleRegistry
|
flickerstreak@1
|
813 self.delayRegistry = oldLib.delayRegistry
|
flickerstreak@1
|
814 self.buckets = oldLib.buckets
|
flickerstreak@1
|
815 self.registry = oldLib.registry
|
flickerstreak@1
|
816 self.frame = oldLib.frame
|
flickerstreak@1
|
817 self.debugTable = oldLib.debugTable
|
flickerstreak@1
|
818 self.playerLogin = oldLib.pew or DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.defaultLanguage and true
|
flickerstreak@1
|
819 self.postInit = oldLib.postInit or self.playerLogin and ChatTypeInfo and ChatTypeInfo.WHISPER and ChatTypeInfo.WHISPER.r and true
|
flickerstreak@1
|
820 self.ALL_EVENTS = oldLib.ALL_EVENTS
|
flickerstreak@1
|
821 self.FAKE_NIL = oldLib.FAKE_NIL
|
flickerstreak@1
|
822 self.RATE = oldLib.RATE
|
flickerstreak@1
|
823 end
|
flickerstreak@1
|
824 if not self.registry then
|
flickerstreak@1
|
825 self.registry = {}
|
flickerstreak@1
|
826 end
|
flickerstreak@1
|
827 if not self.frame then
|
flickerstreak@1
|
828 self.frame = CreateFrame("Frame", "AceEvent20Frame")
|
flickerstreak@1
|
829 end
|
flickerstreak@1
|
830 if not self.ALL_EVENTS then
|
flickerstreak@1
|
831 self.ALL_EVENTS = {}
|
flickerstreak@1
|
832 end
|
flickerstreak@1
|
833 if not self.FAKE_NIL then
|
flickerstreak@1
|
834 self.FAKE_NIL = {}
|
flickerstreak@1
|
835 end
|
flickerstreak@1
|
836 if not self.RATE then
|
flickerstreak@1
|
837 self.RATE = {}
|
flickerstreak@1
|
838 end
|
flickerstreak@1
|
839 ALL_EVENTS = self.ALL_EVENTS
|
flickerstreak@1
|
840 FAKE_NIL = self.FAKE_NIL
|
flickerstreak@1
|
841 RATE = self.RATE
|
flickerstreak@1
|
842 local inPlw = false
|
flickerstreak@1
|
843 local blacklist = {
|
flickerstreak@1
|
844 UNIT_INVENTORY_CHANGED = true,
|
flickerstreak@1
|
845 BAG_UPDATE = true,
|
flickerstreak@1
|
846 ITEM_LOCK_CHANGED = true,
|
flickerstreak@1
|
847 ACTIONBAR_SLOT_CHANGED = true,
|
flickerstreak@1
|
848 }
|
flickerstreak@1
|
849 self.frame:SetScript("OnEvent", function(_, event, ...)
|
flickerstreak@1
|
850 if event == "PLAYER_ENTERING_WORLD" then
|
flickerstreak@1
|
851 inPlw = false
|
flickerstreak@1
|
852 elseif event == "PLAYER_LEAVING_WORLD" then
|
flickerstreak@1
|
853 inPlw = true
|
flickerstreak@1
|
854 end
|
flickerstreak@1
|
855 if event and (not inPlw or not blacklist[event]) then
|
flickerstreak@1
|
856 self:TriggerEvent(event, ...)
|
flickerstreak@1
|
857 end
|
flickerstreak@1
|
858 end)
|
flickerstreak@1
|
859 if self.delayRegistry then
|
flickerstreak@1
|
860 delayRegistry = self.delayRegistry
|
flickerstreak@1
|
861 self.frame:SetScript("OnUpdate", OnUpdate)
|
flickerstreak@1
|
862 end
|
flickerstreak@1
|
863
|
flickerstreak@1
|
864 self:UnregisterAllEvents()
|
flickerstreak@1
|
865 self:CancelAllScheduledEvents()
|
flickerstreak@1
|
866
|
flickerstreak@1
|
867 registeringFromAceEvent = true
|
flickerstreak@1
|
868 self:RegisterEvent("LOOT_OPENED", function()
|
flickerstreak@1
|
869 SendAddonMessage("LOOT_OPENED", "", "RAID")
|
flickerstreak@1
|
870 end)
|
flickerstreak@1
|
871 registeringFromAceEvent = nil
|
flickerstreak@1
|
872
|
flickerstreak@1
|
873 if not self.playerLogin then
|
flickerstreak@1
|
874 registeringFromAceEvent = true
|
flickerstreak@1
|
875 self:RegisterEvent("PLAYER_LOGIN", function()
|
flickerstreak@1
|
876 self.playerLogin = true
|
flickerstreak@1
|
877 end, true)
|
flickerstreak@1
|
878 registeringFromAceEvent = nil
|
flickerstreak@1
|
879 end
|
flickerstreak@1
|
880
|
flickerstreak@1
|
881 if not self.postInit then
|
flickerstreak@1
|
882 local isReload = true
|
flickerstreak@1
|
883 local function func()
|
flickerstreak@1
|
884 self.postInit = true
|
flickerstreak@1
|
885 self:TriggerEvent("AceEvent_FullyInitialized")
|
flickerstreak@1
|
886 if self.registry["CHAT_MSG_CHANNEL_NOTICE"] and self.registry["CHAT_MSG_CHANNEL_NOTICE"][self] then
|
flickerstreak@1
|
887 self:UnregisterEvent("CHAT_MSG_CHANNEL_NOTICE")
|
flickerstreak@1
|
888 end
|
flickerstreak@1
|
889 if self.registry["MEETINGSTONE_CHANGED"] and self.registry["MEETINGSTONE_CHANGED"][self] then
|
flickerstreak@1
|
890 self:UnregisterEvent("MEETINGSTONE_CHANGED")
|
flickerstreak@1
|
891 end
|
flickerstreak@1
|
892 if self.registry["MINIMAP_ZONE_CHANGED"] and self.registry["MINIMAP_ZONE_CHANGED"][self] then
|
flickerstreak@1
|
893 self:UnregisterEvent("MINIMAP_ZONE_CHANGED")
|
flickerstreak@1
|
894 end
|
flickerstreak@1
|
895 if self.registry["LANGUAGE_LIST_CHANGED"] and self.registry["LANGUAGE_LIST_CHANGED"][self] then
|
flickerstreak@1
|
896 self:UnregisterEvent("LANGUAGE_LIST_CHANGED")
|
flickerstreak@1
|
897 end
|
flickerstreak@1
|
898 end
|
flickerstreak@1
|
899 registeringFromAceEvent = true
|
flickerstreak@1
|
900 local f = function()
|
flickerstreak@1
|
901 self.playerLogin = true
|
flickerstreak@1
|
902 self:ScheduleEvent("AceEvent_FullyInitialized", func, 1)
|
flickerstreak@1
|
903 end
|
flickerstreak@1
|
904 self:RegisterEvent("MEETINGSTONE_CHANGED", f, true)
|
flickerstreak@1
|
905 self:RegisterEvent("CHAT_MSG_CHANNEL_NOTICE", function()
|
flickerstreak@1
|
906 self:ScheduleEvent("AceEvent_FullyInitialized", func, 0.05)
|
flickerstreak@1
|
907 end)
|
flickerstreak@1
|
908 self:RegisterEvent("LANGUAGE_LIST_CHANGED", function()
|
flickerstreak@1
|
909 if self.registry["MEETINGSTONE_CHANGED"] and self.registry["MEETINGSTONE_CHANGED"][self] then
|
flickerstreak@1
|
910 registeringFromAceEvent = true
|
flickerstreak@1
|
911 self:UnregisterEvent("MEETINGSTONE_CHANGED")
|
flickerstreak@1
|
912 self:RegisterEvent("MINIMAP_ZONE_CHANGED", f, true)
|
flickerstreak@1
|
913 registeringFromAceEvent = nil
|
flickerstreak@1
|
914 end
|
flickerstreak@1
|
915 end)
|
flickerstreak@1
|
916 self:ScheduleEvent("AceEvent_FullyInitialized", func, 10)
|
flickerstreak@1
|
917 registeringFromAceEvent = nil
|
flickerstreak@1
|
918 end
|
flickerstreak@1
|
919
|
flickerstreak@1
|
920 self:activate(oldLib, oldDeactivate)
|
flickerstreak@1
|
921 if oldLib then
|
flickerstreak@1
|
922 oldDeactivate(oldLib)
|
flickerstreak@1
|
923 end
|
flickerstreak@1
|
924 end
|
flickerstreak@1
|
925
|
flickerstreak@1
|
926 AceLibrary:Register(AceEvent, MAJOR_VERSION, MINOR_VERSION, activate)
|