From 651d7f074a6a1bc176174e7c0a49c2425db4ab32 Mon Sep 17 00:00:00 2001 From: Lucy Date: Sun, 1 Mar 2026 17:31:35 -0500 Subject: [PATCH] minor optimizations for APC `late_process` (#95274) ## About The Pull Request just some micro-opts for `/obj/machinery/power/apc/proc/late_process`, ported from https://github.com/Monkestation/Monkestation2.0/pull/10529 firstly, i converted `if(!area || !area.requires_power)` to `if(!area?.requires_power)` secondly, when checking cell percentages, it called `cell.percent()` repeatedly... instead of, y'know, just calling it once and setting it as a var. i fixed that. ## Why It's Good For The Game less proc overhead and less duplicate calls should be better ## Changelog :cl: code: Minor code optimizations for APC processing. /:cl: --- code/modules/power/apc/apc_main.dm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/code/modules/power/apc/apc_main.dm b/code/modules/power/apc/apc_main.dm index 8cf44a970ee..2f53861f406 100644 --- a/code/modules/power/apc/apc_main.dm +++ b/code/modules/power/apc/apc_main.dm @@ -586,7 +586,7 @@ update_appearance() if(machine_stat & (BROKEN|MAINT)) return - if(!area || !area.requires_power) + if(!area?.requires_power) return if(failure_timer) failure_timer-- @@ -631,6 +631,7 @@ if(cell && !shorted) //need to check to make sure the cell is still there since rigged/corrupted cells can randomly explode after give(). // set channels depending on how much charge we have left + var/cell_percent = cell.percent() if(cell.charge <= 0) // zero charge, turn all off equipment = autoset(equipment, AUTOSET_FORCE_OFF) lighting = autoset(lighting, AUTOSET_FORCE_OFF) @@ -639,7 +640,7 @@ if(!nightshift_lights || (nightshift_lights && !low_power_nightshift_lights)) low_power_nightshift_lights = TRUE INVOKE_ASYNC(src, PROC_REF(set_nightshift), TRUE) - else if(cell.percent() < APC_CHANNEL_LIGHT_TRESHOLD) // turn off lighting & equipment + else if(cell_percent < APC_CHANNEL_LIGHT_TRESHOLD) // turn off lighting & equipment equipment = autoset(equipment, AUTOSET_OFF) lighting = autoset(lighting, AUTOSET_OFF) environ = autoset(environ, AUTOSET_ON) @@ -647,7 +648,7 @@ if(!nightshift_lights || (nightshift_lights && !low_power_nightshift_lights)) low_power_nightshift_lights = TRUE INVOKE_ASYNC(src, PROC_REF(set_nightshift), TRUE) - else if(cell.percent() < APC_CHANNEL_EQUIP_TRESHOLD) // turn off equipment + else if(cell_percent < APC_CHANNEL_EQUIP_TRESHOLD) // turn off equipment equipment = autoset(equipment, AUTOSET_OFF) lighting = autoset(lighting, AUTOSET_ON) environ = autoset(environ, AUTOSET_ON) @@ -663,7 +664,7 @@ low_power_nightshift_lights = FALSE if(!SSnightshift.nightshift_active) INVOKE_ASYNC(src, PROC_REF(set_nightshift), FALSE) - if(cell.percent() > APC_CHANNEL_ALARM_TRESHOLD) + if(cell_percent > APC_CHANNEL_ALARM_TRESHOLD) alarm_manager.clear_alarm(ALARM_POWER) else // no cell, switch everything off