mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 05:00:55 +01:00
[MIRROR] Optimizes INVOKE_ASYNC by making it a macro and avoiding a proc call [MDB IGNORE] (#19668)
* Optimizes INVOKE_ASYNC by making it a macro and avoiding a proc call (#73264) ## About The Pull Request This is quite literally the same behavior but faster, and also catches improper arguments better than the old macro/proc approach. Credit to Lohikar for writing the macro. Port of https://github.com/DaedalusDock/daedalusdock/pull/196 Also, `world.ImmediateInvokeAsync()` never set a return value, so expecting one was never valid behavior. At MSO's request, the documentation of `spawn(-1)`: As per the reference, calling `spawn()` with a negative value will execute the spawned code until a blocking action (such as `sleep()`) is encountered. Then, it will step outside of the spawned code, and continue the proc. This is the same behavior as calling a `waitfor = FALSE` proc. Specifically, under the hood, `spawn(-1)` creates a copy of the callstack like `sleep()`, incase the spawned code is blocked and needs to be rescheduled. As an added bonus, `spawn(-1)` silences SHOULD_NOT_SLEEP errors, whereas `waitfor = FALSE` does not. ## Why It's Good For The Game ITS FREE FUCKING CPU TIME --------- Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com> Co-authored-by: Kyle Spier-Swenson <kyleshome@ gmail.com> * Optimizes INVOKE_ASYNC by making it a macro and avoiding a proc call --------- Co-authored-by: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Co-authored-by: Mothblocks <35135081+Mothblocks@ users.noreply.github.com> Co-authored-by: Kyle Spier-Swenson <kyleshome@ gmail.com>
This commit is contained in:
co-authored by
Mothblocks
Kyle Spier-Swenson
Kapu1178
parent
f4327644a2
commit
c41ff0aaa6
@@ -33,8 +33,9 @@
|
||||
|
||||
/datum/component/construction/proc/action(datum/source, obj/item/I, mob/living/user)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
return INVOKE_ASYNC(src, PROC_REF(check_step), I, user)
|
||||
ASYNC //This proc will never actually sleep, it calls do_after with a time of 0.
|
||||
. = check_step(I, user)
|
||||
return .
|
||||
|
||||
/datum/component/construction/proc/update_index(diff)
|
||||
index += diff
|
||||
|
||||
@@ -121,7 +121,10 @@
|
||||
holochange.name = "[holochange.credits] credit holochip"
|
||||
if(ishuman(user))
|
||||
var/mob/living/carbon/human/paying_customer = user
|
||||
if(!INVOKE_ASYNC(paying_customer, TYPE_PROC_REF(/mob, put_in_hands), holochange))
|
||||
var/successfully_put_in_hands
|
||||
ASYNC //Put_in_hands can sleep, we don't want that to block this proc.
|
||||
successfully_put_in_hands = paying_customer.put_in_hands(holochange)
|
||||
if(!successfully_put_in_hands)
|
||||
user.pulling = holochange
|
||||
else
|
||||
user.pulling = holochange
|
||||
|
||||
Reference in New Issue
Block a user