|
1 | | -TIMERS_VERSION = "1.06" |
| 1 | +TIMERS_VERSION = "1.07" |
2 | 2 |
|
3 | 3 | --[[ |
4 | | -
|
| 4 | + 1.07 modified by Perry (fixed stack overflow if lots of timers finish at the same time and removed HandleErrors throwing error outside tools mode) |
5 | 5 | 1.06 modified by Celireor (now uses binary heap priority queue instead of iteration to determine timer of shortest duration) |
6 | 6 |
|
7 | 7 | DO NOT MODIFY A REALTIME TIMER TO USE GAMETIME OR VICE VERSA MIDWAY WITHOUT FIRST REMOVING AND RE-ADDING THE TIMER |
|
132 | 132 | TIMERS_THINK = 0.01 |
133 | 133 |
|
134 | 134 | if Timers == nil then |
135 | | - print ( '[Timers] creating Timers' ) |
| 135 | + print ( '[Timers] creating Timers ['..TIMERS_VERSION..']' ) |
136 | 136 | Timers = {} |
137 | 137 | setmetatable(Timers, { |
138 | 138 | __call = function(t, ...) |
@@ -176,15 +176,11 @@ function Timers:Think() |
176 | 176 | end |
177 | 177 |
|
178 | 178 | function Timers:ExecuteTimers(timerList, now) |
179 | | - --Empty timer, ignore |
180 | | - if not timerList[1] then return end |
181 | | - |
182 | 179 | --Timers are alr. sorted by end time upon insertion |
183 | 180 | local currentTimer = timerList[1] |
184 | 181 |
|
185 | | - currentTimer.endTime = currentTimer.endTime or now |
186 | 182 | --Check if timer has finished |
187 | | - if now >= currentTimer.endTime then |
| 183 | + while currentTimer and (now >= currentTimer.endTime) do |
188 | 184 | -- Remove from timers list |
189 | 185 | timerList:Remove(currentTimer) |
190 | 186 | Timers.runningTimer = k |
@@ -217,17 +213,16 @@ function Timers:ExecuteTimers(timerList, now) |
217 | 213 | -- Nope, handle the error |
218 | 214 | Timers:HandleEventError(timerResult) |
219 | 215 | end |
220 | | - --run again! |
221 | | - self:ExecuteTimers(timerList, now) |
| 216 | + --Check next timer in heap |
| 217 | + currentTimer = timerList[1] |
222 | 218 | end |
223 | 219 | end |
224 | 220 |
|
225 | 221 | function Timers:HandleEventError(err) |
226 | | - if IsInToolsMode() then |
227 | | - print(err) |
228 | | - else |
229 | | - StatsClient:HandleError(err) |
230 | | - end |
| 222 | + print(err) |
| 223 | + --if not IsInToolsMode() then |
| 224 | + -- If you want to send errors from inside timers on live servers to your own webserver, do it here |
| 225 | + --end |
231 | 226 | end |
232 | 227 |
|
233 | 228 | function Timers:CreateTimer(arg1, arg2, context) |
|
0 commit comments