vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Guild Event Manager by Kiki of European Cho'gall (Alliance) |
||
3 | Chronos module |
||
4 | ]] |
||
5 | |||
6 | --[[ |
||
7 | Schedule code - Taken from Chronos By Alexander Brazie |
||
8 | ]] |
||
9 | |||
10 | -- GEMSystem Data |
||
11 | GEMSystem_Data = { |
||
12 | -- Initialize the startup time |
||
13 | elaspedTime = 0; |
||
14 | |||
15 | -- Last ID |
||
16 | lastID = nil; |
||
17 | |||
18 | -- Initialize the Timers |
||
19 | timers = {}; |
||
20 | |||
21 | -- Intialize the anonymous todo list |
||
22 | anonTodo = {}; |
||
23 | }; |
||
24 | |||
25 | function GEMSystem_OnLoad() |
||
26 | GEMSystem_Data.elapsedTime = 0; |
||
27 | end |
||
28 | |||
29 | function GEMSystem_startTimer(id) |
||
30 | if ( not id ) then |
||
31 | id = this:GetName(); |
||
32 | end |
||
33 | |||
34 | -- Create a table for this id's timers |
||
35 | if ( not GEMSystem_Data.timers[id] ) then |
||
36 | GEMSystem_Data.timers[id] = {}; |
||
37 | end |
||
38 | |||
39 | -- Clear out an entry if the table is too big. |
||
40 | if ( table.getn(GEMSystem_Data.timers[id]) >= 100) then |
||
41 | table.remove(GEMSystem_Data.timers[id], 1 ); |
||
42 | end |
||
43 | |||
44 | -- Add a new timer entry |
||
45 | table.insert(GEMSystem_Data.timers[id], GetTime() ); |
||
46 | end |
||
47 | |||
48 | function GEMSystem_endTimer(id) |
||
49 | if ( not id ) then |
||
50 | id = this:GetName(); |
||
51 | end |
||
52 | |||
53 | -- Create a table for this id's timers |
||
54 | if ( not GEMSystem_Data.timers[id] ) then |
||
55 | GEMSystem_Data.timers[id] = {}; |
||
56 | end |
||
57 | |||
58 | -- Check to see if there is any timers started |
||
59 | if ( table.getn(GEMSystem_Data.timers[id]) == 0 ) then |
||
60 | return 0, GetTime(), GetTime(); |
||
61 | end |
||
62 | |||
63 | -- Grab the last timer called |
||
64 | local startTime = table.remove ( GEMSystem_Data.timers[id] ); |
||
65 | local now = GetTime(); |
||
66 | |||
67 | return (now - startTime), startTime, now; |
||
68 | end |
||
69 | |||
70 | |||
71 | function GEMSystem_OnUpdate(dt) |
||
72 | if ( GEMSystem_Data.elapsedTime ) then |
||
73 | GEMSystem_Data.elapsedTime = GEMSystem_Data.elapsedTime + dt; |
||
74 | else |
||
75 | GEMSystem_Data.elapsedTime = dt; |
||
76 | end |
||
77 | |||
78 | local timeThisUpdate = 0; |
||
79 | local largest = 0; |
||
80 | local largestName = nil; |
||
81 | |||
82 | if ( not GEMSystem_Data.anonTodo ) then |
||
83 | GEMSystem_Data.anonTodo = {}; |
||
84 | end |
||
85 | |||
86 | -- Handle Anonymous Scheduled Tasks |
||
87 | for k,v in GEMSystem_Data.anonTodo do |
||
88 | GEMSystem_Data.lastID = k; |
||
89 | -- Call all handlers whose time has been exceeded |
||
90 | while(v[1] and v[1].time <= GetTime()) do |
||
91 | -- Lets start the timer |
||
92 | GEMSystem_startTimer(); |
||
93 | |||
94 | local todo = table.remove(v,1); |
||
95 | if(todo.args) then |
||
96 | if ( todo.handler ) then |
||
97 | todo.handler(unpack(todo.args)); |
||
98 | end |
||
99 | else |
||
100 | if ( todo.handler ) then |
||
101 | todo.handler(); |
||
102 | end |
||
103 | end |
||
104 | -- End the timer |
||
105 | local runTime = GEMSystem_endTimer(); |
||
106 | |||
107 | -- Update the elapsed time |
||
108 | timeThisUpdate = timeThisUpdate + runTime; |
||
109 | |||
110 | -- Check if this was the biggest hog yet |
||
111 | if ( runTime > largest ) then |
||
112 | largest = runTime; |
||
113 | largestName = k; |
||
114 | end |
||
115 | |||
116 | -- Check if we've overrun our limit |
||
117 | if ( timeThisUpdate > .3 ) then |
||
118 | break; |
||
119 | end |
||
120 | end |
||
121 | |||
122 | -- Clean out the table |
||
123 | if ( table.getn(v) == 0 ) then |
||
124 | GEMSystem_Data.anonTodo[k] = nil; |
||
125 | end |
||
126 | end |
||
127 | end |
||
128 | |||
129 | function GEMSystem_Schedule(when,handler,...) |
||
130 | -- Assign an id |
||
131 | local id = ""; |
||
132 | if ( not this ) then |
||
133 | id = "Keybinding"; |
||
134 | else |
||
135 | id = this:GetName(); |
||
136 | end |
||
137 | if ( not id ) then |
||
138 | id = "_DEFAULT"; |
||
139 | end |
||
140 | if ( not when ) then |
||
141 | return; |
||
142 | end |
||
143 | |||
144 | -- Ensure we're not looping GEMSystemFrame |
||
145 | if ( id == "GEMSystemFrame" and GEMSystem_Data.lastID ) then |
||
146 | id = GEMSystem_Data.lastID; |
||
147 | end |
||
148 | |||
149 | -- Create the new task |
||
150 | local todo = {}; |
||
151 | todo.time = when + GetTime(); |
||
152 | todo.handler = handler; |
||
153 | todo.args = arg; |
||
154 | |||
155 | -- Create a new table if one does not exist |
||
156 | if ( not GEMSystem_Data.anonTodo[id] ) then |
||
157 | GEMSystem_Data.anonTodo[id] = {}; |
||
158 | end |
||
159 | |||
160 | -- Find the correct index within the frame's table |
||
161 | local i = 1; |
||
162 | while(GEMSystem_Data.anonTodo[id][i] and |
||
163 | GEMSystem_Data.anonTodo[id][i].time < todo.time) do |
||
164 | i = i + 1; |
||
165 | end |
||
166 | |||
167 | -- Add the new task for the current frame |
||
168 | table.insert(GEMSystem_Data.anonTodo[id],i,todo); |
||
169 | |||
170 | -- |
||
171 | -- Ensure we don't have too many events |
||
172 | -- (For now, we just ignore it and pop a message) |
||
173 | -- |
||
174 | if ( table.getn(GEMSystem_Data.anonTodo[id] ) > 100 and not GEMSystem_Data.anonTodo[id].errorSent ) then |
||
175 | GEMSystem_Data.anonTodo[id].errorSent = true; |
||
176 | end |
||
177 | end |
||
178 |