Instrument performance update - Scans for hearers every 4 ticks instead of per note. (#2108)

This commit is contained in:
CitadelStationBot
2017-07-24 06:06:52 -05:00
committed by kevinz000
parent 79b5b7409e
commit 2c567685fb
+17 -4
View File
@@ -1,4 +1,5 @@
#define MUSICIAN_HEARCHECK_MINDELAY 4
#define MUSIC_MAXLINES 300
#define MUSIC_MAXLINECHARS 50
@@ -16,6 +17,8 @@
var/instrumentDir = "piano" // the folder with the sounds
var/instrumentExt = "ogg" // the file extension
var/obj/instrumentObj = null // the associated obj playing the sound
var/last_hearcheck = 0
var/list/hearers
/datum/song/New(dir, obj, ext = "ogg")
tempo = sanitize_tempo(tempo)
@@ -61,10 +64,17 @@
return
// and play
var/turf/source = get_turf(instrumentObj)
for(var/mob/M in get_hearers_in_view(15, source))
if(!M.client || !(M.client.prefs.toggles & SOUND_INSTRUMENTS))
continue
M.playsound_local(source, soundfile, 100, falloff = 5)
if((world.time - MUSICIAN_HEARCHECK_MINDELAY) > last_hearcheck)
hearers = list()
for(var/mob/M in get_hearers_in_view(15, source))
if(!M.client || !(M.client.prefs.toggles & SOUND_INSTRUMENTS))
continue
LAZYSET(hearers, M, TRUE)
last_hearcheck = world.time
if(LAZYLEN(hearers))
for(var/i in hearers)
var/mob/M = hearers[i]
M.playsound_local(source, soundfile, 100, falloff = 5)
/datum/song/proc/updateDialog(mob/user)
instrumentObj.updateDialog() // assumes it's an object in world, override if otherwise
@@ -94,6 +104,7 @@
//to_chat(world, "note: [note]")
if(!playing || shouldStopPlaying(user))//If the instrument is playing, or special case
playing = FALSE
hearers = null
return
if(!lentext(note))
continue
@@ -125,6 +136,7 @@
else
sleep(tempo)
repeat--
hearers = null
playing = FALSE
repeat = 0
updateDialog(user)
@@ -286,6 +298,7 @@
else if(href_list["stop"])
playing = FALSE
hearers = null
updateDialog(usr)
return