mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-24 12:37:50 +01:00
Merge pull request #16511 from VOREStation/verb-subsystem
Verb manager subsystem & Speech controller
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
Stack End Detector.
|
||||
Can detect if a given code stack has exited, used by the mc for stack overflow detection.
|
||||
|
||||
**/
|
||||
/datum/stack_end_detector
|
||||
var/datum/weakref/_WF
|
||||
var/datum/stack_canary/_canary
|
||||
|
||||
/datum/stack_end_detector/New()
|
||||
_canary = new()
|
||||
_WF = WEAKREF(_canary)
|
||||
|
||||
/** Prime the stack overflow detector.
|
||||
Store the return value of this proc call in a proc level var.
|
||||
Can only be called once.
|
||||
**/
|
||||
/datum/stack_end_detector/proc/prime_canary()
|
||||
if (!_canary)
|
||||
CRASH("Prime_canary called twice")
|
||||
. = _canary
|
||||
_canary = null
|
||||
|
||||
/// Returns true if the stack is still going. Calling before the canary has been primed also returns true
|
||||
/datum/stack_end_detector/proc/check()
|
||||
return !!_WF.resolve()
|
||||
|
||||
/// Stack canary. Will go away if the stack it was primed by is ended by byond for return or stack overflow reasons.
|
||||
/datum/stack_canary
|
||||
|
||||
/// empty proc to avoid warnings about unused variables. Call this proc on your canary in the stack it's watching.
|
||||
/datum/stack_canary/proc/use_variable()
|
||||
@@ -0,0 +1,27 @@
|
||||
///like normal callbacks but they also record their creation time for measurement purposes
|
||||
///they also require the same usr/user that made the callback to both still exist and to still have a client in order to execute
|
||||
/datum/callback/verb_callback
|
||||
///the tick this callback datum was created in. used for testing latency
|
||||
var/creation_time = 0
|
||||
|
||||
/datum/callback/verb_callback/New(thingtocall, proctocall, ...)
|
||||
creation_time = DS2TICKS(world.time)
|
||||
. = ..()
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
/datum/callback/verb_callback/Invoke(...)
|
||||
var/mob/our_user = user?.resolve()
|
||||
if(QDELETED(our_user) || isnull(our_user.client))
|
||||
return
|
||||
var/mob/temp = usr
|
||||
. = ..()
|
||||
usr = temp
|
||||
|
||||
/datum/callback/verb_callback/InvokeAsync(...)
|
||||
var/mob/our_user = user?.resolve()
|
||||
if(QDELETED(our_user) || isnull(our_user.client))
|
||||
return
|
||||
var/mob/temp = usr
|
||||
. = ..()
|
||||
usr = temp
|
||||
#endif
|
||||
Reference in New Issue
Block a user