Skip to content

Commit 1daa1a8

Browse files
committed
Fix timer issues and upgrade tstl
1 parent a531e72 commit 1daa1a8

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

package-lock.json

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@moddota/panorama-types": "^1.20.0",
1818
"fs-extra": "^9.0.0",
1919
"npm-run-all": "^4.1.5",
20-
"typescript": "^4.2.3",
21-
"typescript-to-lua": "^1.4.4"
20+
"typescript": "^4.7.4",
21+
"typescript-to-lua": "^1.7.1"
2222
}
2323
}

src/vscripts/lib/timers.lua

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
TIMERS_VERSION = "1.06"
1+
TIMERS_VERSION = "1.07"
22

33
--[[
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)
55
1.06 modified by Celireor (now uses binary heap priority queue instead of iteration to determine timer of shortest duration)
66
77
DO NOT MODIFY A REALTIME TIMER TO USE GAMETIME OR VICE VERSA MIDWAY WITHOUT FIRST REMOVING AND RE-ADDING THE TIMER
@@ -132,7 +132,7 @@ end
132132
TIMERS_THINK = 0.01
133133

134134
if Timers == nil then
135-
print ( '[Timers] creating Timers' )
135+
print ( '[Timers] creating Timers ['..TIMERS_VERSION..']' )
136136
Timers = {}
137137
setmetatable(Timers, {
138138
__call = function(t, ...)
@@ -176,15 +176,11 @@ function Timers:Think()
176176
end
177177

178178
function Timers:ExecuteTimers(timerList, now)
179-
--Empty timer, ignore
180-
if not timerList[1] then return end
181-
182179
--Timers are alr. sorted by end time upon insertion
183180
local currentTimer = timerList[1]
184181

185-
currentTimer.endTime = currentTimer.endTime or now
186182
--Check if timer has finished
187-
if now >= currentTimer.endTime then
183+
while currentTimer and (now >= currentTimer.endTime) do
188184
-- Remove from timers list
189185
timerList:Remove(currentTimer)
190186
Timers.runningTimer = k
@@ -217,17 +213,16 @@ function Timers:ExecuteTimers(timerList, now)
217213
-- Nope, handle the error
218214
Timers:HandleEventError(timerResult)
219215
end
220-
--run again!
221-
self:ExecuteTimers(timerList, now)
216+
--Check next timer in heap
217+
currentTimer = timerList[1]
222218
end
223219
end
224220

225221
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
231226
end
232227

233228
function Timers:CreateTimer(arg1, arg2, context)

0 commit comments

Comments
 (0)