[READY]Makes addtimer use callbacks (#22660)

* Makes addtimer use callbacks

* I broke the comment

* I fucked up the regex

* this was a silly idea.
This commit is contained in:
Kyle Spier-Swenson
2017-01-04 16:02:56 +13:00
committed by oranges
parent fd337f0741
commit bee4b132a3
183 changed files with 358 additions and 376 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ var/list/obj/item/device/paicard/pai_card_list = list()
continue
//G << 'sound/misc/server-ready.ogg' //Alerting them to their consideration
G << "<span class='ghostalert'>Someone is requesting a pAI personality! Use the pAI button to submit yourself as one.</span>"
addtimer(src, "spam_again", spam_delay)
addtimer(CALLBACK(src, .proc/spam_again), spam_delay)
var/list/available = list()
for(var/datum/paiCandidate/c in SSpai.candidates)
if(c.ready)
+12 -30
View File
@@ -26,30 +26,19 @@ var/datum/subsystem/timer/SStimer
can_fire = 0 //nothing to do, lets stop firing.
return
for(var/datum/timedevent/event in processing)
if(!event.thingToCall || qdeleted(event.thingToCall))
qdel(event)
if(event.timeToRun <= world.time)
runevent(event)
event.callback.InvokeAsync()
qdel(event)
if (MC_TICK_CHECK)
return
/datum/subsystem/timer/proc/runevent(datum/timedevent/event)
set waitfor = 0
if(event.thingToCall == GLOBAL_PROC && istext(event.procToCall))
call("/proc/[event.procToCall]")(arglist(event.argList))
else
call(event.thingToCall, event.procToCall)(arglist(event.argList))
/datum/subsystem/timer/Recover()
processing |= SStimer.processing
hashes |= SStimer.hashes
/datum/timedevent
var/thingToCall
var/procToCall
var/datum/callback/callback
var/timeToRun
var/argList
var/id
var/hash
var/static/nextid = 1
@@ -62,39 +51,32 @@ var/datum/subsystem/timer/SStimer
SStimer.hashes -= hash
return QDEL_HINT_IWILLGC
/proc/addtimer(thingToCall, procToCall, wait, unique = TIMER_NORMAL, ...)
if (!thingToCall || !procToCall)
/proc/addtimer(datum/callback/callback, wait, unique = TIMER_NORMAL)
if (!callback)
return
if (!SStimer.can_fire)
SStimer.can_fire = 1
var/datum/timedevent/event = new()
event.thingToCall = thingToCall
event.procToCall = procToCall
event.callback = callback
event.timeToRun = world.time + wait
var/hashlist = args.Copy()
var/list/hashlist = args.Copy()
hashlist[1] = "[thingToCall](\ref[thingToCall])"
hashlist[1] = "[callback.object](\ref[callback.object])"
hashlist.Insert(2, callback.delegate, callback.arguments)
event.hash = jointext(hashlist, null)
var/bad_args = unique != TIMER_NORMAL && unique != TIMER_UNIQUE
if(args.len > 4 || bad_args)
if(bad_args)
stack_trace("Invalid arguments in call to addtimer! Attempt to call [thingToCall] proc [procToCall]")
event.argList = args.Copy(4)
else
event.argList = args.Copy(5)
// Check for dupes if unique = 1.
if(!bad_args && unique != TIMER_NORMAL) //faster than checking if(unique == TIMER_UNIQUE)
if(unique == TIMER_UNIQUE)
var/datum/timedevent/hash_event = SStimer.hashes[event.hash]
if(hash_event)
return hash_event.id
SStimer.hashes[event.hash] = event
if (wait <= 0)
SStimer.runevent(event)
callback.InvokeAsync()
SStimer.hashes -= event.hash
return
// If we are unique (or we're not checking that), add the timer and return the id.
SStimer.processing += event
+1 -1
View File
@@ -29,7 +29,7 @@ var/datum/subsystem/weather/SSweather
var/datum/weather/W = pickweight(possible_weather_for_this_z)
run_weather(W.name, Z)
eligible_zlevels -= Z
addtimer(src, "make_z_eligible", rand(3000, 6000) + W.weather_duration_upper, TIMER_UNIQUE, Z) //Around 5-10 minutes between weathers
addtimer(CALLBACK(src, .proc/make_z_eligible, Z), rand(3000, 6000) + W.weather_duration_upper, TIMER_UNIQUE) //Around 5-10 minutes between weathers
/datum/subsystem/weather/Initialize(start_timeofday)
..()