well it appears to function
[QuestHelper.git] / manager_event.lua
blob008e88e5560e75ccd5bd76c0d90173c906bcfaf2
1 QuestHelper_File["manager_event.lua"] = "Development Version"
2 QuestHelper_Loadtime["manager_event.lua"] = GetTime()
4 -- zorba why does this file exist, are you a terrible person? you are a terrible person aren't you
5 -- yep, I'm a terrible person
7 -- File exists to centralize all the event hooks in one place. QH should never (rarely) eat CPU without going through this file. As a nice side effect, I can use this to measure when QH is using CPU. yaaaaay
10 local EventRegistrar = {}
12 local qh_event_frame = CreateFrame("Frame")
14 local function OnEvent(_, event, ...)
15 local tstart = GetTime()
16 for _, v in pairs(EventRegistrar[event]) do
17 v.func(...)
18 end
19 QH_Timeslice_Increment(GetTime() - tstart, "collect_event")
20 end
22 qh_event_frame:UnregisterAllEvents()
23 qh_event_frame:SetScript("OnEvent", OnEvent)
25 function QH_Event(event, func, identifier)
26 QuestHelper: Assert(func)
27 if type(event) == "table" then
28 for _, v in ipairs(event) do
29 QH_Event(v, func, identifier)
30 end
31 else
32 if not identifier then identifier = "(unknown event " .. event .. ")" end
33 if not EventRegistrar[event] then
34 qh_event_frame:RegisterEvent(event)
35 EventRegistrar[event] = {}
36 end
37 table.insert(EventRegistrar[event], {func = func, id = identifier})
38 end
39 end
42 local OnUpdate = {}
43 local OnUpdateHigh = {}
44 local function OnUpdateTrigger()
45 for _, v in pairs(OnUpdateHigh) do
46 v.func()
47 end
49 for _, v in pairs(OnUpdate) do
50 v.func()
51 end
53 QH_Timeslice_Work()
54 end
56 function QH_OnUpdate(func, identifier)
57 if not identifier then identifier = "(unknown onupdate)" end
58 table.insert(OnUpdate, {func = func, id = identifier})
59 end
61 function QH_OnUpdate_High(func, identifier)
62 if not identifier then identifier = "(unknown high-onupdate)" end
63 table.insert(OnUpdateHigh, {func = func, id = identifier})
64 end
66 qh_event_frame:SetScript("OnUpdate", OnUpdateTrigger)
69 function QH_Hook(target, hookname, func, identifier)
70 target:SetScript(hookname, func)
71 end