Files
Bubberstation/code/datums/components/sound_player.dm
Mothblocks fa7688d043 Save 0.6-0.7s of init time by splitting registering lists of signals into its own proc, and optimizing QDELETED (#71056)
- Makes QDELETED use isnull(x) instead of !x, giving about 0.2 to 0.25s
of speed.
- Make disposal constructs only update icon state rather than go through
expensive overlay code. Unfortunately did not have much effect, but is
something they should've been doing nonetheless.
- Makes RegisterSignal only take signals directly as opposed to
allocating a fresh list of signals. Very few consumers actually used
this and it costs about 0.4s. Also I think this is just a bad API anyway
and that separate procs are important

`\bRegisterSignal\((.*)list\(` replaced with `RegisterSignals($1list(`
2022-11-22 07:40:05 +00:00

40 lines
902 B
Plaintext

/**
* Sound Player component
*
* Component that will play a sound upon recieving some signal
*/
/datum/component/sound_player
///Volume of the sound when played
var/volume
///The list of sounds played, picked randomly.
var/list/sounds
///Uses left before the sound player deletes itself. If set to a negative number that will mean infinite uses.
var/uses
/datum/component/sound_player/Initialize(
volume = 30,
sounds = list('sound/items/bikehorn.ogg'),
uses = -1,
signal_list = list(COMSIG_ATOM_ATTACK_HAND),
)
src.volume = volume
src.sounds = sounds
src.uses = uses
RegisterSignals(parent, signal_list, PROC_REF(play_sound))
/**
* Attempt to play the sound on parent
*
* If out of uses, will qdel itself.
*/
/datum/component/sound_player/proc/play_sound()
SIGNAL_HANDLER
playsound(parent, pick(sounds), volume, TRUE)
if(uses <= -1)
return
uses--
if(!uses)
qdel(src)