From 6074568bbcb389a2f24536044a8efc6de658ecd2 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Wed, 7 Dec 2022 04:05:41 +0100 Subject: [PATCH] [MIRROR] Don't update radio icon unless necessary, don't create radios in vending machines until needed -- Saves 0.091s of init time [MDB IGNORE] (#17943) * Don't update radio icon unless necessary, don't create radios in vending machines until needed -- Saves 0.091s of init time * Update code/modules/vending/_vending.dm Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Co-authored-by: Tom <8881105+tf-4@users.noreply.github.com> --- .../game/objects/items/devices/radio/radio.dm | 24 +++++++++++++++++-- code/modules/vending/_vending.dm | 13 +++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/code/game/objects/items/devices/radio/radio.dm b/code/game/objects/items/devices/radio/radio.dm index 277f55d3ab2..7a79b5bacae 100644 --- a/code/game/objects/items/devices/radio/radio.dm +++ b/code/game/objects/items/devices/radio/radio.dm @@ -84,6 +84,13 @@ /// overlay when speaking a message (is displayed simultaniously with speaker_active) var/overlay_mic_active = "m_active" + /// When set to FALSE, will avoid calling update_icon() in set_broadcasting and co. + /// Used to save time on updating icon several times over initialization. + VAR_PRIVATE/perform_update_icon = TRUE + + /// If TRUE, will set the icon in initializations. + VAR_PRIVATE/should_update_icon = FALSE + /obj/item/radio/Initialize(mapload) wires = new /datum/wires/radio(src) secure_radio_connections = list() @@ -94,10 +101,15 @@ for(var/ch_name in channels) secure_radio_connections[ch_name] = add_radio(src, GLOB.radiochannels[ch_name]) + perform_update_icon = FALSE set_listening(listening) set_broadcasting(broadcasting) set_frequency(sanitize_frequency(frequency, freerange, syndie)) set_on(on) + perform_update_icon = TRUE + + if (should_update_icon) + update_appearance(UPDATE_ICON) AddElement(/datum/element/empprotection, EMP_PROTECT_WIRES) @@ -200,7 +212,11 @@ readd_listening_radio_channels() else if(!listening) remove_radio_all(src) - update_icon() + + if (perform_update_icon && !isnull(overlay_speaker_idle)) + update_icon() + else if (!perform_update_icon) + should_update_icon = TRUE /** * setter for broadcasting that makes us not hearing sensitive if not broadcasting and hearing sensitive if broadcasting @@ -219,7 +235,11 @@ become_hearing_sensitive(INNATE_TRAIT) else if(!broadcasting) lose_hearing_sensitivity(INNATE_TRAIT) - update_icon() + + if (perform_update_icon && !isnull(overlay_mic_idle)) + update_icon() + else if (!perform_update_icon) + should_update_icon = TRUE ///setter for the on var that sets both broadcasting and listening to off or whatever they were supposed to be /obj/item/radio/proc/set_on(new_on) diff --git a/code/modules/vending/_vending.dm b/code/modules/vending/_vending.dm index e3f8df210be..1db21509119 100644 --- a/code/modules/vending/_vending.dm +++ b/code/modules/vending/_vending.dm @@ -186,7 +186,7 @@ var/light_mask /// used for narcing on underages - var/obj/item/radio/Radio + var/obj/item/radio/sec_radio /** @@ -226,14 +226,12 @@ circuit.onstation = onstation //sync up the circuit so the pricing schema is carried over if it's reconstructed. else if(circuit && (circuit.onstation != onstation)) //check if they're not the same to minimize the amount of edited values. onstation = circuit.onstation //if it was constructed outside mapload, sync the vendor up with the circuit's var so you can't bypass price requirements by moving / reconstructing it off station. - Radio = new /obj/item/radio(src) - Radio.set_listening(FALSE) /obj/machinery/vending/Destroy() QDEL_NULL(wires) QDEL_NULL(coin) QDEL_NULL(bill) - QDEL_NULL(Radio) + QDEL_NULL(sec_radio) return ..() /obj/machinery/vending/can_speak() @@ -1068,8 +1066,11 @@ GLOBAL_LIST_EMPTY(vending_products) else if(age_restrictions && R.age_restricted && (!C.registered_age || C.registered_age < AGE_MINOR)) say("You are not of legal age to purchase [R.name].") if(!(usr in GLOB.narcd_underages)) - Radio.set_frequency(FREQ_SECURITY) - Radio.talk_into(src, "SECURITY ALERT: [usr] recorded attempting to purchase [R.name] in [get_area(src)]. Please watch for substance abuse.", FREQ_SECURITY) //SKYRAT EDIT CHANGE + if (isnull(sec_radio)) + sec_radio = new + sec_radio.set_listening(FALSE) + sec_radio.set_frequency(FREQ_SECURITY) + sec_radio.talk_into(src, "SECURITY ALERT: [usr] recorded attempting to purchase [R.name] in [get_area(src)]. Please watch for substance abuse.", FREQ_SECURITY) // SKYRAT EDIT CHANGE GLOB.narcd_underages += usr flick(icon_deny,src) vend_ready = TRUE